From 6330fd914ca6cbf08b7ece91150fed45e4d5160a Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Tue, 5 May 2026 20:10:23 +0700 Subject: [PATCH] fix: update POS payment line matching and implement multi-currency support for payment registration in Odoo 19 --- models/pos_session.py | 4 ++-- wizard/account_payment_register.py | 28 +++++++++++++++++++--------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/models/pos_session.py b/models/pos_session.py index afc95c3..4f83f9f 100644 --- a/models/pos_session.py +++ b/models/pos_session.py @@ -171,10 +171,10 @@ class PosSession(models.Model): lambda l: l.account_id == receivable_account and l.credit > 0 ) # Find all matching debit lines in the session move - pm_names = [pm.name for pm in pms] + # Odoo 19 names these lines as "SessionName - PMName" pos_debit_lines = session.move_id.line_ids.filtered( lambda l: l.account_id == receivable_account and l.debit > 0 and \ - any(name in l.name for name in pm_names) + any(l.name.endswith(f" - {pm.name}") for pm in pms) ) if clearing_credit_line and pos_debit_lines: diff --git a/wizard/account_payment_register.py b/wizard/account_payment_register.py index 60fff79..87f2699 100644 --- a/wizard/account_payment_register.py +++ b/wizard/account_payment_register.py @@ -40,6 +40,16 @@ class AccountPaymentRegister(models.TransientModel): # Debit: Payable Account (clears the vendor bill) # Credit: Inter-company (RK) Account (Liability to Parent) + # Currency logic: Odoo 19 requires debit/credit in company currency + # and amount_currency in foreign currency. + amount_company_curr = abs(sum(lines.mapped('amount_residual'))) + amount_currency = 0.0 + currency_id = False + + if self.currency_id != branch_company.currency_id: + amount_currency = sum(lines.mapped('amount_residual_currency')) + currency_id = self.currency_id.id + clearing_move_vals = { 'move_type': 'entry', 'company_id': branch_company.id, @@ -51,19 +61,19 @@ class AccountPaymentRegister(models.TransientModel): 'name': _("Clearing: %s") % (", ".join(lines.move_id.mapped('name'))), 'partner_id': self.partner_id.id, 'account_id': lines[0].account_id.id, # The payable account - 'debit': amount if self.payment_type == 'outbound' else 0.0, - 'credit': amount if self.payment_type == 'inbound' else 0.0, - 'currency_id': self.currency_id.id, - 'amount_currency': amount if self.payment_type == 'outbound' else -amount, + 'debit': amount_company_curr if self.payment_type == 'outbound' else 0.0, + 'credit': amount_company_curr if self.payment_type == 'inbound' else 0.0, + 'currency_id': currency_id, + 'amount_currency': amount_currency if self.payment_type == 'outbound' else -amount_currency, }), (0, 0, { 'name': _("Due to Parent (%s)") % parent_company.name, 'partner_id': False, 'account_id': journal.branch_intercompany_account_id.id, - 'debit': amount if self.payment_type == 'inbound' else 0.0, - 'credit': amount if self.payment_type == 'outbound' else 0.0, - 'currency_id': self.currency_id.id, - 'amount_currency': -amount if self.payment_type == 'outbound' else amount, + 'debit': amount_company_curr if self.payment_type == 'inbound' else 0.0, + 'credit': amount_company_curr if self.payment_type == 'outbound' else 0.0, + 'currency_id': currency_id, + 'amount_currency': -amount_currency if self.payment_type == 'outbound' else amount_currency, }), ], } @@ -83,7 +93,7 @@ class AccountPaymentRegister(models.TransientModel): 'payment_type': self.payment_type, 'partner_type': self.partner_type, 'partner_id': self.partner_id.id, - 'amount': amount, + 'amount': abs(amount_currency) if currency_id else amount_company_curr, 'currency_id': self.currency_id.id, 'date': self.payment_date, 'memo': _("Centralized Pay for %s (%s)") % (branch_company.name, ", ".join(lines.move_id.mapped('name'))),