From c4c2d1d1d059699d603fdf3931002caf4123d6fa Mon Sep 17 00:00:00 2001 From: Jordi Ballester Alomar Date: Wed, 31 Jan 2024 13:16:27 +0100 Subject: [PATCH] [FIX] account_reconcile_oca: improve error messages and allow to reconcile with different partners Sometimes you may need to reconcile journal items where the partner is different. It's not a good practice but may need to be done in cases such as when an invoice and a payment are posted with two partners that are in reality the same company, or because you just need to reconcile to clean up. --- .../models/account_account_reconcile.py | 6 ++++-- .../models/account_move_line.py | 17 +++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/account_reconcile_oca/models/account_account_reconcile.py b/account_reconcile_oca/models/account_account_reconcile.py index e1877539..fe977dcc 100644 --- a/account_reconcile_oca/models/account_account_reconcile.py +++ b/account_reconcile_oca/models/account_account_reconcile.py @@ -33,8 +33,10 @@ class AccountAccountReconcile(models.Model): ) def _select(self): - account_account_name_field = self.env["ir.model.fields"].search( - [("model", "=", "account.account"), ("name", "=", "name")] + account_account_name_field = ( + self.env["ir.model.fields"] + .sudo() + .search([("model", "=", "account.account"), ("name", "=", "name")]) ) account_name = ( f"a.name ->> '{self.env.user.lang}'" diff --git a/account_reconcile_oca/models/account_move_line.py b/account_reconcile_oca/models/account_move_line.py index 2244b7d0..7362a983 100644 --- a/account_reconcile_oca/models/account_move_line.py +++ b/account_reconcile_oca/models/account_move_line.py @@ -12,21 +12,18 @@ class AccountMoveLine(models.Model): def action_reconcile_manually(self): if not self: return {} - self.mapped("account_id").ensure_one() - partner = self.mapped("partner_id") - if partner: - partner.ensure_one() - if self.filtered(lambda r: r.partner_id != partner): + accounts = self.mapped("account_id") + if len(accounts) > 1: raise ValidationError( - _("You must reconcile information on the same partner") + _("You can only reconcile journal items belonging to the same account.") ) + partner = self.mapped("partner_id") action = self.env["ir.actions.act_window"]._for_xml_id( "account_reconcile_oca.account_account_reconcile_act_window" ) - action["domain"] = [ - ("account_id", "=", self.mapped("account_id").id), - ("partner_id", "=", partner.id), - ] + action["domain"] = [("account_id", "=", self.mapped("account_id").id)] + if len(partner) == 1: + action["domain"] += [("partner_id", "=", partner.id)] action["context"] = self.env.context.copy() action["context"]["default_account_move_lines"] = self.filtered( lambda r: not r.reconciled