Skip to content

Commit

Permalink
[FIX] account_invoice_report_grouped_by_picking: Method abs is called…
Browse files Browse the repository at this point in the history
… when remaining_qty is near of zero

Cherry-pick a38da1d
  • Loading branch information
carlosdauden committed Oct 18, 2024
1 parent b8b3da2 commit 6532bf1
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions account_invoice_report_grouped_by_picking/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# 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).
import datetime
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):
Expand Down Expand Up @@ -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."""
Expand All @@ -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(
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 6532bf1

Please sign in to comment.