[IMP] gamification: prevent misconfiguration

Prevent selecting wrong field or models or computed fields

Fixes #8545
This commit is contained in:
Martin Trigaux 2016-05-25 12:34:20 +02:00
parent be48a1402c
commit 97492a12a9
No known key found for this signature in database
GPG Key ID: 7B0E288E7C0F83A7
2 changed files with 57 additions and 4 deletions

View File

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 8.0\n" "Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-21 14:08+0000\n" "POT-Creation-Date: 2016-05-25 12:58+0000\n"
"PO-Revision-Date: 2015-01-21 14:08+0000\n" "PO-Revision-Date: 2016-05-25 12:58+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -562,6 +562,18 @@ msgstr ""
msgid "Display Mode" msgid "Display Mode"
msgstr "" msgstr ""
#. module: gamification
#: field:gamification.badge,display_name:0
#: field:gamification.badge.user,display_name:0
#: field:gamification.badge.user.wizard,display_name:0
#: field:gamification.challenge,display_name:0
#: field:gamification.challenge.line,display_name:0
#: field:gamification.goal,display_name:0
#: field:gamification.goal.definition,display_name:0
#: field:gamification.goal.wizard,display_name:0
msgid "Display Name"
msgstr ""
#. module: gamification #. module: gamification
#: field:gamification.goal.definition,display_mode:0 #: field:gamification.goal.definition,display_mode:0
msgid "Displayed as" msgid "Displayed as"
@ -967,6 +979,18 @@ msgstr ""
msgid "Last Message Date" msgid "Last Message Date"
msgstr "" msgstr ""
#. module: gamification
#: field:gamification.badge,__last_update:0
#: field:gamification.badge.user,__last_update:0
#: field:gamification.badge.user.wizard,__last_update:0
#: field:gamification.challenge,__last_update:0
#: field:gamification.challenge.line,__last_update:0
#: field:gamification.goal,__last_update:0
#: field:gamification.goal.definition,__last_update:0
#: field:gamification.goal.wizard,__last_update:0
msgid "Last Modified on"
msgstr ""
#. module: gamification #. module: gamification
#: field:gamification.challenge,last_report_date:0 #: field:gamification.challenge,last_report_date:0
msgid "Last Report Date" msgid "Last Report Date"
@ -1585,6 +1609,22 @@ msgstr ""
msgid "The maximum number of time this badge can be sent per month per person." msgid "The maximum number of time this badge can be sent per month per person."
msgstr "" msgstr ""
#. module: gamification
#: code:addons/gamification/models/goal.py:160
#, python-format
msgid "The model configuration for the definition %s seems incorrect, please check it.\n"
"\n"
"%s not found"
msgstr ""
#. module: gamification
#: code:addons/gamification/models/goal.py:158
#, python-format
msgid "The model configuration for the definition %s seems incorrect, please check it.\n"
"\n"
"%s not stored"
msgstr ""
#. module: gamification #. module: gamification
#: help:gamification.goal.definition,model_id:0 #: help:gamification.goal.definition,model_id:0
msgid "The model object for the field to evaluate" msgid "The model object for the field to evaluate"

View File

@ -148,18 +148,31 @@ class gamification_goal_definition(osv.Model):
raise osv.except_osv(_('Error!'),_("The domain for the definition %s seems incorrect, please check it.\n\n%s" % (definition.name, msg))) raise osv.except_osv(_('Error!'),_("The domain for the definition %s seems incorrect, please check it.\n\n%s" % (definition.name, msg)))
return True 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:
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): def create(self, cr, uid, vals, context=None):
res_id = super(gamification_goal_definition, self).create(cr, uid, vals, context=context) res_id = super(gamification_goal_definition, self).create(cr, uid, vals, context=context)
if vals.get('computation_mode') in ('count', 'sum'): if vals.get('computation_mode') in ('count', 'sum'):
self._check_domain_validity(cr, uid, [res_id], context=context) 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 return res_id
def write(self, cr, uid, ids, vals, context=None): def write(self, cr, uid, ids, vals, context=None):
res = super(gamification_goal_definition, self).write(cr, uid, ids, vals, context=context) 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')): 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) 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 return res
def on_change_model_id(self, cr, uid, ids, model_id, context=None): def on_change_model_id(self, cr, uid, ids, model_id, context=None):