-
-
Notifications
You must be signed in to change notification settings - Fork 342
[16.0][ADD] account_edi_ubl_move_line_uom_and_packaging_unece #1311
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
Open
sbejaoui
wants to merge
2
commits into
OCA:16.0
Choose a base branch
from
acsone:16.0-account_edi_ubl_move_line_packaging-sbj
base: 16.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
88 changes: 88 additions & 0 deletions
88
account_edi_ubl_move_line_uom_and_packaging_unece/README.rst
This file contains hidden or 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,88 @@ | ||
| .. image:: https://odoo-community.org/readme-banner-image | ||
| :target: https://odoo-community.org/get-involved?utm_source=readme | ||
| :alt: Odoo Community Association | ||
|
|
||
| ==================================================== | ||
| Account EDI UBL move line uom and packaging By UNECE | ||
| ==================================================== | ||
|
|
||
| .. | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! This file is generated by oca-gen-addon-readme !! | ||
| !! changes will be overwritten. !! | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| !! source digest: sha256:ebd29e113a10e013c7bbd975c13d2358bafcf2fa840aea421b284b7640925999 | ||
| !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
|
|
||
| .. |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/license-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%2Fedi-lightgray.png?logo=github | ||
| :target: https://github.com/OCA/edi/tree/16.0/account_edi_ubl_move_line_uom_and_packaging_unece | ||
| :alt: OCA/edi | ||
| .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
| :target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_edi_ubl_move_line_uom_and_packaging_unece | ||
| :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/edi&target_branch=16.0 | ||
| :alt: Try me on Runboat | ||
|
|
||
| |badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
|
||
| Adds support for UNECE unit codes during UBL invoice import to | ||
| automatically detect and assign the appropriate unit of measure or | ||
| product packaging on invoice lines. | ||
|
|
||
| When a UNECE code matches a product packaging, the packaging is set with | ||
| priority. Otherwise, the corresponding unit of measure is applied based | ||
| on the UNECE code. | ||
|
|
||
| **Table of contents** | ||
|
|
||
| .. contents:: | ||
| :local: | ||
|
|
||
| Bug Tracker | ||
| =========== | ||
|
|
||
| Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/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/edi/issues/new?body=module:%20account_edi_ubl_move_line_uom_and_packaging_unece%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 | ||
| ------- | ||
|
|
||
| * ACSONE SA/NV | ||
| * BCIM | ||
|
|
||
| Contributors | ||
| ------------ | ||
|
|
||
| - Souheil Bejaoui - ACSONE SA/NV souheil.bejaoui@acsone.eu | ||
| - Jacques-Etienne Baudoux - BCIM je@bcim.be | ||
|
|
||
| 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. | ||
|
|
||
| This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/account_edi_ubl_move_line_uom_and_packaging_unece>`_ project on GitHub. | ||
|
|
||
| You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains hidden or 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 @@ | ||
| from . import models |
20 changes: 20 additions & 0 deletions
20
account_edi_ubl_move_line_uom_and_packaging_unece/__manifest__.py
This file contains hidden or 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,20 @@ | ||
| # Copyright 2026 ACSONE SA/NV, BCIM | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| { | ||
| "name": "Account EDI UBL move line uom and packaging By UNECE", | ||
| "summary": """Adds UNECE-based detection of UoM and packaging on invoice | ||
| lines during UBL import.""", | ||
| "version": "16.0.1.0.0", | ||
| "license": "AGPL-3", | ||
| "author": "ACSONE SA/NV, BCIM,Odoo Community Association (OCA)", | ||
| "website": "https://github.com/OCA/edi", | ||
| "depends": [ | ||
| "account_move_line_packaging", | ||
| "account_edi_ubl_cii", | ||
| "uom_unece", | ||
| "product_packaging_unece", | ||
| ], | ||
| "data": ["views/account_move.xml"], | ||
| "demo": [], | ||
| } |
2 changes: 2 additions & 0 deletions
2
account_edi_ubl_move_line_uom_and_packaging_unece/models/__init__.py
This file contains hidden or 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,2 @@ | ||
| from . import account_edi_xml_ubl_20 | ||
| from . import account_move_line |
92 changes: 92 additions & 0 deletions
92
account_edi_ubl_move_line_uom_and_packaging_unece/models/account_edi_xml_ubl_20.py
This file contains hidden or 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,92 @@ | ||
| # Copyright 2026 ACSONE SA/NV, BCIM | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import models | ||
|
|
||
|
|
||
| class AccountEdiXmlUbl_20(models.AbstractModel): | ||
|
|
||
| _inherit = "account.edi.xml.ubl_20" | ||
|
|
||
| def _set_invoice_line_ubl_billed_quantity_and_unece_unit_code( | ||
| self, tree, invoice_line | ||
| ): | ||
| billed_quantity_xpath = ( | ||
| "./{*}InvoicedQuantity" | ||
| if invoice_line.move_id.move_type in ("in_invoice", "out_invoice") | ||
| else "./{*}CreditedQuantity" | ||
| ) | ||
| billed_quantity_node = tree.find(billed_quantity_xpath) | ||
| if billed_quantity_node is None: | ||
| return | ||
| invoice_line.ubl_billed_quantity = float(billed_quantity_node.text) | ||
| unit_code = billed_quantity_node.attrib.get("unitCode") | ||
| if unit_code: | ||
| invoice_line.ubl_unece_unit_code = unit_code | ||
|
|
||
| def _set_invoice_ubl_price_unit(self, tree, invoice_line): | ||
| price_unit_node = tree.find("./{*}Price/{*}PriceAmount") | ||
| if price_unit_node is None: | ||
| return | ||
| invoice_line.ubl_price_unit = float(price_unit_node.text) | ||
|
|
||
| def _import_fill_invoice_line_form( | ||
| self, journal, tree, invoice, invoice_line, qty_factor | ||
| ): | ||
| res = super()._import_fill_invoice_line_form( | ||
| journal, tree, invoice, invoice_line, qty_factor | ||
| ) | ||
| self._set_invoice_line_ubl_billed_quantity_and_unece_unit_code( | ||
| tree, invoice_line | ||
| ) | ||
| self._set_invoice_ubl_price_unit(tree, invoice_line) | ||
| if not invoice_line.ubl_unece_unit_code: | ||
| return res | ||
| if not self._import_fill_invoice_line_packaging(invoice_line): | ||
| self._import_fill_invoice_line_uom(invoice_line) | ||
| return res | ||
|
|
||
| def _import_fill_invoice_line_uom(self, invoice_line): | ||
| uom_id = self.env["uom.uom"].get_uom_id_by_unece_code( | ||
| invoice_line.ubl_unece_unit_code | ||
| ) | ||
| if not uom_id: | ||
| return False | ||
| uom = self.env["uom.uom"].browse(uom_id) | ||
| if ( | ||
| invoice_line.product_id | ||
| and uom.category_id | ||
| != invoice_line.product_id.product_tmpl_id.uom_id.category_id | ||
| ): | ||
| return False | ||
| invoice_line.product_uom_id = uom | ||
| invoice_line.price_unit = invoice_line.ubl_price_unit | ||
| return True | ||
|
|
||
| def _import_fill_invoice_line_packaging(self, invoice_line): | ||
| # the unitCode attr is based on UNECE Rec 20 (UoM) | ||
| # when Rec 21 (packaging) codes are used, they may be prefixed with "X" | ||
| # we therefore check both formats (e.g. "8A" and "X8A") | ||
| pl_model = self.env["product.packaging.level"] | ||
| packaging_level_ids = pl_model.get_packaging_level_ids_by_unece_code( | ||
| invoice_line.ubl_unece_unit_code, | ||
| invoice_line.ubl_unece_unit_code.lstrip("X"), | ||
| ) | ||
| if not packaging_level_ids: | ||
| return False | ||
| product_packaging = self.env["product.packaging"].search( | ||
| [ | ||
| ("product_id", "=", invoice_line.product_id.id), | ||
| ("packaging_level_id", "in", packaging_level_ids), | ||
| ], | ||
| limit=1, | ||
| ) | ||
| if product_packaging: | ||
| invoice_line.product_packaging_id = product_packaging | ||
| invoice_line.product_packaging_qty = invoice_line.ubl_billed_quantity | ||
| if product_packaging.qty > 0 and invoice_line.ubl_price_unit: | ||
| invoice_line.price_unit = ( | ||
| invoice_line.ubl_price_unit / product_packaging.qty | ||
| ) | ||
| return True | ||
| return False | ||
30 changes: 30 additions & 0 deletions
30
account_edi_ubl_move_line_uom_and_packaging_unece/models/account_move_line.py
This file contains hidden or 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,30 @@ | ||
| # Copyright 2026 ACSONE SA/NV | ||
| # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
|
|
||
| from odoo import fields, models | ||
|
|
||
|
|
||
| class AccountMoveLine(models.Model): | ||
|
|
||
| _inherit = "account.move.line" | ||
|
|
||
| ubl_unece_unit_code = fields.Char( | ||
| readonly=True, | ||
| string="Unece Unit Code", | ||
| help=( | ||
| "Technical field storing the UNECE unit code from UBL import. " | ||
| "Used during purchase reconciliation to identify the corresponding " | ||
| "packaging when a purchase order line is manually selected." | ||
| ), | ||
| ) | ||
| ubl_billed_quantity = fields.Float( | ||
| readonly=True, | ||
| help="Technical field storing the billed quantity from the UBL import. " | ||
| "During purchase reconciliation, it allows restoring the original supplier quantity " | ||
| "when the quantity has been altered by packaging selection.", | ||
| ) | ||
| ubl_price_unit = fields.Float( | ||
| string="UBL P.U", | ||
| readonly=True, | ||
| help="Technical field storing the unit price from the UBL import.", | ||
| ) |
2 changes: 2 additions & 0 deletions
2
account_edi_ubl_move_line_uom_and_packaging_unece/readme/CONTRIBUTORS.md
This file contains hidden or 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,2 @@ | ||
| - Souheil Bejaoui - ACSONE SA/NV <souheil.bejaoui@acsone.eu> | ||
| - Jacques-Etienne Baudoux - BCIM <je@bcim.be> |
5 changes: 5 additions & 0 deletions
5
account_edi_ubl_move_line_uom_and_packaging_unece/readme/DESCRIPTION.md
This file contains hidden or 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,5 @@ | ||
| Adds support for UNECE unit codes during UBL invoice import to automatically detect and | ||
| assign the appropriate unit of measure or product packaging on invoice lines. | ||
|
|
||
| When a UNECE code matches a product packaging, the packaging is set with priority. | ||
| Otherwise, the corresponding unit of measure is applied based on the UNECE code. |
Binary file added
BIN
+9.23 KB
account_edi_ubl_move_line_uom_and_packaging_unece/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.