-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pos_receipt_replace_user_by_trigram: Drop compute function
The compute function does not allow any customization on how the trigram had to be generated, and there a multiple ways to define how trigram must be generated. Moreover, the compute did generate duplicates and there was no way to fix manually since the field was not stored. Also, making it stored but still computed did risk unwanted updates in case name was updated. Having a basic stored field allows each company to customize how trigram can be generated using a server action. The logic previously provided is then moved to a cron that can be customized to suit trigram generation for each company.
- Loading branch information
1 parent
5c70694
commit a1740b2
Showing
5 changed files
with
35 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo noupdate="1"> | ||
<record forcecreate="True" id="ir_cron_generate_pos_trigram" model="ir.cron"> | ||
<field name="name">POS: generate user trigram</field> | ||
<field name="model_id" ref="base.model_res_partner" /> | ||
<field name="state">code</field> | ||
<field eval="False" name="active" /> | ||
<field name="user_id" ref="base.user_root" /> | ||
<field name="interval_number">1</field> | ||
<field name="interval_type">hours</field> | ||
<field name="numbercall">1</field> | ||
<field name="code"> | ||
def get_trigram(*args): | ||
valid = [x.strip() for x in args if x and x.strip()] | ||
if valid: | ||
if len(valid) > 1: | ||
trigram = valid[0][:1] + valid[1][:2] | ||
else: | ||
trigram = valid[0][:3] | ||
else: | ||
trigram = "" | ||
return trigram | ||
|
||
partners = model.search([('pos_trigram', '=', ''), ('user_ids', '=', True)]) | ||
for partner in partners: | ||
firstname, lastname = partner.split(' ', 1) | ||
partner.write({'pos_trigram': get_trigram(firstname, lastname)}) | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,10 @@ | ||
# Copyright 2024 Camptocamp SA | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, fields, models | ||
|
||
from .. import utils | ||
from odoo import fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
_inherit = "res.partner" | ||
|
||
pos_trigram = fields.Char(compute="_compute_pos_trigram") | ||
|
||
@api.depends("firstname", "lastname") | ||
def _compute_pos_trigram(self): | ||
for partner in self: | ||
partner.pos_trigram = utils.get_trigram(partner.firstname, partner.lastname) | ||
pos_trigram = fields.Char() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.