From 6f1405b59de4f0881d83c3cc30311efd5ccb6bcb Mon Sep 17 00:00:00 2001 From: jev-odoo Date: Thu, 5 Nov 2020 08:42:07 +0000 Subject: [PATCH] [FIX] point_of_sale: Select only allowed payment method Before this fix, in the pos.payment form, you were able to select any pos.payment.method. Saving with a pos.payment.method that is not allowed in the pos.config of the session caused a traceback. opw-2372025 closes odoo/odoo#61728 X-original-commit: ff648a0ace9cf72274211662707e7ee33fc73252 Related: odoo/enterprise#14731 Signed-off-by: Nicolas Martinelli (nim) --- addons/point_of_sale/i18n/point_of_sale.pot | 6 ++++++ addons/point_of_sale/models/pos_payment.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index eadc1410f82..b9c9cbcf57d 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -4700,6 +4700,12 @@ msgid "" "The payment methods and the point of sale must belong to the same company." msgstr "" +#. module: point_of_sale +#: code:addons/point_of_sale/models/pos_payment.py:0 +#, python-format +msgid "The payment method selected is not allowed in the config of the POS session." +msgstr "" + #. module: point_of_sale #: model:ir.model.fields,help:point_of_sale.field_pos_order__config_id #: model:ir.model.fields,help:point_of_sale.field_pos_session__config_id diff --git a/addons/point_of_sale/models/pos_payment.py b/addons/point_of_sale/models/pos_payment.py index 389a7fdde05..3fe006c0749 100644 --- a/addons/point_of_sale/models/pos_payment.py +++ b/addons/point_of_sale/models/pos_payment.py @@ -1,5 +1,6 @@ from odoo import api, fields, models, _ from odoo.tools import formatLang +from odoo.exceptions import ValidationError class PosPayment(models.Model): @@ -41,6 +42,12 @@ class PosPayment(models.Model): res.append((payment.id, formatLang(self.env, payment.amount, currency_obj=payment.currency_id))) return res + @api.constrains('payment_method_id') + def _check_payment_method_id(self): + for payment in self: + if payment.payment_method_id not in payment.session_id.config_id.payment_method_ids: + raise ValidationError(_('The payment method selected is not allowed in the config of the POS session.')) + def _export_for_ui(self, payment): return { 'payment_method_id': payment.payment_method_id.id,