Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ADD] module product_harmonized_system_per_country #281

Open
wants to merge 4 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions product_harmonized_system_per_country/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
=============================================
Product Harmonized System Codes per countries
=============================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:afd00899a20aac3c96a9b21fbcfc0c4a66f1617290ff92124a6b6987e5d9c975
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fintrastat--extrastat-lightgray.png?logo=github
:target: https://github.com/OCA/intrastat-extrastat/tree/16.0/product_harmonized_system_per_country
:alt: OCA/intrastat-extrastat
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/intrastat-extrastat-16-0/intrastat-extrastat-16-0-product_harmonized_system_per_country
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/intrastat-extrastat&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module contains the objects for Harmonised System Codes (H.S. codes) with applicable country.


**Table of contents**

.. contents::
:local:

Installation
============

This module is NOT compatible with the *account_intrastat* module from Odoo Enterprise.

Usage
=====

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 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.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/intrastat-extrastat/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/intrastat-extrastat/issues/new?body=module:%20product_harmonized_system_per_country%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* Emilie SOUTIRAS
* Groupe Voltaire

Contributors
~~~~~~~~~~~~

* Emilie SOUTIRAS, Groupe Voltaire <emilie.soutiras@groupevoltaire.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-emiliesoutiras| image:: https://github.com/emiliesoutiras.png?size=40px
:target: https://github.com/emiliesoutiras
:alt: emiliesoutiras

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-emiliesoutiras|

This module is part of the `OCA/intrastat-extrastat <https://github.com/OCA/intrastat-extrastat/tree/16.0/product_harmonized_system_per_country>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions product_harmonized_system_per_country/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions product_harmonized_system_per_country/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": "Product Harmonized System Codes per countries",
"version": "16.0.1.1.0",
"category": "Reporting",
"license": "AGPL-3",
"summary": "Module for to custom H.S. Codes par country",
"author": "Emilie SOUTIRAS, Groupe Voltaire, Odoo Community Association (OCA)",
"maintainers": ["emiliesoutiras"],
"website": "https://github.com/OCA/intrastat-extrastat",
"depends": ["delivery", "intrastat_product"],
"data": [
"views/hs_code.xml",
"report/deliveryslip_report.xml",
],
"installable": True,
}
9 changes: 9 additions & 0 deletions product_harmonized_system_per_country/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_move
from . import hs_code
from . import product_category
from . import product_product
from . import product_template
44 changes: 44 additions & 0 deletions product_harmonized_system_per_country/models/account_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import models


class AccountMove(models.Model):
_inherit = "account.move"

def _get_intrastat_lines_info(self):
destination_country = self.partner_id.country_id or False
self.env.context = dict(self.env.context)
self.env.context.update({"hs_code_for_country": destination_country.id})
res = {}
for line in (
self.invoice_line_ids.filtered(
lambda x: x.product_id.get_hs_code_recursively()
and x.product_id.origin_country_id
)
if not self.intrastat_line_ids
else self.intrastat_line_ids
):
res.setdefault(line.product_id.id, {"weight": 0})
vals = self._prepare_intrastat_line_info(line)
if vals.get("hs_code_id"):
weight = vals.pop("weight")
res[line.product_id.id].update(vals)
res[line.product_id.id]["weight"] += weight
else:
res.pop(line.product_id.id)

Check warning on line 31 in product_harmonized_system_per_country/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

product_harmonized_system_per_country/models/account_move.py#L31

Added line #L31 was not covered by tests
if res:
res = dict(
sorted(
res.items(), key=lambda val: val[1]["product_id"].display_name or ""
)
)
return res.values()

def _prepare_intrastat_line_info(self, line):
res = super()._prepare_intrastat_line_info(line)
if "hs_code_id" in res:
res.update({"hs_code_id": line.product_id.get_hs_code_recursively()})
return res
60 changes: 60 additions & 0 deletions product_harmonized_system_per_country/models/hs_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class HSCode(models.Model):
_inherit = "hs.code"

country_id = fields.Many2one(
comodel_name="res.country", string="Applicable country"
)
parent_id = fields.Many2one(
comodel_name="hs.code",
string="Parent H.S. Code",
ondelete="set null",
)
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",
)

def _compute_related_hs_code(self):
for code in self:
res = code | code.parent_id | code.child_ids
if code.parent_id:
res |= code.parent_id.child_ids

Check warning on line 34 in product_harmonized_system_per_country/models/hs_code.py

View check run for this annotation

Codecov / codecov/patch

product_harmonized_system_per_country/models/hs_code.py#L34

Added line #L34 was not covered by tests
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:
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)
)
res = (
res.sorted()
.sorted(key="company_id", reverse=True)
.sorted(key="country_id", reverse=True)
)
else:
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]
return res
20 changes: 20 additions & 0 deletions product_harmonized_system_per_country/models/product_category.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
import logging

from odoo import models

_logger = logging.getLogger(__name__)


class ProductCategory(models.Model):
_inherit = "product.category"

def get_hs_code_recursively(self):
self.ensure_one()
if self.hs_code_id:
res = self.hs_code_id.filter_per_country()
else:
res = super().get_hs_code_recursively()

Check warning on line 19 in product_harmonized_system_per_country/models/product_category.py

View check run for this annotation

Codecov / codecov/patch

product_harmonized_system_per_country/models/product_category.py#L19

Added line #L19 was not covered by tests
return res
19 changes: 19 additions & 0 deletions product_harmonized_system_per_country/models/product_product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://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.filter_per_country()
else:
res = super().get_hs_code_recursively()
return res
emiliesoutiras marked this conversation as resolved.
Show resolved Hide resolved
25 changes: 25 additions & 0 deletions product_harmonized_system_per_country/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2024 Groupe Voltaire
# @author Emilie SOUTIRAS <emilie.soutiras@groupevoltaire.com>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductTemplate(models.Model):
_inherit = "product.template"

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 = (

Check warning on line 19 in product_harmonized_system_per_country/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_harmonized_system_per_country/models/product_template.py#L19

Added line #L19 was not covered by tests
pdt_tmpl.hs_code_id.filter_per_country().hs_code or ""
)
else:
pdt_tmpl.hs_code = (

Check warning on line 23 in product_harmonized_system_per_country/models/product_template.py

View check run for this annotation

Codecov / codecov/patch

product_harmonized_system_per_country/models/product_template.py#L23

Added line #L23 was not covered by tests
pdt_tmpl.categ_id.get_hs_code_recursively().hs_code or ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Emilie SOUTIRAS, Groupe Voltaire <emilie.soutiras@groupevoltaire.com>
2 changes: 2 additions & 0 deletions product_harmonized_system_per_country/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module contains the objects for Harmonised System Codes (H.S. codes) with applicable country.

1 change: 1 addition & 0 deletions product_harmonized_system_per_country/readme/INSTALL.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module is NOT compatible with the *account_intrastat* module from Odoo Enterprise.
3 changes: 3 additions & 0 deletions product_harmonized_system_per_country/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
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 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.
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>-->
emiliesoutiras marked this conversation as resolved.
Show resolved Hide resolved
</field>
</record>
</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading