From 6470ee74b8cae9c62a47118850533e9a8e8301ac Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Tue, 7 Aug 2018 10:36:26 +0200 Subject: [FIX] point_of_sale: return with rounding < 0.01 - Set the currency to a rounding of 0.001 - Create a POS order: Unit Price: 0.12 Quantity: 0.1 - Pay and validate - From the backend, return the products on the create order - Click on 'Payment' The proposed amount is 0.01, not 0.012. It is not possible to complete the payment process since the field is rounded at DB level to 2 digits of precision. We make consistent the `amount` field with the various amounts on the `pos.order`. By using a `digits=0` and forcing the rounding, we avoid inconsistent rounding between the order and the payment. opw-1864344 --- addons/point_of_sale/wizard/pos_payment.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/point_of_sale/wizard/pos_payment.py b/addons/point_of_sale/wizard/pos_payment.py index e4b494badde..a2578ffef9c 100644 --- a/addons/point_of_sale/wizard/pos_payment.py +++ b/addons/point_of_sale/wizard/pos_payment.py @@ -2,6 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import api, fields, models, _ +from odoo.tools import float_is_zero class PosMakePayment(models.TransientModel): @@ -30,7 +31,7 @@ class PosMakePayment(models.TransientModel): session_id = fields.Many2one('pos.session', required=True, default=_default_session) journal_id = fields.Many2one('account.journal', string='Payment Mode', required=True, default=_default_journal) - amount = fields.Float(digits=(16, 2), required=True, default=_default_amount) + amount = fields.Float(digits=0, required=True, default=_default_amount) payment_name = fields.Char(string='Payment Reference') payment_date = fields.Date(string='Payment Date', required=True, default=lambda *a: fields.Datetime.now()) @@ -49,11 +50,13 @@ class PosMakePayment(models.TransientModel): """ self.ensure_one() order = self.env['pos.order'].browse(self.env.context.get('active_id', False)) + currency = order.pricelist_id.currency_id amount = order.amount_total - order.amount_paid data = self.read()[0] # add_payment expect a journal key data['journal'] = data['journal_id'][0] - if amount != 0.0: + data['amount'] = currency.round(data['amount']) if currency else data['amount'] + if not float_is_zero(amount, precision_rounding=currency.rounding or 0.01): order.add_payment(data) if order.test_paid(): order.action_pos_order_paid() -- cgit v1.2.3