diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index 8431f21256f..57049deb16e 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -5568,6 +5568,13 @@ msgid "" " the point of sale interface." msgstr "" +#. module: point_of_sale +#: code:addons/point_of_sale/models/pos_config.py:0 +#, python-format +msgid "" +"You must have at least one payment method configured to launch a session." +msgstr "" + #. module: point_of_sale #: code:addons/point_of_sale/models/pos_config.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 fde7cc69678..627c83e6e54 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -384,6 +384,13 @@ class PosConfig(models.Model): _("You must configure an intermediary account for the payment methods: %s.") % method_names ) + def _check_payment_method_ids(self): + self.ensure_one() + if not self.payment_method_ids: + raise ValidationError( + _("You must have at least one payment method configured to launch a session.") + ) + @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))): @@ -604,6 +611,7 @@ class PosConfig(models.Model): self._check_company_payment() self._check_currencies() self._check_profit_loss_cash_journal() + self._check_payment_method_ids() self._check_payment_method_receivable_accounts() self.env['pos.session'].create({ 'user_id': self.env.uid, @@ -654,7 +662,7 @@ class PosConfig(models.Model): def assign_payment_journals(self, company): for pos_config in self: - if pos_config.payment_method_ids: + if pos_config.payment_method_ids or pos_config.has_active_session: continue cash_journal = self.env['account.journal'].search([('company_id', '=', company.id), ('type', '=', 'cash')], limit=1) pos_receivable_account = company.account_default_pos_receivable_account_id diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index 159f8b51788..70b8d662075 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -296,30 +296,31 @@ class PosSession(models.Model): def _validate_session(self): self.ensure_one() - self.cash_real_transaction = self.cash_register_total_entry_encoding - self.cash_real_expected = self.cash_register_balance_end - self.cash_real_difference = self.cash_register_difference - if self.state == 'closed': - raise UserError(_('This session is already closed.')) - self._check_if_no_draft_orders() - if self.update_stock_at_closing: - self._create_picking_at_end_of_session() - # Users without any accounting rights won't be able to create the journal entry. If this - # case, switch to sudo for creation and posting. - sudo = False - if ( - not self.env['account.move'].check_access_rights('create', raise_exception=False) - and self.user_has_groups('point_of_sale.group_pos_user') - ): - sudo = True - self.sudo().with_company(self.company_id)._create_account_move() - else: - self.with_company(self.company_id)._create_account_move() - if self.move_id.line_ids: - # Set the uninvoiced orders' state to 'done' - self.env['pos.order'].search([('session_id', '=', self.id), ('state', '=', 'paid')]).write({'state': 'done'}) - else: - self.move_id.unlink() + if self.order_ids: + self.cash_real_transaction = self.cash_register_total_entry_encoding + self.cash_real_expected = self.cash_register_balance_end + self.cash_real_difference = self.cash_register_difference + if self.state == 'closed': + raise UserError(_('This session is already closed.')) + self._check_if_no_draft_orders() + if self.update_stock_at_closing: + self._create_picking_at_end_of_session() + # Users without any accounting rights won't be able to create the journal entry. If this + # case, switch to sudo for creation and posting. + sudo = False + if ( + not self.env['account.move'].check_access_rights('create', raise_exception=False) + and self.user_has_groups('point_of_sale.group_pos_user') + ): + sudo = True + self.sudo().with_company(self.company_id)._create_account_move() + else: + self.with_company(self.company_id)._create_account_move() + if self.move_id.line_ids: + # Set the uninvoiced orders' state to 'done' + self.env['pos.order'].search([('session_id', '=', self.id), ('state', '=', 'paid')]).write({'state': 'done'}) + else: + self.move_id.unlink() self.write({'state': 'closed'}) return { 'type': 'ir.actions.client',