-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] restructuring to link hs codes together instead of listing hs c…
…odes on products
- Loading branch information
1 parent
667c8fb
commit 7ff590f
Showing
10 changed files
with
95 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
# Copyright (c) 2024 Groupe Voltaire | ||
# @author Emilie SOUTIRAS <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
from odoo import fields, models | ||
|
||
|
||
class HSCode(models.Model): | ||
|
@@ -11,44 +10,38 @@ class HSCode(models.Model): | |
country_id = fields.Many2one( | ||
comodel_name="res.country", string="Applicable country" | ||
) | ||
pdt_categ_ids = fields.Many2many( | ||
comodel_name="product.category", | ||
relation="hs_code_pdt_category_rel", | ||
column1="pdt_categ_id", | ||
column2="hs_code_id", | ||
string="Product Categories on H.S. Codes list", | ||
readonly=True, | ||
parent_id = fields.Many2one( | ||
comodel_name="hs.code", | ||
string="Parent H.S. Code", | ||
ondelete="set null", | ||
) | ||
pdt_tmpl_ids = fields.Many2many( | ||
comodel_name="product.template", | ||
relation="hs_code_pdt_tmpl_rel", | ||
column1="pdt_tmpl_id", | ||
column2="hs_code_id", | ||
string="Products on H.S. Codes list", | ||
readonly=True, | ||
child_ids = fields.One2many( | ||
comodel_name="hs.code", | ||
inverse_name="parent_id", | ||
string="Child H.S. Codes related for other countries", | ||
copy=False, | ||
) | ||
related_hs_code_ids = fields.Many2many( | ||
comodel_name="hs.code", | ||
compute="_compute_related_hs_code", | ||
string="All related H.S. Codes", | ||
) | ||
|
||
@api.depends("product_categ_ids", "pdt_categ_ids") | ||
def _compute_product_categ_count(self): | ||
for code in self: | ||
code.product_categ_count = len( | ||
set(code.product_categ_ids.ids).union(set(code.pdt_categ_ids.ids)) | ||
) | ||
|
||
@api.depends("product_tmpl_ids", "pdt_tmpl_ids") | ||
def _compute_product_tmpl_count(self): | ||
def _compute_related_hs_code(self): | ||
for code in self: | ||
code.product_tmpl_count = len( | ||
set(code.product_tmpl_ids.ids).union(set(code.pdt_tmpl_ids.ids)) | ||
) | ||
res = code | code.parent_id | code.child_ids | ||
if code.parent_id: | ||
res |= code.parent_id.child_ids | ||
code.related_hs_code_ids = res | ||
|
||
def filter_per_country(self): | ||
country_id = self.env.context.get("hs_code_for_country", False) | ||
active_companies = self.env.context.get("allowed_company_ids") | ||
company_ids = [active_companies[0]] if active_companies else [] | ||
company_ids += [False] | ||
if country_id: | ||
res = self.filtered( | ||
self._compute_related_hs_code() | ||
res = self.related_hs_code_ids.filtered( | ||
lambda hs: (not hs.country_id or hs.country_id.id == country_id) | ||
and (hs.company_id.id in company_ids) | ||
) | ||
|
@@ -58,7 +51,9 @@ def filter_per_country(self): | |
.sorted(key="country_id", reverse=True) | ||
) | ||
else: | ||
res = self.filtered(lambda hs: (hs.company_id.id in company_ids)) | ||
res = self.related_hs_code_ids.filtered( | ||
lambda hs: (hs.company_id.id in company_ids) | ||
) | ||
res = res.sorted(key="company_id", reverse=True) | ||
if res: | ||
res = res[0] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,22 +2,27 @@ | |
# @author Emilie SOUTIRAS <[email protected]> | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import fields, models | ||
from odoo import api, fields, models | ||
|
||
|
||
class ProductTemplate(models.Model): | ||
_inherit = "product.template" | ||
|
||
hs_code_ids = fields.Many2many( | ||
comodel_name="hs.code", | ||
relation="hs_code_pdt_tmpl_rel", | ||
column1="hs_code_id", | ||
column2="pdt_tmpl_id", | ||
string="H.S. Codes", | ||
help="Harmonised System Codes. This list is used to filter by " | ||
"destination country. If no code is set, the simple H.S. Code " | ||
"is used, otherwise those of the related product category.", | ||
hs_code = fields.Char(compute="_compute_hs_code", store=False) | ||
|
||
@api.depends( | ||
"hs_code_id", "hs_code_id.parent_id", "hs_code_id.child_ids", "categ_id" | ||
) | ||
def _compute_hs_code(self): | ||
for pdt_tmpl in self: | ||
if pdt_tmpl.hs_code_id: | ||
pdt_tmpl.hs_code = ( | ||
pdt_tmpl.hs_code_id.filter_per_country().hs_code or "" | ||
) | ||
else: | ||
pdt_tmpl.hs_code = ( | ||
pdt_tmpl.categ_id.get_hs_code_recursively().hs_code or "" | ||
) | ||
|
||
|
||
class ProductProduct(models.Model): | ||
|
@@ -27,8 +32,8 @@ def get_hs_code_recursively(self): | |
res = self.env["hs.code"] | ||
if self: | ||
self.ensure_one() | ||
if self.hs_code_ids: | ||
res = self.hs_code_ids.filter_per_country() | ||
if self.hs_code_id: | ||
res = self.hs_code_id.filter_per_country() | ||
else: | ||
res = super().get_hs_code_recursively() | ||
return res |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
This module only depends on the *intrastat_product* module, whiwh depends on *product_harmonized_systems* module. | ||
This module depends on the *delivery* module and the *intrastat_product* module, which depends on the *product_harmonized_systems* module. | ||
|
||
This module adds the applicable country field to HS Codes, and provides a list of HS Codes by product and/or category, in order to dynamically find the code corresponding to the destination country. | ||
This module adds the 'applicable country' field to the HS Code model, and enables HS Codes to be linked together as parent/child, so that the code corresponding to the destination country can be dynamically found from a single HS Code. |
26 changes: 26 additions & 0 deletions
26
product_harmonized_system_per_country/report/deliveryslip_report.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<!-- Delivery slip --> | ||
<template id="report_deliveryslip" inherit_id="stock.report_deliveryslip"> | ||
<xpath expr="//t[@t-call]" position="before"> | ||
<t | ||
t-set="o" | ||
t-value="o.with_context(hs_code_for_country=o.sudo().sale_id.partner_id.country_id.id or False)" | ||
/> | ||
</xpath> | ||
</template> | ||
<record id="report_delivery_document2" model="ir.ui.view"> | ||
<field name="name">stock.picking.report.delivery.inherit</field> | ||
<field name="inherit_id" ref="delivery.report_delivery_document2" /> | ||
<field name="priority" eval="1000" /> | ||
<field name="arch" type="xml"> | ||
<xpath expr="//t[@t-set='has_hs_code']" position="attributes"> | ||
<attribute name="t-value"> | ||
o.move_ids.filtered(lambda l: l.product_id.hs_code) | ||
</attribute> | ||
</xpath> | ||
<!-- <xpath expr="//span[@t-field='']" position="replace">--> | ||
<!-- </xpath>--> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters