[IMP] gamification: allow to select fields of inherited models
This commit is contained in:
parent
423a9f3011
commit
f0c3856be2
|
@ -81,6 +81,8 @@ class gamification_goal_definition(osv.Model):
|
|||
'model_id': fields.many2one('ir.model',
|
||||
string='Model',
|
||||
help='The model object for the field to evaluate'),
|
||||
'model_inherited_model_ids': fields.related('model_id', 'inherited_model_ids', type="many2many", obj="ir.model",
|
||||
string="Inherited models", readonly="True"),
|
||||
'field_id': fields.many2one('ir.model.fields',
|
||||
string='Field to Sum',
|
||||
help='The field containing the value to evaluate'),
|
||||
|
@ -160,6 +162,13 @@ class gamification_goal_definition(osv.Model):
|
|||
|
||||
return res
|
||||
|
||||
def on_change_model_id(self, cr, uid, ids, model_id, context=None):
|
||||
"""Prefill field model_inherited_model_ids"""
|
||||
if not model_id:
|
||||
return {'value': {'model_inherited_model_ids': []}}
|
||||
model = self.pool['ir.model'].browse(cr, uid, model_id, context=context)
|
||||
# format (6, 0, []) to construct the domain ('model_id', 'in', m and m[0] and m[0][2])
|
||||
return {'value': {'model_inherited_model_ids': [(6, 0, [m.id for m in model.inherited_model_ids])]}}
|
||||
|
||||
class gamification_goal(osv.Model):
|
||||
"""Goal instance for a user
|
||||
|
|
|
@ -244,9 +244,20 @@
|
|||
<field widget="radio" name="computation_mode"/>
|
||||
|
||||
<!-- Hide the fields below if manually -->
|
||||
<field name="model_id" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))], 'required':[('computation_mode','in',('sum', 'count'))]}" class="oe_inline"/>
|
||||
<field name="field_id" attrs="{'invisible':[('computation_mode','!=','sum')], 'required':[('computation_mode','=','sum')]}" domain="[('model_id', '=', model_id)]" class="oe_inline"/>
|
||||
<field name="field_date_id" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))]}" domain="[('ttype', 'in', ('date', 'datetime')), ('model_id', '=', model_id)]" class="oe_inline"/>
|
||||
<field name="model_id" class="oe_inline" on_change="on_change_model_id(model_id)"
|
||||
attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))], 'required':[('computation_mode','in',('sum', 'count'))]}"/>
|
||||
<field name="model_inherited_model_ids" invisible="True" />
|
||||
<field name="field_id" class="oe_inline"
|
||||
attrs="{'invisible':[('computation_mode','!=','sum')], 'required':[('computation_mode','=','sum')]}"
|
||||
domain="['|',
|
||||
('model_id', '=', model_id),
|
||||
('model_id', 'in', model_inherited_model_ids and model_inherited_model_ids[0] and model_inherited_model_ids[0][2])]" />
|
||||
<field name="field_date_id" class="oe_inline" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))]}"
|
||||
domain="[
|
||||
('ttype', 'in', ('date', 'datetime')),
|
||||
'|',
|
||||
('model_id', '=', model_id),
|
||||
('model_id', 'in', model_inherited_model_ids and model_inherited_model_ids[0] and model_inherited_model_ids[0][2])]" />
|
||||
<field name="domain" attrs="{'invisible':[('computation_mode','not in',('sum', 'count'))], 'required':[('computation_mode','in',('sum', 'count'))]}" class="oe_inline"/>
|
||||
<field name="compute_code" attrs="{'invisible':[('computation_mode','!=','python')], 'required':[('computation_mode','=','python')]}" placeholder="e.g. result = pool.get('mail.followers').search(cr, uid, [('res_model', '=', 'mail.group'), ('partner_id', '=', object.user_id.partner_id.id)], count=True, context=context)"/>
|
||||
<field name="condition" widget="radio"/>
|
||||
|
|
|
@ -96,8 +96,9 @@ class ir_model(osv.osv):
|
|||
return res
|
||||
|
||||
def _inherited_models(self, cr, uid, ids, field_name, arg, context=None):
|
||||
res = dict.fromkeys(ids, [])
|
||||
res = {}
|
||||
for model in self.browse(cr, uid, ids, context=context):
|
||||
res[model.id] = []
|
||||
inherited_models = [model_name for model_name in self.pool[model.model]._inherits]
|
||||
if inherited_models:
|
||||
res[model.id] = self.search(cr, uid, [('model', 'in', inherited_models)], context=context)
|
||||
|
|
Loading…
Reference in New Issue