1 /*---------------------------------------------------------
2 * Odoo Pivot Table view
3 *---------------------------------------------------------*/
8 var instance = openerp,
9 _lt = instance.web._lt,
11 QWeb = instance.web.qweb;
13 instance.web.views.add('pivot', 'instance.web.PivotView');
15 instance.web.PivotView = instance.web.View.extend({
16 template: 'PivotView',
17 display_name: _lt('Pivot'),
20 init: function(parent, dataset, view_id, options) {
21 this._super(parent, dataset, view_id, options);
22 this.model = new instance.web.Model(dataset.model, {group_by_no_leaf: true});
23 this.action_manager = parent.action_manager;
25 this.$buttons = options.$buttons;
28 this.groupable_fields = {};
30 this.row_groupbys = [];
31 this.col_groupbys = [];
32 this.active_measures = [];
36 load_fields = this.model.call('fields_get', [])
37 .then(this.prepare_fields.bind(this));
39 return $.when(this._super(), load_fields).then(function () {
40 var context = {measures: _.pairs(self.measures)};
41 self.$buttons.html(QWeb.render('PivotView.buttons', self), context);
44 view_loading: function (fvg) {
46 this.do_push_state({});
47 fvg.arch.children.forEach(function (field) {
48 var name = field.attrs.name + (field.attrs.interval || '');
49 //noinspection FallThroughInSwitchStatementJS
50 switch (field.attrs.type) {
52 self.active_measures.push(name);
55 self.col_groupbys.push(name);
58 if ('operator' in field.attrs) {
59 self.active_measures.push(name);
63 self.row_groupbys.push(name);
67 prepare_fields: function (fields) {
69 groupable_types = ['many2one', 'char', 'boolean',
70 'selection', 'date', 'datetime'];
72 _.each(fields, function (field, name) {
73 if ((name !== 'id') && (field.store === true)) {
74 if (field.type === 'integer' || field.type === 'float') {
75 self.measures[name] = field;
77 if (_.contains(groupable_types, field.type)) {
78 self.groupable_fields[name] = field;
83 do_search: function (domain, context, group_by) {
84 console.log('do_search', domain, context, group_by);
86 context.measure = "lol";