From 231dc66f0f617247599219420bb1df3eebc0ad47 Mon Sep 17 00:00:00 2001 From: Joseph Caburnay Date: Tue, 16 Nov 2021 13:16:11 +0000 Subject: [PATCH] [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 --- addons/point_of_sale/models/pos_session.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 0d093ab9f0e..88de5607bcb 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -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,