[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
This commit is contained in:
parent
740fb5bf05
commit
0df2c9e559
|
@ -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
|
||||
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue