Skip to content
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
88 changes: 88 additions & 0 deletions account_edi_ubl_move_line_uom_and_packaging_unece/README.rst
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.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions account_edi_ubl_move_line_uom_and_packaging_unece/__manifest__.py
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": [],
}
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
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(
Comment thread
sbejaoui marked this conversation as resolved.
[
("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
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.",
)
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>
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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading