From 6532bf1cae87c27a88ea5f28d7ebcb9a51d88113 Mon Sep 17 00:00:00 2001 From: Carlos Dauden Date: Thu, 17 Oct 2024 22:30:20 +0200 Subject: [PATCH] [FIX] account_invoice_report_grouped_by_picking: Method abs is called when remaining_qty is near of zero Cherry-pick a38da1de12fb7c2ab55213f68e9e2a93523de425 --- .../models/account_move.py | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/account_invoice_report_grouped_by_picking/models/account_move.py b/account_invoice_report_grouped_by_picking/models/account_move.py index 5e17ce690..f577a96bc 100644 --- a/account_invoice_report_grouped_by_picking/models/account_move.py +++ b/account_invoice_report_grouped_by_picking/models/account_move.py @@ -1,4 +1,4 @@ -# Copyright 2017-2023 Tecnativa - Carlos Dauden +# Copyright 2017-2024 Tecnativa - Carlos Dauden # Copyright 2018 Tecnativa - David Vidal # Copyright 2018-2019 Tecnativa - Pedro M. Baeza # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). @@ -6,7 +6,7 @@ from collections import OrderedDict from odoo import api, models -from odoo.tools import float_is_zero +from odoo.tools import float_round class AccountMove(models.Model): @@ -52,6 +52,11 @@ def _process_section_note_lines_grouped( if previous_note and key_note not in lines_dic: lines_dic[key_note] = 0.0 + def _get_grouped_by_picking_sorted_lines(self): + return self.invoice_line_ids.sorted( + lambda ln: (-ln.sequence, ln.date, ln.move_name, -ln.id), reverse=True + ) + def lines_grouped_by_picking(self): """This prepares a data structure for printing the invoice report grouped by pickings.""" @@ -76,9 +81,8 @@ def lines_grouped_by_picking(self): # Now group by picking by direct link or via same SO as picking's one previous_section = previous_note = False last_section_notes = [] - for line in self.invoice_line_ids.sorted( - lambda ln: (-ln.sequence, ln.date, ln.move_name, -ln.id), reverse=True - ): + sorted_lines = self._get_grouped_by_picking_sorted_lines() + for line in sorted_lines: if line.display_type == "line_section": previous_section = line last_section_notes.append( @@ -140,20 +144,20 @@ def lines_grouped_by_picking(self): remaining_qty -= qty # To avoid to print duplicate lines because the invoice is a refund # without returned goods to refund. + remaining_qty = float_round( + remaining_qty, precision_rounding=line.product_id.uom_id.rounding or 0.01 + ) if ( self.move_type == "out_refund" and not has_returned_qty - and picking_dict and remaining_qty and line.product_id.type != "service" + and picking_dict ): remaining_qty = 0.0 for key in picking_dict: picking_dict[key] = abs(picking_dict[key]) - if not float_is_zero( - remaining_qty, - precision_rounding=line.product_id.uom_id.rounding or 0.01, - ): + if remaining_qty: self._process_section_note_lines_grouped( previous_section, previous_note, lines_dict )