Skip to content

Conversation

@fw-bot
Copy link
Contributor

@fw-bot fw-bot commented Mar 28, 2025

Currently, an error can occur in _find_matching_po_and_inv_lines when some invoice lines have a price_unit of 0. This happens because the matching logic sorts and matches lines by (price_unit, qty), leading to "Journal Items" (line_ids) being incorrectly matched with purchase order lines.

The issue arises because the _find_matching_po_and_inv_lines function checks all line_ids, instead of only invoice_line_ids. When a PO line has a price_unit of 0, it might match with a line that isn't an actual invoice line. As a result, unmatched_lines becomes incorrect, and it could remove a valid invoice line. Then, later, when calculating inv_and_po_lines, the process only considers invoice_line_ids. Since no matching line is found, an error occurs when attempting to delete the line (id is False).

Steps to reproduce:

  1. Create a purchase order with:
    • 1 product A with price_unit = 0
  2. Confirm the purchase order.
  3. Upload an EDI XML bill (e.g., IT localization) with:
    • A reference to the purchase order
    • 1 product B with price_unit = 100

Since all bill lines are processed, a tax line or a payment term line might incorrectly match with the PO line, causing the error.

opw-4513869

Forward-Port-Of: #197637

@robodoo
Copy link
Contributor

robodoo commented Mar 28, 2025

Pull request status dashboard

@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 28, 2025

This PR targets saas-18.1 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Mar 28, 2025
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 28, 2025
@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 28, 2025

@LouisGobert @svs-odoo ci/runbot failed on this forward-port PR

Currently, an error can occur in `_find_matching_po_and_inv_lines`
when some invoice lines have a price_unit of 0. This happens because
the matching logic sorts and matches lines by `(price_unit, qty)`,
leading to "Journal Items" (`line_ids`) being incorrectly matched
with purchase order lines.

The issue arises because the `_find_matching_po_and_inv_lines`
function checks all `line_ids`, instead of only `invoice_line_ids`.
When a PO line has a price_unit of 0, it might match with a line
that isn't an actual invoice line. As a result, `unmatched_lines`
becomes incorrect, and it could remove a valid invoice line.
Then, later, when calculating `inv_and_po_lines`, the process only
considers `invoice_line_ids`. Since no matching line is found,
an error occurs when attempting to delete the line (id is False).

Steps to reproduce:
1. Create a purchase order with:
   - 1 product A with price_unit = 0
2. Confirm the purchase order.
3. Upload an EDI XML bill (e.g., IT localization) with:
   - A reference to the purchase order
   - 1 product B with price_unit = 100

Since all bill lines are processed, a tax line or a payment term line
might incorrectly match with the PO line, causing the error.

opw-4513869

X-original-commit: f9cc651
@LouisGobert LouisGobert force-pushed the saas-18.1-17.0-purchase-fix-match-only-invoice-lines-loug-426410-fw branch from 1b4f349 to 6b70feb Compare March 28, 2025 21:46
@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 28, 2025

@LouisGobert @svs-odoo this PR was modified / updated and has become a normal PR. It must be merged directly.

@LouisGobert
Copy link
Contributor

@robodoo r+

@robodoo
Copy link
Contributor

robodoo commented Mar 28, 2025

@LouisGobert @svs-odoo 'ci/runbot' failed on this reviewed PR.

robodoo pushed a commit that referenced this pull request Mar 29, 2025
Currently, an error can occur in `_find_matching_po_and_inv_lines`
when some invoice lines have a price_unit of 0. This happens because
the matching logic sorts and matches lines by `(price_unit, qty)`,
leading to "Journal Items" (`line_ids`) being incorrectly matched
with purchase order lines.

The issue arises because the `_find_matching_po_and_inv_lines`
function checks all `line_ids`, instead of only `invoice_line_ids`.
When a PO line has a price_unit of 0, it might match with a line
that isn't an actual invoice line. As a result, `unmatched_lines`
becomes incorrect, and it could remove a valid invoice line.
Then, later, when calculating `inv_and_po_lines`, the process only
considers `invoice_line_ids`. Since no matching line is found,
an error occurs when attempting to delete the line (id is False).

Steps to reproduce:
1. Create a purchase order with:
   - 1 product A with price_unit = 0
2. Confirm the purchase order.
3. Upload an EDI XML bill (e.g., IT localization) with:
   - A reference to the purchase order
   - 1 product B with price_unit = 100

Since all bill lines are processed, a tax line or a payment term line
might incorrectly match with the PO line, causing the error.

opw-4513869

closes #204022

X-original-commit: f9cc651
Signed-off-by: Steve Van Essche <svs@odoo.com>
Signed-off-by: Louis Gobert (loug) <loug@odoo.com>
@robodoo robodoo closed this Mar 29, 2025
@fw-bot fw-bot deleted the saas-18.1-17.0-purchase-fix-match-only-invoice-lines-loug-426410-fw branch April 5, 2025 13:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants