diff --git a/account_invoice_section_sale_order/models/account_move.py b/account_invoice_section_sale_order/models/account_move.py index 80b54fc77c2..70b37d6e531 100644 --- a/account_invoice_section_sale_order/models/account_move.py +++ b/account_invoice_section_sale_order/models/account_move.py @@ -10,6 +10,15 @@ class AccountMove(models.Model): def _get_ordered_invoice_lines(self): """Sort invoice lines according to the section ordering""" + invoice_section_grouping = self.company_id.invoice_section_grouping + if invoice_section_grouping == "sale_order": + return self.invoice_line_ids.sorted( + key=lambda r: ( + f"{r.mapped('sale_line_ids.order_id.id')}" + f"{r.mapped('sale_line_ids.sequence')}" + f"{r.mapped('sale_line_ids.id')}" + ) + ) return self.invoice_line_ids.sorted( key=self.env["account.move.line"]._get_section_ordering() )