Skip to content

Commit

Permalink
[FIX] point_of_sale: use correct amount for pos order reversal
Browse files Browse the repository at this point in the history
When you are using a different currency in a PoS config, invoicing
a POS order that was created in a previous session, causes an
unbalanced entry error. Because the amount_currency and balance of
the payment moves are incorrect.

Steps to reproduce:

- Create POS config with currency other than company currency
- Create order in a session
- Close the session
- Open a new session
- Load paid orders
- Try to invoice the created order

opw-3479292

closes odoo#136294

X-original-commit: 17a8b70
Signed-off-by: Joseph Caburnay (jcb) <[email protected]>
Signed-off-by: Pedram Bi Ria (pebr) <[email protected]>
  • Loading branch information
pedrambiria committed Sep 22, 2023
1 parent 2c377f4 commit d2e771b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions addons/point_of_sale/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,8 +809,8 @@ def _prepare_aml_values_list_per_nature(self):
'name': f"{reversed_move_receivable_account_id.code} {reversed_move_receivable_account_id.code}",
'account_id': reversed_move_receivable_account_id.id,
'currency_id': self.currency_id.id,
'amount_currency': self.session_id._amount_converter(payment_id.amount, self.date_order, False),
'balance': payment_id.amount,
'amount_currency': payment_id.amount,
'balance': self.session_id._amount_converter(payment_id.amount, self.date_order, False),
})

return aml_vals_list_per_nature
Expand Down
25 changes: 23 additions & 2 deletions addons/point_of_sale/tests/test_point_of_sale_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import time
from freezegun import freeze_time
from datetime import datetime

import odoo
from odoo import fields, tools
Expand Down Expand Up @@ -1548,6 +1549,24 @@ def test_invoicing_after_closing_session(self):
self.pos_config.write({
'payment_method_ids': [(4, self.customer_account_payment_method.id, 0)],
})
# change the currency of PoS config
(self.currency_data['currency'].rate_ids | self.company.currency_id.rate_ids).unlink()
self.env['res.currency.rate'].create({
'rate': 0.5,
'currency_id': self.currency_data['currency'].id,
'name': datetime.today().date(),
})
self.pos_config.journal_id.write({
'currency_id': self.currency_data['currency'].id
})
other_pricelist = self.env['product.pricelist'].create({
'name': 'Public Pricelist Other',
'currency_id': self.currency_data['currency'].id,
})
self.pos_config.write({
'pricelist_id': other_pricelist.id,
'available_pricelist_ids': [(6, 0, other_pricelist.ids)],
})
self.pos_config.open_ui()
current_session = self.pos_config.current_session_id

Expand Down Expand Up @@ -1603,8 +1622,10 @@ def test_invoicing_after_closing_session(self):
#check that both use the same account
self.assertEqual(len(reverser_customer_payment_entry), 2)
self.assertTrue(order.account_move.line_ids.partner_id == self.partner1.commercial_partner_id)
self.assertEqual(reverser_customer_payment_entry[0].balance, -2.0)
self.assertEqual(reverser_customer_payment_entry[1].balance, -4.0)
self.assertEqual(reverser_customer_payment_entry[0].balance, -4.0)
self.assertEqual(reverser_customer_payment_entry[1].balance, -8.0)
self.assertEqual(reverser_customer_payment_entry[0].amount_currency, -2.0)
self.assertEqual(reverser_customer_payment_entry[1].amount_currency, -4.0)
self.assertEqual(original_customer_payment_entry.account_id.id, reverser_customer_payment_entry.account_id.id)
self.assertEqual(reverser_customer_payment_entry.partner_id, original_customer_payment_entry.partner_id)

Expand Down

0 comments on commit d2e771b

Please sign in to comment.