Skip to content

Commit

Permalink
[FIX] temp model test name & fix OCA remarks
Browse files Browse the repository at this point in the history
  • Loading branch information
mourad-ehm committed Nov 27, 2017
1 parent 1906fc8 commit b0f591f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
22 changes: 10 additions & 12 deletions base_exception/models/base_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ class ExceptionRule(models.Model):
active = fields.Boolean('Active')
next_state = fields.Char(
'Next state',
help="If we detect exception we set de state of object (ex purchase) "
help="If we detect exception we set the state of object (ex purchase) "
"to the next_state (ex 'to approve'). If there are more than one "
"exception detected and all have a value for next_state, we use"
"the exception having the smallest sequence value")
code = fields.Text(
'Python Code',
help="Python code executed to check if the exception apply or "
"not. The code must apply block = True to apply the "
"exception.",
"exception. Use failed = True to block the exception",
default="""
# Python code. Use failed = True to block the base.exception.
# You can use the following variables :
Expand All @@ -79,10 +79,10 @@ def _check_next_state_value(self):
select_vals = self.env[
rule.model].fields_get()[
'state']['selection']
if rule.next_state\
not in [s[0] for s in select_vals]:
select_vals_code = [s[0] for s in select_vals]
if rule.next_state not in select_vals_code:
raise ValidationError(
_('The value "%s" you chose for the "next state" '
_('The value "%s" you choose for the "next state" '
'field state of "%s" is wrong.'
' Value must be in this list %s')
% (rule.next_state,
Expand Down Expand Up @@ -121,14 +121,14 @@ def _compute_main_error(self):
@api.multi
def _popup_exceptions(self):
action = self._get_popup_action()
action = action.read()[0]
action.update({
action_data = action.read()[0]
action_data.update({
'context': {
'active_id': self.ids[0],
'active_ids': self.ids
}
})
return action
return action_data

@api.model
def _get_popup_action(self):
Expand Down Expand Up @@ -225,10 +225,8 @@ def _detect_exceptions(self, model_exceptions,
if self._rule_eval(rule, self.rule_group, self):
exception_ids.append(rule.id)
if rule.next_state:
if not next_state_rule:
next_state_rule = rule
elif next_state_rule and\
rule.sequence < next_state_rule.sequence:
if not next_state_rule or\
rule.sequence < next_state_rule.sequence:
next_state_rule = rule
if sub_exceptions:
for obj_line in self._get_lines():
Expand Down
2 changes: 1 addition & 1 deletion base_exception/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ access_exception_rule_manager,base.exception,model_exception_rule,base_exception
access_base_exception,base.exception,model_base_exception,base.group_user,1,0,0,0
access_base_exception_manager,base.exception,model_base_exception,base_exception.group_exception_rule_manager,1,1,1,1
access_base_exception_test_purchase,access_base_exception_test_purchase,model_base_exception_test_purchase,base.group_system,1,1,1,1
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
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
7 changes: 4 additions & 3 deletions base_exception/tests/test_tmp_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class PurchaseTest(models.Model):
string="Status", readonly=True, default='draft')
active = fields.Boolean(default=True)
partner_id = fields.Many2one('res.partner', string='Partner')
line_ids = fields.One2many('base.exception.test.model.line', 'lead_id')
line_ids = fields.One2many('base.exception.test.purchase.line', 'lead_id')
amount_total = fields.Float(compute='_compute_amount_total', store=True)

@api.depends('line_ids')
Expand Down Expand Up @@ -62,10 +62,11 @@ def test_base_get_lines(self):


class LineTest(models.Model):
_name = "base.exception.test.model.line"
_name = "base.exception.test.purchase.line"
_description = "Base Ecxeption Test Model Line"

name = fields.Char()
lead_id = fields.Many2one('base.exception.test.model', ondelete='cascade')
lead_id = fields.Many2one('base.exception.test.purchase',
ondelete='cascade')
qty = fields.Float()
amount = fields.Float()
7 changes: 5 additions & 2 deletions base_exception/wizard/base_exception_confirm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
# Mourad EL HADJ MIMOUNE <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError


class ExceptionRuleConfirm(models.AbstractModel):
Expand All @@ -22,7 +23,9 @@ def default_get(self, field_list):
current_model = self._context.get('active_model')
model_except_obj = self.env[current_model]
active_ids = self._context.get('active_ids')
assert len(active_ids) == 1, "Only 1 ID accepted, got %r" % active_ids
if len(active_ids) > 1:
raise ValidationError(
_('Only 1 ID accepted, got %r.') % active_ids)
active_id = active_ids[0]
related_model_except = model_except_obj.browse(active_id)
exception_ids = [e.id for e in related_model_except.exception_ids]
Expand Down

0 comments on commit b0f591f

Please sign in to comment.