From efc828fb4e87cf43a79b5c9d60d548c47ab055d9 Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Tue, 29 Nov 2022 14:25:19 +0100 Subject: [PATCH] [FIX] rma_purchase: Reconcile the interim accounts when vendor bill is posted --- rma_purchase/models/account_move.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/rma_purchase/models/account_move.py b/rma_purchase/models/account_move.py index e43c6a15..77f9d00e 100644 --- a/rma_purchase/models/account_move.py +++ b/rma_purchase/models/account_move.py @@ -11,3 +11,31 @@ class AccountMove(models.Model): data = super(AccountMove, self)._prepare_invoice_line_from_rma_line(line) data["purchase_line_id"]: line.id return data + + def action_post(self): + res = super(AccountMove, self).action_post() + for move in self: + rma_mls = move.line_ids.filtered(lambda l: l.rma_line_id) + if rma_mls: + # Try to reconcile the interim accounts for RMA lines + rmas = rma_mls.mapped("rma_line_id") + for rma in rmas: + product_accounts = ( + rma.product_id.product_tmpl_id._get_product_accounts() + ) + if rma.type == "customer": + product_interim_account = product_accounts["stock_output"] + else: + product_interim_account = product_accounts["stock_input"] + if product_interim_account.reconcile: + # Get the in and out moves + amls = self.env["account.move.line"].search( + [ + ("rma_line_id", "=", rma.id), + ("account_id", "=", product_interim_account.id), + ("parent_state", "=", "posted"), + ("reconciled", "=", False), + ] + ) + amls.reconcile() + return res