Skip to content

Commit 344c5e7

Browse files
committed
[FIX] account_invoice_report_grouped_by_picking: use correct key 'quantity' in section/note dicts
When a credit note contains section or note lines, the report template crashes with KeyError: 'quantity' because the dict for these lines used the key 'qty' instead of 'quantity'. Now section/note line dicts use the correct 'quantity' key to match the template expectation. Includes test that creates a credit note with a section line and verifies the report renders without KeyError.
1 parent 4cdff22 commit 344c5e7

2 files changed

Lines changed: 60 additions & 1 deletion

File tree

account_invoice_report_grouped_by_picking/models/account_move.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ def lines_grouped_by_picking(self):
9292
{
9393
"picking": picking_obj,
9494
"line": line,
95-
"qty": 0.0,
95+
"quantity": 0.0,
9696
"is_last_section_notes": True,
9797
}
9898
)

account_invoice_report_grouped_by_picking/tests/test_account_invoice_group_picking.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,3 +373,62 @@ def test_account_invoice_group_picking_refund_without_return(self):
373373
)
374374
# information about pickings is printed
375375
self.assertTrue(picking.name in tbody)
376+
377+
def test_account_invoice_refund_with_section_line(self):
378+
"""Credit note with section/note lines should not raise KeyError.
379+
380+
Before the fix, section/note line dicts used 'qty' key instead of
381+
'quantity'. The QWeb report template accesses group['quantity'],
382+
causing KeyError on credit notes with section/note lines.
383+
"""
384+
self.sale.action_confirm()
385+
picking = self.sale.picking_ids[:1]
386+
picking.action_confirm()
387+
picking.move_line_ids.write({"quantity": 1})
388+
wiz_act = picking.button_validate()
389+
wiz = Form(
390+
self.env[wiz_act["res_model"]].with_context(**wiz_act["context"])
391+
).save()
392+
wiz.process()
393+
invoice = self.sale._create_invoices()
394+
# Add section line to invoice
395+
self.env["account.move.line"].create(
396+
{
397+
"name": "Test Section",
398+
"move_id": invoice.id,
399+
"display_type": "line_section",
400+
"account_id": invoice.invoice_line_ids[0].account_id.id,
401+
}
402+
)
403+
invoice.action_post()
404+
# Create refund without return picking
405+
move_reversal = (
406+
self.env["account.move.reversal"]
407+
.with_context(active_model="account.move", active_ids=invoice.ids)
408+
.create(
409+
{
410+
"date": fields.Date.today(),
411+
"reason": "test section line",
412+
"journal_id": invoice.journal_id.id,
413+
}
414+
)
415+
)
416+
reversal = move_reversal.refund_moves()
417+
refund_invoice = self.env["account.move"].browse(reversal["res_id"])
418+
# This should NOT raise KeyError: 'quantity'
419+
groups = refund_invoice.lines_grouped_by_picking()
420+
self.assertTrue(groups)
421+
# Every group must have 'quantity' key (section/note dicts had 'qty')
422+
for group in groups:
423+
self.assertIn(
424+
"quantity",
425+
group,
426+
"All groups must have 'quantity' key for QWeb template",
427+
)
428+
# Render the report — this would crash with KeyError without the fix
429+
content = html.document_fromstring(
430+
self.env["ir.actions.report"]._render_qweb_html(
431+
"account.account_invoices", refund_invoice.id
432+
)[0]
433+
)
434+
self.assertIsNotNone(content)

0 commit comments

Comments
 (0)