Skip to content

Conversation

@sbejaoui
Copy link

Extend UBL vendor bill import to automatically match and link bill lines to purchase order lines using the OrderReference and product label

Extend UBL vendor bill import to automatically match and link bill lines to purchase order lines using the OrderReference and product label
@sbejaoui
Copy link
Author

cc/ @phschmidt , @jbaudoux , @rousseldenis

Copy link

@phschmidt phschmidt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functional review

[
"|",
("name", "=", order_ref),
("partner_ref", "=", order_ref),
Copy link
Contributor

@jbaudoux jbaudoux Dec 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

partner_ref should compare to OrderReference/SalesOrderID and not OrderReference/ID

res = super()._import_fill_invoice_form(journal, tree, invoice, qty_factor)
if journal.type != "purchase":
return res
invoice_origin_node = tree.find("./{*}OrderReference/{*}ID")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you should only search for the parent here as ID is mandatory when the parent is there and then parse ID and SalesOrderID

invoice_origin_node = tree.find("./{*}OrderReference/{*}ID")
if invoice_origin_node is None:
return res
order_ref = invoice_origin_node.text
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

then handover this to the called method below

if invoice_line.purchase_line_id:
return False
product = self._get_matching_product(invoice_line)
purchase_line = purchase_lines.filtered(lambda line: line.product_id == product)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if no product is found and there are PO lines without product?

Suggested change
purchase_line = purchase_lines.filtered(lambda line: line.product_id == product)
purchase_line = purchase_lines.filtered(lambda line: line.product_id and line.product_id == product)

Comment on lines +84 to +90
res = super()._import_fill_invoice_line_form(
journal, tree, invoice, invoice_line, qty_factor
)
supplier_product_code = self._find_value(
"./cac:Item/cac:SellersItemIdentification/cbc:ID", tree
)
if invoice_line.product_id or not supplier_product_code:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is I think a bug in the call to super that retrieves the product. It's searching for a product with default_code based on the SellersItemIdentification while it should be BuyersItemIdentification
https://github.com/odoo/odoo/blob/f07949e4ccdb5d7a17a6678b008fa6785ec3fb12/addons/account_edi_ubl_cii/models/account_edi_xml_ubl_20.py#L727
I would force a new call to the method _retrieve_product with the right argument

invoice_line.purchase_line_id = purchase_line
return True

def _get_matching_product(self, invoice_line):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of this? The product matching should already be resolved by _retrieve_product and what you improved in _import_fill_invoice_line_form?

What could be usefull is to match a PO line name based on the invoice line name, in case the seller or buyer does not manage the line with a product

@sbejaoui sbejaoui force-pushed the 16.0-account_edi_ubl_cii_purchase_match-sbj branch from debf5ad to 7b6468c Compare December 29, 2025 14:21
@sbejaoui sbejaoui force-pushed the 16.0-account_edi_ubl_cii_purchase_match-sbj branch from 7b6468c to ed80be9 Compare December 29, 2025 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants