From eb84a309992cb6545180294ab51f51d7eefbafc3 Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Wed, 11 Apr 2018 12:56:57 -0700 Subject: [PATCH] [FIX] pos_mercury: don't lose credit card info Due to historical reasons the amount on a statement line is used to find it again so the credit card information can be added to it. Doing a search directly on 'amount' will fail in rare cases when the currency rounding doesn't result in a float with the same amount of decimals as the rounding specifies. E.g.: >>> currency = env['res.currency'].browse(3) >>> currency.rounding 0.01 >>> currency.round(74.85000000000001) 74.85000000000001 When that happens the credit card information is not saved in the backend. To avoid this we do the float comparison properly with float_compare afterwards. PS. Ideally the logic in add_payment should be moved to an override of _prepare_bank_statement_line_payment_values. This way we wouldn't have to do these awkward things to find the statement line. But this approach is not suited for a stable release. opw-1832156 --- addons/pos_mercury/models/pos_mercury.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/pos_mercury/models/pos_mercury.py b/addons/pos_mercury/models/pos_mercury.py index 707f85692e0..6af9d437af9 100644 --- a/addons/pos_mercury/models/pos_mercury.py +++ b/addons/pos_mercury/models/pos_mercury.py @@ -4,6 +4,7 @@ import logging from odoo import models, fields, api, _ +from odoo.tools.float_utils import float_compare _logger = logging.getLogger(__name__) @@ -71,8 +72,9 @@ class PosOrder(models.Model): statement_id = super(PosOrder, self).add_payment(data) statement_lines = self.env['account.bank.statement.line'].search([('statement_id', '=', statement_id), ('pos_statement_id', '=', self.id), - ('journal_id', '=', data['journal']), - ('amount', '=', data['amount'])]) + ('journal_id', '=', data['journal'])]) + statement_lines = statement_lines.filtered(lambda line: float_compare(line.amount, data['amount'], + precision_rounding=line.journal_currency_id.rounding) == 0) # we can get multiple statement_lines when there are >1 credit # card payments with the same amount. In that case it doesn't