@@ -45,15 +45,15 @@ class ExceptionRule(models.Model):
4545 active = fields .Boolean ('Active' )
4646 next_state = fields .Char (
4747 'Next state' ,
48- help = "If we detect exception we set de state of object (ex purchase) "
48+ help = "If we detect exception we set the state of object (ex purchase) "
4949 "to the next_state (ex 'to approve'). If there are more than one "
5050 "exception detected and all have a value for next_state, we use"
5151 "the exception having the smallest sequence value" )
5252 code = fields .Text (
5353 'Python Code' ,
5454 help = "Python code executed to check if the exception apply or "
5555 "not. The code must apply block = True to apply the "
56- "exception." ,
56+ "exception. Use failed = True to block the exception " ,
5757 default = """
5858# Python code. Use failed = True to block the base.exception.
5959# You can use the following variables :
@@ -63,7 +63,7 @@ class ExceptionRule(models.Model):
6363# base.exception line (ex rule_group = sale for sale order)
6464# - object: same as order or line, browse_record of the base.exception or
6565# base.exception line
66- # - pool: ORM model pool (i.e. self.pool )
66+ # - env: Odoo Environment (i.e. self.env )
6767# - time: Python time module
6868# - cr: database cursor
6969# - uid: current user id
@@ -79,10 +79,10 @@ def _check_next_state_value(self):
7979 select_vals = self .env [
8080 rule .model ].fields_get ()[
8181 'state' ]['selection' ]
82- if rule . next_state \
83- not in [ s [ 0 ] for s in select_vals ] :
82+ select_vals_code = [ s [ 0 ] for s in select_vals ]
83+ if rule . next_state not in select_vals_code :
8484 raise ValidationError (
85- _ ('The value "%s" you chose for the "next state" '
85+ _ ('The value "%s" you choose for the "next state" '
8686 'field state of "%s" is wrong.'
8787 ' Value must be in this list %s' )
8888 % (rule .next_state ,
@@ -121,14 +121,14 @@ def _compute_main_error(self):
121121 @api .multi
122122 def _popup_exceptions (self ):
123123 action = self ._get_popup_action ()
124- action = action .read ()[0 ]
125- action .update ({
124+ action_data = action .read ()[0 ]
125+ action_data .update ({
126126 'context' : {
127127 'active_id' : self .ids [0 ],
128128 'active_ids' : self .ids
129129 }
130130 })
131- return action
131+ return action_data
132132
133133 @api .model
134134 def _get_popup_action (self ):
@@ -189,12 +189,12 @@ def detect_exceptions(self):
189189 def _exception_rule_eval_context (self , obj_name , rec ):
190190 user = self .env ['res.users' ].browse (self ._uid )
191191 return {obj_name : rec ,
192- 'self' : self .pool . get ( rec ._name ) ,
192+ 'self' : self .env [ rec ._name ] ,
193193 'object' : rec ,
194194 'obj' : rec ,
195- 'pool ' : self .pool ,
196- 'cr' : self ._cr ,
197- 'uid' : self ._uid ,
195+ 'env ' : self .env ,
196+ 'cr' : self .env . cr ,
197+ 'uid' : self .env . user . id ,
198198 'user' : user ,
199199 'time' : time ,
200200 # copy context to prevent side-effects of eval
@@ -225,10 +225,8 @@ def _detect_exceptions(self, model_exceptions,
225225 if self ._rule_eval (rule , self .rule_group , self ):
226226 exception_ids .append (rule .id )
227227 if rule .next_state :
228- if not next_state_rule :
229- next_state_rule = rule
230- elif next_state_rule and \
231- rule .sequence < next_state_rule .sequence :
228+ if not next_state_rule or \
229+ rule .sequence < next_state_rule .sequence :
232230 next_state_rule = rule
233231 if sub_exceptions :
234232 for obj_line in self ._get_lines ():
0 commit comments