From 44ce99ec9a371273105256a9a428d6c3c4f19484 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Wed, 21 Dec 2022 12:03:21 +0000 Subject: [PATCH] [FIX] point_of_sale: Prevent multiple cash payment method in PoS Current behavior: When creating a PoS config, it is possible to have multiple cash payment method. Wich is not supported by the PoS. opw-3030125 closes odoo/odoo#109331 X-original-commit: 7ba362b60a38a993fdeec920e6c90a754ddeb910 Signed-off-by: Trinh Jacky (trj) Signed-off-by: Engels Robin (roen) --- addons/point_of_sale/i18n/point_of_sale.pot | 7 +++++++ addons/point_of_sale/models/pos_config.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index cc5c41832de..701e441b302 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -6943,6 +6943,13 @@ msgid "" " Or you can add demo data for testing purpose. Please mind that this is an irreversible action." msgstr "" +#. module: point_of_sale +#. odoo-python +#: code:addons/point_of_sale/models/pos_config.py:0 +#, python-format +msgid "You can only have one cash payment method." +msgstr "" + #. module: point_of_sale #: code:addons/point_of_sale/models/pos_session.py:0 #, python-format diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 42200fe2cb1..74a739515d0 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -180,6 +180,13 @@ class PosConfig(models.Model): for config in self: config.cash_control = bool(config.payment_method_ids.filtered('is_cash_count')) + @api.onchange('payment_method_ids') + def _check_cash_payment_method(self): + for config in self: + if len(config.payment_method_ids.filtered('is_cash_count')) > 1: + config.payment_method_ids = config.payment_method_ids._origin + raise ValidationError(_('You can only have one cash payment method.')) + @api.depends('company_id') def _compute_company_has_template(self): for config in self: