diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-05-26 14:06:36 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-05-26 14:06:36 +0200 |
| commit | 413ba9445c4d7298b9ce5ebbb6439946bebdccaf (patch) | |
| tree | 9d6a4ef4ab1629b2e0a2df96d22178f62af19c98 /addons/gamification/models | |
| parent | 31d8507d78fa85bf9fea1c20506855d52a25aa43 (diff) | |
| parent | 24eebbd25c5e1cbfb31e42f10271ccdb4185e5fc (diff) | |
[MERGE] forward port of branch 9.0 up to 24eebbd
Diffstat (limited to 'addons/gamification/models')
| -rw-r--r-- | addons/gamification/models/goal.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/addons/gamification/models/goal.py b/addons/gamification/models/goal.py index 557a2811609..a219d7ddc01 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -129,18 +129,36 @@ class gamification_goal_definition(osv.Model): raise UserError(_("The domain for the definition %s seems incorrect, please check it.\n\n%s") % (definition.name, msg)) return True + def _check_model_validity(self, cr, uid, ids, context=None): + """ make sure the selected field and model are usable""" + for definition in self.browse(cr, uid, ids, context=context): + try: + if not definition.model_id or not definition.field_id: + continue + + model = self.pool[definition.model_id.model] + field = model._fields[definition.field_id.name] + if not field.store: + raise UserError( + _("The model configuration for the definition %s seems incorrect, please check it.\n\n%s not stored") % (definition.name, definition.field_id.name)) + except KeyError, e: + raise UserError( + _("The model configuration for the definition %s seems incorrect, please check it.\n\n%s not found") % (definition.name, e.message)) + def create(self, cr, uid, vals, context=None): res_id = super(gamification_goal_definition, self).create(cr, uid, vals, context=context) if vals.get('computation_mode') in ('count', 'sum'): self._check_domain_validity(cr, uid, [res_id], context=context) - + if vals.get('field_id'): + self._check_model_validity(cr, uid, [res_id], context=context) return res_id def write(self, cr, uid, ids, vals, context=None): res = super(gamification_goal_definition, self).write(cr, uid, ids, vals, context=context) if vals.get('computation_mode', 'count') in ('count', 'sum') and (vals.get('domain') or vals.get('model_id')): self._check_domain_validity(cr, uid, ids, context=context) - + if vals.get('field_id') or vals.get('model_id') or vals.get('batch_mode'): + self._check_model_validity(cr, uid, ids, context=context) return res def on_change_model_id(self, cr, uid, ids, model_id, context=None): |
