Browse Source

[IMP] kpi_dashboard: Allow to set a context on the action

myc-14.0-py3o
Enric Tobella 4 years ago
parent
commit
841f590edb
  1. 10
      kpi_dashboard/models/kpi_kpi.py
  2. 5
      kpi_dashboard/static/src/js/widget/abstract_widget.js
  3. 5
      kpi_dashboard/static/src/xml/dashboard.xml
  4. 1
      kpi_dashboard/views/kpi_kpi.xml

10
kpi_dashboard/models/kpi_kpi.py

@ -187,15 +187,17 @@ class KpiKpiAction(models.Model):
('ir.actions.client', 'ir.actions.client')],
required=True,
)
context = fields.Char()
def read_dashboard(self):
result = []
result = {}
for r in self:
result.append({
result[r.id] = {
'id': r.action.id,
'type': r.action._name,
'name': r.action.name
})
'name': r.action.name,
'context': safe_eval(r.context or '{}')
}
return result

5
kpi_dashboard/static/src/js/widget/abstract_widget.js

@ -82,7 +82,10 @@ odoo.define('kpi_dashboard.AbstractWidget', function (require) {
_onClickDirectAction: function(event) {
event.preventDefault();
var $data = $(event.currentTarget).closest('a');
return this.do_action($($data).data('id'));
var action = this.actions[$($data).data('id')];
return this.do_action(action.id, {
additional_context: action.context
});
}
});

5
kpi_dashboard/static/src/xml/dashboard.xml

@ -19,9 +19,10 @@
</t>
<t t-name="kpi_dashboard.ManagePanel">
<t t-if="widget.actions" >
<t t-foreach="widget.actions" t-as="action">
<t t-foreach="widget.actions" t-as="action_id">
<t t-set="action" t-value="widget.actions[action_id]"/>
<div role="menuitem" class="">
<a role="menuitem" href="#" class="direct_action" t-att-data-id="action.id" t-att-data-type="action.type">Go to <t t-esc="action.name"/></a>
<a role="menuitem" href="#" class="direct_action" t-att-data-id="action_id" t-att-data-type="action.type">Go to <t t-esc="action.name"/></a>
</div>
</t>
</t>

1
kpi_dashboard/views/kpi_kpi.xml

@ -104,6 +104,7 @@
<field name="action_ids">
<tree editable="bottom">
<field name="action"/>
<field name="context"/>
</tree>
</field>
</page>

Loading…
Cancel
Save