[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
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user