[IMP] adds support for various intervals when grouping by date in graph view (addon web_graph)
bzr revid: ged@openerp.com-20140113133800-3n1hi5ajpioktr3d
This commit is contained in:
parent
58598420fc
commit
e2bb629c3c
|
@ -369,7 +369,7 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix
|
|||
return;
|
||||
}
|
||||
var fields = _.map(this.important_fields, function (field) {
|
||||
return {id: field, value: self.fields[field].string};
|
||||
return {id: field, value: self.fields[field].string, type:self.fields[field].type};
|
||||
});
|
||||
this.dropdown = $(QWeb.render('field_selection', {fields:fields, header_id:id}));
|
||||
$(event.target).after(this.dropdown);
|
||||
|
@ -383,9 +383,15 @@ instance.web_graph.Graph = instance.web.Widget.extend(openerp.EventDispatcherMix
|
|||
|
||||
field_selection: function (event) {
|
||||
var id = event.target.attributes['data-id'].nodeValue,
|
||||
field_id = event.target.attributes['data-field-id'].nodeValue;
|
||||
field_id = event.target.attributes['data-field-id'].nodeValue,
|
||||
interval;
|
||||
event.preventDefault();
|
||||
this.pivot.expand(id, field_id);
|
||||
if (this.fields[field_id].type === 'date' || this.fields[field_id].type === 'datetime') {
|
||||
interval = event.target.attributes['data-interval'].nodeValue;
|
||||
this.pivot.expand(id, {field: field_id, interval: interval});
|
||||
} else {
|
||||
this.pivot.expand(id, field_id);
|
||||
}
|
||||
},
|
||||
|
||||
/******************************************************************************
|
||||
|
|
|
@ -107,6 +107,9 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherM
|
|||
},
|
||||
|
||||
create_field_value: function (f) {
|
||||
if (f.field && f.interval) {
|
||||
return {field:f.field, string: this.fields[f.field].string, type:this.fields[f.field].type, interval: f.interval};
|
||||
}
|
||||
return (f.field && f.string && f.type) ? f : {field: f, string: this.fields[f].string, type: this.fields[f].type};
|
||||
},
|
||||
|
||||
|
@ -376,11 +379,37 @@ openerp.web_graph.PivotTable = openerp.web.Class.extend(openerp.EventDispatcherM
|
|||
|
||||
_query_db: function (groupby, fields, domain, path) {
|
||||
var self = this,
|
||||
field_ids = _.without(_.pluck(fields, 'field'), '__count');
|
||||
// To do : add code to check if groupby is date/datetime
|
||||
// and in that case, add the correct code to the context
|
||||
field_ids = _.without(_.pluck(fields, 'field'), '__count'),
|
||||
context = {};
|
||||
|
||||
if (groupby.interval) {
|
||||
context.datetime_format = {};
|
||||
var display_format;
|
||||
switch (groupby.interval) {
|
||||
case 'day':
|
||||
display_format = 'dd MMMM YYYY';
|
||||
break;
|
||||
case 'week':
|
||||
display_format = 'w YYYY';
|
||||
break;
|
||||
case 'month':
|
||||
display_format = 'MMMM YYYY';
|
||||
break;
|
||||
case 'quarter':
|
||||
display_format = 'QQQ YYYY';
|
||||
break;
|
||||
case 'year':
|
||||
display_format = 'YYYY';
|
||||
break;
|
||||
}
|
||||
context.datetime_format[groupby.field] = {
|
||||
interval: groupby.interval,
|
||||
display_format: display_format
|
||||
};
|
||||
}
|
||||
return this.model.query(field_ids)
|
||||
.filter(domain)
|
||||
.context(context)
|
||||
.group_by(groupby.field)
|
||||
.then(function (results) {
|
||||
var groups = _.filter(results, function (group) {
|
||||
|
|
|
@ -47,11 +47,41 @@
|
|||
<span class="btn btn-default field-selection dropdown-toggle" data-toggle="dropdown"></span>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<t t-foreach="fields" t-as="field">
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value"/>
|
||||
</a>
|
||||
</li>
|
||||
<t t-if="(field.type === 'date') || (field.type === 'datetime')">
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-interval="'day'" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value + ' (day)'"/>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-interval="'week'" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value + ' (week)'"/>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-interval="'month'" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value + ' (month)'"/>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-interval="'quarter'" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value + ' (quarter)'"/>
|
||||
</a>
|
||||
</li>
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-interval="'year'" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value + ' (year)'"/>
|
||||
</a>
|
||||
</li>
|
||||
</t>
|
||||
|
||||
<t t-if="(field.type !== 'date') && (field.type !== 'datetime')">
|
||||
<li>
|
||||
<a class="field-selection" t-att-data-field-id="field.id" t-att-data-id="header_id" href="#">
|
||||
<t t-esc="field.value"/>
|
||||
</a>
|
||||
</li>
|
||||
</t>
|
||||
</t>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue