Skip to content

Commit cb280e1

Browse files
committed
[IMP] account_product_fiscal_classification: track all important fields, on account.product.fiscal.classification model
1 parent cd2a0ad commit cb280e1

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

account_product_fiscal_classification/models/account_product_fiscal_classification.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,31 @@
22
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
44

5-
from odoo import _, api, fields, models
5+
from odoo import Command, _, api, fields, models
66
from odoo.exceptions import ValidationError
77

88

99
class AccountProductFiscalClassification(models.Model):
1010
_name = "account.product.fiscal.classification"
1111
_description = "Fiscal Classification"
1212
_order = "name"
13+
_inherit = ["mail.activity.mixin", "mail.thread"]
1314

14-
name = fields.Char(required=True)
15+
name = fields.Char(required=True, tracking=True)
1516

1617
description = fields.Text()
1718

1819
active = fields.Boolean(
1920
default=True,
21+
tracking=True,
2022
help="If unchecked, it will allow you to hide the Fiscal"
2123
" Classification without removing it.",
2224
)
2325

2426
company_id = fields.Many2one(
2527
comodel_name="res.company",
2628
string="Company",
29+
tracking=True,
2730
help="Specify a company"
2831
" if you want to define this Fiscal Classification only for specific"
2932
" company. Otherwise, this Fiscal Classification will be available"
@@ -46,6 +49,7 @@ class AccountProductFiscalClassification(models.Model):
4649
column1="fiscal_classification_id",
4750
column2="tax_id",
4851
string="Purchase Taxes",
52+
tracking=True,
4953
domain="""[
5054
('type_tax_use', 'in', ['purchase', 'all'])]""",
5155
)
@@ -56,6 +60,7 @@ class AccountProductFiscalClassification(models.Model):
5660
column1="fiscal_classification_id",
5761
column2="tax_id",
5862
string="Sale Taxes",
63+
tracking=True,
5964
domain="""[
6065
('type_tax_use', 'in', ['sale', 'all'])]""",
6166
)
@@ -107,6 +112,28 @@ def unlink(self):
107112
)
108113
return super().unlink()
109114

115+
def _mail_track(self, tracked_fields, initial_values):
116+
changes, tracking_value_ids = super()._mail_track(
117+
tracked_fields, initial_values
118+
)
119+
# Many2many tracking
120+
if len(changes) > len(tracking_value_ids):
121+
for changed_field in changes:
122+
if tracked_fields[changed_field]["type"] in ["one2many", "many2many"]:
123+
field = self.env["ir.model.fields"]._get(self._name, changed_field)
124+
vals = {
125+
"field": field.id,
126+
"field_desc": field.field_description,
127+
"field_type": field.ttype,
128+
"tracking_sequence": field.tracking,
129+
"old_value_char": ", ".join(
130+
initial_values[changed_field].mapped("name")
131+
),
132+
"new_value_char": ", ".join(self[changed_field].mapped("name")),
133+
}
134+
tracking_value_ids.append(Command.create(vals))
135+
return changes, tracking_value_ids
136+
110137
# Custom Sections
111138
@api.model
112139
def _prepare_vals_from_taxes(self, purchase_taxes, sale_taxes):

account_product_fiscal_classification/views/view_account_product_fiscal_classification.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@
100100
</page>
101101
</notebook>
102102
</sheet>
103+
<div class="oe_chatter">
104+
<field name="message_follower_ids" />
105+
<field name="activity_ids" />
106+
<field name="message_ids" />
107+
</div>
103108
</form>
104109
</field>
105110
</record>

0 commit comments

Comments
 (0)