Skip to content
Snippets Groups Projects
Commit cf0ffeda authored by pedrambiria's avatar pedrambiria
Browse files

[FIX] point_of_sale: cash rounding combination of cash and bank


There were two cases that caused the issue:
Consider a cash rounding with Precision 5 and only cash.

If you have an order that the total amount is 40 and pay 38 by
bank and 0 with cash (cash rounding), it will raise an error.

If you have an order that the total amount is 41 and pay 38 by
the bank and 5 with cash, it will raise another error.

opw-3302114

closes odoo/odoo#121626

Signed-off-by: default avatarJoseph Caburnay (jcb) <jcb@odoo.com>
parent 06719a84
No related branches found
No related tags found
No related merge requests found
......@@ -527,7 +527,7 @@ class PosOrder(models.Model):
account_id = new_move.invoice_cash_rounding_id.profit_account_id.id
if rounding_line:
if rounding_line_difference:
rounding_line.with_context(check_move_validity=False).write({
rounding_line.with_context(skip_invoice_sync=True, check_move_validity=False).write({
'debit': rounding_applied < 0.0 and -rounding_applied or 0.0,
'credit': rounding_applied > 0.0 and rounding_applied or 0.0,
'account_id': account_id,
......@@ -535,19 +535,17 @@ class PosOrder(models.Model):
})
else:
self.env['account.move.line'].with_context(check_move_validity=False).create({
'debit': rounding_applied < 0.0 and -rounding_applied or 0.0,
'credit': rounding_applied > 0.0 and rounding_applied or 0.0,
self.env['account.move.line'].with_context(skip_invoice_sync=True, check_move_validity=False).create({
'balance': -rounding_applied,
'quantity': 1.0,
'amount_currency': rounding_applied,
'partner_id': new_move.partner_id.id,
'move_id': new_move.id,
'currency_id': new_move.currency_id if new_move.currency_id != new_move.company_id.currency_id else False,
'currency_id': new_move.currency_id.id,
'company_id': new_move.company_id.id,
'company_currency_id': new_move.company_id.currency_id.id,
'display_type': 'rounding',
'sequence': 9999,
'name': new_move.invoice_cash_rounding_id.name,
'name': self.config_id.rounding_method.name,
'account_id': account_id,
})
else:
......@@ -828,7 +826,7 @@ class PosOrder(models.Model):
new_move = order._create_invoice(move_vals)
order.write({'account_move': new_move.id, 'state': 'invoiced'})
new_move.sudo().with_company(order.company_id)._post()
new_move.sudo().with_company(order.company_id).with_context(skip_invoice_sync=True)._post()
moves += new_move
payment_moves = order._apply_invoice_payments()
......
......@@ -4,6 +4,7 @@ odoo.define('point_of_sale.tour.PaymentScreen', function (require) {
const { Chrome } = require('point_of_sale.tour.ChromeTourMethods');
const { ProductScreen } = require('point_of_sale.tour.ProductScreenTourMethods');
const { PaymentScreen } = require('point_of_sale.tour.PaymentScreenTourMethods');
const { ReceiptScreen } = require('point_of_sale.tour.ReceiptScreenTourMethods');
const { TicketScreen } = require('point_of_sale.tour.TicketScreenTourMethods');
const { getSteps, startSteps } = require('point_of_sale.tour.utils');
var Tour = require('web_tour.tour');
......@@ -189,6 +190,50 @@ odoo.define('point_of_sale.tour.PaymentScreen', function (require) {
startSteps();
ProductScreen.do.confirmOpeningPopup();
ProductScreen.do.clickHomeCategory();
ProductScreen.exec.addOrderline('Product Test 40', '1');
ProductScreen.do.clickPartnerButton();
ProductScreen.do.clickCustomer('Nicole Ford');
ProductScreen.do.clickPayButton();
PaymentScreen.check.totalIs('40.00');
PaymentScreen.do.clickPaymentMethod('Bank');
PaymentScreen.do.pressNumpad('3 8');
PaymentScreen.check.remainingIs('2.0');
PaymentScreen.do.clickPaymentMethod('Cash');
PaymentScreen.check.remainingIs('0.0');
PaymentScreen.check.changeIs('0.0');
PaymentScreen.do.clickInvoiceButton();
PaymentScreen.do.clickValidate();
ReceiptScreen.check.receiptIsThere();
ReceiptScreen.do.clickNextOrder();
ProductScreen.do.clickHomeCategory();
ProductScreen.exec.addOrderline('Product Test 41', '1');
ProductScreen.do.clickPartnerButton();
ProductScreen.do.clickCustomer('Nicole Ford');
ProductScreen.do.clickPayButton();
PaymentScreen.check.totalIs('41.00');
PaymentScreen.do.clickPaymentMethod('Bank');
PaymentScreen.do.pressNumpad('3 8');
PaymentScreen.check.remainingIs('3.0');
PaymentScreen.do.clickPaymentMethod('Cash');
PaymentScreen.check.remainingIs('0.0');
PaymentScreen.check.changeIs('0.0');
PaymentScreen.do.clickInvoiceButton();
PaymentScreen.do.clickValidate();
ReceiptScreen.check.receiptIsThere();
Tour.register('PaymentScreenRoundingHalfUpCashAndBank', { test: true, url: '/pos/ui' }, getSteps());
startSteps();
ProductScreen.do.confirmOpeningPopup();
ProductScreen.do.clickHomeCategory();
ProductScreen.exec.addOrderline('Product Test', '1');
......
......@@ -668,6 +668,49 @@ class TestUi(TestPointOfSaleHttpCommon):
self.main_pos_config.open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenRoundingHalfUp', login="accountman")
def test_rounding_half_up_cash_and_bank(self):
company = self.main_pos_config.company_id
rouding_method = self.env['account.cash.rounding'].create({
'name': 'Rounding HALF-UP',
'rounding': 5,
'rounding_method': 'HALF-UP',
'strategy': 'add_invoice_line',
'profit_account_id': company['default_cash_difference_income_account_id'].id,
'loss_account_id': company['default_cash_difference_expense_account_id'].id,
})
self.env['product.product'].create({
'name': 'Product Test 40',
'available_in_pos': True,
'list_price': 40,
'taxes_id': False,
})
self.env['product.product'].create({
'name': 'Product Test 41',
'available_in_pos': True,
'list_price': 41,
'taxes_id': False,
})
self.main_pos_config.write({
'rounding_method': rouding_method.id,
'cash_rounding': True,
'only_round_cash_method': True
})
self.main_pos_config.open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PaymentScreenRoundingHalfUpCashAndBank', login="accountman")
invoiced_orders = self.env['pos.order'].search([('state', '=', 'invoiced')])
self.assertEqual(len(invoiced_orders), 2, 'There should be 2 invoiced orders.')
for order in invoiced_orders:
rounding_line = order.account_move.line_ids.filtered(lambda line: line.display_type == 'rounding')
self.assertEqual(len(rounding_line), 1, 'There should be 1 rounding line.')
rounding_applied = order.amount_total - order.amount_paid
self.assertEqual(rounding_line.balance, rounding_applied, 'Rounding amount is incorrect!')
def test_pos_closing_cash_details(self):
"""Test if the cash closing details correctly show the cash difference
if there is a difference at the opening of the PoS session. This also test if the accounting
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment