[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.
pull/630/head
Jordi Ballester Alomar 2024-01-31 13:16:27 +01:00 committed by Enric Tobella
parent 88620ee169
commit 7f6fb6f3aa
2 changed files with 11 additions and 12 deletions

View File

@ -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}'"

View File

@ -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