[FIX] web: handle the case of a field domain without set model
Some domain fields are initialized with a model which depends of another form field value. Sometimes, this value is False and the domain selector cannot be used during that time (and was even performing useless RPC). Now, in this case, the field domain is fully replaced by a message which explains that a model have to be set. If you don't want this message to be shown, you still have the possibility to not show the field domain when there is no model thanks to the "invisible" attrs.
This commit is contained in:
@@ -447,9 +447,11 @@ var FieldDomain = common.AbstractField.extend(common.ReinitializeFieldMixin).ext
|
||||
},
|
||||
initialize_content: function () {
|
||||
this._super.apply(this, arguments);
|
||||
this.$recordsCountDisplay = this.$(".o_domain_records_count");
|
||||
this.$showSelectionButton = this.$(".o_domain_show_selection_button");
|
||||
this.$errorMessage = this.$(".o_domain_error_message");
|
||||
this.$panel = this.$(".o_form_field_domain_panel");
|
||||
this.$showSelectionButton = this.$panel.find(".o_domain_show_selection_button");
|
||||
this.$recordsCountDisplay = this.$showSelectionButton.find(".o_domain_records_count");
|
||||
this.$errorMessage = this.$panel.find(".o_domain_error_message");
|
||||
this.$modelMissing = this.$(".o_domain_model_missing");
|
||||
},
|
||||
set_value: function (value, noDomainSelectorRender) {
|
||||
this._noDomainSelectorRender = !!noDomainSelectorRender;
|
||||
@@ -459,6 +461,17 @@ var FieldDomain = common.AbstractField.extend(common.ReinitializeFieldMixin).ext
|
||||
render_value: function() {
|
||||
this._super.apply(this, arguments);
|
||||
|
||||
// If there is no set model, the field should only display the corresponding error message
|
||||
this.$panel.toggleClass("o_hidden", !this.model);
|
||||
this.$modelMissing.toggleClass("o_hidden", !!this.model);
|
||||
if (!this.model) {
|
||||
if (this.domainSelector) {
|
||||
this.domainSelector.destroy();
|
||||
this.domainSelector = undefined;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var domain = pyeval.eval("domain", this.get("value") || "[]");
|
||||
|
||||
// Recreate domain widget with new domain value
|
||||
|
||||
@@ -680,6 +680,7 @@
|
||||
<button t-if="widget.options.in_dialog && !widget.get('effective_readonly')"
|
||||
class="btn btn-sm btn-primary o_form_field_domain_dialog_button">Edit domain</button>
|
||||
</div>
|
||||
<div class="o_domain_model_missing o_hidden">Select a model to add a filter.</div>
|
||||
</div>
|
||||
|
||||
<t t-name="DomainNode.ControlPanel">
|
||||
|
||||
Reference in New Issue
Block a user