Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion account_invoice_report_grouped_by_picking/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Account Invoice Grouped by Picking",
"summary": "Print invoice lines grouped by picking",
"version": "19.0.1.0.0",
"version": "19.0.1.0.1",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please don't change manually the module version. It's done on merge.

"category": "Accounting & Finance",
"website": "https://github.com/OCA/account-invoice-reporting",
"author": "Tecnativa, Odoo Community Association (OCA)",
Expand Down
18 changes: 14 additions & 4 deletions account_invoice_report_grouped_by_picking/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ def _get_signed_quantity_done(self, invoice_line, move, sign):
account_invoice_report_grouped_by_picking_sale_mrp module
"""
if move.location_id.usage == "customer":
return -move.quantity * sign
if move.location_dest_id.usage == "customer":
return move.quantity * sign
return 0
qty = -move.quantity * sign
elif move.location_dest_id.usage == "customer":
qty = move.quantity * sign
else:
return 0
# move.quantity is in the move's (stock) UoM, but it is summed and
# subtracted against the invoice line quantity, which is in the invoice
# line UoM. Convert so both are in the same unit; otherwise the printed
# quantity is wrong and a bogus remainder line appears when they differ.
line_uom = invoice_line.product_uom_id
move_uom = move.product_uom
if qty and line_uom and move_uom and line_uom != move_uom:
qty = move_uom._compute_quantity(qty, line_uom, round=False)
return qty

def _process_section_note_lines_grouped(
self, previous_section, previous_note, lines_dic, pick_order=None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,61 @@ def test_account_invoice_group_picking(self):
self.assertTrue(self.sale.invoice_ids.picking_ids[:1].name in tbody)
self.assertTrue(self.sale2.invoice_ids.picking_ids[:1].name in tbody)

def test_account_invoice_group_picking_uom_conversion(self):
"""Grouped quantity is expressed in the invoice line UoM, not the stock
move UoM, and no bogus remainder line is produced when they differ."""
uom_unit = self.env.ref("uom.product_uom_unit")
uom_pack = self.env.ref("uom.product_uom_pack_6")
product_pack = self.env["product.product"].create(
{
"name": "Product sold per pack",
"invoice_policy": "delivery",
"uom_id": uom_unit.id,
"uom_ids": [(4, uom_unit.id), (4, uom_pack.id)],
}
)
sale = self.env["sale.order"].create(
{
"partner_id": self.partner.id,
"order_line": [
(
0,
0,
{
"name": product_pack.name,
"product_id": product_pack.id,
"product_uom_qty": 2,
"product_uom_id": uom_pack.id,
"price_unit": 100.0,
},
)
],
}
)
sale.action_confirm()
# The delivery moves are in units (12), the invoice line is in packs (2).
picking = sale.picking_ids[:1]
picking.action_confirm()
picking.move_line_ids.write({"quantity": 12})
wiz_act = picking.button_validate()
if isinstance(wiz_act, dict) and wiz_act.get("res_model"):
wiz = Form(
self.env[wiz_act["res_model"]].with_context(**wiz_act["context"])
).save()
wiz.process()
invoice = sale._create_invoices()
product_groups = [
group
for group in invoice.lines_grouped_by_picking()
if group["line"].product_id
]
# Exactly one group (one delivery), no phantom remainder line.
self.assertEqual(len(product_groups), 1)
group = product_groups[0]
self.assertEqual(group["picking"], picking)
self.assertEqual(group["line"].product_uom_id, uom_pack)
self.assertAlmostEqual(group["quantity"], 2.0)

def test_account_invoice_group_picking_return(self):
self.sale.action_confirm()
# deliver lines2
Expand Down
Loading