Skip to content

[FIX] purchase_stock_ux: exclude fully-returned lines from vendor bill#339

Open
mav-adhoc wants to merge 4 commits into
ingadhoc:19.0from
adhoc-dev:19.0-t-69417-mav
Open

[FIX] purchase_stock_ux: exclude fully-returned lines from vendor bill#339
mav-adhoc wants to merge 4 commits into
ingadhoc:19.0from
adhoc-dev:19.0-t-69417-mav

Conversation

@mav-adhoc

Copy link
Copy Markdown
Contributor

Summary

When creating a vendor bill from a PO that has lines with qty_to_invoice = 0
(fully returned with to_refund=True), the draft invoice included those lines
with quantity 0. The user had to delete them manually.

Root cause: Odoo 19 removed the old _get_invoiceable_lines filter from
action_create_invoice and now iterates all order_line unconditionally.
purchase_stock_ux overrides _compute_qty_invoiced to subtract qty_returned
from qty_to_invoice, so fully-returned lines produce qty_to_invoice = 0 and
still end up as invoice lines with that quantity.

Fix: Override action_create_invoice in purchase_stock_ux to skip lines
where float_is_zero(qty_to_invoice) and that are not sections/notes or
downpayments. Section headers are preserved: they are only added when a
subsequent invoiceable line consumes them, so empty sections are also dropped.

Test plan

Two new tests in purchase_stock_ux/tests/test_purchase_order.py:

  • test_invoice_excludes_fully_returned_lines: PO with 2 lines (L0 invoiceable,
    L1 fully returned) → invoice must contain only L0 with no zero-qty lines.
  • test_invoice_partial_return_no_regression: single line, partial return (4/10)
    → invoice with 1 line at quantity 6 (no regression).

Covers acceptance criteria:

  • Mixed PO (invoiceable + fully-returned line) → only invoiceable line in bill
  • Partial return → bill for the net (no regression)
  • Both purchase_method policies produce qty_to_invoice = 0 for fully-returned
    lines, so the filter works for both "Ordered quantities" and "Received quantities"

Internal task: https://www.adhoc.inc/odoo/knowledge/180/project.task/69417

@roboadhoc

Copy link
Copy Markdown
Contributor

Pull request status dashboard

Odoo 19 removed _get_invoiceable_lines and now feeds all order_line into
action_create_invoice unconditionally. Our _compute_qty_invoiced subtracts
qty_returned from qty_to_invoice, so lines where the full quantity was
returned end up as invoice lines with quantity 0, requiring manual deletion.

Override action_create_invoice in purchase_stock_ux to skip lines where
float_is_zero(qty_to_invoice) and that are neither sections nor downpayments.
Sections are preserved for subsequent invoiceable lines in the same block.
In Odoo 19 account.move.line, regular product lines have
display_type='product' (truthy string), not False. The partial return
test was using the old 'not l.display_type' filter which matched zero
lines. Align with the first test's correct filter.
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.

2 participants