From 47ebf579fb376ba8f20f1ec764c7b50d508eb317 Mon Sep 17 00:00:00 2001 From: eLBati Date: Fri, 24 May 2024 15:05:16 +0200 Subject: [PATCH] FIX l10n_it_withholding_tax: wrong WT entry when paying multiple invoices --- l10n_it_withholding_tax/models/account.py | 17 +++++++++++++---- .../models/withholding_tax.py | 3 +++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/l10n_it_withholding_tax/models/account.py b/l10n_it_withholding_tax/models/account.py index c7464c8c329c..96226de8bd33 100644 --- a/l10n_it_withholding_tax/models/account.py +++ b/l10n_it_withholding_tax/models/account.py @@ -105,9 +105,15 @@ def create(self, vals_list): ld = self.env["account.move.line"].browse(vals.get("debit_move_id")) lc = self.env["account.move.line"].browse(vals.get("credit_move_id")) - move_ids = ld.move_id | lc.move_id + move_lines = ld | lc lines = self.env["account.move.line"].search( - [("withholding_tax_generated_by_move_id", "in", move_ids.ids)] + [ + ( + "withholding_tax_generated_by_move_line_id", + "in", + move_lines.ids, + ) + ] ) if lines: is_wt_move = True @@ -544,6 +550,9 @@ class AccountMoveLine(models.Model): withholding_tax_id = fields.Many2one("withholding.tax", string="Withholding Tax") withholding_tax_base = fields.Float() withholding_tax_amount = fields.Float() + withholding_tax_generated_by_move_line_id = fields.Many2one( + "account.move.line", string="Withholding Tax generated from", readonly=True + ) withholding_tax_generated_by_move_id = fields.Many2one( "account.move", string="Withholding Tax generated from", readonly=True ) @@ -555,9 +564,9 @@ def remove_move_reconcile(self): rec_move_ids = self.env["account.partial.reconcile"] domain = [ ( - "withholding_tax_generated_by_move_id", + "withholding_tax_generated_by_move_line_id", "=", - account_move_line.move_id.id, + account_move_line.id, ) ] wt_mls = self.env["account.move.line"].search(domain) diff --git a/l10n_it_withholding_tax/models/withholding_tax.py b/l10n_it_withholding_tax/models/withholding_tax.py index 8c88c1f63d01..37c6446b7329 100644 --- a/l10n_it_withholding_tax/models/withholding_tax.py +++ b/l10n_it_withholding_tax/models/withholding_tax.py @@ -397,6 +397,9 @@ def generate_account_move(self): ml_vals[ "withholding_tax_generated_by_move_id" ] = self.payment_line_id.move_id.id + ml_vals[ + "withholding_tax_generated_by_move_line_id" + ] = self.payment_line_id.id if self.payment_line_id.credit: ml_vals["credit"] = abs(self.amount) else: