diff --git a/README.md b/README.md index 165212d642..76ae6ad87d 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,10 @@ addon | version | maintainers | summary [account_edi_ubl_cii_additional_document](account_edi_ubl_cii_additional_document/) | 16.0.1.0.0 | | Extends account_edi_ubl_cii to import all attachments from UBL invoices (not only PDFs) and link them to the vendor bill. [account_edi_ubl_cii_check_total](account_edi_ubl_cii_check_total/) | 16.0.1.0.0 | sbejaoui | This addon extends the UBL invoice import process to automatically populate the suppliers check total field based on the value found in the XML file. [account_edi_ubl_cii_invoice_line_name_enhance](account_edi_ubl_cii_invoice_line_name_enhance/) | 16.0.1.0.0 | | This module improves invoice line label generation when importing UBL vendor bills by including the product name when it is not already present. +[account_edi_ubl_cii_purchase_match](account_edi_ubl_cii_purchase_match/) | 16.0.1.0.0 | sbejaoui | Extend UBL vendor bill import to automatically match and link bill lines to purchase order lines using the OrderReference and product label. +[account_edi_ubl_cii_retrieve_tax](account_edi_ubl_cii_retrieve_tax/) | 16.0.1.0.0 | sbejaoui jbaudoux | Match taxes on UBL import using UNECE tax codes [account_edi_ubl_cii_supplier_invoice_number](account_edi_ubl_cii_supplier_invoice_number/) | 16.0.1.0.0 | | This addon extends the UBL invoice import process to automatically populate the suppliers invoice number based on the value found in the XML file. +[account_edi_ubl_move_line_uom_and_packaging_unece](account_edi_ubl_move_line_uom_and_packaging_unece/) | 16.0.1.0.0 | | Adds UNECE-based detection of UoM and packaging on invoice lines during UBL import. [account_einvoice_generate](account_einvoice_generate/) | 16.0.1.1.0 | alexis-via | Technical module to generate PDF invoices with embedded XML file [account_invoice_download](account_invoice_download/) | 16.0.1.1.0 | alexis-via | Auto-download supplier invoices and import them [account_invoice_download_ovh](account_invoice_download_ovh/) | 16.0.1.0.0 | alexis-via | Get OVH Invoice via the API diff --git a/account_edi_ubl_cii_purchase_match/README.rst b/account_edi_ubl_cii_purchase_match/README.rst new file mode 100644 index 0000000000..2ebaeb65ba --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/README.rst @@ -0,0 +1,190 @@ +.. 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 Cii Purchase Match +================================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:6638e97230ca6d958934a20e04e9fc3db628053d14a6015261c3d062be6dbed1 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_cii_purchase_match + :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_cii_purchase_match + :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| + +This module extends the UBL vendor bill import process to improve how +vendor bill lines are linked to purchase order lines. + +Instead of replacing the imported UBL lines with the purchase order +lines (standard behavior), this module: + +1. **Reads the OrderReference** in the UBL document. + +2. **Identifies the corresponding Purchase Order** using the vendor + reference (``partner_ref``) or the purchase order ref. + +3. **Matches each UBL line** with a purchase order line based on: + + - product name, + - supplier product name + +4. **Links the vendor bill line** to the matched PO line + +5. When a user manually selects a purchase order line from the bill: + + - the system stores the supplier product name, + - future imports will auto-match using that supplier information. + +This ensures accurate line-level linking while preserving the supplier’s +invoice data. + +**Table of contents** + +.. contents:: + :local: + +Use Cases / Context +=================== + +In the standard behavior, when importing a vendor bill from a UBL +document: + +- If a Purchase Order is found, **all imported UBL lines are replaced** + by the Purchase Order lines. +- This causes a **loss of original UBL data**, such as: + + - line-level descriptions, + - quantities, + - pricing, + - tax information received from the supplier. + +- Additionally, the standard flow performs **no matching based on + product labels**, so incorrect PO lines may be added if PO content + does not reflect what is actually on the invoice. + +Configuration +============= + +No configuration is required to use this module. + +However, for optimal matching: + +- Ensure that *OrderReference* in the vendor UBL document corresponds to + the Purchase Order Ref or the **Vendor Reference** (``partner_ref``). +- Maintain consistent **product names** or **supplier product names** so + that UBL line descriptions can be matched to the correct purchase + order line. + +Optional but recommended: + +- Define supplier product names (``product.supplierinfo``) to improve + matching accuracy. + +Usage +===== + +1. Import a vendor bill in UBL format through: Accounting / Vendors / + Bills / Upload +2. The module will automatically: + + - Extract the OrderReference from the UBL. + - Find the matching purchase order via ``partner_ref`` or purchase + order ref. + - Attempt to match each UBL line with the correct purchase order line + using: + + - product name, + - supplier product name + +3. When a match is found: the vendor bill line is linked to the purchase + order line. +4. If no match is found: + + - Click "Select purchase line" button in invoice line + - Select a purchase order and a purchase order line + +Known issues / Roadmap +====================== + +This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via +UBL. + +Before migrating to future versions, it is recommended to verify +whether: + +- Odoo natively supports precise line-level matching, +- supplier product names and UBL descriptions are matched out of the + box, +- and the original UBL lines are preserved. + +If the standard behavior evolves to fully cover this business +requirement, this module may become unnecessary. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* ACSONE SA/NV + +Contributors +------------ + +- Souheil Bejaoui souheil.bejaoui@acsone.eu + +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-sbejaoui| image:: https://github.com/sbejaoui.png?size=40px + :target: https://github.com/sbejaoui + :alt: sbejaoui + +Current `maintainer `__: + +|maintainer-sbejaoui| + +This module is part of the `OCA/edi `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_edi_ubl_cii_purchase_match/__init__.py b/account_edi_ubl_cii_purchase_match/__init__.py new file mode 100644 index 0000000000..aee8895e7a --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizards diff --git a/account_edi_ubl_cii_purchase_match/__manifest__.py b/account_edi_ubl_cii_purchase_match/__manifest__.py new file mode 100644 index 0000000000..e52db29bb2 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Account Edi Ubl Cii Purchase Match", + "summary": """Extend UBL vendor bill import to automatically match and link bill + lines to purchase order lines using the OrderReference and product label.""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "ACSONE SA/NV,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/edi", + "depends": ["account_edi_ubl_cii", "purchase"], + "data": [ + "security/account_move_line_select_purchase_line_wizard.xml", + "wizards/account_move_line_select_purchase_line_wizard.xml", + "views/account_move.xml", + "views/purchase_order_line.xml", + ], + "demo": [], + "maintainers": ["sbejaoui"], +} diff --git a/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot b/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot new file mode 100644 index 0000000000..e3521e9bf7 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/i18n/account_edi_ubl_cii_purchase_match.pot @@ -0,0 +1,300 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_ubl_cii_purchase_match +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the ordered quantity." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the received quantity." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Unit price differs from the purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_qty_invoiced +msgid "Billed Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Cancel" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "" +"Checked when this invoice has at least one line that does not fully match " +"its related purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "" +"Checked when this invoice line does not fully match its related purchase " +"order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Close" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_uid +msgid "Created by" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_date +msgid "Created on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__currency_id +msgid "Currency" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "" +"Human-readable description of the differences between invoice lines and " +"their related purchase order lines." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "" +"Human-readable description of the differences between this invoice line and " +"the related purchase order line." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__id +msgid "ID" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Invoice" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Invoice line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line +msgid "Journal Item" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__description +msgid "Label" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_line_id +msgid "Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_id +msgid "Move Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_price_subtotal +msgid "Move line Subtotal" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_price_unit +msgid "Move line Unit Price" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "No product" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_product_uom_qty +msgid "Ordered Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_price_subtotal +msgid "PO line Subtotal" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_price_unit +msgid "PO line Unit Price" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__partner_id +msgid "Partner" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_id +msgid "Product" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_domain +msgid "Product Domain" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "Purchase Line Mismatch" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "Purchase Line Mismatch Details" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "Purchase Mismatch" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "Purchase Mismatch Details" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_ids +msgid "Purchase Order" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_quantity +msgid "Quantity" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_qty_received +msgid "Received Qty" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Select Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Select The Purchase Line" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Subtotal" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__supplier_product_code +msgid "Supplier Product Code" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "" +"The following differences were detected between this invoice and its related" +" purchase order lines:\n" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_quantity +msgid "" +"The optional quantity expressed by this line, eg: number of product sold. " +"The quantity is not a legal requirement but is very useful for some reports." +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_edi_xml_ubl_20 +msgid "UBL 2.0" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Unit Price" +msgstr "" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line_select_purchase_line_wizard +msgid "account move line select purchase line wizard" +msgstr "" diff --git a/account_edi_ubl_cii_purchase_match/i18n/fr.po b/account_edi_ubl_cii_purchase_match/i18n/fr.po new file mode 100644 index 0000000000..0c69aadb48 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/i18n/fr.po @@ -0,0 +1,315 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * account_edi_ubl_cii_purchase_match +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-05-27 15:10+0000\n" +"PO-Revision-Date: 2026-05-27 15:10+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the ordered quantity." +msgstr "- La quantité facturée dépasse la quantité commandée." + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Invoiced quantity exceeds the received quantity." +msgstr "- La quantité facturée dépasse la quantité reçue." + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move_line.py:0 +#, python-format +msgid "- Unit price differs from the purchase order line." +msgstr "- Le prix unitaire diffère de celui de la ligne de commande." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_qty_invoiced +msgid "Billed Qty" +msgstr "Qté facturée" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Cancel" +msgstr "Annuler" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "" +"Checked when this invoice has at least one line that does not fully match " +"its related purchase order line." +msgstr "" +"Coché lorsque cette facture comporte au moins une ligne ne correspondant pas " +"entièrement à sa ligne de commande d'achat associée." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "" +"Checked when this invoice line does not fully match its related purchase " +"order line." +msgstr "" +"Coché lorsque cette ligne de facture ne correspond pas entièrement à sa " +"ligne de commande d'achat associée." + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Close" +msgstr "Fermer" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__create_date +msgid "Created on" +msgstr "Créé le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__currency_id +msgid "Currency" +msgstr "Devise" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "" +"Human-readable description of the differences between invoice lines and " +"their related purchase order lines." +msgstr "" +"Description lisible des différences entre les lignes de facture et leurs " +"lignes de commande d'achat associées." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "" +"Human-readable description of the differences between this invoice line and " +"the related purchase order line." +msgstr "" +"Description lisible des différences entre cette ligne de facture et la ligne " +"de commande d'achat associée." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__id +msgid "ID" +msgstr "ID" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.purchase_order_line_form_view +msgid "Invoice" +msgstr "Facture" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Invoice line" +msgstr "Ligne de facture" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move +msgid "Journal Entry" +msgstr "Pièce comptable" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line +msgid "Journal Item" +msgstr "Écriture comptable" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__description +msgid "Label" +msgstr "Libellé" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard____last_update +msgid "Last Modified on" +msgstr "Dernière modification le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_uid +msgid "Last Updated by" +msgstr "Mis à jour par" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__write_date +msgid "Last Updated on" +msgstr "Mis à jour le" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_line_id +msgid "Line" +msgstr "Ligne" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_id +msgid "Move Line" +msgstr "Ligne d'écriture" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_price_subtotal +msgid "Move line Subtotal" +msgstr "Sous-total de la ligne d'écriture" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_price_unit +msgid "Move line Unit Price" +msgstr "Prix unitaire de la ligne d'écriture" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "No product" +msgstr "Aucun produit" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_product_uom_qty +msgid "Ordered Qty" +msgstr "Qté commandée" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_price_subtotal +msgid "PO line Subtotal" +msgstr "Sous-total de la ligne de commande" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_price_unit +msgid "PO line Unit Price" +msgstr "Prix unitaire de la ligne de commande" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__partner_id +msgid "Partner" +msgstr "Partenaire" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_id +msgid "Product" +msgstr "Produit" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__product_domain +msgid "Product Domain" +msgstr "Domaine produit" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Purchase Line" +msgstr "Ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch +msgid "Purchase Line Mismatch" +msgstr "Incohérence ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__purchase_line_mismatch_details +msgid "Purchase Line Mismatch Details" +msgstr "Détails de l'incohérence ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch +msgid "Purchase Mismatch" +msgstr "Incohérence d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_bank_statement_line__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move__purchase_mismatch_details +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_payment__purchase_mismatch_details +msgid "Purchase Mismatch Details" +msgstr "Détails de l'incohérence d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__purchase_order_ids +msgid "Purchase Order" +msgstr "Commande d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_quantity +msgid "Quantity" +msgstr "Quantité" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__po_line_qty_received +msgid "Received Qty" +msgstr "Qté reçue" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_form_view +msgid "Select Purchase Line" +msgstr "Sélectionner une ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Select The Purchase Line" +msgstr "Sélectionner la ligne d'achat" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Subtotal" +msgstr "Sous-total" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,field_description:account_edi_ubl_cii_purchase_match.field_account_move_line__supplier_product_code +msgid "Supplier Product Code" +msgstr "Référence produit fournisseur" + +#. module: account_edi_ubl_cii_purchase_match +#. odoo-python +#: code:addons/account_edi_ubl_cii_purchase_match/models/account_move.py:0 +#, python-format +msgid "" +"The following differences were detected between this invoice and its related" +" purchase order lines:\n" +msgstr "" +"Les différences suivantes ont été détectées entre cette facture et ses " +"lignes de commande d'achat associées :\n" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model.fields,help:account_edi_ubl_cii_purchase_match.field_account_move_line_select_purchase_line_wizard__move_line_quantity +msgid "" +"The optional quantity expressed by this line, eg: number of product sold. " +"The quantity is not a legal requirement but is very useful for some reports." +msgstr "" +"La quantité facultative exprimée par cette ligne, par exemple le nombre de " +"produits vendus. La quantité n'est pas une obligation légale, mais elle est " +"très utile pour certains rapports." + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_edi_xml_ubl_20 +msgid "UBL 2.0" +msgstr "UBL 2.0" + +#. module: account_edi_ubl_cii_purchase_match +#: model_terms:ir.ui.view,arch_db:account_edi_ubl_cii_purchase_match.account_move_line_select_purchase_line_wizard_form_view +msgid "Unit Price" +msgstr "Prix unitaire" + +#. module: account_edi_ubl_cii_purchase_match +#: model:ir.model,name:account_edi_ubl_cii_purchase_match.model_account_move_line_select_purchase_line_wizard +msgid "account move line select purchase line wizard" +msgstr "assistant de sélection de ligne d'achat pour ligne d'écriture" \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/models/__init__.py b/account_edi_ubl_cii_purchase_match/models/__init__.py new file mode 100644 index 0000000000..7a5c2f77f1 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/__init__.py @@ -0,0 +1,3 @@ +from . import account_edi_xml_ubl_20 +from . import account_move +from . import account_move_line diff --git a/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py b/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py new file mode 100644 index 0000000000..a7af12713b --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_edi_xml_ubl_20.py @@ -0,0 +1,149 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountEdiXmlUBL20(models.AbstractModel): + + _inherit = "account.edi.xml.ubl_20" + + def _import_fill_invoice_form(self, journal, tree, invoice, qty_factor): + """ + automatically match the invoice with a purchase order + + - disable standard purchase matching to avoid conflicts + - only apply for vendor bills + - use invoice_origin (UBL OrderReference) to find the related PO + """ + invoice = invoice.with_context(no_purchase_set=True) + res = super()._import_fill_invoice_form(journal, tree, invoice, qty_factor) + if journal.type != "purchase": + return res + if not invoice.invoice_origin: + return res + self._match_invoice_to_purchase_order(invoice) + return res + + def _match_invoice_to_purchase_order(self, invoice): + """ + match the invoice with a purchase order using the order ref + + matching is done on: + - PO name + - Vendor reference (partner_ref) + -o nly confirmed POs are considered + """ + po_candidates = invoice._extract_purchase_references_from_origin() + purchase_orders = self.env["purchase.order"].search( + [ + ("name", "in", po_candidates), + ("state", "in", ("purchase", "done")), + ] + ) + if not purchase_orders: + return False + for invoice_line in invoice.invoice_line_ids: + self._match_invoice_line_to_purchase_order_line( + invoice_line, purchase_orders.order_line + ) + return True + + def _match_invoice_line_to_purchase_order_line(self, invoice_line, purchase_lines): + """Match an invoice line to a purchase order line + + A match is considered when at least one of these conditions is true: + - same product + - same description + - invoice line description matches the purchase line product name + - supplier product code matches one of the vendor codes of the product + - invoice line description matches one of the vendor product names + """ + if invoice_line.purchase_line_id: + return False + for purchase_line in purchase_lines: + product = purchase_line.product_id + seller_product_codes = product.seller_ids.mapped("product_code") + seller_product_names = product.seller_ids.mapped("product_name") + + same_product = product == invoice_line.product_id + same_description = purchase_line.name == invoice_line.name + matches_product_name = product.name == invoice_line.name + matches_supplier_code = bool(invoice_line.supplier_product_code) and ( + invoice_line.supplier_product_code in seller_product_codes + ) + matches_supplier_name = ( + bool(invoice_line.name) and invoice_line.name in seller_product_names + ) + + if any( + [ + same_product, + same_description, + matches_product_name, + matches_supplier_code, + matches_supplier_name, + ] + ): + invoice_line._set_product(product) + invoice_line.purchase_line_id = purchase_line + break + + return True + + def _import_fill_invoice_line_form( + self, journal, tree, invoice, invoice_line, qty_factor + ): + """ + add a fallback product lookup based on the supplier product code. + + the standard import logic doesn't cover this matching path, so if no product + was found after the super call, try to resolve it from supplierinfo using the + UBL SellerItemIdentification value + """ + res = super()._import_fill_invoice_line_form( + journal, tree, invoice, invoice_line, qty_factor + ) + if invoice_line.product_id: + return res + supplier_product_code = self._find_value( + "./cac:Item/cac:SellersItemIdentification/cbc:ID", tree + ) + if not supplier_product_code: + return res + invoice_line.supplier_product_code = supplier_product_code + product = self._retrieve_product_by_supplierinfo( + invoice.partner_id, supplier_product_code + ) + if not product: + return res + invoice_line._set_product(product) + return res + + def _retrieve_product_by_supplierinfo(self, partner, supplier_product_code): + """ + retrieve a product using supplierinfo based on: + - supplier (partner) + - supplier product code + + returns: + - product variant if directly linked + - single variant if template has only one variant + - empty recordset otherwise + """ + product_sinfo = self.env["product.supplierinfo"].search( + [ + ("product_code", "=", supplier_product_code), + ("partner_id", "=", partner.id), + ], + limit=1, + ) + if product_sinfo and product_sinfo.product_id: + return product_sinfo.product_id + if ( + product_sinfo + and product_sinfo.product_tmpl_id + and len(product_sinfo.product_tmpl_id.product_variant_ids) == 1 + ): + return product_sinfo.product_tmpl_id.product_variant_ids + return self.env["product.product"] diff --git a/account_edi_ubl_cii_purchase_match/models/account_move.py b/account_edi_ubl_cii_purchase_match/models/account_move.py new file mode 100644 index 0000000000..8a20149659 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_move.py @@ -0,0 +1,88 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import re + +from odoo import _, api, fields, models + + +class AccountMove(models.Model): + + _inherit = "account.move" + + purchase_mismatch = fields.Boolean( + compute="_compute_purchase_mismatch", + help=( + "Checked when this invoice has at least one line that does not fully " + "match its related purchase order line." + ), + ) + purchase_mismatch_details = fields.Text( + compute="_compute_purchase_mismatch", + help=( + "Human-readable description of the differences between invoice lines " + "and their related purchase order lines." + ), + ) + + @api.depends( + "invoice_line_ids.purchase_line_mismatch", + "invoice_line_ids.purchase_line_mismatch_details", + "invoice_line_ids.product_id", + "invoice_line_ids.name", + ) + def _compute_purchase_mismatch(self): + for rec in self: + mismatch_lines = rec.invoice_line_ids.filtered("purchase_line_mismatch") + + if not mismatch_lines: + rec.purchase_mismatch = False + rec.purchase_mismatch_details = False + continue + + rec.purchase_mismatch = True + + purchase_mismatch_details = _( + "The following differences were detected between this invoice and its " + "related purchase order lines:\n" + ) + for line in mismatch_lines: + product_label = ( + line.product_id.display_name or line.name or _("No product") + ) + purchase_mismatch_details += product_label + "\n" + purchase_mismatch_details += line.purchase_line_mismatch_details + "\n" + rec.purchase_mismatch_details = purchase_mismatch_details + + def _link_invoice_origin_to_purchase_orders(self, timeout=10): + # disable standard purchase linking + return self + + def _get_po_sequence_prefix(self): + """return the prefix used by purchase order sequence""" + seq = ( + self.env["ir.sequence"] + .sudo() + .search([("code", "=", "purchase.order")], limit=1) + ) + if not seq: + return "PO" + prefix = seq.prefix or "" + match = re.match(r"([A-Za-z]+)", prefix) + if match: + return match.group(1) + return "PO" + + def _extract_purchase_references_from_origin(self, invoice_origin=None): + invoice_origin = invoice_origin if invoice_origin else self.invoice_origin + if not invoice_origin: + return [] + prefix = self._get_po_sequence_prefix() + # flake8: noqa: E231 + pattern = rf"(?:#)?({re.escape(prefix)}[-/\s]?\d+(?:[-/\s]?\d+)*)" + matches = re.findall(pattern, invoice_origin, flags=re.IGNORECASE) + normalized = [] + for match in matches: + value = re.sub(r"[\s#]", "", match).upper() + normalized.append(value) + return list(dict.fromkeys(normalized)) diff --git a/account_edi_ubl_cii_purchase_match/models/account_move_line.py b/account_edi_ubl_cii_purchase_match/models/account_move_line.py new file mode 100644 index 0000000000..2d4488076a --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/models/account_move_line.py @@ -0,0 +1,154 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command, _, api, fields, models +from odoo.tools import float_compare + + +class AccountMoveLine(models.Model): + + _inherit = "account.move.line" + supplier_product_code = fields.Char(readonly=True) + purchase_line_mismatch = fields.Boolean( + compute="_compute_purchase_line_mismatch", + help="Checked when this invoice line does not fully match its related purchase" + " order line.", + ) + purchase_line_mismatch_details = fields.Text( + compute="_compute_purchase_line_mismatch", + help="Human-readable description of the differences between this invoice line" + " and the related purchase order line.", + ) + + @api.depends( + "purchase_line_id", "move_id.state", "price_unit", "price_subtotal", "quantity" + ) + def _compute_purchase_line_mismatch(self): + for rec in self: + if not rec.purchase_line_id or rec.move_id.state != "draft": + rec.purchase_line_mismatch = False + rec.purchase_line_mismatch_details = False + continue + + differences = [] + po_line = rec.purchase_line_id + precision = rec.currency_id.rounding or 0.01 + if ( + float_compare( + rec.price_unit, + po_line.price_unit, + precision_rounding=precision, + ) + != 0 + ): + differences.append( + _("- Unit price differs from the purchase order line.") + ) + if ( + float_compare( + po_line.qty_invoiced, + po_line.product_uom_qty, + precision_rounding=po_line.product_uom.rounding or 0.01, + ) + > 0 + ): + differences.append( + _("- Invoiced quantity exceeds the ordered quantity.") + ) + if ( + po_line.product_id.purchase_method == "receive" + and float_compare( + po_line.qty_received, + po_line.qty_invoiced, + precision_rounding=po_line.product_uom.rounding or 0.01, + ) + < 0 + ): + differences.append( + _("- Invoiced quantity exceeds the received quantity.") + ) + if differences: + rec.purchase_line_mismatch = True + rec.purchase_line_mismatch_details = "\n".join(differences) + else: + rec.purchase_line_mismatch = False + rec.purchase_line_mismatch_details = False + + def _update_product_supplier_name(self): + for rec in self: + if not rec.name or not rec.product_id: + continue + seller = rec.product_id.seller_ids.filtered( + lambda s: s.partner_id == rec.move_id.partner_id + and ( + s.product_id == rec.product_id + or s.product_tmpl_id == rec.product_id.product_tmpl_id + ) + ) + if not seller: + rec.product_id.seller_ids.create( + { + "product_id": rec.product_id.id, + "product_code": rec.supplier_product_code, + "price": rec.price_unit, + } + ) + else: + if rec.supplier_product_code: + seller.product_code = rec.supplier_product_code + + def action_select_purchase_line(self): + self.ensure_one() + purchase_orders = self.purchase_line_id.order_id + partner = self.move_id.partner_id + if not purchase_orders and self.move_id.invoice_origin: + po_candidates = self.move_id._extract_purchase_references_from_origin() + purchase_orders = self.env["purchase.order"].search( + [ + ("name", "in", po_candidates), + ("state", "in", ("purchase", "done")), + ("partner_id", "=", partner.id), + ] + ) + context = { + **self.env.context, + **{ + "default_move_line_id": self.id, + "default_partner_id": partner.id, + "default_purchase_order_ids": [Command.set(purchase_orders.ids)], + "default_purchase_order_line_id": self.purchase_line_id.id, + }, + } + return { + "type": "ir.actions.act_window", + "name": "Select Purchase Line", + "res_model": "account.move.line.select.purchase.line.wizard", + "view_mode": "form", + "target": "new", + "context": context, + } + + def action_show_purchase_line(self): + self.ensure_one() + if not self.purchase_line_id: + return {} + form = self.env.ref( + "account_edi_ubl_cii_purchase_match.purchase_order_line_form_view" + ) + return { + "type": "ir.actions.act_window", + "name": self.purchase_line_id.display_name, + "res_model": self.purchase_line_id._name, + "view_mode": "form", + "views": [(form.id, "form")], + "view_id": form.id, + "res_id": self.purchase_line_id.id, + "target": "new", + "context": self.env.context, + } + + def _set_product(self, product): + self.ensure_one() + price_unit = self.price_unit + self.product_id = product + self.price_unit = price_unit diff --git a/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md b/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md new file mode 100644 index 0000000000..dbefa8c9d6 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONFIGURE.md @@ -0,0 +1,12 @@ +No configuration is required to use this module. + +However, for optimal matching: + +- Ensure that *OrderReference* in the vendor UBL document corresponds to the +Purchase Order Ref or the **Vendor Reference** (`partner_ref`). +- Maintain consistent **product names** or **supplier product names** so +that UBL line descriptions can be matched to the correct purchase order line. + +Optional but recommended: +- Define supplier product names (`product.supplierinfo`) to improve matching +accuracy. \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md b/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md new file mode 100644 index 0000000000..ad026776f5 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONTEXT.md @@ -0,0 +1,12 @@ +In the standard behavior, when importing a vendor bill from a UBL document: + +- If a Purchase Order is found, **all imported UBL lines are replaced** by +the Purchase Order lines. +- This causes a **loss of original UBL data**, such as: + - line-level descriptions, + - quantities, + - pricing, + - tax information received from the supplier. +- Additionally, the standard flow performs **no matching based on product labels**, +so incorrect PO lines may be added if PO content does not reflect what is +actually on the invoice. diff --git a/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md b/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..dbdd727b4a --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Souheil Bejaoui diff --git a/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md b/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md new file mode 100644 index 0000000000..ae1764786e --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/DESCRIPTION.md @@ -0,0 +1,20 @@ +This module extends the UBL vendor bill import process to improve how vendor +bill lines are linked to purchase order lines. + +Instead of replacing the imported UBL lines with the purchase order lines +(standard behavior), this module: + +1. **Reads the OrderReference** in the UBL document. +2. **Identifies the corresponding Purchase Order** using the vendor reference +(`partner_ref`) or the purchase order ref. +3. **Matches each UBL line** with a purchase order line based on: + - product name, + - supplier product name + +4. **Links the vendor bill line** to the matched PO line +5. When a user manually selects a purchase order line from the bill: + - the system stores the supplier product name, + - future imports will auto-match using that supplier information. + +This ensures accurate line-level linking while preserving the supplier’s +invoice data. \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md b/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md new file mode 100644 index 0000000000..b5071ac30d --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/ROADMAP.md @@ -0,0 +1,10 @@ +This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via UBL. + +Before migrating to future versions, it is recommended to verify whether: +- Odoo natively supports precise line-level matching, +- supplier product names and UBL descriptions are matched out of the box, +- and the original UBL lines are preserved. + +If the standard behavior evolves to fully cover this business requirement, +this module may become unnecessary. diff --git a/account_edi_ubl_cii_purchase_match/readme/USAGE.md b/account_edi_ubl_cii_purchase_match/readme/USAGE.md new file mode 100644 index 0000000000..fb514c3940 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/readme/USAGE.md @@ -0,0 +1,11 @@ +1. Import a vendor bill in UBL format through: Accounting / Vendors / Bills / Upload +2. The module will automatically: + - Extract the OrderReference from the UBL. + - Find the matching purchase order via `partner_ref` or purchase order ref. + - Attempt to match each UBL line with the correct purchase order line using: + - product name, + - supplier product name +3. When a match is found: the vendor bill line is linked to the purchase order line. +4. If no match is found: + - Click "Select purchase line" button in invoice line + - Select a purchase order and a purchase order line \ No newline at end of file diff --git a/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml b/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml new file mode 100644 index 0000000000..b55260f160 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/security/account_move_line_select_purchase_line_wizard.xml @@ -0,0 +1,24 @@ + + + + + + account.move.line.select.purchase.line.wizard access all + + + + + + + + + diff --git a/account_edi_ubl_cii_purchase_match/static/description/icon.png b/account_edi_ubl_cii_purchase_match/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/account_edi_ubl_cii_purchase_match/static/description/icon.png differ diff --git a/account_edi_ubl_cii_purchase_match/static/description/index.html b/account_edi_ubl_cii_purchase_match/static/description/index.html new file mode 100644 index 0000000000..da7cd91db8 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/static/description/index.html @@ -0,0 +1,534 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Account Edi Ubl Cii Purchase Match

