From aa5f07977b4a8d40c199c422ce70ca743fdd4528 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 27 Dec 2022 01:02:00 +0100 Subject: [PATCH] [MIG] product_harmonized_system to v16 --- product_harmonized_system/__manifest__.py | 10 +++--- .../demo/product_demo.xml | 2 +- product_harmonized_system/models/__init__.py | 1 + product_harmonized_system/models/hs_code.py | 34 +++++++++++-------- .../models/product_category.py | 4 +-- .../models/product_product.py | 21 ++++++++++++ .../models/product_template.py | 28 ++------------- product_harmonized_system/views/hs_code.xml | 8 +++-- .../views/product_category.xml | 12 ++++--- .../views/product_template.xml | 11 +++--- 10 files changed, 69 insertions(+), 62 deletions(-) create mode 100644 product_harmonized_system/models/product_product.py diff --git a/product_harmonized_system/__manifest__.py b/product_harmonized_system/__manifest__.py index d33ac4d..9e368a9 100644 --- a/product_harmonized_system/__manifest__.py +++ b/product_harmonized_system/__manifest__.py @@ -1,6 +1,6 @@ -# Copyright 2018-2020 brain-tec AG (http://www.braintec-group.com) -# Copyright 2011-2020 Akretion (http://www.akretion.com) -# Copyright 2009-2020 Noviat (http://www.noviat.com) +# Copyright 2018-2022 brain-tec AG (http://www.braintec-group.com) +# Copyright 2011-2022 Akretion (http://www.akretion.com) +# Copyright 2009-2022 Noviat (http://www.noviat.com) # Copyright 2022 Tecnativa - Víctor Martínez # @author Benjamin Henquet # @author Kumar Aberer @@ -10,11 +10,11 @@ { "name": "Product Harmonized System Codes", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Reporting", "license": "AGPL-3", "summary": "Base module for Product Import/Export reports", - "author": "brain-tec AG, Akretion, Noviat, " "Odoo Community Association (OCA)", + "author": "brain-tec AG, Akretion, Noviat, Odoo Community Association (OCA)", "maintainers": ["alexis-via", "luc-demeyer"], "website": "https://github.com/OCA/intrastat-extrastat", "depends": ["product"], diff --git a/product_harmonized_system/demo/product_demo.xml b/product_harmonized_system/demo/product_demo.xml index 902f4a8..9aa8b55 100644 --- a/product_harmonized_system/demo/product_demo.xml +++ b/product_harmonized_system/demo/product_demo.xml @@ -1,6 +1,6 @@ diff --git a/product_harmonized_system/models/__init__.py b/product_harmonized_system/models/__init__.py index cd4fd51..fe12a6d 100644 --- a/product_harmonized_system/models/__init__.py +++ b/product_harmonized_system/models/__init__.py @@ -1,3 +1,4 @@ from . import hs_code from . import product_category from . import product_template +from . import product_product diff --git a/product_harmonized_system/models/hs_code.py b/product_harmonized_system/models/hs_code.py index 89c1000..2bb3de4 100644 --- a/product_harmonized_system/models/hs_code.py +++ b/product_harmonized_system/models/hs_code.py @@ -1,5 +1,5 @@ -# Copyright 2011-2020 Akretion France (http://www.akretion.com) -# Copyright 2009-2020 Noviat (http://www.noviat.com) +# Copyright 2011-2022 Akretion France (http://www.akretion.com) +# Copyright 2009-2022 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -18,7 +18,8 @@ class HSCode(models.Model): hs_code = fields.Char( string="H.S. Code", compute="_compute_hs_code", - readonly=True, + store=True, + precompute=True, help="Harmonized System code (6 digits). Full list is " "available from the World Customs Organisation, see " "http://www.wcoomd.org", @@ -64,17 +65,21 @@ class HSCode(models.Model): @api.depends("product_categ_ids") def _compute_product_categ_count(self): - # hs_code_id on product.category is company_dependent=True - # so we can't use a read_group() + rg_res = self.env["product.category"].read_group( + [("hs_code_id", "in", self.ids)], ["hs_code_id"], ["hs_code_id"] + ) + mapped_data = {x["hs_code_id"][0]: x["hs_code_id_count"] for x in rg_res} for code in self: - code.product_categ_count = len(code.product_categ_ids) + code.product_categ_count = mapped_data.get(code.id, 0) @api.depends("product_tmpl_ids") def _compute_product_tmpl_count(self): - # hs_code_id on product.template is company_dependent=True - # so we can't use a read_group() + rg_res = self.env["product.template"].read_group( + [("hs_code_id", "in", self.ids)], ["hs_code_id"], ["hs_code_id"] + ) + mapped_data = {x["hs_code_id"][0]: x["hs_code_id_count"] for x in rg_res} for code in self: - code.product_tmpl_count = len(code.product_tmpl_ids) + code.product_tmpl_count = mapped_data.get(code.id, 0) @api.depends("local_code", "description") def name_get(self): @@ -95,11 +100,12 @@ class HSCode(models.Model): ) ] - @api.model - def create(self, vals): - if vals.get("local_code"): - vals["local_code"] = vals["local_code"].replace(" ", "") - return super().create(vals) + @api.model_create_multi + def create(self, vals_list): + for vals in vals_list: + if vals.get("local_code"): + vals["local_code"] = vals["local_code"].replace(" ", "") + return super().create(vals_list) def write(self, vals): if vals.get("local_code"): diff --git a/product_harmonized_system/models/product_category.py b/product_harmonized_system/models/product_category.py index e9d9750..47cbab8 100644 --- a/product_harmonized_system/models/product_category.py +++ b/product_harmonized_system/models/product_category.py @@ -1,5 +1,5 @@ -# Copyright 2011-2020 Akretion France (http://www.akretion.com) -# Copyright 2009-2020 Noviat (http://www.noviat.com) +# Copyright 2011-2022 Akretion France (http://www.akretion.com) +# Copyright 2009-2022 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). diff --git a/product_harmonized_system/models/product_product.py b/product_harmonized_system/models/product_product.py new file mode 100644 index 0000000..688cdfd --- /dev/null +++ b/product_harmonized_system/models/product_product.py @@ -0,0 +1,21 @@ +# Copyright 2011-2022 Akretion (http://www.akretion.com) +# Copyright 2009-2022 Noviat (http://www.noviat.com) +# @author Alexis de Lattre +# @author Luc de Meyer +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + def get_hs_code_recursively(self): + res = self.env["hs.code"] + if self: + self.ensure_one() + if self.hs_code_id: + res = self.hs_code_id + elif self.categ_id: + res = self.categ_id.get_hs_code_recursively() + return res diff --git a/product_harmonized_system/models/product_template.py b/product_harmonized_system/models/product_template.py index 7aa950d..acb6b6f 100644 --- a/product_harmonized_system/models/product_template.py +++ b/product_harmonized_system/models/product_template.py @@ -1,5 +1,5 @@ -# Copyright 2011-2020 Akretion (http://www.akretion.com) -# Copyright 2009-2020 Noviat (http://www.noviat.com) +# Copyright 2011-2022 Akretion (http://www.akretion.com) +# Copyright 2009-2022 Noviat (http://www.noviat.com) # @author Alexis de Lattre # @author Luc de Meyer # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -24,27 +24,3 @@ class ProductTemplate(models.Model): string="Country of Origin", help="Country of origin of the product i.e. product " "'made in ____'.", ) - origin_state_id = fields.Many2one( - comodel_name="res.country.state", - string="Country State of Origin", - domain="[('country_id', '=?', origin_country_id)]", - help="Country State of origin of the product.\n" - "This field is used for the Intrastat declaration, " - "selecting one of the Northern Ireland counties will set the code 'XI' " - "for products from the United Kingdom whereas code 'XU' " - "will be used for the other UK counties.", - ) - - -class ProductProduct(models.Model): - _inherit = "product.product" - - def get_hs_code_recursively(self): - res = self.env["hs.code"] - if self: - self.ensure_one() - if self.hs_code_id: - res = self.hs_code_id - elif self.categ_id: - res = self.categ_id.get_hs_code_recursively() - return res diff --git a/product_harmonized_system/views/hs_code.xml b/product_harmonized_system/views/hs_code.xml index 9b93a30..0217c2c 100644 --- a/product_harmonized_system/views/hs_code.xml +++ b/product_harmonized_system/views/hs_code.xml @@ -31,8 +31,12 @@ - - + + diff --git a/product_harmonized_system/views/product_category.xml b/product_harmonized_system/views/product_category.xml index 0017f94..2aac2a6 100644 --- a/product_harmonized_system/views/product_category.xml +++ b/product_harmonized_system/views/product_category.xml @@ -1,6 +1,6 @@ @@ -11,11 +11,13 @@ product.category - - - + + + + + - + diff --git a/product_harmonized_system/views/product_template.xml b/product_harmonized_system/views/product_template.xml index 79d2b27..ad29c10 100644 --- a/product_harmonized_system/views/product_template.xml +++ b/product_harmonized_system/views/product_template.xml @@ -1,6 +1,6 @@ @@ -11,7 +11,7 @@ product.template - + - - +