[MIG] product_harmonized_system to v16

This commit is contained in:
Alexis de Lattre
2022-12-27 01:02:00 +01:00
committed by Andreu Orensanz
parent e7d68bd61d
commit aa5f07977b
10 changed files with 69 additions and 62 deletions

View File

@@ -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 <info@noviat.com>
# @author Kumar Aberer <kumar.aberer@braintec-group.com>
@@ -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"],

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2011-2020 Akretion France (http://www.akretion.com/)
Copyright 2011-2022 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->

View File

@@ -1,3 +1,4 @@
from . import hs_code
from . import product_category
from . import product_template
from . import product_product

View File

@@ -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 <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
# 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"):

View File

@@ -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 <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

View File

@@ -0,0 +1,21 @@
# Copyright 2011-2022 Akretion (http://www.akretion.com)
# Copyright 2009-2022 Noviat (http://www.noviat.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
# 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

View File

@@ -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 <alexis.delattre@akretion.com>
# @author Luc de Meyer <info@noviat.com>
# 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

View File

@@ -31,8 +31,12 @@
<tree>
<field name="hs_code" />
<field name="local_code" />
<field name="description" />
<field name="company_id" groups="base.group_multi_company" />
<field name="description" optional="show" />
<field
name="company_id"
groups="base.group_multi_company"
optional="show"
/>
</tree>
</field>
</record>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2010-2020 Akretion (http://www.akretion.com/)
Copyright 2010-2022 Akretion (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@@ -11,11 +11,13 @@
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view" />
<field name="arch" type="xml">
<xpath expr="//group[@name='first']" position="after">
<group name="hs_code" string="Import/Export Properties">
<field name="hs_code_id" />
<group name="first" position="after">
<group name="hs_code">
<group name="hs_code_l2" string="Import/Export Properties">
<field name="hs_code_id" />
</group>
</group>
</xpath>
</group>
</field>
</record>
</odoo>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright 2010-2020 Akretion France (http://www.akretion.com/)
Copyright 2010-2022 Akretion France (http://www.akretion.com/)
@author Alexis de Lattre <alexis.delattre@akretion.com>
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-->
@@ -11,7 +11,7 @@
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="company_id" position="before">
<group name="group_standard_price" position="inside">
<field
name="hs_code_id"
attrs="{'invisible': [('type', '=', 'service')]}"
@@ -19,12 +19,9 @@
<field
name="origin_country_id"
attrs="{'invisible': [('type', '=', 'service')]}"
options="{'no_create': True}"
/>
<field
name="origin_state_id"
attrs="{'invisible': [('type', '=', 'service')]}"
/>
</field>
</group>
</field>
</record>
<record id="product_template_search_view" model="ir.ui.view">