+ +

Beta License: AGPL-3 OCA/edi Translate me on Weblate Try me on Runboat

+

This module extends the UBL vendor bill import process to improve how +vendor bill lines are linked to purchase order lines.

+

Instead of replacing the imported UBL lines with the purchase order +lines (standard behavior), this module:

+
    +
  1. Reads the OrderReference in the UBL document.
  2. +
  3. Identifies the corresponding Purchase Order using the vendor +reference (partner_ref) or the purchase order ref.
  4. +
  5. Matches each UBL line with a purchase order line based on:
      +
    • product name,
    • +
    • supplier product name
    • +
    +
  6. +
  7. Links the vendor bill line to the matched PO line
  8. +
  9. When a user manually selects a purchase order line from the bill:
      +
    • the system stores the supplier product name,
    • +
    • future imports will auto-match using that supplier information.
    • +
    +
  10. +
+

This ensures accurate line-level linking while preserving the supplier’s +invoice data.

+

Table of contents

+ +
+

Use Cases / Context

+

In the standard behavior, when importing a vendor bill from a UBL +document:

+
    +
  • If a Purchase Order is found, all imported UBL lines are replaced +by the Purchase Order lines.
  • +
  • This causes a loss of original UBL data, such as:
      +
    • line-level descriptions,
    • +
    • quantities,
    • +
    • pricing,
    • +
    • tax information received from the supplier.
    • +
    +
  • +
  • Additionally, the standard flow performs no matching based on +product labels, so incorrect PO lines may be added if PO content +does not reflect what is actually on the invoice.
  • +
