From b1a28045180c26d54ce4c5e968c869d020ae2357 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Alexandre=20D=2E=20D=C3=ADaz?=
Date: Fri, 22 Jan 2021 19:23:09 +0100
Subject: [PATCH] [IMP] web_widget_one2many_product_picker: Add auto-save
feature
---
web_widget_one2many_product_picker/README.rst | 5 +++++
web_widget_one2many_product_picker/__manifest__.py | 2 +-
web_widget_one2many_product_picker/readme/CONFIGURE.rst | 5 +++++
.../static/description/index.html | 5 +++++
.../static/src/js/widgets/field_one2many_product_picker.js | 7 +++++++
5 files changed, 23 insertions(+), 1 deletion(-)
diff --git a/web_widget_one2many_product_picker/README.rst b/web_widget_one2many_product_picker/README.rst
index 9db4b125e..3a6070abb 100644
--- a/web_widget_one2many_product_picker/README.rst
+++ b/web_widget_one2many_product_picker/README.rst
@@ -80,6 +80,11 @@ Widget options:
* edit_price > Enable/Disable price edits (True by default)
* show_discount > Enable/Disable display discount (False by default)
* show_subtotal > Enable/Disable show subtotal (True by default)
+* auto_save > Enable/Disable auto save (False by default)
+
+ If using auto save feature, you should keep in mind that the "Save" and "Discard" buttons
+ will lose part of its functionality as the document will be saved every time you
+ modify/create a record with the widget.
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/__manifest__.py b/web_widget_one2many_product_picker/__manifest__.py
index 37c97c0c8..d19bfc69a 100644
--- a/web_widget_one2many_product_picker/__manifest__.py
+++ b/web_widget_one2many_product_picker/__manifest__.py
@@ -4,7 +4,7 @@
{
'name': 'Web Widget One2Many Product Picker',
'summary': 'Widget to select products on one2many fields',
- 'version': '12.0.1.3.0',
+ 'version': '12.0.1.4.0',
'category': 'Website',
'author': "Tecnativa, "
"Odoo Community Association (OCA)",
diff --git a/web_widget_one2many_product_picker/readme/CONFIGURE.rst b/web_widget_one2many_product_picker/readme/CONFIGURE.rst
index 2d1112c87..3fd01a9b4 100644
--- a/web_widget_one2many_product_picker/readme/CONFIGURE.rst
+++ b/web_widget_one2many_product_picker/readme/CONFIGURE.rst
@@ -38,6 +38,11 @@ Widget options:
* edit_price > Enable/Disable price edits (True by default)
* show_discount > Enable/Disable display discount (False by default)
* show_subtotal > Enable/Disable show subtotal (True by default)
+* auto_save > Enable/Disable auto save (False by default)
+
+ If using auto save feature, you should keep in mind that the "Save" and "Discard" buttons
+ will lose part of its functionality as the document will be saved every time you
+ modify/create a record with the widget.
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 67e169734..639e6d921 100644
--- a/web_widget_one2many_product_picker/static/description/index.html
+++ b/web_widget_one2many_product_picker/static/description/index.html
@@ -464,6 +464,11 @@ You need to define the view fields. The view must be of show_subtotal > Enable/Disable show subtotal (True by default)
+auto_save > Enable/Disable auto save (False by default)
+If using auto save feature, you should keep in mind that the “Save” and “Discard” buttons
+will lose part of its functionality as the document will be saved every time you
+modify/create a record with the widget.
+
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/widgets/field_one2many_product_picker.js b/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js
index f31ee21b3..91bd95d1f 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
@@ -437,6 +437,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
price_unit: "price_unit",
discount: "discount",
},
+ auto_save: false,
};
},
@@ -581,6 +582,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_onCreateQuickRecord: function (evt) {
this.parent_controller.model.setPureVirtual(evt.data.id, false);
this._setValue({operation: "ADD", id: evt.data.id});
+ if (this.options.auto_save) {
+ this.parent_controller.saveRecord(undefined, {stayInEdit: true});
+ }
},
/**
@@ -591,6 +595,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
*/
_onUpdateQuickRecord: function (evt) {
this._setValue({operation: "UPDATE", id: evt.data.id, data: evt.data.data});
+ if (this.options.auto_save) {
+ this.parent_controller.saveRecord(undefined, {stayInEdit: true});
+ }
},
/**