[FIX] point_of_sale: can't close session when negative split payment
To reproduce: 1. Create Bank payment method with Identify Customer = True 2. Make order, use the bank payment method in 1. 3. Refund the order, again, use the bank payment method in 1. 4. Try to close the session. Error. This is because the account.payment object being creating has negative amount. We fix this issue in this commit by explicitly providing the destination account based on the partner, and reverting the destination and outstanding accounts when the payment amount is negative. closes odoo/odoo#79966 X-original-commit: e6f1b3893ab33d3d3ddf73e31e4e2ad13f0f2681 Related: odoo/enterprise#22323 Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
@@ -937,11 +937,19 @@ class PosSession(models.Model):
|
||||
if not payment_method.journal_id:
|
||||
return self.env['account.move.line']
|
||||
outstanding_account = payment_method.outstanding_account_id or self.company_id.account_journal_payment_debit_account_id
|
||||
accounting_partner = self.env["res.partner"]._find_accounting_partner(payment.partner_id)
|
||||
destination_account = accounting_partner.property_account_receivable_id
|
||||
|
||||
if float_compare(amounts['amount'], 0, precision_rounding=self.currency_id.rounding) < 0:
|
||||
# revert the accounts because account.payment doesn't accept negative amount.
|
||||
outstanding_account, destination_account = destination_account, outstanding_account
|
||||
|
||||
account_payment = self.env['account.payment'].create({
|
||||
'amount': amounts['amount'],
|
||||
'amount': abs(amounts['amount']),
|
||||
'partner_id': payment.partner_id.id,
|
||||
'journal_id': payment_method.journal_id.id,
|
||||
'force_outstanding_account_id': outstanding_account.id,
|
||||
'destination_account_id': destination_account.id,
|
||||
'ref': _('%s POS payment of %s in %s') % (payment_method.name, payment.partner_id.display_name, self.name),
|
||||
'pos_payment_method_id': payment_method.id,
|
||||
'pos_session_id': self.id,
|
||||
|
||||
Reference in New Issue
Block a user