diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index 88220f5d872..230e39e5cd6 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -5236,6 +5236,13 @@ msgid "" "Orders that where not synced before will be synced next time you close an order while connected to the internet or when you close the session." msgstr "" +#. module: point_of_sale +#: code:addons/point_of_sale/models/pos_config.py:0 +#, python-format +msgid "" +"You must configure an intermediary account for the payment methods: %s." +msgstr "" + #. module: point_of_sale #: model_terms:ir.actions.act_window,help:point_of_sale.product_product_action msgid "" diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index f85107f33f5..235c97bb806 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -356,6 +356,20 @@ class PosConfig(models.Model): ): raise ValidationError(_("All payment methods must be in the same currency as the Sales Journal or the company currency if that is not set.")) + @api.constrains('payment_method_ids') + def _check_payment_method_receivable_accounts(self): + # This is normally not supposed to happen to have a payment method without a receivable account set, + # as this is a required field. However, it happens the receivable account cannot be found during upgrades + # and this is a bommer to block the upgrade for that point, given the user can correct this by himself, + # without requiring a manual intervention from our upgrade support. + # However, this must be ensured this receivable is well set before opening a POS session. + invalid_payment_methods = self.payment_method_ids.filtered(lambda method: not method.receivable_account_id) + if invalid_payment_methods: + method_names = ", ".join(method.name for method in invalid_payment_methods) + raise ValidationError( + _("You must configure an intermediary account for the payment methods: %s.") % method_names + ) + @api.constrains('company_id', 'available_pricelist_ids') def _check_companies(self): if any(self.available_pricelist_ids.mapped(lambda pl: pl.company_id.id not in (False, self.company_id.id))): @@ -568,6 +582,7 @@ class PosConfig(models.Model): self._check_company_payment() self._check_currencies() self._check_profit_loss_cash_journal() + self._check_payment_method_receivable_accounts() self.env['pos.session'].create({ 'user_id': self.env.uid, 'config_id': self.id