From 0df2c9e5596bc96f68e154f3a8482a1283ddf632 Mon Sep 17 00:00:00 2001 From: Stephane Wirtel Date: Thu, 10 May 2012 13:25:33 +0200 Subject: [PATCH] [IMP] point_of_sale: Add two constraints on the pos.session object. 1. We can't create twice sessions of the same user 2. We can't create twice sessions of the same config [IMP] point_of_sale: In the PoS Session wizard, if the journal ask to check the opening control, we don't by pass the code bzr revid: stw@openerp.com-20120510112533-hn6r6abyg1jxepj7 --- addons/point_of_sale/point_of_sale.py | 35 +++++++++++++++++++ .../wizard/pos_session_opening.py | 7 ++++ 2 files changed, 42 insertions(+) diff --git a/addons/point_of_sale/point_of_sale.py b/addons/point_of_sale/point_of_sale.py index 981fafb0c82..4f688797d09 100644 --- a/addons/point_of_sale/point_of_sale.py +++ b/addons/point_of_sale/point_of_sale.py @@ -271,6 +271,41 @@ class pos_session(osv.osv): ('uniq_name', 'unique(name)', "The name of this POS Session must be unique !"), ] + def _check_unicity(self, cr, uid, ids, context=None): + for session in self.browse(cr, uid, ids, context=None): + # open if there is no session in 'opening_control', 'opened', 'closing_control' for one user + domain = [ + ('state', '!=', 'closed'), + ('user_id', '=', uid), + ('id', '!=', session.id), + ] + count = self.search_count(cr, uid, domain, context=context) + + if count: + return False + + return True + + def _check_pos_config(self, cr, uid, ids, context=None): + for session in self.browse(cr, uid, ids, context=None): + domain = [ + ('state', '!=', 'closed'), + ('config_id', '=', session.config.id), + ('id', '!=', session.id), + ] + + count = self.search_count(cr, uid, domain, context=context) + + if count: + return False + + return True + + _constraints = [ + (_check_unicity, "You can create a new session, you have an existing and non closed session !", ['user_id', 'state']), + (_check_pos_config, "There is an existing session for the PoS Config", ['config_id']), + ] + def create(self, cr, uid, values, context=None): config_id = values.get('config_id', False) or False diff --git a/addons/point_of_sale/wizard/pos_session_opening.py b/addons/point_of_sale/wizard/pos_session_opening.py index 8415f8ec357..63ae11721a4 100644 --- a/addons/point_of_sale/wizard/pos_session_opening.py +++ b/addons/point_of_sale/wizard/pos_session_opening.py @@ -22,6 +22,13 @@ class pos_session_opening(osv.osv_memory): 'config_id' : wizard.pos_config_id.id, } session_id = proxy.create(cr, uid, values, context=context) + + if all(journal.opening_control == False + for journal in wizard.pos_config_id.journal_ids): + + wkf_service = netsvc.LocalService('workflow') + wkf_service.trg_validate(uid, 'pos.session', session_id, 'open', cr) + return self._open_session(session_id) def open_existing_session_cb(self, cr, uid, ids, context=None):