diff options
| author | Christophe Simonis <chs@odoo.com> | 2016-05-26 13:56:16 +0200 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2016-05-26 13:56:16 +0200 |
| commit | 24eebbd25c5e1cbfb31e42f10271ccdb4185e5fc (patch) | |
| tree | 571dd135928a73c69ee748d2c51ab088441841ca /addons/gamification/models/goal.py | |
| parent | f92939e75c2d24f26c7e6e68875d0d69d630f6c4 (diff) | |
| parent | 6c6a9f3d609765111e50af0656f637b30724de84 (diff) | |
[MERGE] forward port of branch saas-6 up to 6c6a9f3
Diffstat (limited to 'addons/gamification/models/goal.py')
| -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 2f307e03ca0..c41b0fea484 100644 --- a/addons/gamification/models/goal.py +++ b/addons/gamification/models/goal.py @@ -133,18 +133,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): |
