Skip to content

Conversation

@LouisGobert
Copy link
Contributor

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

@robodoo
Copy link
Contributor

robodoo commented Feb 13, 2025

Pull request status dashboard

@C3POdoo C3POdoo requested review from a team and svs-odoo and removed request for a team February 13, 2025 15:12
@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Feb 13, 2025
@LouisGobert
Copy link
Contributor Author

Hello,

Would it be possible to have this PR reviewed promptly? It is currently blocking the loading of certain IT bills for our clients.

Thank you!

@LouisGobert
Copy link
Contributor Author

@svs-odoo Hello, could I get an update? Thanks 🙂

Copy link
Contributor

@svs-odoo svs-odoo left a comment

Choose a reason for hiding this comment

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

Hello @LouisGobert
Thanks for the fix, it looks good to me !
I let you two small comments about the test

@LouisGobert LouisGobert force-pushed the 17.0-purchase-fix-match-only-invoice-lines-loug branch from 07339a2 to 180cd65 Compare March 25, 2025 13:10
@svs-odoo
Copy link
Contributor

@LouisGobert rebase your branch please

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
@LouisGobert LouisGobert force-pushed the 17.0-purchase-fix-match-only-invoice-lines-loug branch from 180cd65 to 3626b1c Compare March 27, 2025 11:48
@LouisGobert
Copy link
Contributor Author

Done :)

@svs-odoo
Copy link
Contributor

robodoo r+

robodoo pushed a commit that referenced this pull request 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

closes #197637

Signed-off-by: Steve Van Essche <svs@odoo.com>
@robodoo
Copy link
Contributor

robodoo commented Mar 28, 2025

@LouisGobert @svs-odoo staging failed: ci/runbot on 2253a49e627daa156f9f872e1f0b6796c6539a9e (view more at https://runbot.odoo.com/runbot/build/77376053)

@LouisGobert
Copy link
Contributor Author

@robodoo retry

@robodoo
Copy link
Contributor

robodoo commented Mar 28, 2025

@LouisGobert @svs-odoo staging failed: ci/runbot on 90ac32c0942e36c52b83b192a0288ab206ebac83 (view more at https://runbot.odoo.com/runbot/build/77383662)

@LouisGobert
Copy link
Contributor Author

@robodoo retry

robodoo pushed a commit that referenced this pull request 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

closes #197637

Signed-off-by: Steve Van Essche <svs@odoo.com>
@robodoo robodoo closed this Mar 28, 2025
@fw-bot fw-bot deleted the 17.0-purchase-fix-match-only-invoice-lines-loug branch April 4, 2025 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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