From 566d55253f315d4fe9ca65c43208f55fe43adae8 Mon Sep 17 00:00:00 2001 From: LorenzoC0 Date: Fri, 6 Sep 2024 17:03:25 +0200 Subject: [PATCH] [FIX] 1l10n_it_intrastat_statement: Fixed grouping of intrastat lines if a reversed entry is not in the same period of the line --- .../models/intrastat_statement.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/l10n_it_intrastat_statement/models/intrastat_statement.py b/l10n_it_intrastat_statement/models/intrastat_statement.py index 4186ee6762ce..bd503f5ebdbb 100644 --- a/l10n_it_intrastat_statement/models/intrastat_statement.py +++ b/l10n_it_intrastat_statement/models/intrastat_statement.py @@ -809,6 +809,10 @@ def compute_statement(self): (2, 1), # Sale (Purchase) section 2 refunds section 1 (4, 3), # Sale (Purchase) section 4 refunds section 3 ] + + period_date_start = fields.Date.to_date(period_date_start) + period_date_stop = fields.Date.to_date(period_date_stop) + for section_type in ["purchase", "sale"]: for section_number, refund_section_number in refund_map: section_details = (section_type, section_number) @@ -819,7 +823,14 @@ def compute_statement(self): *refund_section_details ) to_refund_model = self.env[refund_section_model] - self.refund_line(line, to_refund_model) + if not ( + line.invoice_id.reversed_entry_id + and ( + line.invoice_id.reversed_entry_id.date < period_date_start + or line.invoice_id.reversed_entry_id.date > period_date_stop + ) + ): + self.refund_line(line, to_refund_model) return True @staticmethod