Merge PR #2185 into 13.0

Signed-off-by pedrobaeza
pull/2210/head
OCA-git-bot 2022-05-04 21:37:13 +00:00
commit b2c17a1048
3 changed files with 17 additions and 13 deletions

View File

@ -31,21 +31,14 @@ class BaseModel(models.BaseModel):
field_obj = self[relation_field] field_obj = self[relation_field]
if field_obj: if field_obj:
relation_id = relation_id.id relation_id = relation_id.id
has_product = ( db_sol = self.search(
self.search( [(relation_field, "=", relation_id), (product_field, "in", product_ids)],
[
(relation_field, "=", relation_id),
(product_field, "in", product_ids),
],
count=True,
limit=1, limit=1,
) )
!= 0 if db_sol:
)
if has_product:
raise ValidationError( raise ValidationError(
_("Can't create the %s: Duplicated product! (Already in database)") _("Can't create the %s: Duplicated product (%s)! (Already in database)")
% relation % (relation, db_sol[product_field].display_name)
) )
@api.model_create_multi @api.model_create_multi

View File

@ -98,6 +98,9 @@ odoo.define(
}, },
canBeUpdated: function() { canBeUpdated: function() {
if (!this.getParent()) {
return false;
}
var model = this.getParent().getBasicFieldParams().model; var model = this.getParent().getBasicFieldParams().model;
for (var widget of this.widgets) { for (var widget of this.widgets) {
if (!widget.state) { if (!widget.state) {
@ -149,6 +152,9 @@ odoo.define(
}, },
getWidgetsWithoutOnchange: function() { getWidgetsWithoutOnchange: function() {
if (!this.getParent()) {
return false;
}
var model = this.getParent().getBasicFieldParams().model; var model = this.getParent().getBasicFieldParams().model;
return _.filter(this.widgets, function(item) { return _.filter(this.widgets, function(item) {
return ( return (

View File

@ -810,6 +810,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_saveDocument: function(ids_to_update) { _saveDocument: function(ids_to_update) {
var widgets = this.renderer.getWidgetsWithoutOnchange(); var widgets = this.renderer.getWidgetsWithoutOnchange();
if ( if (
widgets === false ||
!_.isEmpty(this._ids_to_wait) || !_.isEmpty(this._ids_to_wait) ||
_.isEmpty(ids_to_update) || _.isEmpty(ids_to_update) ||
!_.isEmpty(widgets) !_.isEmpty(widgets)
@ -1140,6 +1141,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_onResumeAutoSave: function() { _onResumeAutoSave: function() {
// Check if can resume // Check if can resume
if ( if (
!this._is_auto_save_paused ||
this.$(".oe_product_picker_quick_modif_price").is(":visible") || this.$(".oe_product_picker_quick_modif_price").is(":visible") ||
this.$(".oe_search_input").is(":focus") || this.$(".oe_search_input").is(":focus") ||
this.$(".oe_flip_card.active").length this.$(".oe_flip_card.active").length
@ -1148,6 +1150,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
} }
if (this._need_resume_auto_save) { if (this._need_resume_auto_save) {
if (this._auto_save_timeout) {
clearTimeout(this._auto_save_timeout);
}
this._auto_save_timeout = setTimeout( this._auto_save_timeout = setTimeout(
this._saveDocument.bind(this), this._saveDocument.bind(this),
this.options.auto_save_delay, this.options.auto_save_delay,