[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#61954 X-original-commit: 17bc5d31722c1a90b03ada16f8e100b8713095ca Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user