+
+
+

Configuration

+

No configuration is required to use this module.

+

However, for optimal matching:

+
    +
  • Ensure that OrderReference in the vendor UBL document corresponds to +the Purchase Order Ref or the Vendor Reference (partner_ref).
  • +
  • Maintain consistent product names or supplier product names so +that UBL line descriptions can be matched to the correct purchase +order line.
  • +
+

Optional but recommended:

+
    +
  • Define supplier product names (product.supplierinfo) to improve +matching accuracy.
  • +
+
+
+

Usage

+
    +
  1. Import a vendor bill in UBL format through: Accounting / Vendors / +Bills / Upload
  2. +
  3. The module will automatically:
      +
    • Extract the OrderReference from the UBL.
    • +
    • Find the matching purchase order via partner_ref or purchase +order ref.
    • +
    • Attempt to match each UBL line with the correct purchase order line +using:
        +
      • product name,
      • +
      • supplier product name
      • +
      +
    • +
    +
  4. +
  5. When a match is found: the vendor bill line is linked to the purchase +order line.
  6. +
  7. If no match is found:
      +
    • Click “Select purchase line” button in invoice line
    • +
    • Select a purchase order and a purchase order line
    • +
    +
  8. +
+
+
+

Known issues / Roadmap

+

This module implements custom purchase order line matching and replaces +the standard behavior of linking vendor bills to purchase orders via +UBL.

