diff options
| author | Pierre Masereel <pim@odoo.com> | 2020-11-18 12:13:06 +0000 |
|---|---|---|
| committer | Pierre Masereel <pim@odoo.com> | 2020-11-18 13:17:43 +0000 |
| commit | 17bc5d31722c1a90b03ada16f8e100b8713095ca (patch) | |
| tree | 449a09bf7b15d374b79c9416472ae7d09078a557 | |
| parent | ff43c875a7566ef4473452fc359e73fbf589b615 (diff) | |
[FIX] point_of_sale: avoid trouble when no chart template installed
When a session is created and no orders can be created because of
misconfiguration. We should be able to close the session.
When a chart of account is installed, we should not try to create
payment methods on config that have active session as it is forbidden.
Check that there is at least one payment method configured when
launching a session.
closes odoo/odoo#61933
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
| -rw-r--r-- | addons/point_of_sale/i18n/point_of_sale.pot | 7 | ||||
| -rw-r--r-- | addons/point_of_sale/models/pos_config.py | 10 | ||||
| -rw-r--r-- | addons/point_of_sale/models/pos_session.py | 49 |
3 files changed, 41 insertions, 25 deletions
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 @@ -5571,6 +5571,13 @@ 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 msgid "You need a loss and profit account on your cash journal." msgstr "" diff --git a/addons/point_of_sale/models/pos_config.py b/addons/point_of_sale/models/pos_config.py index 7d3b24351c0..5bed690d113 100644 --- a/addons/point_of_sale/models/pos_config.py +++ b/addons/point_of_sale/models/pos_config.py @@ -383,6 +383,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))): @@ -603,6 +610,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, @@ -653,7 +661,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 881def64931..9e992d20083 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', |
