[FIX] point_of_sale: handle POS clients with a closed session
People sometimes have an open POS client (/pos/web) which is associated to a closed POS session. This causes multiple issues. The most important problem occurs when a user closes the session and opens a new session without refreshing the POS client. When doing this new POS orders will become part of the old, already closed session and no new accounting entries will be generated. In order to fix this we make sure to check that the session that's associated with the order that we get from the client is still open. If it isn't we'll try to find a new, compatible session and add the order there. If we cannot find a compatible session we'll create a new one based on the old, closed one. When creating this new session we bypass the opening_control phase which normally takes care of opening cash control. opw-652356
This commit is contained in:
parent
e6a3852c1f
commit
35e9fa5c41
|
@ -586,14 +586,45 @@ class pos_order(osv.osv):
|
||||||
'journal': ui_paymentline['journal_id'],
|
'journal': ui_paymentline['journal_id'],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This deals with orders that belong to a closed session. In order
|
||||||
|
# to recover from this we:
|
||||||
|
# - assign the order to another compatible open session
|
||||||
|
# - if that doesn't exist, create a new one
|
||||||
|
def _get_valid_session(self, cr, uid, order, context=None):
|
||||||
|
session = self.pool.get('pos.session')
|
||||||
|
closed_session = session.browse(cr, uid, order['pos_session_id'], context=context)
|
||||||
|
open_sessions = session.search(cr, uid, [('state', '=', 'opened'),
|
||||||
|
('config_id', '=', closed_session.config_id.id),
|
||||||
|
('user_id', '=', closed_session.user_id.id)],
|
||||||
|
limit=1, order="start_at DESC", context=context)
|
||||||
|
|
||||||
|
if open_sessions:
|
||||||
|
return open_sessions[0]
|
||||||
|
else:
|
||||||
|
new_session_id = session.create(cr, uid, {
|
||||||
|
'config_id': closed_session.config_id.id,
|
||||||
|
}, context=context)
|
||||||
|
new_session = session.browse(cr, uid, new_session_id, context=context)
|
||||||
|
|
||||||
|
# bypass opening_control (necessary when using cash control)
|
||||||
|
new_session.signal_workflow('open')
|
||||||
|
|
||||||
|
return new_session_id
|
||||||
|
|
||||||
def _process_order(self, cr, uid, order, context=None):
|
def _process_order(self, cr, uid, order, context=None):
|
||||||
|
session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context)
|
||||||
|
|
||||||
|
if session.state == 'closing_control' or session.state == 'closed':
|
||||||
|
session_id = self._get_valid_session(cr, uid, order, context=context)
|
||||||
|
session = self.pool.get('pos.session').browse(cr, uid, session_id, context=context)
|
||||||
|
order['pos_session_id'] = session_id
|
||||||
|
|
||||||
order_id = self.create(cr, uid, self._order_fields(cr, uid, order, context=context),context)
|
order_id = self.create(cr, uid, self._order_fields(cr, uid, order, context=context),context)
|
||||||
journal_ids = set()
|
journal_ids = set()
|
||||||
for payments in order['statement_ids']:
|
for payments in order['statement_ids']:
|
||||||
self.add_payment(cr, uid, order_id, self._payment_fields(cr, uid, payments[2], context=context), context=context)
|
self.add_payment(cr, uid, order_id, self._payment_fields(cr, uid, payments[2], context=context), context=context)
|
||||||
journal_ids.add(payments[2]['journal_id'])
|
journal_ids.add(payments[2]['journal_id'])
|
||||||
|
|
||||||
session = self.pool.get('pos.session').browse(cr, uid, order['pos_session_id'], context=context)
|
|
||||||
if session.sequence_number <= order['sequence_number']:
|
if session.sequence_number <= order['sequence_number']:
|
||||||
session.write({'sequence_number': order['sequence_number'] + 1})
|
session.write({'sequence_number': order['sequence_number'] + 1})
|
||||||
session.refresh()
|
session.refresh()
|
||||||
|
|
Loading…
Reference in New Issue