[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) <nim@odoo.com>
This commit is contained in:
jev-odoo
2020-11-13 15:59:47 +00:00
committed by Nicolas Martinelli
parent 3c53748d7a
commit 6f1405b59d
2 changed files with 13 additions and 0 deletions
@@ -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
@@ -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,