From f9da3590261b304f9c12f01f5800cec50faebc1a Mon Sep 17 00:00:00 2001 From: roen-odoo <roen@odoo.com> 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#108443 Signed-off-by: Trinh Jacky (trj) <trj@odoo.com> --- addons/point_of_sale/i18n/point_of_sale.pot | 6 ++++++ addons/point_of_sale/models/pos_config.py | 7 +++++++ addons/point_of_sale/tests/common.py | 23 +++++++++------------ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index b9e3c3fe82e9..eb35d415a95f 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -6728,6 +6728,12 @@ msgid "" "Would you like to proceed anyway?" msgstr "" +#. module: point_of_sale +#: 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/account_bank_statement.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 90c4b84b0cb9..07c7d04481de 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -184,6 +184,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('use_pricelist', 'available_pricelist_ids') def _compute_allowed_pricelist_ids(self): for config in self: diff --git a/addons/point_of_sale/tests/common.py b/addons/point_of_sale/tests/common.py index 6aeebfdc33b7..1bdcd9a3b4d8 100644 --- a/addons/point_of_sale/tests/common.py +++ b/addons/point_of_sale/tests/common.py @@ -332,19 +332,16 @@ class TestPoSCommon(ValuationReconciliationTestCommon): 'outstanding_account_id': cls.outstanding_bank.id, }) - new_config = Form(cls.env['pos.config']) - new_config.name = 'Shop Other' - new_config.invoice_journal_id = other_invoice_journal - new_config.journal_id = other_sales_journal - new_config.use_pricelist = True - new_config.available_pricelist_ids.clear() - new_config.available_pricelist_ids.add(other_pricelist) - new_config.pricelist_id = other_pricelist - new_config.payment_method_ids.clear() - new_config.payment_method_ids.add(cls.cash_pm2) - new_config.payment_method_ids.add(cls.bank_pm2) - config = new_config.save() - return config + new_config = cls.env['pos.config'].create({ + 'name': 'Shop Other', + 'invoice_journal_id': other_invoice_journal.id, + 'journal_id': other_sales_journal.id, + 'use_pricelist': True, + 'available_pricelist_ids': [(6, 0, [other_pricelist.id])], + 'pricelist_id': other_pricelist.id, + 'payment_method_ids': [(6, 0, [cls.cash_pm2.id, cls.bank_pm2.id])], + }) + return new_config @classmethod def _create_categ_anglo(cls): -- GitLab