Skip to content

Commit

Permalink
[FIX] web: char_domain rendering on record switch
Browse files Browse the repository at this point in the history
When using the left/riht arrow to switch of record
in a form view,
the rendering of the `char_domain` widget was done too
early, before all fields are ready / set, and if the
domain of the previous record could not be applied
on the current record, it leaded to a traceback.

This revision introduce a new deffered,
because I coudln't find one that was doing
what I was looking for:
 - `is_initialized` is a defferred which is
 resolved when the form view has finished
 its rendering for the first time
 - `reload_mutex` is a mutex used only when reloading or
 switch to left/right record.

While the one needed in this case is a deferred
which is resolved when the record has finished
being rendered, wether when its when coming
from the list view to the form view (and it's
not the first time the form view is loaded,
e.g. list view -> form view -> list view -> form view, another record),
or on the switch of left/right record.

opw-671594
  • Loading branch information
beledouxdenis committed Mar 10, 2016
1 parent abe5859 commit 4fb2e76
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion addons/web/static/src/js/view_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
"footer_to_buttons": false,
});
this.is_initialized = $.Deferred();
this.record_loaded = $.Deferred();
this.mutating_mutex = new $.Mutex();
this.save_list = [];
this.render_value_defs = [];
Expand Down Expand Up @@ -329,6 +330,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
this._actualize_mode();
this.set({ 'title' : record.id ? record.display_name : _t("New") });

this.record_loaded = $.Deferred();
_(this.fields).each(function (field, f) {
field._dirty_flag = false;
field._inhibit_on_change_flag = true;
Expand All @@ -344,6 +346,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
self.on_form_changed();
self.rendering_engine.init_fields();
self.is_initialized.resolve();
self.record_loaded.resolve();
self.do_update_pager(record.id === null || record.id === undefined);
if (self.sidebar) {
self.sidebar.do_attachement_update(self.dataset, self.datarecord.id);
Expand Down Expand Up @@ -2568,7 +2571,7 @@ instance.web.form.FieldCharDomain = instance.web.form.AbstractField.extend(insta
});
if (this.options.model_field){
this.field_manager.fields[this.options.model_field].on("change:value", this, function(){
if (self.view && self.view.onchanges_mutex){
if (self.view && self.view.record_loaded.state == "resolved" && self.view.onchanges_mutex){
self.view.onchanges_mutex.def.then(function(){
self.display_field();
});
Expand Down

0 comments on commit 4fb2e76

Please sign in to comment.