[FIX] point_of_sale: restore rescue field
Properly fix #15101 Unstable patch of fix made at #15862
This commit is contained in:
@@ -17,7 +17,7 @@ class PosController(http.Controller):
|
||||
pos_sessions = request.env['pos.session'].search([
|
||||
('state', '=', 'opened'),
|
||||
('user_id', '=', request.session.uid),
|
||||
('name', 'not like', '(RESCUE FOR')])
|
||||
('rescue', '=', False)])
|
||||
if not pos_sessions:
|
||||
return werkzeug.utils.redirect('/web#action=point_of_sale.action_client_pos_menu')
|
||||
pos_sessions.login()
|
||||
|
||||
@@ -148,7 +148,7 @@ class PosConfig(models.Model):
|
||||
for pos_config in self:
|
||||
session = pos_config.session_ids.filtered(lambda r: r.user_id.id == self.env.uid and \
|
||||
not r.state == 'closed' and \
|
||||
'(RESCUE FOR' not in r.name)
|
||||
not r.rescue)
|
||||
# sessions ordered by id desc
|
||||
pos_config.current_session_id = session and session[0].id or False
|
||||
pos_config.current_session_state = session and session[0].state or False
|
||||
@@ -171,7 +171,7 @@ class PosConfig(models.Model):
|
||||
@api.depends('session_ids')
|
||||
def _compute_current_session_user(self):
|
||||
for pos_config in self:
|
||||
session = pos_config.session_ids.filtered(lambda s: s.state == 'opened' and '(RESCUE FOR' not in s.name)
|
||||
session = pos_config.session_ids.filtered(lambda s: s.state == 'opened' and not s.rescue)
|
||||
pos_config.pos_session_username = session and session[0].user_id.name or False
|
||||
|
||||
@api.constrains('company_id', 'stock_location_id')
|
||||
|
||||
@@ -67,8 +67,9 @@ class PosOrder(models.Model):
|
||||
order['name'],
|
||||
order['amount_total'])
|
||||
rescue_session = PosSession.search([
|
||||
('name', 'like', '(RESCUE FOR %(session)s)' % {'session': closed_session.name}),
|
||||
('state', 'not in', ('closed', 'closing_control')),
|
||||
('rescue', '=', True),
|
||||
('config_id', '=', closed_session.config_id.id),
|
||||
], limit=1)
|
||||
if rescue_session:
|
||||
_logger.warning('reusing recovery session %s for saving order %s', rescue_session.name, order['name'])
|
||||
@@ -77,7 +78,8 @@ class PosOrder(models.Model):
|
||||
_logger.warning('attempting to create recovery session for saving order %s', order['name'])
|
||||
new_session = PosSession.create({
|
||||
'config_id': closed_session.config_id.id,
|
||||
'name': '(RESCUE FOR %(session)s)' % {'session': closed_session.name},
|
||||
'name': _('(RESCUE FOR %(session)s)') % {'session': closed_session.name},
|
||||
'rescue': True, # avoid conflict with live sessions
|
||||
})
|
||||
# bypass opening_control (necessary when using cash control)
|
||||
new_session.action_pos_session_open()
|
||||
|
||||
@@ -103,6 +103,10 @@ class PosSession(models.Model):
|
||||
order_ids = fields.One2many('pos.order', 'session_id', string='Orders')
|
||||
statement_ids = fields.One2many('account.bank.statement', 'pos_session_id', string='Bank Statement', readonly=True)
|
||||
picking_count = fields.Integer(compute='_compute_picking_count')
|
||||
rescue = fields.Boolean(string='Recovery Session',
|
||||
help="Auto-generated session for orphan orders, ignored in constraints",
|
||||
readonly=True,
|
||||
copy=False)
|
||||
|
||||
_sql_constraints = [('uniq_name', 'unique(name)', "The name of this POS Session must be unique !")]
|
||||
|
||||
@@ -140,7 +144,7 @@ class PosSession(models.Model):
|
||||
if self.search_count([
|
||||
('state', 'not in', ('closed', 'closing_control')),
|
||||
('user_id', '=', self.user_id.id),
|
||||
('name', 'not like', 'RESCUE FOR'),
|
||||
('rescue', '=', False)
|
||||
]) > 1:
|
||||
raise ValidationError(_("You cannot create two active sessions with the same responsible!"))
|
||||
|
||||
@@ -149,7 +153,7 @@ class PosSession(models.Model):
|
||||
if self.search_count([
|
||||
('state', '!=', 'closed'),
|
||||
('config_id', '=', self.config_id.id),
|
||||
('name', 'not like', 'RESCUE FOR'),
|
||||
('rescue', '=', False)
|
||||
]) > 1:
|
||||
raise ValidationError(_("You cannot create two active sessions related to the same point of sale!"))
|
||||
|
||||
|
||||
@@ -586,6 +586,7 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
rescue_session = self.PosSession.search([
|
||||
('config_id', '=', self.pos_config.id),
|
||||
('state', '=', 'opened'),
|
||||
('rescue', '=', True)
|
||||
])
|
||||
self.assertEqual(len(rescue_session), 1, "One (and only one) rescue session should be created for orphan orders")
|
||||
self.assertIn("(RESCUE FOR %s)" % current_session.name, rescue_session.name, "Rescue session is not linked to the previous one")
|
||||
|
||||
Reference in New Issue
Block a user