+

Before migrating to future versions, it is recommended to verify +whether:

+
    +
  • Odoo natively supports precise line-level matching,
  • +
  • supplier product names and UBL descriptions are matched out of the +box,
  • +
  • and the original UBL lines are preserved.
  • +
+

If the standard behavior evolves to fully cover this business +requirement, this module may become unnecessary.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

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

+
+
+

Credits

+
+

Authors

+
    +
  • ACSONE SA/NV
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

sbejaoui

+

This module is part of the OCA/edi project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/account_edi_ubl_cii_purchase_match/tests/__init__.py b/account_edi_ubl_cii_purchase_match/tests/__init__.py new file mode 100644 index 0000000000..df41f3af05 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/__init__.py @@ -0,0 +1 @@ +from . import test_account_edi_ubl_cii_purchase_match diff --git a/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py b/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py new file mode 100644 index 0000000000..755e3d03cd --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_account_edi_ubl_cii_purchase_match.py @@ -0,0 +1,423 @@ +# Copyright 2025 ACSONE SA/NV +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import Command +from odoo.tests import tagged +from odoo.tools import file_open + +from odoo.addons.account.tests.common import AccountTestInvoicingCommon + + +@tagged("post_install", "-at_install") +class TestAccountEdiUblCiiPurchaseMatch(AccountTestInvoicingCommon): + @classmethod + def setUpClass(cls, chart_template_ref=None): + super().setUpClass() + cls.env["ir.config_parameter"].sudo().set_param( + "account_edi.product_name_match", True + ) + cls.env["ir.sequence"].search( + [("code", "=", "purchase.order")], limit=1 + ).prefix = "PO" + cls.product = cls.env["product.product"].create( + {"name": "test_product", "standard_price": 100} + ) + cls.partner = cls.env["res.partner"].create( + {"name": "ALD Automotive LU", "vat": "LU25587702"} + ) + cls.purchase_order = cls.env["purchase.order"].create( + { + "name": "PO0032", + "partner_id": cls.partner.id, + "order_line": [ + Command.create( + { + "name": cls.product.name, + "product_id": cls.product.id, + "product_qty": 1, + "price_unit": 657, + } + ), + ], + } + ) + cls.po_line = cls.purchase_order.order_line + cls.purchase_order.button_confirm() + + def _import_invoice(self, journal, file_path=None): + if file_path is None: + file_path = ( + "account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example.xml" + ) + with file_open(file_path, "rb") as file: + xml_attachment = self.env["ir.attachment"].create( + { + "mimetype": "application/xml", + "name": "test_invoice.xml", + "raw": file.read(), + } + ) + move = ( + self.env["account.journal"] + .with_context(default_journal_id=journal.id) + ._create_document_from_attachment(xml_attachment.id) + ) + return move + + def _create_purchase_order(self, product, name=None): + po = self.env["purchase.order"].create( + { + "partner_id": self.partner.id, + "order_line": [ + Command.create( + { + "name": product.name, + "product_id": product.id, + "product_qty": 1, + "price_unit": 1000, + } + ), + ], + } + ) + if name: + po.name = name + po.button_confirm() + return po + + def test_0(self): + """ + Default behavior + without matching criteria, no purchase line or product + is assigned. Sale journals are also ignored + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + self.assertEqual(bill.partner_id, self.partner) + inv_line = bill.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + invoice = self._import_invoice(self.company_data["default_journal_sale"]) + self.assertEqual(invoice.partner_id, self.partner) + inv_line = invoice.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + + def test_1(self): + """ + OrderReference matches a purchase order, but no product match is found. + Standard behavior is disabled: no PO lines are created from the PO, only the + UBL invoice line is imported + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(len(inv_line), 1) # standard behavior is desabled + self.assertFalse(inv_line.purchase_line_id) + self.assertFalse(inv_line.product_id) + + def test_2(self): + """ + The product name matches the UBL line description, so the vendor bill line is + linked to the PO line and the product is set accordingly + """ + self.product.name = "Locations and leasing" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + return inv_line + + def test_3(self): + """ + The supplier product name (defined on the product variant via supplierinfo) + matches the UBL line description, so the bill line is correctly linked to the + PO line and product + """ + + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_name": "Locations and leasing", + "product_id": self.product.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_4(self): + """ + The supplier product name (defined on the product template via supplierinfo) + matches the UBL line description, so the bill line is linked to the PO line and + product + """ + + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_name": "Locations and leasing", + "product_tmpl_id": self.product.product_tmpl_id.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_5(self): + """ + When no product match is found, the user manually links the bill line to the PO + line, the supplier info is updated with the product supplier name + On the next import, the supplierinfo is used to automatically match the + bill line with the correct PO line + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertFalse(inv_line.purchase_line_id) + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + self.assertEqual(wizard.move_line_id, inv_line) + self.assertEqual(wizard.purchase_order_ids, self.purchase_order) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(inv_line.purchase_line_id, self.po_line) + bill.unlink() + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + + def test_6(self): + """ + price unit imported from file is unchanged after po auto match + """ + inv_line = self.test_2() + self.assertEqual(inv_line.price_unit, 657.0) + inv_line.product_id = False + inv_line.product_id = self.product + self.assertEqual(inv_line.price_unit, 100) + + def test_7(self): + """ + price unit imported from file is unchanged after po manual match + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(inv_line.price_unit, 657.0) + + def test_8(self): + """match product by default_code""" + self.product.default_code = "leasing001" + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_9(self): + """match product by supplier code""" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_code": "leasing001", + "product_id": self.product.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_10(self): + """match product by supplier code for product template suuplierinfo""" + self.env["product.supplierinfo"].create( + { + "partner_id": self.partner.id, + "product_code": "leasing001", + "product_tmpl_id": self.product.product_tmpl_id.id, + } + ) + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.purchase_line_id, self.po_line) + self.assertEqual(inv_line.product_id, self.product) + + def test_11(self): + """ + product supplier code is stored in seller information at manual match + """ + bill = self._import_invoice(self.company_data["default_journal_purchase"]) + inv_line = bill.invoice_line_ids + self.assertEqual(inv_line.supplier_product_code, "leasing001") + self.assertEqual(inv_line.price_unit, 657.0) + action = inv_line.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + wizard.product_id = self.product + wizard.select_purchase_line() + self.assertEqual(self.product.seller_ids.product_code, "leasing001") + + def test_12(self): + """test purchase price unit mismatch warning""" + self.product.default_code = "leasing001" + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_price_unit_mismatch.xml", + ) + self.assertTrue(bill.purchase_mismatch) + self.assertIn( + "Unit price differs from the purchase order line", + bill.purchase_mismatch_details, + ) + bill.action_post() + self.assertFalse(bill.purchase_mismatch) + self.assertFalse(bill.purchase_mismatch_details) + + def test_13(self): + """test purchase invoiced qty mismatch warning""" + self.product.default_code = "leasing001" + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_invoiced_qty_mismatch.xml", + ) + self.assertTrue(bill.purchase_mismatch) + self.assertIn( + "Invoiced quantity exceeds the ordered quantity", + bill.purchase_mismatch_details, + ) + bill.action_post() + self.assertFalse(bill.purchase_mismatch) + self.assertFalse(bill.purchase_mismatch_details) + + def _extract_refs(self, invoice_origin): + return self.env["account.move"]._extract_purchase_references_from_origin( + invoice_origin + ) + + def test_14(self): + """extract multiple purchase order references""" + + # single PO reference + refs = self._extract_refs("PO0001") + self.assertSetEqual(set(refs), {"PO0001"}) + + # multiple references separated by comma + refs = self._extract_refs("PO0001,PO0002") + self.assertSetEqual(set(refs), {"PO0001", "PO0002"}) + + # multiple references separated by semicolon + refs = self._extract_refs("PO0001;PO0002") + self.assertSetEqual(set(refs), {"PO0001", "PO0002"}) + + # references prefixed with '#' + refs = self._extract_refs("#PO0001,#PO0002") + self.assertSetEqual(set(refs), {"PO0001", "PO0002"}) + + # mixed separators and '#' prefix + refs = self._extract_refs("#PO0001 ; PO0002 / #PO0003") + self.assertSetEqual(set(refs), {"PO0001", "PO0002", "PO0003"}) + + # references embedded in free text + refs = self._extract_refs("invoice related to PO0001 and PO0002") + self.assertSetEqual(set(refs), {"PO0001", "PO0002"}) + + # deduplicate extracted purchase order references + refs = self._extract_refs("PO0001,#PO0001,PO0002,PO0001") + self.assertSetEqual(set(refs), {"PO0001", "PO0002"}) + + # empty string should return no references + refs = self._extract_refs("") + self.assertSetEqual(set(refs), set()) + + # falsy value should return no references + refs = self._extract_refs(False) + self.assertSetEqual(set(refs), set()) + + # extraction with custom static prefix + self.env["ir.sequence"].search( + [("code", "=", "purchase.order")], limit=1 + ).prefix = "ACH" + refs = self._extract_refs("ACH0001,#ACH0001,ACH0002,ACH0001") + self.assertSetEqual(set(refs), {"ACH0001", "ACH0002"}) + + # extraction with dynamic prefix including year (ACH%(year)s/) + self.env["ir.sequence"].search( + [("code", "=", "purchase.order")], limit=1 + ).prefix = "ACH%(year)s/" + refs = self._extract_refs( + "ACH2026/0001,#ACH2026/0001,ACH2026/0002,ACH2026/0001" + ) + self.assertSetEqual(set(refs), {"ACH2026/0001", "ACH2026/0002"}) + + def test_15(self): + """import with multi po""" + self.product.default_code = "leasing001" + product2 = self.env["product.product"].create( + { + "name": "test_product", + "standard_price": 100, + "default_code": "leasing002", + } + ) + self._create_purchase_order(self.product, name="PO0001") + self._create_purchase_order(product2, name="PO0002") + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_multi_po.xml", + ) + inv_l1 = bill.invoice_line_ids.filtered( + lambda line: line.product_id.code == "leasing001" + ) + inv_l2 = bill.invoice_line_ids.filtered( + lambda line: line.product_id.code == "leasing002" + ) + self.assertEqual(inv_l1.product_id, self.product) + self.assertEqual(inv_l2.product_id, product2) + self.assertEqual(inv_l1.purchase_line_id.order_id.name, "PO0001") + self.assertEqual(inv_l2.purchase_line_id.order_id.name, "PO0002") + + def test_16(self): + """match wizard should propose multiple PO""" + product2 = self.env["product.product"].create( + {"name": "test_product", "standard_price": 100} + ) + self._create_purchase_order(self.product, name="PO0001") + self._create_purchase_order(product2, name="PO0002") + bill = self._import_invoice( + self.company_data["default_journal_purchase"], + file_path="account_edi_ubl_cii_purchase_match/tests/test_files/" + "bis3_bill_example_multi_po.xml", + ) + self.assertEqual(len(bill.invoice_line_ids), 2) + self.assertFalse(bill.invoice_line_ids.product_id) + self.assertFalse(bill.invoice_line_ids.purchase_line_id) + inv_l1 = bill.invoice_line_ids[0] + action = inv_l1.action_select_purchase_line() + wizard = ( + self.env[action.get("res_model")] + .with_context(**action.get("context")) + .create({}) + ) + self.assertEqual(len(wizard.purchase_order_ids), 2) + self.assertSetEqual( + set(wizard.purchase_order_ids.mapped("name")), {"PO0002", "PO0001"} + ) diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml new file mode 100644 index 0000000000..0bdbb74fed --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example.xml @@ -0,0 +1,144 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + PO0032 + 2023-08-04 + 2023-09-04 + 380 + EUR + + PO0032 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + PO0032 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + S + 16.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations and leasing + + leasing001 + + + S + 16.0 + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml new file mode 100644 index 0000000000..9c9e4ac1b3 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_invoiced_qty_mismatch.xml @@ -0,0 +1,144 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + PO0032 + 2023-08-04 + 2023-09-04 + 380 + EUR + + PO0032 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + PO0032 + + LU071241358706500000 + + + + 160 + + 1000 + 160 + + S + 16.0 + + VAT + + + + + + 1000 + 1000 + 1160 + 0.00 + 1160 + + + 1 + 10.0 + 1000 + + Locations and leasing + Locations and leasing + + leasing001 + + + S + 16.0 + + VAT + + + + + 1000 + + + diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_multi_po.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_multi_po.xml new file mode 100644 index 0000000000..023209b8cb --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_multi_po.xml @@ -0,0 +1,166 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + #PO0001,#PO0002 + 2023-08-04 + 2023-09-04 + 380 + EUR + + #PO0001,#PO0002 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + #PO0001,#PO0002 + + LU071241358706500000 + + + + 105.12 + + 657.00 + 105.12 + + S + 16.0 + + VAT + + + + + + 657.00 + 657.00 + 762.12 + 0.00 + 762.12 + + + 1 + 1.0 + 657.00 + + Locations and leasing + Locations and leasing + + leasing001 + + + S + 16.0 + + VAT + + + + + 657.00 + + + + 2 + 1.0 + 657.00 + + Locations and leasing + Locations and leasing + + leasing002 + + + S + 16.0 + + VAT + + + + + 657.00 + + + diff --git a/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml new file mode 100644 index 0000000000..d9e6ccac4e --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/tests/test_files/bis3_bill_example_price_unit_mismatch.xml @@ -0,0 +1,144 @@ + + + urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + PO0032 + 2023-08-04 + 2023-09-04 + 380 + EUR + + PO0032 + S00012 + + + FAC_2023_00052.pdf + + + + + + LU25587702 + + ALD Automotive LU + + + 270 rte d'Arlon + Strassen + 8010 + + LU + + + + LU12977109 + + VAT + + + + ALD Automotive LU + LU12977109 + + + ALD Automotive LU + adl@test.com + + + + + + LU25587702 + + Odoo Lu + + + Rue de l'industrie 13 + Windhof + + LU + + + + LU25587702 + + VAT + + + + Odoo Lu + LU25587702 + + + Odoo Lu + odoo@test.com + + + + + + + Rue de l'industrie 13 + Windhof + + LU + + + + + + 30 + PO0032 + + LU071241358706500000 + + + + 160 + + 1000 + 160 + + S + 16.0 + + VAT + + + + + + 1000 + 1000 + 1160 + 0.00 + 1160 + + + 1 + 1.0 + 1000 + + Locations and leasing + Locations and leasing + + leasing001 + + + S + 16.0 + + VAT + + + + + 1000 + + + diff --git a/account_edi_ubl_cii_purchase_match/views/account_move.xml b/account_edi_ubl_cii_purchase_match/views/account_move.xml new file mode 100644 index 0000000000..2ae7a31cf9 --- /dev/null +++ b/account_edi_ubl_cii_purchase_match/views/account_move.xml @@ -0,0 +1,51 @@ + + + + + + account.move + + + + + + +