Skip to content

Commit cdad436

Browse files
committed
[FIX] point_of_sale: fix accounting entries
When a payment difference was created in the PoS, it was introducing errors in the accounting entries. Steps to reproduce: ------------------- * Make sure bank payment method has an outstanding account * Open PoS and make a sale paid by bank for 100$ * Close the session and introduce a payment difference of -10$ * Check the accounting entries created for the PoS session > Observation: The difference is correctly recorded but the payment appears as a payment of 90$ instead of 100$. Why the fix: ------------ We revert this fix (odoo#196253) that was wrongly modifying the payment amount to fix the session report. opw-4723227 closes odoo#219684 X-original-commit: d97cdc5 Signed-off-by: Adrien Guilliams (adgu) <adgu@odoo.com> Signed-off-by: Robin Engels (roen) <roen@odoo.com>
1 parent 1ebe578 commit cdad436

2 files changed

Lines changed: 61 additions & 4 deletions

File tree

addons/point_of_sale/models/pos_session.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -689,10 +689,10 @@ def _create_diff_account_move_for_split_payment_method(self, payment_method, dif
689689
def _get_diff_account_move_ref(self, payment_method):
690690
return _('Closing difference in %(payment_method)s (%(session)s)', payment_method=payment_method.name, session=self.name)
691691

692-
def _get_diff_vals(self, payment_method_id, diff_amount):
692+
def _get_diff_vals(self, payment_method_id, diff_amount, outstanding_account=False):
693693
payment_method = self.env['pos.payment.method'].browse(payment_method_id)
694694
diff_compare_to_zero = self.currency_id.compare_amounts(diff_amount, 0)
695-
source_account = payment_method.outstanding_account_id
695+
source_account = payment_method.outstanding_account_id or outstanding_account
696696
destination_account = self.env['account.account']
697697

698698
if (diff_compare_to_zero > 0):
@@ -1141,7 +1141,7 @@ def _create_combine_account_payment(self, payment_method, amounts, diff_amount):
11411141
destination_account = self._get_receivable_account(payment_method)
11421142

11431143
account_payment = self.env['account.payment'].with_context(pos_payment=True).create({
1144-
'amount': abs(amounts['amount']) + diff_amount,
1144+
'amount': abs(amounts['amount']),
11451145
'journal_id': payment_method.journal_id.id,
11461146
'force_outstanding_account_id': outstanding_account.id,
11471147
'destination_account_id': destination_account.id,
@@ -1173,7 +1173,7 @@ def _create_combine_account_payment(self, payment_method, amounts, diff_amount):
11731173
return account_payment.move_id.line_ids.filtered(lambda line: line.account_id == self._get_receivable_account(payment_method))
11741174

11751175
def _apply_diff_on_account_payment_move(self, account_payment, payment_method, diff_amount):
1176-
diff_vals = self._get_diff_vals(payment_method.id, diff_amount)
1176+
diff_vals = self._get_diff_vals(payment_method.id, diff_amount, account_payment.outstanding_account_id)
11771177
if not diff_vals:
11781178
return
11791179
source_vals, dest_vals = diff_vals
@@ -1190,6 +1190,9 @@ def _apply_diff_on_account_payment_move(self, account_payment, payment_method, d
11901190
})
11911191
]
11921192
})
1193+
account_payment.write({
1194+
'amount': abs(new_balance),
1195+
})
11931196
account_payment.move_id.action_post()
11941197

11951198
def _create_split_account_payment(self, payment, amounts):

addons/point_of_sale/tests/test_point_of_sale_flow.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,3 +2446,57 @@ def test_sum_only_pos_locations(self):
24462446
self.assertEqual(len(result), 1, "Should return exactly one lot")
24472447
self.assertEqual(result[0]['name'], 'TEST_LOT')
24482448
self.assertEqual(result[0]['product_qty'], 15.0, "Should sum only quantities from POS source locations")
2449+
2450+
def test_payment_difference_accounting_items(self):
2451+
"""Verify that the amount of the accounting items are correct when closing a session with a payment difference."""
2452+
self.product1 = self.env['product.product'].create({
2453+
'name': 'Test Product',
2454+
'lst_price': 100,
2455+
})
2456+
# Make a sale paid by bank
2457+
self.pos_config.open_ui()
2458+
session_id = self.pos_config.current_session_id
2459+
order = self.env['pos.order'].create({
2460+
'company_id': self.env.company.id,
2461+
'session_id': session_id.id,
2462+
'partner_id': False,
2463+
'lines': [Command.create({
2464+
'name': 'OL/0001',
2465+
'product_id': self.product1.id,
2466+
'price_unit': 100.00,
2467+
'discount': 0,
2468+
'qty': 1,
2469+
'tax_ids': False,
2470+
'price_subtotal': 100.00,
2471+
'price_subtotal_incl': 100.00,
2472+
})],
2473+
'pricelist_id': self.pos_config.pricelist_id.id,
2474+
'amount_paid': 100.00,
2475+
'amount_total': 100.00,
2476+
'amount_tax': 0.0,
2477+
'amount_return': 0.0,
2478+
'to_invoice': False,
2479+
})
2480+
2481+
# Make payment
2482+
payment_context = {"active_ids": order.ids, "active_id": order.id}
2483+
order_payment = self.env['pos.make.payment'].with_context(**payment_context).create({
2484+
'amount': order.amount_total,
2485+
'payment_method_id': self.bank_payment_method.id
2486+
})
2487+
order_payment.with_context(**payment_context).check()
2488+
2489+
session_id.action_pos_session_closing_control(bank_payment_method_diffs={self.bank_payment_method.id: -10.00})
2490+
self.bank_payment_move = session_id._get_related_account_moves().filtered(lambda move: 'Combine Bank' in move.ref)
2491+
self.assertRecordValues(self.bank_payment_move.line_ids.sorted('balance'), [{
2492+
'balance': -100.0,
2493+
'account_id': self.bank_payment_method.receivable_account_id.id,
2494+
},
2495+
{
2496+
'balance': 10.0,
2497+
'account_id': self.bank_payment_method.journal_id.loss_account_id.id,
2498+
},
2499+
{
2500+
'balance': 90.0,
2501+
'account_id': self.bank_payment_move.payment_ids.outstanding_account_id.id,
2502+
}])

0 commit comments

Comments
 (0)