[IMP]pms: ensure partner payment and invoice in reconcile

This commit is contained in:
Darío Lodeiros
2024-03-16 17:41:15 +01:00
parent 7b5397a820
commit 2e2bd930be

View File

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