Browse Source

[IMP] improve view and onchange on multi expression

pull/189/head
Sébastien BEAU 9 years ago
committed by Stéphane Bidoul
parent
commit
d976ede644
  1. 48
      mis_builder/models/mis_builder.py
  2. 27
      mis_builder/views/mis_builder.xml

48
mis_builder/models/mis_builder.py

@ -158,38 +158,6 @@ class MisReportKpi(models.Model):
})] })]
}) })
@api.model
def create(self, vals):
kpi = super(MisReportKpi, self).create(vals)
if kpi.multi:
kpi._populate_expression()
return kpi
@api.multi
def write(self, vals):
res = super(MisReportKpi, self).write(vals)
if vals.get('multi'):
self._populate_expression()
return res
@api.multi
def _populate_expression(self):
for kpi in self:
if kpi.multi:
if kpi.expression_ids:
expression = kpi.expression_ids[0].name
else:
expression = "AccountingNone"
existing_subkpis = kpi.expression_ids.mapped('subkpi_id')
expressions = []
for subkpi in kpi.report_id.subkpi_ids:
if not subkpi in existing_subkpis:
self.env['mis.report.kpi.expression'].create({
'name': expression,
'kpi_id': kpi.id,
'subkpi_id': subkpi.id,
})
@api.onchange('multi') @api.onchange('multi')
def _onchange_multi(self): def _onchange_multi(self):
for kpi in self: for kpi in self:
@ -198,6 +166,14 @@ class MisReportKpi(models.Model):
kpi.expression = kpi.expression_ids[0].name kpi.expression = kpi.expression_ids[0].name
else: else:
kpi.expression = None kpi.expression = None
else:
expressions = []
for subkpi in kpi.report_id.subkpi_ids:
expressions.append((0, 0, {
'name': kpi.expression,
'subkpi_id': subkpi.id,
}))
kpi.expression_ids = expressions
@api.onchange('description') @api.onchange('description')
def _onchange_description(self): def _onchange_description(self):
@ -587,14 +563,14 @@ class MisReport(models.Model):
'#ERR', '#ERR',
'\n\n%s' % (traceback.format_exc(),))) '\n\n%s' % (traceback.format_exc(),)))
except: except:
raise
vals.append(DataError( vals.append(DataError(
'#ERR', '#ERR',
'\n\n%s' % (traceback.format_exc(),))) '\n\n%s' % (traceback.format_exc(),)))
#TODO escape total
localdict[kpi.name] = SimpleArray(vals)
res[kpi] = SimpleArray(vals)
if kpi.multi:
vals = SimpleArray(vals)
localdict[kpi.name] = vals
res[kpi] = vals
if len(recompute_queue) == 0: if len(recompute_queue) == 0:
# nothing to recompute, we are done # nothing to recompute, we are done

27
mis_builder/views/mis_builder.xml

@ -58,8 +58,7 @@
<field name="description"/> <field name="description"/>
<field name="name"/> <field name="name"/>
<field name="multi"/> <field name="multi"/>
<field name="expression"
attrs="{'readonly': [('multi', '=', True)]}"/>
<field name="expression"/>
<field name="type"/> <field name="type"/>
<field name="dp" attrs="{'invisible': [('type', '=', 'str')]}"/> <field name="dp" attrs="{'invisible': [('type', '=', 'str')]}"/>
<field name="divider" attrs="{'invisible': [('type', '=', 'str')]}"/> <field name="divider" attrs="{'invisible': [('type', '=', 'str')]}"/>
@ -109,16 +108,6 @@
<group col="4"> <group col="4">
<field name="description"/> <field name="description"/>
<field name="name"/> <field name="name"/>
<field name="multi"/>
<field name="expression_ids" colspan="4" nolabel="1"
attrs="{'invisible': [('multi', '=', False)]}">
<tree editable="bottom">
<field name="subkpi_id"/>
<field name="name"/>
</tree>
</field>
<field name="expression" colspan="4" nolabel="1"
attrs="{'invisible': [('multi', '=', True)]}"/>
<field name="type"/> <field name="type"/>
<field name="dp" <field name="dp"
attrs="{'invisible': [('type', '=', 'str')]}"/> attrs="{'invisible': [('type', '=', 'str')]}"/>
@ -132,6 +121,20 @@
<field name="css_style" colspan="4"/> <field name="css_style" colspan="4"/>
<!--<field name="sequence" />--> <!--<field name="sequence" />-->
</group> </group>
<group string="Expression">
<field name="multi"/>
<field name="expression_ids" colspan="4" nolabel="1"
delete="0" create="0"
attrs="{'invisible': [('multi', '=', False)]}">
<tree editable="bottom">
<field name="subkpi_id"/>
<field name="name"/>
</tree>
</field>
<field name="expression" colspan="4" nolabel="1"
attrs="{'invisible': [('multi', '=', True)],
'readonly': [('multi', '=', True)]}"/>
</group>
<group col="2" string="Legend (for kpi expressions)"> <group col="2" string="Legend (for kpi expressions)">
<group> <group>
<label colspan="2" string="Expressions are of the form &lt;field&gt;&lt;mode&gt;[accounts][domain]"/> <label colspan="2" string="Expressions are of the form &lt;field&gt;&lt;mode&gt;[accounts][domain]"/>

Loading…
Cancel
Save