diff options
| author | Joren Van Onder <jov@odoo.com> | 2015-10-29 09:59:35 +0100 |
|---|---|---|
| committer | Joren Van Onder <jov@odoo.com> | 2015-10-29 15:56:25 +0100 |
| commit | 87a3fe92de43dd7fce7e3364a5ca8dbb417ca7f8 (patch) | |
| tree | 19b3b620d4fdc415a4d898140a94d2635cb1648e | |
| parent | 05381a8bedb6b4abf44a915c10626da854206fb4 (diff) | |
[FIX] point_of_sale: forward port of 35e9fa5c410db78fbad9492afc57b5e7c05a9cb4
Non-trivial port because 9.0 has rescue sessions that kind of try to
solve the same problems, however:
- they do not automatically put orders into a compatible, newly opened
session because it explicitly searches for rescue sessions. So if
you open a new session and create a new order in a POS associated to
a closed session you will end up with two open sessions (one rescue,
one regular).
- they throw exceptions with cash control enabled
- they're a bit more complicated because they introduce the idea of
'rescue' sessions, which the 8.0 fix does not (it just uses regular
sessions).
So this reverts bed409322d71935903f6c2e9880bc6462c58b78e without
changing the database and while still ensuring that databases with
existing POS rescue sessions don't break.
| -rw-r--r-- | addons/point_of_sale/point_of_sale.py | 48 |
1 files changed, 30 insertions, 18 deletions
diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 69adc32ccf0..cb36fde2b1b 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -676,27 +676,39 @@ class pos_order(osv.osv): 'journal': ui_paymentline['journal_id'], } - def _get_rescue_session(self, cr, uid, order, context=None): - """ Find or generate a rescue session """ - pos_session = self.pool['pos.session'] - date = order.get('creation_date', time.strftime(tools.DEFAULT_SERVER_DATETIME_FORMAT)) - closed_session = pos_session.browse(cr, uid, order['pos_session_id'], context=context) - rescue_session_ids = pos_session.search(cr, uid, [ - ('rescue', '=', True), ('config_id', '=', closed_session.config_id.id), - ('start_at', '<=', date), ('state', '=', 'opened') - ], limit=1, context=context) - if not rescue_session_ids: - return pos_session.copy(cr, uid, order['pos_session_id'], default={ - 'rescue': True, + # 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) - return rescue_session_ids[0] + 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): - session = self.pool['pos.session'].browse(cr, uid, order['pos_session_id'], context=context) - if session.state == 'closed': - rescue_session_id = self._get_rescue_session(cr, uid, order, context=context) - order['pos_session_id'] = rescue_session_id - session = self.pool['pos.session'].browse(cr, uid, rescue_session_id, context=context) + 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) journal_ids = set() for payments in order['statement_ids']: |
