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
66from odoo .exceptions import ValidationError
77
88
99class 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 ):
0 commit comments