Skip to content

Commit

Permalink
[IMP] Mis builder analytic account & tags filters - Send operator to …
Browse files Browse the repository at this point in the history
…context
  • Loading branch information
apineux committed Oct 1, 2019
1 parent 6a85622 commit 7967068
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
25 changes: 16 additions & 9 deletions mis_builder/models/mis_report_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,17 +307,22 @@ def _onchange_source(self):
def _get_filter_domain_from_context(self):
filters = []
mis_report_filters = self.env.context.get('mis_report_filters', {})
for filter_name, values in mis_report_filters.items():
if values:
value = values.get('value')
for filter_name, domain in mis_report_filters.items():
if domain:
value = domain.get('value')
operator = domain.get('operator')
if not value:
continue
if not isinstance(value, list):
value = [value]
many_ids = self.report_instance_id.resolve_2many_commands(
filter_name, value, ['id'])
for m in many_ids:
filters.append((filter_name, 'in', [m['id']]))
# Operator = 'all' when coming from JS widget
if operator == 'all':
if not isinstance(value, list):
value = [value]

This comment has been minimized.

Copy link
@sbidoul

sbidoul Oct 1, 2019

Member

I would error if value is not a list.

many_ids = self.report_instance_id.resolve_2many_commands(
filter_name, value, ['id'])
for m in many_ids:
filters.append((filter_name, 'in', [m['id']]))
else:
filters.append((filter_name, operator, value))
return filters

@api.multi
Expand Down Expand Up @@ -607,10 +612,12 @@ def _add_analytic_filters_to_context(self, context):
if self.analytic_account_id:
context['mis_report_filters']['analytic_account_id'] = {
'value': self.analytic_account_id.id,
'operator': 'all',

This comment has been minimized.

Copy link
@sbidoul

sbidoul Oct 1, 2019

Member

Can we keep '=' (the default) here?

}
if self.analytic_tag_ids:
context['mis_report_filters']['analytic_tag_ids'] = {
'value': self.analytic_tag_ids.ids,
'operator': 'all',
}

@api.multi
Expand Down
9 changes: 3 additions & 6 deletions mis_builder/static/src/js/mis_report_widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ odoo.define('mis_builder.widget', function (require) {
self.init_filter(attr_name);
self.filter_values[attr_name]['value'] =
field_object.get_value() || undefined;
self.filter_values[attr_name]['operator'] = 'all';
},

set_filter_operator: function(operator, attr_name) {
Expand Down Expand Up @@ -209,7 +210,7 @@ odoo.define('mis_builder.widget', function (require) {
},
});
self.init_filter_value(analytic_account_id_m2o, field_name);
analytic_account_id_m2o.prependTo(self.get_mis_builder_filter_box());
analytic_account_id_m2o.appendTo(self.$("#analytic_account"));
analytic_account_id_m2o.$input.focusout(function () {
self.set_filter_value(analytic_account_id_m2o, field_name);
});
Expand Down Expand Up @@ -246,7 +247,7 @@ odoo.define('mis_builder.widget', function (require) {
},
});
self.init_filter_value(analytic_tag_ids_m2m, field_name);
analytic_tag_ids_m2m.prependTo(self.get_mis_builder_filter_box());
analytic_tag_ids_m2m.appendTo(self.$("#analytic_tags"));
analytic_tag_ids_m2m.on("change:value", this, function () {
self.set_filter_value(analytic_tag_ids_m2m, field_name);
});
Expand Down Expand Up @@ -316,10 +317,6 @@ odoo.define('mis_builder.widget', function (require) {
});
},

get_mis_builder_filter_box: function () {
var self = this;
return self.$(".oe_mis_builder_analytic_filter_box");
},

This comment has been minimized.

Copy link
@sbidoul

sbidoul Oct 1, 2019

Member

I liked this one :)

This comment has been minimized.

Copy link
@sbidoul

sbidoul Oct 1, 2019

Member

And it's probably used in extension modules which add filters.

});

core.form_widget_registry.add('mis_report_widget', MisReportWidget);
Expand Down
5 changes: 4 additions & 1 deletion mis_builder/static/src/xml/mis_report_widget.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
<t t-if="widget.mis_report_data">
<h2><t t-esc="widget.mis_report_data.report_name" /></h2>
<div>
<div class="oe_mis_builder_analytic_filter_box oe_left" style="position: relative; display: inline-block;"/>
<div class="oe_mis_builder_analytic_filter_box oe_left" style="position: relative; display: inline-block;">
<div id="analytic_account"/>
<div id="analytic_tags"/>
</div>
<div class="oe_mis_builder_buttons oe_right oe_button_box">
<button class="oe_mis_builder_refresh btn btn-sm oe_button"><span class="fa fa-refresh"/> Refresh</button>
<button class="oe_mis_builder_print btn btn-sm oe_button"><span class="fa fa-print"/> Print</button>
Expand Down

0 comments on commit 7967068

Please sign in to comment.