[IMP] mis_builder: query group by
parent
568242ac82
commit
94e66a5ad7
|
@ -261,6 +261,11 @@ class mis_report_query(orm.Model):
|
||||||
store={'mis.report.query':
|
store={'mis.report.query':
|
||||||
(lambda self, cr, uid, ids, c={}:
|
(lambda self, cr, uid, ids, c={}:
|
||||||
ids, ['field_ids'], 20), }),
|
ids, ['field_ids'], 20), }),
|
||||||
|
'groupby': fields.boolean(string="Group by"),
|
||||||
|
'groupby_field_ids': fields.many2many('ir.model.fields',
|
||||||
|
'ir_model_fields_'
|
||||||
|
'mis_report_query_groupby_rel',
|
||||||
|
string='Fields to group by'),
|
||||||
'date_field': fields.many2one('ir.model.fields', required=True,
|
'date_field': fields.many2one('ir.model.fields', required=True,
|
||||||
string='Date field',
|
string='Date field',
|
||||||
domain=[('ttype', 'in',
|
domain=[('ttype', 'in',
|
||||||
|
@ -521,11 +526,21 @@ class mis_report_instance_period(orm.Model):
|
||||||
if obj._columns.get('company_id', False):
|
if obj._columns.get('company_id', False):
|
||||||
domain.extend(['|', ('company_id', '=', False),
|
domain.extend(['|', ('company_id', '=', False),
|
||||||
('company_id', '=', c.company_id.id)])
|
('company_id', '=', c.company_id.id)])
|
||||||
field_names = [field.name for field in query.field_ids]
|
field_names = [f.name for f in query.field_ids]
|
||||||
obj_ids = obj.search(cr, uid, domain, context=context)
|
if not query.groupby:
|
||||||
obj_datas = obj.read(
|
obj_ids = obj.search(cr, uid, domain, context=context)
|
||||||
cr, uid, obj_ids, field_names, context=context)
|
obj_datas = obj.read(
|
||||||
res[query.name] = [AutoStruct(**d) for d in obj_datas]
|
cr, uid, obj_ids, field_names, context=context)
|
||||||
|
res[query.name] = [AutoStruct(**d) for d in obj_datas]
|
||||||
|
else:
|
||||||
|
groupby_field_names = [f.name for f in query.groupby_field_ids]
|
||||||
|
obj_datas = obj.read_group(
|
||||||
|
cr, uid, domain, field_names, groupby_field_names,
|
||||||
|
context=context)
|
||||||
|
if groupby_field_names or not obj_datas:
|
||||||
|
res[query.name] = [AutoStruct(**d) for d in obj_datas]
|
||||||
|
else:
|
||||||
|
res[query.name] = AutoStruct(**obj_datas[0])
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _compute(self, cr, uid, lang_id, c, aep, context=None):
|
def _compute(self, cr, uid, lang_id, c, aep, context=None):
|
||||||
|
|
|
@ -36,6 +36,8 @@
|
||||||
<field name="field_ids" domain="[('model_id', '=', model_id)]" widget="many2many_tags"
|
<field name="field_ids" domain="[('model_id', '=', model_id)]" widget="many2many_tags"
|
||||||
on_change="onchange_field_ids(field_ids, context)"/>
|
on_change="onchange_field_ids(field_ids, context)"/>
|
||||||
<field name="field_names"/>
|
<field name="field_names"/>
|
||||||
|
<field name="groupby"/>
|
||||||
|
<field name="groupby_field_ids" domain="[('model_id', '=', model_id)]" widget="many2many_tags"/>
|
||||||
<field name="date_field" domain="[('model_id', '=', model_id), ('ttype', 'in', ('date', 'datetime'))]"/>
|
<field name="date_field" domain="[('model_id', '=', model_id), ('ttype', 'in', ('date', 'datetime'))]"/>
|
||||||
<field name="domain"/>
|
<field name="domain"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
Loading…
Reference in New Issue