fix: update outstanding account logic for Odoo 19 compatibility
This commit is contained in:
parent
407ebba230
commit
82a6e39adc
@ -143,7 +143,10 @@ class AccountPayment(models.Model):
|
|||||||
# This module creates additional lines that don't fit the standard pattern
|
# This module creates additional lines that don't fit the standard pattern
|
||||||
has_substract = hasattr(pay, 'amount_substract') and pay.amount_substract and pay.amount_substract > 0
|
has_substract = hasattr(pay, 'amount_substract') and pay.amount_substract and pay.amount_substract > 0
|
||||||
|
|
||||||
if not has_substract:
|
# POS Combination Payments can have multiple liquidity lines
|
||||||
|
is_pos_payment = pay._context.get('pos_payment')
|
||||||
|
|
||||||
|
if not has_substract and not is_pos_payment:
|
||||||
if len(liquidity_lines) != 1:
|
if len(liquidity_lines) != 1:
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"Journal Entry %s is not valid. In order to proceed, the journal items must "
|
"Journal Entry %s is not valid. In order to proceed, the journal items must "
|
||||||
@ -175,24 +178,34 @@ class AccountPayment(models.Model):
|
|||||||
move.display_name,
|
move.display_name,
|
||||||
))
|
))
|
||||||
|
|
||||||
if counterpart_lines.account_id.account_type == 'asset_receivable':
|
if counterpart_lines:
|
||||||
partner_type = 'customer'
|
account_type = counterpart_lines[0].account_id.account_type
|
||||||
|
if account_type == 'asset_receivable':
|
||||||
|
partner_type = 'customer'
|
||||||
|
elif account_type == 'liability_payable':
|
||||||
|
partner_type = 'supplier'
|
||||||
|
else:
|
||||||
|
partner_type = 'customer' if pay.payment_type == 'inbound' else 'supplier'
|
||||||
else:
|
else:
|
||||||
partner_type = 'supplier'
|
partner_type = 'customer' if pay.payment_type == 'inbound' else 'supplier'
|
||||||
|
|
||||||
liquidity_amount = liquidity_lines.amount_currency
|
liquidity_amount = sum(liquidity_lines.mapped('amount_currency')) if len(liquidity_lines) > 1 else liquidity_lines.amount_currency
|
||||||
|
|
||||||
move_vals_to_write.update({
|
# Use the first line for currency and partner if multiple
|
||||||
'currency_id': liquidity_lines.currency_id.id,
|
first_liquidity_line = liquidity_lines[0] if len(liquidity_lines) > 0 else liquidity_lines
|
||||||
'partner_id': liquidity_lines.partner_id.id,
|
|
||||||
})
|
if first_liquidity_line:
|
||||||
payment_vals_to_write.update({
|
move_vals_to_write.update({
|
||||||
'amount': abs(liquidity_amount),
|
'currency_id': first_liquidity_line.currency_id.id,
|
||||||
'partner_type': partner_type,
|
'partner_id': first_liquidity_line.partner_id.id,
|
||||||
'currency_id': liquidity_lines.currency_id.id,
|
})
|
||||||
'destination_account_id': counterpart_lines.account_id.id,
|
payment_vals_to_write.update({
|
||||||
'partner_id': liquidity_lines.partner_id.id,
|
'amount': abs(liquidity_amount),
|
||||||
})
|
'partner_type': partner_type,
|
||||||
|
'currency_id': first_liquidity_line.currency_id.id,
|
||||||
|
'destination_account_id': counterpart_lines[0].account_id.id if counterpart_lines else False,
|
||||||
|
'partner_id': first_liquidity_line.partner_id.id,
|
||||||
|
})
|
||||||
if liquidity_amount > 0.0:
|
if liquidity_amount > 0.0:
|
||||||
payment_vals_to_write.update({'payment_type': 'inbound'})
|
payment_vals_to_write.update({'payment_type': 'inbound'})
|
||||||
elif liquidity_amount < 0.0:
|
elif liquidity_amount < 0.0:
|
||||||
@ -213,7 +226,21 @@ class AccountPayment(models.Model):
|
|||||||
pay.outstanding_account_id = pay.journal_id.default_account_id
|
pay.outstanding_account_id = pay.journal_id.default_account_id
|
||||||
else:
|
else:
|
||||||
# Fallback to the original logic if no default account is set
|
# Fallback to the original logic if no default account is set
|
||||||
pay.outstanding_account_id = pay._get_outstanding_account(pay.payment_type)
|
if pay.payment_type == 'inbound':
|
||||||
|
pay.outstanding_account_id = (pay.payment_method_line_id.payment_account_id
|
||||||
|
or pay.journal_id.default_account_id)
|
||||||
|
elif pay.payment_type == 'outbound':
|
||||||
|
pay.outstanding_account_id = (pay.payment_method_line_id.payment_account_id
|
||||||
|
or pay.journal_id.default_account_id)
|
||||||
|
else:
|
||||||
|
pay.outstanding_account_id = False
|
||||||
else:
|
else:
|
||||||
# For bank/cash journals, use the original logic
|
# For bank/cash journals, use the original logic
|
||||||
pay.outstanding_account_id = pay._get_outstanding_account(pay.payment_type)
|
if pay.payment_type == 'inbound':
|
||||||
|
pay.outstanding_account_id = (pay.payment_method_line_id.payment_account_id
|
||||||
|
or pay.journal_id.default_account_id)
|
||||||
|
elif pay.payment_type == 'outbound':
|
||||||
|
pay.outstanding_account_id = (pay.payment_method_line_id.payment_account_id
|
||||||
|
or pay.journal_id.default_account_id)
|
||||||
|
else:
|
||||||
|
pay.outstanding_account_id = False
|
||||||
Loading…
Reference in New Issue
Block a user