Skip to content

Commit

Permalink
[FIX] web: can't save if a o2m line have a modifier and try to read db
Browse files Browse the repository at this point in the history
When the user click on save, 'is_valid' is called on each field.
The o2m test all sub-field (apply modifier and check value).
But, if a modifier change the read-only attribute, the field is reinitialized and call 'render_value' without check 'no_rerender' value.
The relational fields call the db in render_value, and the x2m is invalid because a request is pending.
(change X2ManyListView to keep the 'no_rerender' initial value)

opw-653120
  • Loading branch information
Gorash committed Mar 1, 2016
1 parent 20ab363 commit a46a3f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 5 additions & 3 deletions addons/web/static/src/js/views/form_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ var ReinitializeWidgetMixin = {
var ReinitializeFieldMixin = _.extend({}, ReinitializeWidgetMixin, {
reinitialize: function() {
ReinitializeWidgetMixin.reinitialize.call(this);
var res = this.render_value();
if (this.view && this.view.render_value_defs){
this.view.render_value_defs.push(res);
if (!this.no_rerender) {
var res = this.render_value();
if (this.view && this.view.render_value_defs){
this.view.render_value_defs.push(res);
}
}
},
});
Expand Down
6 changes: 2 additions & 4 deletions addons/web/static/src/js/views/form_relational_widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -963,17 +963,15 @@ var X2ManyListView = ListView.extend({
var current_values = {};
_.each(fields, function(field){
field._inhibit_on_change_flag = true;
field.__no_rerender = field.no_rerender;
field.no_rerender = true;
current_values[field.name] = field.get('value');
});
var cached_records = _.filter(this.dataset.cache, function(item){return !_.isEmpty(item.values)});
var valid = _.every(cached_records, function(record){
_.each(fields, function(field){
var value = record.values[field.name];
var tmp = field.no_rerender;
field.no_rerender = true;
field.set_value(_.isArray(value) && _.isArray(value[0]) ? [COMMANDS.delete_all()].concat(value) : value);
field.no_rerender = tmp;
});
return _.every(fields, function(field){
field.process_modifiers();
Expand All @@ -984,7 +982,7 @@ var X2ManyListView = ListView.extend({
_.each(fields, function(field){
field.set('value', current_values[field.name], {silent: true});
field._inhibit_on_change_flag = false;
field.no_rerender = false;
field.no_rerender = field.__no_rerender;
});
return valid;
},
Expand Down

0 comments on commit a46a3f9

Please sign in to comment.