From 2e2bd930beec47bdbe568b2ae4e967d4868daa72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Sat, 16 Mar 2024 17:41:15 +0100 Subject: [PATCH] [IMP]pms: ensure partner payment and invoice in reconcile --- pms/models/account_move.py | 45 ++++++++++++++++++++++++++++++-------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/pms/models/account_move.py b/pms/models/account_move.py index 7ac3b0206..752aa6444 100644 --- a/pms/models/account_move.py +++ b/pms/models/account_move.py @@ -289,15 +289,7 @@ class AccountMove(models.Model): ) if to_reconcile: (pay_term_lines + to_reconcile).reconcile() - # Set partner in payment - for record in to_reconcile: - if record.payment_id and not record.payment_id.partner_id: - record.payment_id.partner_id = move.partner_id - if ( - record.statement_line_id - and not record.statement_line_id.partner_id - ): - record.statement_line_id.partner_id = move.partner_id + return True def _post(self, soft=True): @@ -310,6 +302,41 @@ class AccountMove(models.Model): self._autoreconcile_folio_payments() return res + def reconcile(self): + """ + Reconcile the account move + """ + res = super(AccountMove, self).reconcile() + # Update partner in payments and statement lines + for record in self: + if record.payment_id: + old_payment_partner = record.payment_id.partner_id + if old_payment_partner != record.partner_id: + record.payment_id.partner_id = record.partner_id + if old_payment_partner: + record.payment_id.message_post( + body=_( + f""" + Partner modify automatically from invoice {record.name}: + {old_payment_partner.name} to {record.partner_id.name} + """ + ) + ) + if record.statement_line_id: + old_statement_partner = record.statement_line_id.partner_id + if old_statement_partner != record.partner_id: + record.statement_line_id.partner_id = record.partner_id + if old_statement_partner: + record.statement_line_id.message_post( + body=_( + f""" + Partner modify automatically from invoice {record.name}: + {old_statement_partner.name} to {record.partner_id.name} + """ + ) + ) + return res + def match_pays_by_amount(self, payments, invoice): """ Match payments by amount