From fabcf02c9d1b931fade45ba1404a7b5ada6bb69a 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 f46f07f536ed..e11c846da7c6 100644 --- a/l10n_it_withholding_tax/models/account.py +++ b/l10n_it_withholding_tax/models/account.py @@ -103,9 +103,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 @@ -542,6 +548,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 ) @@ -553,9 +562,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: