Skip to content

Commit 69af81c

Browse files
committed
[FIX] account_invoice_report_grouped_by_picking: skip non-return moves on refunds
When a credit note is created without physical return, its lines inherit move_line_ids from the original delivery moves. The report processed these delivery moves as if they were return moves, showing wrong picking associations and wrong quantities. Now delivery moves (location_id.usage != 'customer') are skipped for out_refund invoices. Affected lines fall through to the module's existing lines_dict/no_picking path and render under 'Without reference' in the report. Updates test assertions to verify product lines have no picking and 'Without reference' appears when no return picking exists.
1 parent 344c5e7 commit 69af81c

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

account_invoice_report_grouped_by_picking/models/account_move.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ def lines_grouped_by_picking(self):
103103
remaining_qty = line.quantity
104104
# Process moves related to the line
105105
for move in line.move_line_ids:
106+
# For credit notes without return, move_line_ids
107+
# contain delivery moves from the original invoice.
108+
# These must be skipped so lines fall through to
109+
# lines_dict -> "Without reference" in the report.
110+
if (
111+
self.move_type == "out_refund"
112+
and move.location_id.usage != "customer"
113+
):
114+
continue
106115
key = (move.picking_id, line)
107116
self._process_section_note_lines_grouped(
108117
previous_section, previous_note, picking_dict, move.picking_id

account_invoice_report_grouped_by_picking/tests/test_account_invoice_group_picking.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,19 @@ def test_account_invoice_return_without_returned_good(self):
201201
refund_invoice = self.env["account.move"].browse(reversal["res_id"])
202202
groups = refund_invoice.lines_grouped_by_picking()
203203
self.assertEqual(len(groups), 2)
204+
# Product lines should not have a picking when no return picking exists
205+
product_groups = [
206+
g
207+
for g in groups
208+
if g["line"].display_type not in ("line_section", "line_note")
209+
and g["line"].product_id.type != "service"
210+
]
211+
for group in product_groups:
212+
self.assertFalse(
213+
group["picking"],
214+
"Product line should not be grouped under a picking "
215+
"when there is no return picking",
216+
)
204217

205218
def test_account_invoice_group_picking_refund(self):
206219
# confirm quotation
@@ -351,7 +364,19 @@ def test_account_invoice_group_picking_refund_without_return(self):
351364
# invoice = self.env["account.move"].browse(inv_id)
352365
groups = new_invoice.lines_grouped_by_picking()
353366
self.assertEqual(len(groups), 2)
354-
self.assertEqual(groups[0]["picking"], groups[1]["picking"])
367+
# Product lines should not have a picking when no return picking exists
368+
product_groups = [
369+
g
370+
for g in groups
371+
if g["line"].display_type not in ("line_section", "line_note")
372+
and g["line"].product_id.type != "service"
373+
]
374+
for group in product_groups:
375+
self.assertFalse(
376+
group["picking"],
377+
"Product line should not be grouped under a picking "
378+
"when there is no return picking",
379+
)
355380
# Test report
356381
content = html.document_fromstring(
357382
self.env["ir.actions.report"]._render_qweb_html(
@@ -373,6 +398,13 @@ def test_account_invoice_group_picking_refund_without_return(self):
373398
)
374399
# information about pickings is printed
375400
self.assertTrue(picking.name in tbody)
401+
# "Without reference" header appears for lines without picking
402+
self.assertIn(
403+
"Without reference",
404+
tbody,
405+
"Report should show 'Without reference' for credit note "
406+
"lines with no return picking",
407+
)
376408

377409
def test_account_invoice_refund_with_section_line(self):
378410
"""Credit note with section/note lines should not raise KeyError.

0 commit comments

Comments
 (0)