mirror of https://github.com/OCA/web.git
[IMP] web_widget_one2many_product_picker: self-refresh
Adds support to refresh the widget when a document field changespull/1941/head
parent
d49286056f
commit
959fbde243
|
@ -87,6 +87,7 @@ Widget options:
|
||||||
modify/create a record with the widget.
|
modify/create a record with the widget.
|
||||||
|
|
||||||
* ignore_warning > Enable/Disable display onchange warnings (False by default)
|
* ignore_warning > Enable/Disable display onchange warnings (False by default)
|
||||||
|
* trigger_refresh_fields > Fields in the main record that dispatch a widget refresh (["partner_id", "currency_id"] by default)
|
||||||
|
|
||||||
All widget options are optional.
|
All widget options are optional.
|
||||||
Notice that you can call '_' method to use translations. This only can be used with this widget.
|
Notice that you can call '_' method to use translations. This only can be used with this widget.
|
||||||
|
|
|
@ -45,6 +45,7 @@ Widget options:
|
||||||
modify/create a record with the widget.
|
modify/create a record with the widget.
|
||||||
|
|
||||||
* ignore_warning > Enable/Disable display onchange warnings (False by default)
|
* ignore_warning > Enable/Disable display onchange warnings (False by default)
|
||||||
|
* trigger_refresh_fields > Fields in the main record that dispatch a widget refresh (["partner_id", "currency_id"] by default)
|
||||||
|
|
||||||
All widget options are optional.
|
All widget options are optional.
|
||||||
Notice that you can call '_' method to use translations. This only can be used with this widget.
|
Notice that you can call '_' method to use translations. This only can be used with this widget.
|
||||||
|
|
|
@ -473,6 +473,8 @@ modify/create a record with the widget.</p>
|
||||||
</li>
|
</li>
|
||||||
<li><p class="first">ignore_warning > Enable/Disable display onchange warnings (False by default)</p>
|
<li><p class="first">ignore_warning > Enable/Disable display onchange warnings (False by default)</p>
|
||||||
</li>
|
</li>
|
||||||
|
<li><p class="first">trigger_refresh_fields > Fields in the main record that dispatch a widget refresh ([“partner_id”, “currency_id”] by default)</p>
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>All widget options are optional.
|
<p>All widget options are optional.
|
||||||
Notice that you can call ‘_’ method to use translations. This only can be used with this widget.</p>
|
Notice that you can call ‘_’ method to use translations. This only can be used with this widget.</p>
|
||||||
|
|
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright 2021 Tecnativa - Alexandre Díaz
|
||||||
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
odoo.define("web_widget_one2many_product_picker.BasicController", function(require) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
const BasicController = require("web.BasicController");
|
||||||
|
|
||||||
|
BasicController.include({
|
||||||
|
/**
|
||||||
|
* This is necessary to refresh 'one2many_product_picker' when some 'trigger_refresh_fields' fields changes.
|
||||||
|
*
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
|
_confirmChange: function(id, fields, e) {
|
||||||
|
id = id || this.handle;
|
||||||
|
var self = this;
|
||||||
|
return this._super.apply(this, arguments).then(function () {
|
||||||
|
if (self.renderer && !_.isEmpty(self.renderer.allFieldWidgets)) {
|
||||||
|
var product_picker_widgets = _.filter(
|
||||||
|
self.renderer.allFieldWidgets[id],
|
||||||
|
item => item.attrs.widget === "one2many_product_picker"
|
||||||
|
);
|
||||||
|
_.invoke(
|
||||||
|
product_picker_widgets,
|
||||||
|
"onDocumentConfirmChanges",
|
||||||
|
fields,
|
||||||
|
e
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
|
@ -163,6 +163,21 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Because the widget shows "pure virtual" information, we don't have any 'onchange' linked.
|
||||||
|
* This method forces 'refresh' the widget if the selected fields was changed.
|
||||||
|
*
|
||||||
|
* @param {Array} fields
|
||||||
|
* @param {Event} e
|
||||||
|
*/
|
||||||
|
onDocumentConfirmChanges: function(fields, e) {
|
||||||
|
var trigger_fields = this.options.trigger_refresh_fields || [];
|
||||||
|
if (_.difference(trigger_fields, fields).length !== trigger_fields.length) {
|
||||||
|
this._reset(this.parent_controller.model.get(this.parent_controller.handle), e);
|
||||||
|
this.doRenderSearchRecords();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
|
@ -438,6 +453,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
price_unit: "price_unit",
|
price_unit: "price_unit",
|
||||||
discount: "discount",
|
discount: "discount",
|
||||||
},
|
},
|
||||||
|
trigger_refresh_fields: ["partner_id", "currency_id"],
|
||||||
auto_save: false,
|
auto_save: false,
|
||||||
ignore_warning: false,
|
ignore_warning: false,
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form.js"></script>
|
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form.js"></script>
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_view.js"></script>
|
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_view.js"></script>
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_model.js"></script>
|
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_model.js"></script>
|
||||||
|
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_controller.js"></script>
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js"></script>
|
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js"></script>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
Loading…
Reference in New Issue