[FIX] payment_mercado_pago: forbid float amounts for currencies w/o minor unit

The Chilean Peso and Colombian Peso don't have a minor unit. MercadoPago
requires amounts be expressed as integers. Failing to send such amounts
as integers results in an error.

opw-3292798

closes odoo/odoo#138859

X-original-commit: 75fa1e55207050e57b8b912b5e0607c8a3e31515
Signed-off-by: Antoine Vandevenne (anv) <anv@odoo.com>
This commit is contained in:
Horacio Tellez (hote)
2023-10-18 16:52:01 +00:00
committed by Antoine Vandevenne (anv)
parent 9b776f59f0
commit dff6a0fe55
2 changed files with 124 additions and 2 deletions
@@ -0,0 +1,109 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * payment_mercado_pago
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server saas~16.4\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-07-25 11:23+0000\n"
"PO-Revision-Date: 2023-07-25 11:23+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: payment_mercado_pago
#: model_terms:ir.ui.view,arch_db:payment_mercado_pago.payment_provider_form
msgid "Access Token"
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model.fields,field_description:payment_mercado_pago.field_payment_provider__code
msgid "Code"
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_provider.py:0
#, python-format
msgid "Could not establish the connection to the API."
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model.fields.selection,name:payment_mercado_pago.selection__payment_provider__code__mercado_pago
msgid "Mercado Pago"
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model.fields,field_description:payment_mercado_pago.field_payment_provider__mercado_pago_access_token
msgid "Mercado Pago Access Token"
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "No transaction found matching reference %s."
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model,name:payment_mercado_pago.model_payment_provider
msgid "Payment Provider"
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model,name:payment_mercado_pago.model_payment_transaction
msgid "Payment Transaction"
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "Prices in the currency %s must be expressed in integer values."
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "Received data with invalid status: %s"
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "Received data with missing payment id."
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "Received data with missing reference."
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_transaction.py:0
#, python-format
msgid "Received data with missing status."
msgstr ""
#. module: payment_mercado_pago
#. odoo-python
#: code:addons/payment_mercado_pago/models/payment_provider.py:0
#, python-format
msgid ""
"The communication with the API failed. Mercado Pago gave us the following "
"information: '%s' (code %s)"
msgstr ""
#. module: payment_mercado_pago
#: model:ir.model.fields,help:payment_mercado_pago.field_payment_provider__code
msgid "The technical code of this payment provider."
msgstr ""
@@ -6,7 +6,7 @@ import pprint
from werkzeug import urls
from odoo import _, models
from odoo.exceptions import ValidationError
from odoo.exceptions import UserError, ValidationError
from odoo.addons.payment_mercado_pago import const
from odoo.addons.payment_mercado_pago.controllers.main import MercadoPagoController
@@ -61,6 +61,19 @@ class PaymentTransaction(models.Model):
webhook_url = urls.url_join(
base_url, f'{MercadoPagoController._webhook_url}/{self.reference}'
) # Append the reference to identify the transaction from the webhook notification data.
# In the case where we are issuing a preference request in CLP or COP, we must ensure that
# the price unit is an integer because these currencies do not have a minor unit.
unit_price = self.amount
if self.currency_id.name in ('CLP', 'COP'):
rounded_unit_price = int(self.amount)
if rounded_unit_price != self.amount:
raise UserError(_(
"Prices in the currency %s must be expressed in integer values.",
self.currency_id.name,
))
unit_price = rounded_unit_price
return {
'auto_return': 'all',
'back_urls': {
@@ -73,7 +86,7 @@ class PaymentTransaction(models.Model):
'title': self.reference,
'quantity': 1,
'currency_id': self.currency_id.name,
'unit_price': self.amount,
'unit_price': unit_price,
}],
'notification_url': webhook_url,
'payer': {