fix: update POS payment line matching and implement multi-currency support for payment registration in Odoo 19
This commit is contained in:
parent
fdafdefccd
commit
6330fd914c
@ -171,10 +171,10 @@ class PosSession(models.Model):
|
|||||||
lambda l: l.account_id == receivable_account and l.credit > 0
|
lambda l: l.account_id == receivable_account and l.credit > 0
|
||||||
)
|
)
|
||||||
# Find all matching debit lines in the session move
|
# 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(
|
pos_debit_lines = session.move_id.line_ids.filtered(
|
||||||
lambda l: l.account_id == receivable_account and l.debit > 0 and \
|
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:
|
if clearing_credit_line and pos_debit_lines:
|
||||||
|
|||||||
@ -40,6 +40,16 @@ class AccountPaymentRegister(models.TransientModel):
|
|||||||
# Debit: Payable Account (clears the vendor bill)
|
# Debit: Payable Account (clears the vendor bill)
|
||||||
# Credit: Inter-company (RK) Account (Liability to Parent)
|
# 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 = {
|
clearing_move_vals = {
|
||||||
'move_type': 'entry',
|
'move_type': 'entry',
|
||||||
'company_id': branch_company.id,
|
'company_id': branch_company.id,
|
||||||
@ -51,19 +61,19 @@ class AccountPaymentRegister(models.TransientModel):
|
|||||||
'name': _("Clearing: %s") % (", ".join(lines.move_id.mapped('name'))),
|
'name': _("Clearing: %s") % (", ".join(lines.move_id.mapped('name'))),
|
||||||
'partner_id': self.partner_id.id,
|
'partner_id': self.partner_id.id,
|
||||||
'account_id': lines[0].account_id.id, # The payable account
|
'account_id': lines[0].account_id.id, # The payable account
|
||||||
'debit': amount if self.payment_type == 'outbound' else 0.0,
|
'debit': amount_company_curr if self.payment_type == 'outbound' else 0.0,
|
||||||
'credit': amount if self.payment_type == 'inbound' else 0.0,
|
'credit': amount_company_curr if self.payment_type == 'inbound' else 0.0,
|
||||||
'currency_id': self.currency_id.id,
|
'currency_id': currency_id,
|
||||||
'amount_currency': amount if self.payment_type == 'outbound' else -amount,
|
'amount_currency': amount_currency if self.payment_type == 'outbound' else -amount_currency,
|
||||||
}),
|
}),
|
||||||
(0, 0, {
|
(0, 0, {
|
||||||
'name': _("Due to Parent (%s)") % parent_company.name,
|
'name': _("Due to Parent (%s)") % parent_company.name,
|
||||||
'partner_id': False,
|
'partner_id': False,
|
||||||
'account_id': journal.branch_intercompany_account_id.id,
|
'account_id': journal.branch_intercompany_account_id.id,
|
||||||
'debit': amount if self.payment_type == 'inbound' else 0.0,
|
'debit': amount_company_curr if self.payment_type == 'inbound' else 0.0,
|
||||||
'credit': amount if self.payment_type == 'outbound' else 0.0,
|
'credit': amount_company_curr if self.payment_type == 'outbound' else 0.0,
|
||||||
'currency_id': self.currency_id.id,
|
'currency_id': currency_id,
|
||||||
'amount_currency': -amount if self.payment_type == 'outbound' else amount,
|
'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,
|
'payment_type': self.payment_type,
|
||||||
'partner_type': self.partner_type,
|
'partner_type': self.partner_type,
|
||||||
'partner_id': self.partner_id.id,
|
'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,
|
'currency_id': self.currency_id.id,
|
||||||
'date': self.payment_date,
|
'date': self.payment_date,
|
||||||
'memo': _("Centralized Pay for %s (%s)") % (branch_company.name, ", ".join(lines.move_id.mapped('name'))),
|
'memo': _("Centralized Pay for %s (%s)") % (branch_company.name, ", ".join(lines.move_id.mapped('name'))),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user