Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0] pos_receipt_replace_user_by_trigram: Drop compute function #1274

Open
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pos_receipt_replace_user_by_trigram/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"version": "16.0.1.0.0",
"depends": [
"point_of_sale",
"partner_firstname",
],
"assets": {
"point_of_sale.assets": [
Expand All @@ -22,6 +21,7 @@
],
},
"data": [
"data/ir_cron.xml",
"views/res_config_settings.xml",
"views/res_users.xml",
],
Expand Down
30 changes: 30 additions & 0 deletions pos_receipt_replace_user_by_trigram/data/ir_cron.xml
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) &gt; 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>
11 changes: 2 additions & 9 deletions pos_receipt_replace_user_by_trigram/models/res_partner.py
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(tracking=True)
2 changes: 2 additions & 0 deletions pos_receipt_replace_user_by_trigram/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ By default, username on receipts is replaced by his Trigram.

In "Point of Sale" configuration "Bills & Receipts" section, you can deactivate "Replace User by trigram in POS receipt" feature:
.. image:: ../static/img/pos_config.png

Generation of trigram is done through scheduled action 'POS: generate user trigram' that can be customized and executed manually.
1 change: 0 additions & 1 deletion pos_receipt_replace_user_by_trigram/tests/__init__.py

This file was deleted.

27 changes: 0 additions & 27 deletions pos_receipt_replace_user_by_trigram/tests/test_get_trigram.py

This file was deleted.

11 changes: 0 additions & 11 deletions pos_receipt_replace_user_by_trigram/utils.py

This file was deleted.

Loading