Skip to content

Commit 736b73e

Browse files
committed
[FIX] temp model test name & fix OCA remarks
1 parent 1906fc8 commit 736b73e

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

base_exception/models/base_exception.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -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():

base_exception/security/ir.model.access.csv

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ access_exception_rule_manager,base.exception,model_exception_rule,base_exception
44
access_base_exception,base.exception,model_base_exception,base.group_user,1,0,0,0
55
access_base_exception_manager,base.exception,model_base_exception,base_exception.group_exception_rule_manager,1,1,1,1
66
access_base_exception_test_purchase,access_base_exception_test_purchase,model_base_exception_test_purchase,base.group_system,1,1,1,1
7-
access_base_exception_test_model_line,access_base_exception_test_model_line,model_base_exception_test_model_line,base.group_system,1,1,1,1
7+
access_base_exception_test_purchasel_line,access_base_exception_test_purchasel_line,model_base_exception_test_purchase_line,base.group_system,1,1,1,1

base_exception/tests/test_tmp_model.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class PurchaseTest(models.Model):
2222
string="Status", readonly=True, default='draft')
2323
active = fields.Boolean(default=True)
2424
partner_id = fields.Many2one('res.partner', string='Partner')
25-
line_ids = fields.One2many('base.exception.test.model.line', 'lead_id')
25+
line_ids = fields.One2many('base.exception.test.purchase.line', 'lead_id')
2626
amount_total = fields.Float(compute='_compute_amount_total', store=True)
2727

2828
@api.depends('line_ids')
@@ -62,10 +62,11 @@ def test_base_get_lines(self):
6262

6363

6464
class LineTest(models.Model):
65-
_name = "base.exception.test.model.line"
65+
_name = "base.exception.test.purchase.line"
6666
_description = "Base Ecxeption Test Model Line"
6767

6868
name = fields.Char()
69-
lead_id = fields.Many2one('base.exception.test.model', ondelete='cascade')
69+
lead_id = fields.Many2one('base.exception.test.purchase',
70+
ondelete='cascade')
7071
qty = fields.Float()
7172
amount = fields.Float()

base_exception/wizard/base_exception_confirm.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
# Mourad EL HADJ MIMOUNE <mourad.elhadj.mimoune@akretion.com>
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
55

6-
from odoo import api, fields, models
6+
from odoo import api, fields, models, _
7+
from odoo.exceptions import ValidationError
78

89

910
class ExceptionRuleConfirm(models.AbstractModel):
@@ -22,7 +23,9 @@ def default_get(self, field_list):
2223
current_model = self._context.get('active_model')
2324
model_except_obj = self.env[current_model]
2425
active_ids = self._context.get('active_ids')
25-
assert len(active_ids) == 1, "Only 1 ID accepted, got %r" % active_ids
26+
if len(active_ids) > 1:
27+
raise ValidationError(
28+
_('Only 1 ID accepted, got %r.') % active_ids)
2629
active_id = active_ids[0]
2730
related_model_except = model_except_obj.browse(active_id)
2831
exception_ids = [e.id for e in related_model_except.exception_ids]

0 commit comments

Comments
 (0)