[IMP] web_widget_one2many_product_picker: Add auto-save feature

This commit is contained in:
Alexandre D. Díaz
2021-01-22 19:23:09 +01:00
parent dbb8754729
commit 93aacf9bb0
4 changed files with 22 additions and 0 deletions

View File

@@ -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.

View File

@@ -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.

View File

@@ -464,6 +464,11 @@ You need to define the view fields. The view must be of <tt class="docutils lite
</li>
<li><p class="first">show_subtotal &gt; Enable/Disable show subtotal (True by default)</p>
</li>
<li><p class="first">auto_save &gt; Enable/Disable auto save (False by default)</p>
<p>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.</p>
</li>
</ul>
<p>All widget options are optional.
Notice that you can call _ method to use translations. This only can be used with this widget.</p>

View File

@@ -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});
}
},
/**