diff --git a/web_widget_one2many_product_picker/README.rst b/web_widget_one2many_product_picker/README.rst index bd6dc7ef0..3a79e39c0 100644 --- a/web_widget_one2many_product_picker/README.rst +++ b/web_widget_one2many_product_picker/README.rst @@ -87,6 +87,7 @@ Widget options: modify/create a record with the widget. * 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. Notice that you can call '_' method to use translations. This only can be used with this widget. diff --git a/web_widget_one2many_product_picker/readme/CONFIGURE.rst b/web_widget_one2many_product_picker/readme/CONFIGURE.rst index 29d8e9813..0794fea11 100644 --- a/web_widget_one2many_product_picker/readme/CONFIGURE.rst +++ b/web_widget_one2many_product_picker/readme/CONFIGURE.rst @@ -45,6 +45,7 @@ Widget options: modify/create a record with the widget. * 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. Notice that you can call '_' method to use translations. This only can be used with this widget. diff --git a/web_widget_one2many_product_picker/static/description/index.html b/web_widget_one2many_product_picker/static/description/index.html index de595921c..13701db51 100644 --- a/web_widget_one2many_product_picker/static/description/index.html +++ b/web_widget_one2many_product_picker/static/description/index.html @@ -473,6 +473,8 @@ modify/create a record with the widget.
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. Notice that you can call ‘_’ method to use translations. This only can be used with this widget.
diff --git a/web_widget_one2many_product_picker/static/src/js/views/basic_controller.js b/web_widget_one2many_product_picker/static/src/js/views/basic_controller.js new file mode 100644 index 000000000..45c1c74fa --- /dev/null +++ b/web_widget_one2many_product_picker/static/src/js/views/basic_controller.js @@ -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 + ); + } + }); + }, + }); +}); diff --git a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js index d3d1acbac..08e6a576d 100644 --- a/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js +++ b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js @@ -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 */ @@ -438,6 +453,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun price_unit: "price_unit", discount: "discount", }, + trigger_refresh_fields: ["partner_id", "currency_id"], auto_save: false, ignore_warning: false, }; diff --git a/web_widget_one2many_product_picker/templates/assets.xml b/web_widget_one2many_product_picker/templates/assets.xml index 3c476236a..560e49df9 100644 --- a/web_widget_one2many_product_picker/templates/assets.xml +++ b/web_widget_one2many_product_picker/templates/assets.xml @@ -26,6 +26,7 @@ +