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,