Browse Source

[MIG] web_widget_x2many_2d_matrix: Migration to 9.0

pull/871/head
Pedro M. Baeza 8 years ago
committed by Simone Orsi
parent
commit
e3a2ca214f
  1. 9
      web_widget_x2many_2d_matrix/README.rst
  2. 2
      web_widget_x2many_2d_matrix/__openerp__.py
  3. 53
      web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js

9
web_widget_x2many_2d_matrix/README.rst

@ -110,6 +110,15 @@ Known issues / Roadmap
====================== ======================
* it would be worth trying to instantiate the proper field widget and let it render the input * it would be worth trying to instantiate the proper field widget and let it render the input
* If you pass values with an onchange, you need to overwrite the model's method
`onchange` for making the widget work::
@api.multi
def onchange(self, values, field_name, field_onchange):
if "one2many_field" in field_onchange:
for sub in [<field_list>]:
field_onchange.setdefault("one2many_field." + sub, u"")
return super(model, self).onchange(values, field_name, field_onchange)
Bug Tracker Bug Tracker
=========== ===========

2
web_widget_x2many_2d_matrix/__openerp__.py

@ -5,7 +5,7 @@
{ {
"name": "2D matrix for x2many fields", "name": "2D matrix for x2many fields",
"version": "8.0.1.1.0",
"version": "9.0.1.0.0",
"author": "Therp BV, " "author": "Therp BV, "
"Tecnativa," "Tecnativa,"
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",

53
web_widget_x2many_2d_matrix/static/src/js/web_widget_x2many_2d_matrix.js

@ -2,12 +2,16 @@
* Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com> * Copyright 2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
openerp.web_widget_x2many_2d_matrix = function(instance)
{
instance.web.form.widgets.add(
'x2many_2d_matrix',
'instance.web_widget_x2many_2d_matrix.FieldX2Many2dMatrix');
instance.web_widget_x2many_2d_matrix.FieldX2Many2dMatrix = instance.web.form.FieldOne2Many.extend({
odoo.define('web_widget_x2many_2d_matrix.widget', function (require) {
"use strict";
var core = require('web.core');
var formats = require('web.formats');
var FieldOne2Many = core.form_widget_registry.get('one2many');
var Model = require('web.Model');
var data = require('web.data');
var WidgetX2Many2dMatrix = FieldOne2Many.extend({
template: 'FieldX2Many2dMatrix', template: 'FieldX2Many2dMatrix',
widget_class: 'oe_form_field_x2many_2d_matrix', widget_class: 'oe_form_field_x2many_2d_matrix',
@ -46,7 +50,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
this.field_editability = node.attrs.field_editability || this.field_editability; this.field_editability = node.attrs.field_editability || this.field_editability;
this.show_row_totals = node.attrs.show_row_totals || this.show_row_totals; this.show_row_totals = node.attrs.show_row_totals || this.show_row_totals;
this.show_column_totals = node.attrs.show_column_totals || this.show_column_totals; this.show_column_totals = node.attrs.show_column_totals || this.show_column_totals;
return this._super.apply(this, arguments);
return this._super(field_manager, node);
}, },
// return a field's value, id in case it's a one2many field // return a field's value, id in case it's a one2many field
@ -67,10 +71,10 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
}, },
// setup our datastructure for simple access in the template // setup our datastructure for simple access in the template
set_value: function()
set_value: function(value_)
{ {
var self = this, var self = this,
result = this._super.apply(this, arguments);
result = this._super(value_);
self.by_x_axis = {}; self.by_x_axis = {};
self.by_y_axis = {}; self.by_y_axis = {};
@ -150,7 +154,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
{ {
return; return;
} }
var model = new instance.web.Model(self.fields[field].relation);
var model = new Model(self.fields[field].relation);
deferrends.push(model.call( deferrends.push(model.call(
'name_get', 'name_get',
[_.map(_.keys(rows), function(key) {return parseInt(key)})]) [_.map(_.keys(rows), function(key) {return parseInt(key)})])
@ -171,7 +175,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
self.compute_totals(); self.compute_totals();
self.setup_many2one_axes(); self.setup_many2one_axes();
self.$el.find('.edit').on( self.$el.find('.edit').on(
'change', self.proxy(self.xy_value_change));
'change', self.proxy(self.xy_value_change));
self.effective_readonly_change(); self.effective_readonly_change();
} }
return jQuery.when.apply(jQuery, deferrends); return jQuery.when.apply(jQuery, deferrends);
@ -290,14 +294,14 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
// parse a value from user input // parse a value from user input
parse_xy_value: function(val) parse_xy_value: function(val)
{ {
return instance.web.parse_value(
return formats.parse_value(
val, {'type': this.fields[this.field_value].type}); val, {'type': this.fields[this.field_value].type});
}, },
// format a value from the database for display // format a value from the database for display
format_xy_value: function(val) format_xy_value: function(val)
{ {
return instance.web.format_value(
return formats.format_value(
val, {'type': this.fields[this.field_value].type}); val, {'type': this.fields[this.field_value].type});
}, },
@ -381,7 +385,7 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
this.on("change:effective_readonly", this.on("change:effective_readonly",
this, this.proxy(this.effective_readonly_change)); this, this.proxy(this.effective_readonly_change));
this.effective_readonly_change(); this.effective_readonly_change();
return this._super.apply(this, arguments);
return this._super();
}, },
xy_value_change: function(e) xy_value_change: function(e)
@ -423,9 +427,20 @@ openerp.web_widget_x2many_2d_matrix = function(instance)
return this.$el.find('.oe_form_invalid').length == 0; return this.$el.find('.oe_form_invalid').length == 0;
}, },
// deactivate view related functions
load_views: function() {},
reload_current_view: function() {},
get_active_view: function() {},
load_views: function() {
// Needed for removing the initial empty tree view when the widget
// is loaded
var self = this,
result = this._super();
return $.when(result).then(function()
{
self.set_value(false);
});
},
}); });
}
core.form_widget_registry.add('x2many_2d_matrix', WidgetX2Many2dMatrix);
return WidgetX2Many2dMatrix;
});
Loading…
Cancel
Save