mirror of https://github.com/OCA/web.git
[IMP] web_widget_one2many_product_picker: black, isort, prettier
parent
78fdd8580c
commit
eb1a53d92a
|
@ -0,0 +1 @@
|
||||||
|
../../../../web_widget_one2many_product_picker
|
|
@ -0,0 +1,6 @@
|
||||||
|
import setuptools
|
||||||
|
|
||||||
|
setuptools.setup(
|
||||||
|
setup_requires=['setuptools-odoo'],
|
||||||
|
odoo_addon=True,
|
||||||
|
)
|
|
@ -2,23 +2,16 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Web Widget One2Many Product Picker',
|
"name": "Web Widget One2Many Product Picker",
|
||||||
'summary': 'Widget to select products on one2many fields',
|
"summary": "Widget to select products on one2many fields",
|
||||||
'version': '12.0.2.3.0',
|
"version": "12.0.2.3.0",
|
||||||
'category': 'Website',
|
"category": "Website",
|
||||||
'author': "Tecnativa, "
|
"author": "Tecnativa, " "Odoo Community Association (OCA)",
|
||||||
"Odoo Community Association (OCA)",
|
"website": "https://www.tecnativa.com",
|
||||||
'website': 'https://www.tecnativa.com',
|
"license": "AGPL-3",
|
||||||
'license': 'AGPL-3',
|
"depends": ["product",],
|
||||||
'depends': [
|
"data": ["templates/assets.xml",],
|
||||||
'product',
|
"qweb": ["static/src/xml/one2many_product_picker.xml",],
|
||||||
],
|
"installable": True,
|
||||||
'data': [
|
"auto_install": False,
|
||||||
'templates/assets.xml',
|
|
||||||
],
|
|
||||||
'qweb': [
|
|
||||||
'static/src/xml/one2many_product_picker.xml',
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
'auto_install': False,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,23 +4,23 @@ from odoo import api, fields, models, tools
|
||||||
|
|
||||||
|
|
||||||
class ProductProduct(models.Model):
|
class ProductProduct(models.Model):
|
||||||
_inherit = 'product.product'
|
_inherit = "product.product"
|
||||||
|
|
||||||
image_variant_medium = fields.Binary(
|
image_variant_medium = fields.Binary(
|
||||||
"Variant Image Medium (Computed)",
|
"Variant Image Medium (Computed)",
|
||||||
compute='_compute_variant_image',
|
compute="_compute_variant_image",
|
||||||
help="This field holds the image used as image for the product variant"
|
help="This field holds the image used as image for the product variant"
|
||||||
"or product image medium, limited to 512x512px.",
|
"or product image medium, limited to 512x512px.",
|
||||||
)
|
)
|
||||||
|
|
||||||
image_variant_big = fields.Binary(
|
image_variant_big = fields.Binary(
|
||||||
"Variant Image Big (Computed)",
|
"Variant Image Big (Computed)",
|
||||||
compute='_compute_variant_image',
|
compute="_compute_variant_image",
|
||||||
help="This field holds the image used as image for the product variant"
|
help="This field holds the image used as image for the product variant"
|
||||||
"or product image, limited to 1024x1024px.",
|
"or product image, limited to 1024x1024px.",
|
||||||
)
|
)
|
||||||
|
|
||||||
@api.depends('image_variant', 'product_tmpl_id.image')
|
@api.depends("image_variant", "product_tmpl_id.image")
|
||||||
def _compute_variant_image(self):
|
def _compute_variant_image(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.image_variant:
|
if record.image_variant:
|
||||||
|
@ -28,8 +28,9 @@ class ProductProduct(models.Model):
|
||||||
record.image_variant,
|
record.image_variant,
|
||||||
return_big=False,
|
return_big=False,
|
||||||
return_small=False,
|
return_small=False,
|
||||||
avoid_resize_medium=True)
|
avoid_resize_medium=True,
|
||||||
record.image_variant_medium = resized_images['image_medium']
|
)
|
||||||
|
record.image_variant_medium = resized_images["image_medium"]
|
||||||
record.image_variant_big = record.image_variant
|
record.image_variant_big = record.image_variant
|
||||||
else:
|
else:
|
||||||
record.image_variant_medium = record.product_tmpl_id.image_medium
|
record.image_variant_medium = record.product_tmpl_id.image_medium
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define("web_widget_one2many_product_picker.tools", function (
|
odoo.define("web_widget_one2many_product_picker.tools", function(require) {
|
||||||
require
|
|
||||||
) {
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var field_utils = require("web.field_utils");
|
var field_utils = require("web.field_utils");
|
||||||
|
@ -29,10 +27,7 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
function monetary(value, field_info, currency_field, data) {
|
function monetary(value, field_info, currency_field, data) {
|
||||||
return field_utils.format.monetary(
|
return field_utils.format.monetary(value, field_info, {
|
||||||
value,
|
|
||||||
field_info,
|
|
||||||
{
|
|
||||||
data: data,
|
data: data,
|
||||||
currency_field: currency_field,
|
currency_field: currency_field,
|
||||||
field_digits: true,
|
field_digits: true,
|
||||||
|
@ -43,5 +38,4 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
|
||||||
monetary: monetary,
|
monetary: monetary,
|
||||||
priceReduce: priceReduce,
|
priceReduce: priceReduce,
|
||||||
};
|
};
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,9 +8,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
var Widget = require("web.Widget");
|
var Widget = require("web.Widget");
|
||||||
var widgetRegistry = require("web.widget_registry");
|
var widgetRegistry = require("web.widget_registry");
|
||||||
var ProductPickerQuickCreateFormView = require(
|
var ProductPickerQuickCreateFormView = require("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView")
|
||||||
"web_widget_one2many_product_picker.ProductPickerQuickCreateFormView"
|
.ProductPickerQuickCreateFormView;
|
||||||
).ProductPickerQuickCreateFormView;
|
|
||||||
|
|
||||||
var qweb = core.qweb;
|
var qweb = core.qweb;
|
||||||
|
|
||||||
|
@ -70,7 +69,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
var refinedContext = _.extend(
|
var refinedContext = _.extend(
|
||||||
{},
|
{},
|
||||||
this.main_state.getContext(),
|
this.main_state.getContext(),
|
||||||
this.nodeContext);
|
this.nodeContext
|
||||||
|
);
|
||||||
_.extend(refinedContext, this.editContext);
|
_.extend(refinedContext, this.editContext);
|
||||||
this.formView = new ProductPickerQuickCreateFormView(fieldsView, {
|
this.formView = new ProductPickerQuickCreateFormView(fieldsView, {
|
||||||
context: refinedContext,
|
context: refinedContext,
|
||||||
|
@ -89,7 +89,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
model: this.basicFieldParams.model,
|
model: this.basicFieldParams.model,
|
||||||
mainRecordData: this.getParent().getParent().state,
|
mainRecordData: this.getParent().getParent().state,
|
||||||
});
|
});
|
||||||
// if (this.id) {
|
// If (this.id) {
|
||||||
// this.basicFieldParams.model.save(this.id, {savePoint: true});
|
// this.basicFieldParams.model.save(this.id, {savePoint: true});
|
||||||
// }
|
// }
|
||||||
var def2 = this.formView.getController(this).then(function(controller) {
|
var def2 = this.formView.getController(this).then(function(controller) {
|
||||||
|
@ -112,7 +112,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
* @returns {String}
|
* @returns {String}
|
||||||
*/
|
*/
|
||||||
_generateFormArch: function() {
|
_generateFormArch: function() {
|
||||||
var template = "<templates><t t-name='One2ManyProductPicker.QuickCreateForm'>";
|
var template =
|
||||||
|
"<templates><t t-name='One2ManyProductPicker.QuickCreateForm'>";
|
||||||
template += this.basicFieldParams.field.views.form.arch;
|
template += this.basicFieldParams.field.views.form.arch;
|
||||||
template += "</t></templates>";
|
template += "</t></templates>";
|
||||||
qweb.add_template(template);
|
qweb.add_template(template);
|
||||||
|
@ -128,10 +129,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
*/
|
*/
|
||||||
_onReloadView: function(evt) {
|
_onReloadView: function(evt) {
|
||||||
this.editContext = {
|
this.editContext = {
|
||||||
'ignore_onchanges': [this.compareKey],
|
ignore_onchanges: [this.compareKey],
|
||||||
'base_record_id': evt.data.baseRecordID || null,
|
base_record_id: evt.data.baseRecordID || null,
|
||||||
'base_record_res_id': evt.data.baseRecordResID || null,
|
base_record_res_id: evt.data.baseRecordResID || null,
|
||||||
'base_record_compare_value': evt.data.baseRecordCompareValue || null,
|
base_record_compare_value: evt.data.baseRecordCompareValue || null,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (evt.data.baseRecordCompareValue === evt.data.compareValue) {
|
if (evt.data.baseRecordCompareValue === evt.data.compareValue) {
|
||||||
|
@ -140,10 +141,17 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
this.start();
|
this.start();
|
||||||
} else {
|
} else {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.getParent()._generateVirtualState({}, this.editContext).then(function (state) {
|
this.getParent()
|
||||||
|
._generateVirtualState({}, this.editContext)
|
||||||
|
.then(function(state) {
|
||||||
var data = {};
|
var data = {};
|
||||||
data[self.compareKey] = {operation: 'ADD', id: evt.data.compareValue};
|
data[self.compareKey] = {
|
||||||
self.basicFieldParams.model._applyChange(state.id, data).then(function () {
|
operation: "ADD",
|
||||||
|
id: evt.data.compareValue,
|
||||||
|
};
|
||||||
|
self.basicFieldParams.model
|
||||||
|
._applyChange(state.id, data)
|
||||||
|
.then(function() {
|
||||||
self.res_id = state.res_id;
|
self.res_id = state.res_id;
|
||||||
self.id = state.id;
|
self.id = state.id;
|
||||||
self.start();
|
self.start();
|
||||||
|
@ -153,7 +161,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
widgetRegistry.add("product_picker_quick_create_form", ProductPickerQuickCreateForm);
|
widgetRegistry.add(
|
||||||
|
"product_picker_quick_create_form",
|
||||||
|
ProductPickerQuickCreateForm
|
||||||
|
);
|
||||||
|
|
||||||
return ProductPickerQuickCreateForm;
|
return ProductPickerQuickCreateForm;
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView", function (
|
odoo.define(
|
||||||
require
|
"web_widget_one2many_product_picker.ProductPickerQuickCreateFormView",
|
||||||
) {
|
function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +20,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
_applyOnChange: function(values, record, viewType) {
|
_applyOnChange: function(values, record, viewType) {
|
||||||
var vt = viewType || record.viewType;
|
var vt = viewType || record.viewType;
|
||||||
// Ignore changes by record context 'ignore_onchanges' fields
|
// Ignore changes by record context 'ignore_onchanges' fields
|
||||||
if ('ignore_onchanges' in record.context) {
|
if ("ignore_onchanges" in record.context) {
|
||||||
var ignore_changes = record.context.ignore_onchanges;
|
var ignore_changes = record.context.ignore_onchanges;
|
||||||
for (var index in ignore_changes) {
|
for (var index in ignore_changes) {
|
||||||
var field_name = ignore_changes[index];
|
var field_name = ignore_changes[index];
|
||||||
|
@ -32,23 +32,21 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
var ProductPickerQuickCreateFormRenderer =
|
var ProductPickerQuickCreateFormRenderer = QuickCreateFormView.prototype.config.Renderer.extend(
|
||||||
QuickCreateFormView.prototype.config.Renderer.extend(
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
start: function() {
|
start: function() {
|
||||||
this.$el.addClass(
|
this.$el.addClass(
|
||||||
"oe_one2many_product_picker_form_view o_xxs_form_view");
|
"oe_one2many_product_picker_form_view o_xxs_form_view"
|
||||||
|
);
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var ProductPickerQuickCreateFormController =
|
var ProductPickerQuickCreateFormController = QuickCreateFormView.prototype.config.Controller.extend(
|
||||||
QuickCreateFormView.prototype.config.Controller.extend(
|
|
||||||
{
|
{
|
||||||
events: _.extend({}, QuickCreateFormView.prototype.events, {
|
events: _.extend({}, QuickCreateFormView.prototype.events, {
|
||||||
"click .oe_record_add": "_onClickAdd",
|
"click .oe_record_add": "_onClickAdd",
|
||||||
|
@ -70,7 +68,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
*/
|
*/
|
||||||
auto: function() {
|
auto: function() {
|
||||||
var record = this.model.get(this.handle);
|
var record = this.model.get(this.handle);
|
||||||
if (record.context.has_changes_confirmed || typeof record.context.has_changes_confirmed === "undefined") {
|
if (
|
||||||
|
record.context.has_changes_confirmed ||
|
||||||
|
typeof record.context.has_changes_confirmed === "undefined"
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var state = this._getRecordState();
|
var state = this._getRecordState();
|
||||||
|
@ -118,11 +119,9 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_updateButtons: function() {
|
_updateButtons: function() {
|
||||||
this.$el.find(
|
this.$el.find(".oe_one2many_product_picker_form_buttons").remove();
|
||||||
".oe_one2many_product_picker_form_buttons").remove();
|
|
||||||
this.$el.find(".o_form_view").append(
|
this.$el.find(".o_form_view").append(
|
||||||
qweb.render(
|
qweb.render("One2ManyProductPicker.QuickCreate.FormButtons", {
|
||||||
"One2ManyProductPicker.QuickCreate.FormButtons", {
|
|
||||||
state: this._getRecordState(),
|
state: this._getRecordState(),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
@ -151,7 +150,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_enableQuickCreate: function() {
|
_enableQuickCreate: function() {
|
||||||
|
|
||||||
// Allows to create again
|
// Allows to create again
|
||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
this.$el.removeClass("o_disabled");
|
this.$el.removeClass("o_disabled");
|
||||||
|
@ -197,17 +195,16 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
compareValue: new_value,
|
compareValue: new_value,
|
||||||
};
|
};
|
||||||
var record = this.model.get(this.handle);
|
var record = this.model.get(this.handle);
|
||||||
if (!('base_record_id' in record.context)) {
|
if (!("base_record_id" in record.context)) {
|
||||||
var old_value = record.data[this.compareKey];
|
var old_value = record.data[this.compareKey];
|
||||||
if (typeof old_value === 'object') {
|
if (typeof old_value === "object") {
|
||||||
old_value = old_value.data.id;
|
old_value = old_value.data.id;
|
||||||
}
|
}
|
||||||
reload_values.baseRecordID = record.id;
|
reload_values.baseRecordID = record.id;
|
||||||
reload_values.baseRecordResID = record.ref;
|
reload_values.baseRecordResID = record.ref;
|
||||||
reload_values.baseRecordCompareValue = old_value;
|
reload_values.baseRecordCompareValue = old_value;
|
||||||
} else {
|
} else {
|
||||||
reload_values.baseRecordID =
|
reload_values.baseRecordID = record.context.base_record_id;
|
||||||
record.context.base_record_id;
|
|
||||||
reload_values.baseRecordResID =
|
reload_values.baseRecordResID =
|
||||||
record.context.base_record_res_id;
|
record.context.base_record_res_id;
|
||||||
reload_values.baseRecordCompareValue =
|
reload_values.baseRecordCompareValue =
|
||||||
|
@ -239,7 +236,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
*/
|
*/
|
||||||
_add: function() {
|
_add: function() {
|
||||||
if (this._disabled) {
|
if (this._disabled) {
|
||||||
|
|
||||||
// Don't do anything if we are already creating a record
|
// Don't do anything if we are already creating a record
|
||||||
return $.Deferred();
|
return $.Deferred();
|
||||||
}
|
}
|
||||||
|
@ -261,7 +257,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
id: record.id,
|
id: record.id,
|
||||||
});
|
});
|
||||||
self.model.unsetDirty(self.handle);
|
self.model.unsetDirty(self.handle);
|
||||||
//self._updateButtons();
|
// Self._updateButtons();
|
||||||
self._enableQuickCreate();
|
self._enableQuickCreate();
|
||||||
},
|
},
|
||||||
block: true,
|
block: true,
|
||||||
|
@ -271,7 +267,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
|
|
||||||
_remove: function() {
|
_remove: function() {
|
||||||
if (this._disabled) {
|
if (this._disabled) {
|
||||||
|
|
||||||
// Don't do anything if we are already creating a record
|
// Don't do anything if we are already creating a record
|
||||||
return $.Deferred();
|
return $.Deferred();
|
||||||
}
|
}
|
||||||
|
@ -287,7 +282,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
_change: function() {
|
_change: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this._disabled) {
|
if (this._disabled) {
|
||||||
|
|
||||||
// Don't do anything if we are already creating a record
|
// Don't do anything if we are already creating a record
|
||||||
return $.Deferred();
|
return $.Deferred();
|
||||||
}
|
}
|
||||||
|
@ -303,7 +297,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
id: record.id,
|
id: record.id,
|
||||||
});
|
});
|
||||||
self.model.unsetDirty(self.handle);
|
self.model.unsetDirty(self.handle);
|
||||||
//self._updateButtons();
|
// Self._updateButtons();
|
||||||
self._enableQuickCreate();
|
self._enableQuickCreate();
|
||||||
},
|
},
|
||||||
block: true,
|
block: true,
|
||||||
|
@ -313,7 +307,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
_discard: function() {
|
_discard: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
if (this._disabled) {
|
if (this._disabled) {
|
||||||
|
|
||||||
// Don't do anything if we are already creating a record
|
// Don't do anything if we are already creating a record
|
||||||
return $.Deferred();
|
return $.Deferred();
|
||||||
}
|
}
|
||||||
|
@ -401,4 +394,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
|
||||||
ProductPickerQuickCreateFormController: ProductPickerQuickCreateFormController,
|
ProductPickerQuickCreateFormController: ProductPickerQuickCreateFormController,
|
||||||
ProductPickerQuickCreateFormView: ProductPickerQuickCreateFormView,
|
ProductPickerQuickCreateFormView: ProductPickerQuickCreateFormView,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -1,15 +1,14 @@
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm", function (
|
odoo.define(
|
||||||
require
|
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm",
|
||||||
) {
|
function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
var Widget = require("web.Widget");
|
var Widget = require("web.Widget");
|
||||||
var ProductPickerQuickModifPriceFormView = require(
|
var ProductPickerQuickModifPriceFormView = require("web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView")
|
||||||
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView"
|
.ProductPickerQuickModifPriceFormView;
|
||||||
).ProductPickerQuickModifPriceFormView;
|
|
||||||
|
|
||||||
var qweb = core.qweb;
|
var qweb = core.qweb;
|
||||||
|
|
||||||
|
@ -110,23 +109,29 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
template += this.basicFieldParams.field.views.form.arch;
|
template += this.basicFieldParams.field.views.form.arch;
|
||||||
template += "</t></templates>";
|
template += "</t></templates>";
|
||||||
qweb.add_template(template);
|
qweb.add_template(template);
|
||||||
var $arch = $(qweb.render("One2ManyProductPicker.QuickModifPrice.Form", {
|
var $arch = $(
|
||||||
|
qweb.render("One2ManyProductPicker.QuickModifPrice.Form", {
|
||||||
field_map: this.fieldMap,
|
field_map: this.fieldMap,
|
||||||
record_search: this.searchRecord,
|
record_search: this.searchRecord,
|
||||||
}));
|
})
|
||||||
|
);
|
||||||
|
|
||||||
var field_names = Object.keys(wanted_field_states);
|
var field_names = Object.keys(wanted_field_states);
|
||||||
var gen_arch = "<form><group>";
|
var gen_arch = "<form><group>";
|
||||||
for (var index in field_names) {
|
for (var index in field_names) {
|
||||||
var field_name = field_names[index];
|
var field_name = field_names[index];
|
||||||
var $field = $arch.find("field[name='" + field_name + "']");
|
var $field = $arch.find("field[name='" + field_name + "']");
|
||||||
var modifiers =
|
var modifiers = $field.attr("modifiers")
|
||||||
$field.attr("modifiers") ? JSON.parse($field.attr("modifiers")) : {};
|
? JSON.parse($field.attr("modifiers"))
|
||||||
|
: {};
|
||||||
modifiers.invisible = false;
|
modifiers.invisible = false;
|
||||||
modifiers.readonly = wanted_field_states[field_name];
|
modifiers.readonly = wanted_field_states[field_name];
|
||||||
$field.attr("modifiers", JSON.stringify(modifiers));
|
$field.attr("modifiers", JSON.stringify(modifiers));
|
||||||
$field.attr("invisible", "0");
|
$field.attr("invisible", "0");
|
||||||
$field.attr("readonly", wanted_field_states[field_name]?"1":"0");
|
$field.attr(
|
||||||
|
"readonly",
|
||||||
|
wanted_field_states[field_name] ? "1" : "0"
|
||||||
|
);
|
||||||
gen_arch += $field[0].outerHTML;
|
gen_arch += $field[0].outerHTML;
|
||||||
}
|
}
|
||||||
gen_arch += "</group></form>";
|
gen_arch += "</group></form>";
|
||||||
|
@ -149,4 +154,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
});
|
});
|
||||||
|
|
||||||
return ProductPickerQuickModifPriceForm;
|
return ProductPickerQuickModifPriceForm;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView", function (
|
odoo.define(
|
||||||
require
|
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView",
|
||||||
) {
|
function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,8 +16,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
|
|
||||||
var qweb = core.qweb;
|
var qweb = core.qweb;
|
||||||
|
|
||||||
var ProductPickerQuickModifPriceFormRenderer =
|
var ProductPickerQuickModifPriceFormRenderer = QuickCreateFormView.prototype.config.Renderer.extend(
|
||||||
QuickCreateFormView.prototype.config.Renderer.extend(
|
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
|
@ -25,7 +24,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
start: function() {
|
start: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$el.addClass(
|
this.$el.addClass(
|
||||||
"oe_one2many_product_picker_form_view o_xxs_form_view");
|
"oe_one2many_product_picker_form_view o_xxs_form_view"
|
||||||
|
);
|
||||||
return this._super.apply(this, arguments).then(function() {
|
return this._super.apply(this, arguments).then(function() {
|
||||||
self._appendPrice();
|
self._appendPrice();
|
||||||
self._appendButtons();
|
self._appendButtons();
|
||||||
|
@ -36,13 +36,14 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_appendButtons: function() {
|
_appendButtons: function() {
|
||||||
this.$el.find(
|
this.$el.find(".oe_one2many_product_picker_form_buttons").remove();
|
||||||
".oe_one2many_product_picker_form_buttons").remove();
|
|
||||||
this.$el.append(
|
this.$el.append(
|
||||||
qweb.render(
|
qweb.render(
|
||||||
"One2ManyProductPicker.QuickModifPrice.FormButtons", {
|
"One2ManyProductPicker.QuickModifPrice.FormButtons",
|
||||||
|
{
|
||||||
mode: this.mode,
|
mode: this.mode,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -58,8 +59,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
var ProductPickerQuickModifPriceFormController =
|
var ProductPickerQuickModifPriceFormController = QuickCreateFormView.prototype.config.Controller.extend(
|
||||||
QuickCreateFormView.prototype.config.Controller.extend(
|
|
||||||
{
|
{
|
||||||
events: _.extend({}, QuickCreateFormView.prototype.events, {
|
events: _.extend({}, QuickCreateFormView.prototype.events, {
|
||||||
"click .oe_record_change": "_onClickChange",
|
"click .oe_record_change": "_onClickChange",
|
||||||
|
@ -102,8 +102,11 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
var record = this.model.get(this.handle);
|
var record = this.model.get(this.handle);
|
||||||
var price_reduce = tools.priceReduce(
|
var price_reduce = tools.priceReduce(
|
||||||
record.data[this.fieldMap.price_unit],
|
record.data[this.fieldMap.price_unit],
|
||||||
record.data[this.fieldMap.discount]);
|
record.data[this.fieldMap.discount]
|
||||||
this.renderer.$el.find(".oe_price").html(
|
);
|
||||||
|
this.renderer.$el
|
||||||
|
.find(".oe_price")
|
||||||
|
.html(
|
||||||
tools.monetary(
|
tools.monetary(
|
||||||
price_reduce,
|
price_reduce,
|
||||||
this.getParent().state.fields[this.fieldMap.price_unit],
|
this.getParent().state.fields[this.fieldMap.price_unit],
|
||||||
|
@ -117,7 +120,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_disableQuickCreate: function() {
|
_disableQuickCreate: function() {
|
||||||
|
|
||||||
// Ensures that the record won't be created twice
|
// Ensures that the record won't be created twice
|
||||||
this._disabled = true;
|
this._disabled = true;
|
||||||
this.$el.addClass("o_disabled");
|
this.$el.addClass("o_disabled");
|
||||||
|
@ -130,7 +132,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_enableQuickCreate: function() {
|
_enableQuickCreate: function() {
|
||||||
|
|
||||||
// Allows to create again
|
// Allows to create again
|
||||||
this._disabled = false;
|
this._disabled = false;
|
||||||
this.$el.removeClass("o_disabled");
|
this.$el.removeClass("o_disabled");
|
||||||
|
@ -173,7 +174,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
this.getParent().destroy();
|
this.getParent().destroy();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// If is a "normal" record, update it
|
// If is a "normal" record, update it
|
||||||
var record = this.model.get(this.handle);
|
var record = this.model.get(this.handle);
|
||||||
this.trigger_up("update_quick_record", {
|
this.trigger_up("update_quick_record", {
|
||||||
|
@ -222,4 +222,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
|
||||||
ProductPickerQuickModifPriceFormController: ProductPickerQuickModifPriceFormController,
|
ProductPickerQuickModifPriceFormController: ProductPickerQuickModifPriceFormController,
|
||||||
ProductPickerQuickModifPriceFormView: ProductPickerQuickModifPriceFormView,
|
ProductPickerQuickModifPriceFormView: ProductPickerQuickModifPriceFormView,
|
||||||
};
|
};
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -11,9 +11,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var Domain = require("web.Domain");
|
var Domain = require("web.Domain");
|
||||||
var widgetRegistry = require("web.widget_registry");
|
var widgetRegistry = require("web.widget_registry");
|
||||||
var tools = require("web_widget_one2many_product_picker.tools");
|
var tools = require("web_widget_one2many_product_picker.tools");
|
||||||
var ProductPickerQuickModifPriceForm = require(
|
var ProductPickerQuickModifPriceForm = require("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm");
|
||||||
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm");
|
var FieldManagerMixin = require("web.FieldManagerMixin");
|
||||||
var FieldManagerMixin = require('web.FieldManagerMixin');
|
|
||||||
|
|
||||||
var qweb = core.qweb;
|
var qweb = core.qweb;
|
||||||
var _t = core._t;
|
var _t = core._t;
|
||||||
|
@ -81,7 +80,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
destroy: function() {
|
destroy: function() {
|
||||||
this.$card.off("")
|
this.$card.off("");
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -89,7 +88,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
update: function(record) {
|
update: function(record) {
|
||||||
|
|
||||||
// Detach the widgets because the record will empty its $el, which
|
// Detach the widgets because the record will empty its $el, which
|
||||||
// will remove all event handlers on its descendants, and we want
|
// will remove all event handlers on its descendants, and we want
|
||||||
// to keep those handlers alive as we will re-use these widgets
|
// to keep those handlers alive as we will re-use these widgets
|
||||||
|
@ -131,7 +129,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
return _.str.sprintf(
|
return _.str.sprintf(
|
||||||
"/web/image/product.product/%d/%s",
|
"/web/image/product.product/%d/%s",
|
||||||
product_id,
|
product_id,
|
||||||
field_name);
|
field_name
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,7 +146,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
price,
|
price,
|
||||||
this.state.fields[field_name],
|
this.state.fields[field_name],
|
||||||
this.options.currencyField,
|
this.options.currencyField,
|
||||||
this.state.data);
|
this.state.data
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -169,7 +169,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
* @param {Object} recordSearch
|
* @param {Object} recordSearch
|
||||||
*/
|
*/
|
||||||
_setState: function(viewState, recordSearch) {
|
_setState: function(viewState, recordSearch) {
|
||||||
|
|
||||||
// No parent = product_pricker widget destroyed
|
// No parent = product_pricker widget destroyed
|
||||||
// So this is a 'zombie' record. Destroy it!
|
// So this is a 'zombie' record. Destroy it!
|
||||||
if (!this.getParent()) {
|
if (!this.getParent()) {
|
||||||
|
@ -186,7 +185,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
this.recordSearch = recordSearch;
|
this.recordSearch = recordSearch;
|
||||||
}
|
}
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
this.is_virtual = this.state && model.isPureVirtual(this.state.id) || false;
|
this.is_virtual =
|
||||||
|
(this.state && model.isPureVirtual(this.state.id)) || false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -194,7 +194,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
_getQWebContext: function() {
|
_getQWebContext: function() {
|
||||||
|
|
||||||
// Using directly the 'model record' instead of the state because
|
// Using directly the 'model record' instead of the state because
|
||||||
// the state it's a parsed version of this record that doesn't
|
// the state it's a parsed version of this record that doesn't
|
||||||
// contains the '_virtual' attribute.
|
// contains the '_virtual' attribute.
|
||||||
|
@ -202,7 +201,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var record = model.get(this.state.id);
|
var record = model.get(this.state.id);
|
||||||
return {
|
return {
|
||||||
record_search: this.recordSearch,
|
record_search: this.recordSearch,
|
||||||
user_context: this.getSession() && this.getSession().user_context || {},
|
user_context:
|
||||||
|
(this.getSession() && this.getSession().user_context) || {},
|
||||||
image: this._getImageUrl.bind(this),
|
image: this._getImageUrl.bind(this),
|
||||||
compute_domain: this._computeDomain.bind(this),
|
compute_domain: this._computeDomain.bind(this),
|
||||||
state: this.state,
|
state: this.state,
|
||||||
|
@ -212,7 +212,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
show_discount: this.options.showDiscount,
|
show_discount: this.options.showDiscount,
|
||||||
is_virtual: this.is_virtual,
|
is_virtual: this.is_virtual,
|
||||||
modified: record && record.context.product_picker_modified,
|
modified: record && record.context.product_picker_modified,
|
||||||
active_model: '',
|
active_model: "",
|
||||||
auto_save: this.options.autoSave,
|
auto_save: this.options.autoSave,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -240,7 +240,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
_getInternalVirtualRecordData: function() {
|
_getInternalVirtualRecordData: function() {
|
||||||
var data = {};
|
var data = {};
|
||||||
data[this.options.fieldMap.product] = {
|
data[this.options.fieldMap.product] = {
|
||||||
operation: 'ADD',
|
operation: "ADD",
|
||||||
id: this.recordSearch.id,
|
id: this.recordSearch.id,
|
||||||
};
|
};
|
||||||
return data;
|
return data;
|
||||||
|
@ -255,12 +255,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
_generateVirtualState: function(data, context) {
|
_generateVirtualState: function(data, context) {
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
var scontext = _.extend(
|
var scontext = _.extend(
|
||||||
{}, this._getInternalVirtualRecordContext(), context);
|
{},
|
||||||
|
this._getInternalVirtualRecordContext(),
|
||||||
|
context
|
||||||
|
);
|
||||||
// Force qty to 1.0 to launch correct onchanges
|
// Force qty to 1.0 to launch correct onchanges
|
||||||
scontext[`default_${this.options.fieldMap.product_uom_qty}`] = 1.0;
|
scontext[`default_${this.options.fieldMap.product_uom_qty}`] = 1.0;
|
||||||
var sdata = _.extend({}, this._getInternalVirtualRecordData(), data);
|
var sdata = _.extend({}, this._getInternalVirtualRecordData(), data);
|
||||||
return model.createVirtualRecord(
|
return model.createVirtualRecord(this.options.basicFieldParams.value.id, {
|
||||||
this.options.basicFieldParams.value.id, {
|
|
||||||
data: sdata,
|
data: sdata,
|
||||||
context: scontext,
|
context: scontext,
|
||||||
});
|
});
|
||||||
|
@ -282,17 +284,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
this._detachAllWidgets();
|
this._detachAllWidgets();
|
||||||
this.defs = [];
|
this.defs = [];
|
||||||
this._replaceElement(
|
this._replaceElement(
|
||||||
qweb.render(
|
qweb.render("One2ManyProductPicker.FlipCard", this._getQWebContext())
|
||||||
"One2ManyProductPicker.FlipCard",
|
|
||||||
this._getQWebContext()
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
this.$el.data("renderer_widget_index", this.options.renderer_widget_index);
|
this.$el.data("renderer_widget_index", this.options.renderer_widget_index);
|
||||||
this.$card = this.$(".oe_flip_card");
|
this.$card = this.$(".oe_flip_card");
|
||||||
this.$front = this.$(".oe_flip_card_front");
|
this.$front = this.$(".oe_flip_card_front");
|
||||||
this.$back = this.$(".oe_flip_card_back");
|
this.$back = this.$(".oe_flip_card_back");
|
||||||
this._processWidgetFields(this.$front);
|
this._processWidgetFields(this.$front);
|
||||||
this._processWidgets(this.$front, 'front');
|
this._processWidgets(this.$front, "front");
|
||||||
this._processDynamicFields();
|
this._processDynamicFields();
|
||||||
return $.when.apply(this, this.defs);
|
return $.when.apply(this, this.defs);
|
||||||
},
|
},
|
||||||
|
@ -314,27 +313,24 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var field_name = $field.attr("name");
|
var field_name = $field.attr("name");
|
||||||
var field_widget = $field.attr("widget");
|
var field_widget = $field.attr("widget");
|
||||||
|
|
||||||
// a widget is specified for that field or a field is a many2many ;
|
// A widget is specified for that field or a field is a many2many ;
|
||||||
// in this latest case, we want to display the widget many2manytags
|
// in this latest case, we want to display the widget many2manytags
|
||||||
// even if it is not specified in the view.
|
// even if it is not specified in the view.
|
||||||
if (field_widget || self.fields[field_name].type === "many2many") {
|
if (field_widget || self.fields[field_name].type === "many2many") {
|
||||||
var widget = self.subWidgets[field_name];
|
var widget = self.subWidgets[field_name];
|
||||||
if (widget) {
|
if (widget) {
|
||||||
|
// A widget already exists for that field, so reset it
|
||||||
// a widget already exists for that field, so reset it
|
|
||||||
// with the new state
|
// with the new state
|
||||||
widget.reset(self.state);
|
widget.reset(self.state);
|
||||||
$field.replaceWith(widget.$el);
|
$field.replaceWith(widget.$el);
|
||||||
} else {
|
} else {
|
||||||
|
// The widget doesn't exist yet, so instanciate it
|
||||||
// the widget doesn't exist yet, so instanciate it
|
|
||||||
var Widget = self.fieldsInfo[field_name].Widget;
|
var Widget = self.fieldsInfo[field_name].Widget;
|
||||||
if (Widget) {
|
if (Widget) {
|
||||||
widget = self._processWidget($field, field_name, Widget);
|
widget = self._processWidget($field, field_name, Widget);
|
||||||
self.subWidgets[field_name] = widget;
|
self.subWidgets[field_name] = widget;
|
||||||
} else if (config.debug) {
|
} else if (config.debug) {
|
||||||
|
// The widget is not implemented
|
||||||
// the widget is not implemented
|
|
||||||
$field.replaceWith(
|
$field.replaceWith(
|
||||||
$("<span>", {
|
$("<span>", {
|
||||||
text: _.str.sprintf(
|
text: _.str.sprintf(
|
||||||
|
@ -359,8 +355,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
* @returns {Widget} the widget instance
|
* @returns {Widget} the widget instance
|
||||||
*/
|
*/
|
||||||
_processWidget: function($field, field_name, Widget) {
|
_processWidget: function($field, field_name, Widget) {
|
||||||
|
// Some field's attrs might be record dependent (they start with
|
||||||
// some field's attrs might be record dependent (they start with
|
|
||||||
// 't-att-') and should thus be evaluated, which is done by qweb
|
// 't-att-') and should thus be evaluated, which is done by qweb
|
||||||
// we here replace those attrs in the dict of attrs of the state
|
// we here replace those attrs in the dict of attrs of the state
|
||||||
// by their evaluted value, to make it transparent from the
|
// by their evaluted value, to make it transparent from the
|
||||||
|
@ -379,10 +374,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
data: this.state.data,
|
data: this.state.data,
|
||||||
});
|
});
|
||||||
var widget = new Widget(
|
var widget = new Widget(this, field_name, this.getParent().state, options);
|
||||||
this, field_name,
|
|
||||||
this.getParent().state,
|
|
||||||
options);
|
|
||||||
var def = widget.replace($field);
|
var def = widget.replace($field);
|
||||||
if (def.state() === "pending") {
|
if (def.state() === "pending") {
|
||||||
this.defs.push(def);
|
this.defs.push(def);
|
||||||
|
@ -419,7 +411,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var def = widget
|
var def = widget
|
||||||
._widgetRenderAndInsert(function() {
|
._widgetRenderAndInsert(function() {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}).then(function () {
|
})
|
||||||
|
.then(function() {
|
||||||
widget.$el.addClass("o_widget");
|
widget.$el.addClass("o_widget");
|
||||||
$field.replaceWith(widget.$el);
|
$field.replaceWith(widget.$el);
|
||||||
});
|
});
|
||||||
|
@ -475,13 +468,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var field_map = this.options.fieldMap;
|
var field_map = this.options.fieldMap;
|
||||||
if (state_data) {
|
if (state_data) {
|
||||||
var has_discount = state_data[field_map.discount] > 0.0;
|
var has_discount = state_data[field_map.discount] > 0.0;
|
||||||
this.$el.find(".original_price,.discount_price")
|
this.$el
|
||||||
|
.find(".original_price,.discount_price")
|
||||||
.toggleClass("d-none", !has_discount);
|
.toggleClass("d-none", !has_discount);
|
||||||
if (has_discount) {
|
if (has_discount) {
|
||||||
this.$el.find(".price_unit").html(this._calcPriceReduced());
|
this.$el.find(".price_unit").html(this._calcPriceReduced());
|
||||||
} else {
|
} else {
|
||||||
this.$el.find(".price_unit").html(
|
this.$el
|
||||||
this._getMonetaryFieldValue("price_unit"));
|
.find(".price_unit")
|
||||||
|
.html(this._getMonetaryFieldValue("price_unit"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -499,13 +494,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
if (record && record.data[field_map.discount]) {
|
if (record && record.data[field_map.discount]) {
|
||||||
price_reduce = tools.priceReduce(
|
price_reduce = tools.priceReduce(
|
||||||
record.data[field_map.price_unit],
|
record.data[field_map.price_unit],
|
||||||
record.data[field_map.discount]);
|
record.data[field_map.discount]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return price_reduce && tools.monetary(
|
return (
|
||||||
|
price_reduce &&
|
||||||
|
tools.monetary(
|
||||||
price_reduce,
|
price_reduce,
|
||||||
this.state.fields[field_map.price_unit],
|
this.state.fields[field_map.price_unit],
|
||||||
this.options.currencyField,
|
this.options.currencyField,
|
||||||
this.state.data
|
this.state.data
|
||||||
|
)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -517,18 +516,22 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var self = this;
|
var self = this;
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
var record = model.get(this.state.id);
|
var record = model.get(this.state.id);
|
||||||
return model.save(record.id, {
|
return model
|
||||||
|
.save(record.id, {
|
||||||
stayInEdit: true,
|
stayInEdit: true,
|
||||||
reload: true,
|
reload: true,
|
||||||
savePoint: true,
|
savePoint: true,
|
||||||
viewType: "form",
|
viewType: "form",
|
||||||
}).then(function () {
|
})
|
||||||
|
.then(function() {
|
||||||
var record = model.get(self.state.id);
|
var record = model.get(self.state.id);
|
||||||
self.trigger_up("create_quick_record", {
|
self.trigger_up("create_quick_record", {
|
||||||
id: record.id,
|
id: record.id,
|
||||||
callback: function() {
|
callback: function() {
|
||||||
self.$card.find('.o_catch_attention').removeClass('o_catch_attention');
|
self.$card
|
||||||
}
|
.find(".o_catch_attention")
|
||||||
|
.removeClass("o_catch_attention");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
model.unsetDirty(self.state.id);
|
model.unsetDirty(self.state.id);
|
||||||
});
|
});
|
||||||
|
@ -544,8 +547,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
this.trigger_up("update_quick_record", {
|
this.trigger_up("update_quick_record", {
|
||||||
id: record.id,
|
id: record.id,
|
||||||
callback: function() {
|
callback: function() {
|
||||||
self.$card.find('.o_catch_attention').removeClass('o_catch_attention');
|
self.$card
|
||||||
}
|
.find(".o_catch_attention")
|
||||||
|
.removeClass("o_catch_attention");
|
||||||
|
},
|
||||||
});
|
});
|
||||||
model.unsetDirty(this.state.id);
|
model.unsetDirty(this.state.id);
|
||||||
},
|
},
|
||||||
|
@ -557,7 +562,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
_addProduct: function() {
|
_addProduct: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
model.updateRecordContext(this.state.id, {ignore_warning: this.options.ignoreWarning});
|
model.updateRecordContext(this.state.id, {
|
||||||
|
ignore_warning: this.options.ignoreWarning,
|
||||||
|
});
|
||||||
var record = model.get(this.state.id);
|
var record = model.get(this.state.id);
|
||||||
var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
|
var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
|
||||||
if (changes[this.options.fieldMap.product_uom_qty] === 0) {
|
if (changes[this.options.fieldMap.product_uom_qty] === 0) {
|
||||||
|
@ -565,10 +572,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
}
|
}
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
this.$card.addClass("blocked");
|
this.$card.addClass("blocked");
|
||||||
return model.notifyChanges(
|
return model.notifyChanges(record.id, changes).then(function() {
|
||||||
record.id,
|
|
||||||
changes
|
|
||||||
).then(function () {
|
|
||||||
self._saveRecord();
|
self._saveRecord();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -581,15 +585,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
_incProductQty: function(amount) {
|
_incProductQty: function(amount) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var model = this.options.basicFieldParams.model;
|
var model = this.options.basicFieldParams.model;
|
||||||
model.updateRecordContext(this.state.id, {ignore_warning: this.options.ignoreWarning});
|
model.updateRecordContext(this.state.id, {
|
||||||
|
ignore_warning: this.options.ignoreWarning,
|
||||||
|
});
|
||||||
var record = model.get(this.state.id);
|
var record = model.get(this.state.id);
|
||||||
var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
|
var changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
|
||||||
changes[this.options.fieldMap.product_uom_qty] += amount;
|
changes[this.options.fieldMap.product_uom_qty] += amount;
|
||||||
|
|
||||||
return model.notifyChanges(
|
return model.notifyChanges(record.id, changes).then(function() {
|
||||||
record.id,
|
|
||||||
changes
|
|
||||||
).then(function () {
|
|
||||||
self._processDynamicFields();
|
self._processDynamicFields();
|
||||||
self._lazyUpdateRecord();
|
self._lazyUpdateRecord();
|
||||||
});
|
});
|
||||||
|
@ -602,11 +605,11 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var $target = $(target);
|
var $target = $(target);
|
||||||
var $currentTarget = $(currentTarget);
|
var $currentTarget = $(currentTarget);
|
||||||
var $img = $currentTarget.find(".oe_flip_card_front img");
|
var $img = $currentTarget.find(".oe_flip_card_front img");
|
||||||
$target.addClass('o_catch_attention');
|
$target.addClass("o_catch_attention");
|
||||||
$img.addClass('oe_product_picker_catch_attention');
|
$img.addClass("oe_product_picker_catch_attention");
|
||||||
$img.on('animationend', function () {
|
$img.on("animationend", function() {
|
||||||
$img.removeClass('oe_product_picker_catch_attention');
|
$img.removeClass("oe_product_picker_catch_attention");
|
||||||
$img.off('animationend');
|
$img.off("animationend");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -632,7 +635,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
currencyField: this.options.currencyField,
|
currencyField: this.options.currencyField,
|
||||||
});
|
});
|
||||||
this.$modifPricePopup = $(
|
this.$modifPricePopup = $(
|
||||||
qweb.render("One2ManyProductPicker.QuickModifPricePopup"));
|
qweb.render("One2ManyProductPicker.QuickModifPricePopup")
|
||||||
|
);
|
||||||
this.$modifPricePopup.appendTo($(".o_main_content"));
|
this.$modifPricePopup.appendTo($(".o_main_content"));
|
||||||
modif_price_form.attachTo(this.$modifPricePopup);
|
modif_price_form.attachTo(this.$modifPricePopup);
|
||||||
},
|
},
|
||||||
|
@ -645,14 +649,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
*/
|
*/
|
||||||
_onClickFlipCard: function(evt) {
|
_onClickFlipCard: function(evt) {
|
||||||
// Avoid clicks on form elements
|
// Avoid clicks on form elements
|
||||||
if (['INPUT', 'BUTTON', 'A'].indexOf(evt.target.tagName) !== -1 || this.$card.hasClass('blocked')) {
|
if (
|
||||||
|
["INPUT", "BUTTON", "A"].indexOf(evt.target.tagName) !== -1 ||
|
||||||
|
this.$card.hasClass("blocked")
|
||||||
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var $target = $(evt.target);
|
var $target = $(evt.target);
|
||||||
if (!this.options.readOnlyMode) {
|
if (!this.options.readOnlyMode) {
|
||||||
if (
|
if (
|
||||||
$target.hasClass('add_product') ||
|
$target.hasClass("add_product") ||
|
||||||
$target.parents('.add_product').length
|
$target.parents(".add_product").length
|
||||||
) {
|
) {
|
||||||
if (!this.is_adding_product) {
|
if (!this.is_adding_product) {
|
||||||
this.is_adding_product = true;
|
this.is_adding_product = true;
|
||||||
|
@ -661,13 +668,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else if (
|
} else if (
|
||||||
$target.hasClass('product_qty') ||
|
$target.hasClass("product_qty") ||
|
||||||
$target.parents('.product_qty').length
|
$target.parents(".product_qty").length
|
||||||
) {
|
) {
|
||||||
this._incProductQty(1);
|
this._incProductQty(1);
|
||||||
this._doInteractAnim(evt.target, evt.currentTarget);
|
this._doInteractAnim(evt.target, evt.currentTarget);
|
||||||
return;
|
return;
|
||||||
} else if ($target.hasClass('safezone')) {
|
} else if ($target.hasClass("safezone")) {
|
||||||
// Do nothing on safe zones
|
// Do nothing on safe zones
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -675,7 +682,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
if (!this._clickFlipCardDelayed) {
|
if (!this._clickFlipCardDelayed) {
|
||||||
this._clickFlipCardDelayed = setTimeout(
|
this._clickFlipCardDelayed = setTimeout(
|
||||||
this._onClickDelayedFlipCard.bind(this, evt),
|
this._onClickDelayedFlipCard.bind(this, evt),
|
||||||
this._click_card_delayed_time);
|
this._click_card_delayed_time
|
||||||
|
);
|
||||||
}
|
}
|
||||||
++this._clickFlipCardCount;
|
++this._clickFlipCardCount;
|
||||||
if (this._clickFlipCardCount >= 2) {
|
if (this._clickFlipCardCount >= 2) {
|
||||||
|
@ -704,21 +712,23 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
this.defs = [];
|
this.defs = [];
|
||||||
if (!this.widgets.back.length) {
|
if (!this.widgets.back.length) {
|
||||||
this._processWidgetFields(this.$back);
|
this._processWidgetFields(this.$back);
|
||||||
this._processWidgets(this.$back, 'back');
|
this._processWidgets(this.$back, "back");
|
||||||
}
|
}
|
||||||
this._processDynamicFields();
|
this._processDynamicFields();
|
||||||
$.when(this.defs).then(function() {
|
$.when(this.defs).then(function() {
|
||||||
var $actived_card = self.$el.parent().find(".active");
|
var $actived_card = self.$el.parent().find(".active");
|
||||||
$actived_card.removeClass("active");
|
$actived_card.removeClass("active");
|
||||||
$actived_card.find('.oe_flip_card_front').removeClass("d-none");
|
$actived_card.find(".oe_flip_card_front").removeClass("d-none");
|
||||||
self.$card.addClass("active");
|
self.$card.addClass("active");
|
||||||
self.$card.on('transitionend', function () {
|
self.$card.on("transitionend", function() {
|
||||||
self.$front.addClass("d-none");
|
self.$front.addClass("d-none");
|
||||||
self.$card.off('transitionend');
|
self.$card.off("transitionend");
|
||||||
});
|
});
|
||||||
self.trigger_up("record_flip", {
|
self.trigger_up("record_flip", {
|
||||||
widget_index: self.$el.data("renderer_widget_index"),
|
widget_index: self.$el.data("renderer_widget_index"),
|
||||||
prev_widget_index: $actived_card.parent().data("renderer_widget_index"),
|
prev_widget_index: $actived_card
|
||||||
|
.parent()
|
||||||
|
.data("renderer_widget_index"),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -731,17 +741,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
_onDblClickDelayedFlipCard: function(evt) {
|
_onDblClickDelayedFlipCard: function(evt) {
|
||||||
var $target = $(evt.target);
|
var $target = $(evt.target);
|
||||||
if (
|
if (
|
||||||
$target.hasClass('badge_price') ||
|
$target.hasClass("badge_price") ||
|
||||||
$target.parents('.badge_price').length
|
$target.parents(".badge_price").length
|
||||||
) {
|
) {
|
||||||
this._openPriceModifier();
|
this._openPriceModifier();
|
||||||
} else {
|
} else {
|
||||||
var $currentTarget = $(evt.currentTarget);
|
var $currentTarget = $(evt.currentTarget);
|
||||||
var $img = $currentTarget.find(".oe_flip_card_front img");
|
var $img = $currentTarget.find(".oe_flip_card_front img");
|
||||||
var cur_img_src = $img.attr("src");
|
var cur_img_src = $img.attr("src");
|
||||||
if ($currentTarget.hasClass('oe_flip_card_maximized')) {
|
if ($currentTarget.hasClass("oe_flip_card_maximized")) {
|
||||||
$currentTarget.removeClass('oe_flip_card_maximized');
|
$currentTarget.removeClass("oe_flip_card_maximized");
|
||||||
$currentTarget.on('transitionend', function () {
|
$currentTarget.on("transitionend", function() {
|
||||||
$currentTarget.css({
|
$currentTarget.css({
|
||||||
position: "",
|
position: "",
|
||||||
top: "",
|
top: "",
|
||||||
|
@ -750,14 +760,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
height: "",
|
height: "",
|
||||||
zIndex: "",
|
zIndex: "",
|
||||||
});
|
});
|
||||||
$currentTarget.off('transitionend');
|
$currentTarget.off("transitionend");
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
var $actived_card = this.$el.parent().find(".active");
|
var $actived_card = this.$el.parent().find(".active");
|
||||||
if ($actived_card[0] !== $currentTarget[0]) {
|
if ($actived_card[0] !== $currentTarget[0]) {
|
||||||
$actived_card.removeClass("active");
|
$actived_card.removeClass("active");
|
||||||
$actived_card.find('.oe_flip_card_front')
|
$actived_card.find(".oe_flip_card_front").removeClass("d-none");
|
||||||
.removeClass("d-none");
|
|
||||||
}
|
}
|
||||||
var offset = $currentTarget.offset();
|
var offset = $currentTarget.offset();
|
||||||
$currentTarget.css({
|
$currentTarget.css({
|
||||||
|
@ -769,7 +778,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
zIndex: 50,
|
zIndex: 50,
|
||||||
});
|
});
|
||||||
_.defer(function() {
|
_.defer(function() {
|
||||||
$currentTarget.addClass('oe_flip_card_maximized');
|
$currentTarget.addClass("oe_flip_card_maximized");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
$img.attr("src", $img.data("srcAlt"));
|
$img.attr("src", $img.data("srcAlt"));
|
||||||
|
@ -784,9 +793,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
var self = this;
|
var self = this;
|
||||||
this.$card.removeClass("active");
|
this.$card.removeClass("active");
|
||||||
this.$front.removeClass("d-none");
|
this.$front.removeClass("d-none");
|
||||||
if (this.$card.hasClass('oe_flip_card_maximized')) {
|
if (this.$card.hasClass("oe_flip_card_maximized")) {
|
||||||
this.$card.removeClass('oe_flip_card_maximized');
|
this.$card.removeClass("oe_flip_card_maximized");
|
||||||
this.$card.on('transitionend', function () {
|
this.$card.on("transitionend", function() {
|
||||||
self.$card.css({
|
self.$card.css({
|
||||||
position: "",
|
position: "",
|
||||||
top: "",
|
top: "",
|
||||||
|
@ -795,7 +804,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
|
||||||
height: "",
|
height: "",
|
||||||
zIndex: "",
|
zIndex: "",
|
||||||
});
|
});
|
||||||
self.$card.off('transitionend');
|
self.$card.off("transitionend");
|
||||||
if (evt.data.success_callback) {
|
if (evt.data.success_callback) {
|
||||||
evt.data.success_callback();
|
evt.data.success_callback();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,28 +1,26 @@
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", function (
|
odoo.define(
|
||||||
require
|
"web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
) {
|
function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
var BasicRenderer = require("web.BasicRenderer");
|
var BasicRenderer = require("web.BasicRenderer");
|
||||||
var One2ManyProductPickerRecord = require(
|
var One2ManyProductPickerRecord = require("web_widget_one2many_product_picker.One2ManyProductPickerRecord");
|
||||||
"web_widget_one2many_product_picker.One2ManyProductPickerRecord");
|
var ProductPickerQuickCreateForm = require("web_widget_one2many_product_picker.ProductPickerQuickCreateForm");
|
||||||
var ProductPickerQuickCreateForm = require(
|
|
||||||
"web_widget_one2many_product_picker.ProductPickerQuickCreateForm");
|
|
||||||
|
|
||||||
var qweb = core.qweb;
|
var qweb = core.qweb;
|
||||||
|
|
||||||
/* This is the renderer of the main widget */
|
/* This is the renderer of the main widget */
|
||||||
var One2ManyProductPickerRenderer = BasicRenderer.extend({
|
var One2ManyProductPickerRenderer = BasicRenderer.extend({
|
||||||
className: 'oe_one2many_product_picker_view',
|
className: "oe_one2many_product_picker_view",
|
||||||
|
|
||||||
events: {
|
events: {
|
||||||
'click #productPickerLoadMore': '_onClickLoadMore',
|
"click #productPickerLoadMore": "_onClickLoadMore",
|
||||||
},
|
},
|
||||||
custom_events: {
|
custom_events: {
|
||||||
'record_flip': '_onRecordFlip',
|
record_flip: "_onRecordFlip",
|
||||||
},
|
},
|
||||||
|
|
||||||
DELAY_GET_RECORDS: 150,
|
DELAY_GET_RECORDS: 150,
|
||||||
|
@ -35,7 +33,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
this._super.apply(this, arguments);
|
this._super.apply(this, arguments);
|
||||||
this.widgets = [];
|
this.widgets = [];
|
||||||
this.recordOptions = _.extend({}, params.record_options, {
|
this.recordOptions = _.extend({}, params.record_options, {
|
||||||
viewType: 'One2ManyProductPicker',
|
viewType: "One2ManyProductPicker",
|
||||||
});
|
});
|
||||||
|
|
||||||
// Workaround: Odoo initilize this class so we need do this to
|
// Workaround: Odoo initilize this class so we need do this to
|
||||||
|
@ -52,7 +50,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
*/
|
*/
|
||||||
on_attach_callback: function() {
|
on_attach_callback: function() {
|
||||||
this._isInDom = true;
|
this._isInDom = true;
|
||||||
_.invoke(this.widgets, 'on_attach_callback');
|
_.invoke(this.widgets, "on_attach_callback");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +58,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
*/
|
*/
|
||||||
on_detach_callback: function() {
|
on_detach_callback: function() {
|
||||||
this._isInDom = false;
|
this._isInDom = false;
|
||||||
_.invoke(this.widgets, 'on_detach_callback');
|
_.invoke(this.widgets, "on_detach_callback");
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -160,8 +158,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
// create a 'pure virtual' record again.
|
// create a 'pure virtual' record again.
|
||||||
for (var index_destroy in to_destroy) {
|
for (var index_destroy in to_destroy) {
|
||||||
var widget_destroyed = to_destroy[index_destroy];
|
var widget_destroyed = to_destroy[index_destroy];
|
||||||
var widget_product_id = widget_destroyed.state
|
var widget_product_id =
|
||||||
.data[this.options.field_map.product].data.id;
|
widget_destroyed.state.data[this.options.field_map.product].data
|
||||||
|
.id;
|
||||||
var found = false;
|
var found = false;
|
||||||
// If already exists a widget for the product don't try create a new one
|
// If already exists a widget for the product don't try create a new one
|
||||||
for (var eb = this.widgets.length - 1; eb >= 0; --eb) {
|
for (var eb = this.widgets.length - 1; eb >= 0; --eb) {
|
||||||
|
@ -169,7 +168,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
if (
|
if (
|
||||||
widget &&
|
widget &&
|
||||||
widget.state &&
|
widget.state &&
|
||||||
widget.state.data[this.options.field_map.product].data.id === widget_product_id
|
widget.state.data[this.options.field_map.product].data
|
||||||
|
.id === widget_product_id
|
||||||
) {
|
) {
|
||||||
found = true;
|
found = true;
|
||||||
break;
|
break;
|
||||||
|
@ -182,14 +182,19 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
for (var eb = new_states.length - 1; eb >= 0; --eb) {
|
for (var eb = new_states.length - 1; eb >= 0; --eb) {
|
||||||
var state = new_states[eb];
|
var state = new_states[eb];
|
||||||
if (
|
if (
|
||||||
state.data[this.options.field_map.product].data.id === widget_product_id
|
state.data[this.options.field_map.product].data.id ===
|
||||||
|
widget_product_id
|
||||||
) {
|
) {
|
||||||
new_state_id = state.id;
|
new_state_id = state.id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var search_record = _.find(this.search_data, {id: widget_product_id});
|
var search_record = _.find(this.search_data, {
|
||||||
var new_search_record = _.extend({}, search_record, {__id: new_state_id});
|
id: widget_product_id,
|
||||||
|
});
|
||||||
|
var new_search_record = _.extend({}, search_record, {
|
||||||
|
__id: new_state_id,
|
||||||
|
});
|
||||||
var search_record_index = widget_destroyed.$el.index();
|
var search_record_index = widget_destroyed.$el.index();
|
||||||
defs.push(
|
defs.push(
|
||||||
this.appendSearchRecords(
|
this.appendSearchRecords(
|
||||||
|
@ -216,7 +221,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
* @returns {Deferred}
|
* @returns {Deferred}
|
||||||
*/
|
*/
|
||||||
_updateStateRecords: function(old_states) {
|
_updateStateRecords: function(old_states) {
|
||||||
|
|
||||||
// States to remove
|
// States to remove
|
||||||
var states_to_destroy = [];
|
var states_to_destroy = [];
|
||||||
for (var index in old_states) {
|
for (var index in old_states) {
|
||||||
|
@ -248,7 +252,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
for (var e = this.widgets.length - 1; e >= 0; --e) {
|
for (var e = this.widgets.length - 1; e >= 0; --e) {
|
||||||
var widget = this.widgets[e];
|
var widget = this.widgets[e];
|
||||||
if (!widget || !widget.state) {
|
if (!widget || !widget.state) {
|
||||||
|
|
||||||
// Already processed widget (deleted)
|
// Already processed widget (deleted)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -257,9 +260,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
exists = true;
|
exists = true;
|
||||||
break;
|
break;
|
||||||
} else if (
|
} else if (
|
||||||
widget.recordSearch.id === state.data[this.options.field_map.product].data.id
|
widget.recordSearch.id ===
|
||||||
|
state.data[this.options.field_map.product].data.id
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// Is a new record
|
// Is a new record
|
||||||
search_record_index = widget.$el.index();
|
search_record_index = widget.$el.index();
|
||||||
search_record = widget.recordSearch;
|
search_record = widget.recordSearch;
|
||||||
|
@ -268,7 +271,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
// Remove "pure virtual" records that have the same product that the new record
|
// Remove "pure virtual" records that have the same product that the new record
|
||||||
if (
|
if (
|
||||||
widget.is_virtual &&
|
widget.is_virtual &&
|
||||||
widget.state.data[this.options.field_map.product].data.id === state.data[this.options.field_map.product].data.id
|
widget.state.data[this.options.field_map.product].data
|
||||||
|
.id ===
|
||||||
|
state.data[this.options.field_map.product].data.id
|
||||||
) {
|
) {
|
||||||
to_destroy.push(widget);
|
to_destroy.push(widget);
|
||||||
delete this.widgets[e];
|
delete this.widgets[e];
|
||||||
|
@ -279,8 +284,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
|
|
||||||
// Need add a new one?
|
// Need add a new one?
|
||||||
if (!exists && search_record_index !== -1) {
|
if (!exists && search_record_index !== -1) {
|
||||||
var new_search_record = _.extend({}, search_record, {__id: state.id});
|
var new_search_record = _.extend({}, search_record, {
|
||||||
defs.push(this.appendSearchRecords([new_search_record], false, true, search_record_index)[0]);
|
__id: state.id,
|
||||||
|
});
|
||||||
|
defs.push(
|
||||||
|
this.appendSearchRecords(
|
||||||
|
[new_search_record],
|
||||||
|
false,
|
||||||
|
true,
|
||||||
|
search_record_index
|
||||||
|
)[0]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,8 +312,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
this.$recordsContainer = $("<DIV/>", {
|
this.$recordsContainer = $("<DIV/>", {
|
||||||
class: "w-100 row",
|
class: "w-100 row",
|
||||||
});
|
});
|
||||||
this.$extraButtonsContainer = $(qweb.render("One2ManyProductPicker.ExtraButtons"));
|
this.$extraButtonsContainer = $(
|
||||||
this.$btnLoadMore = this.$extraButtonsContainer.find("#productPickerLoadMore");
|
qweb.render("One2ManyProductPicker.ExtraButtons")
|
||||||
|
);
|
||||||
|
this.$btnLoadMore = this.$extraButtonsContainer.find(
|
||||||
|
"#productPickerLoadMore"
|
||||||
|
);
|
||||||
this.search_data = this._sort_search_data(this.search_data);
|
this.search_data = this._sort_search_data(this.search_data);
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
var defs = self.appendSearchRecords(self.search_data, true);
|
var defs = self.appendSearchRecords(self.search_data, true);
|
||||||
|
@ -308,7 +326,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
self.$el.empty();
|
self.$el.empty();
|
||||||
self.$el.append(self.$recordsContainer);
|
self.$el.append(self.$recordsContainer);
|
||||||
self.$el.append(self.$extraButtonsContainer);
|
self.$el.append(self.$extraButtonsContainer);
|
||||||
self.showLoadMore(self.last_search_data_count >= self.options.records_per_page);
|
self.showLoadMore(
|
||||||
|
self.last_search_data_count >= self.options.records_per_page
|
||||||
|
);
|
||||||
if (self._isInDom) {
|
if (self._isInDom) {
|
||||||
_.invoke(self.widgets, "on_attach_callback");
|
_.invoke(self.widgets, "on_attach_callback");
|
||||||
}
|
}
|
||||||
|
@ -334,9 +354,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var sorted_datas = _.chain(datas).sortBy('_order_value').map(function(item) {
|
var sorted_datas = _.chain(datas)
|
||||||
return _.omit(item, '_order_value');
|
.sortBy("_order_value")
|
||||||
}).value().reverse();
|
.map(function(item) {
|
||||||
|
return _.omit(item, "_order_value");
|
||||||
|
})
|
||||||
|
.value()
|
||||||
|
.reverse();
|
||||||
return sorted_datas;
|
return sorted_datas;
|
||||||
}
|
}
|
||||||
return datas;
|
return datas;
|
||||||
|
@ -361,7 +385,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
var state_record = this.state.data[index_data];
|
var state_record = this.state.data[index_data];
|
||||||
var field = state_record.data[field_name];
|
var field = state_record.data[field_name];
|
||||||
if (
|
if (
|
||||||
(typeof field === "object" && field.data.id === record_search.id) ||
|
(typeof field === "object" &&
|
||||||
|
field.data.id === record_search.id) ||
|
||||||
field === record_search.id
|
field === record_search.id
|
||||||
) {
|
) {
|
||||||
records.push(
|
records.push(
|
||||||
|
@ -423,10 +448,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
* @param {Boolean} no_process_records
|
* @param {Boolean} no_process_records
|
||||||
* @param {Number} position
|
* @param {Number} position
|
||||||
*/
|
*/
|
||||||
_appendSearchRecords: function (search_records, no_process_records, position) {
|
_appendSearchRecords: function(
|
||||||
|
search_records,
|
||||||
|
no_process_records,
|
||||||
|
position
|
||||||
|
) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var processed_records =
|
var processed_records = no_process_records
|
||||||
no_process_records?search_records:this._processSearchRecords(search_records);
|
? search_records
|
||||||
|
: this._processSearchRecords(search_records);
|
||||||
_.each(processed_records, function(search_record) {
|
_.each(processed_records, function(search_record) {
|
||||||
var state_data = self._getRecordDataById(search_record.__id);
|
var state_data = self._getRecordDataById(search_record.__id);
|
||||||
var widget_options = self._getRecordOptions(search_record);
|
var widget_options = self._getRecordOptions(search_record);
|
||||||
|
@ -450,13 +480,16 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
// At this point the widget will use the existing state (line) or
|
// At this point the widget will use the existing state (line) or
|
||||||
// the search data. Using search data instead of waiting for
|
// the search data. Using search data instead of waiting for
|
||||||
// simulated state gives a low FCP time.
|
// simulated state gives a low FCP time.
|
||||||
var def = ProductPickerRecord.appendTo(self.$recordsContainer)
|
var def = ProductPickerRecord.appendTo(self.$recordsContainer).then(
|
||||||
.then(function (widget, widget_position) {
|
function(widget, widget_position) {
|
||||||
if (typeof widget_position !== "undefined") {
|
if (typeof widget_position !== "undefined") {
|
||||||
var $elm = this.$el.find("> div > div:nth("+widget_position+")");
|
var $elm = this.$el.find(
|
||||||
|
"> div > div:nth(" + widget_position + ")"
|
||||||
|
);
|
||||||
widget.$el.insertAfter($elm);
|
widget.$el.insertAfter($elm);
|
||||||
}
|
}
|
||||||
}.bind(self, ProductPickerRecord, position));
|
}.bind(self, ProductPickerRecord, position)
|
||||||
|
);
|
||||||
if (def.state() === "pending") {
|
if (def.state() === "pending") {
|
||||||
self.defs.push(def);
|
self.defs.push(def);
|
||||||
}
|
}
|
||||||
|
@ -479,7 +512,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
* @param {Number} position
|
* @param {Number} position
|
||||||
* @returns {Array[Deferred]}
|
* @returns {Array[Deferred]}
|
||||||
*/
|
*/
|
||||||
appendSearchRecords: function (search_records, no_attach_widgets, no_process_records, position) {
|
appendSearchRecords: function(
|
||||||
|
search_records,
|
||||||
|
no_attach_widgets,
|
||||||
|
no_process_records,
|
||||||
|
position
|
||||||
|
) {
|
||||||
var self = this;
|
var self = this;
|
||||||
this.trigger_up("loading_records");
|
this.trigger_up("loading_records");
|
||||||
this.defs = [];
|
this.defs = [];
|
||||||
|
@ -522,7 +560,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
var $actived_card = this.$el.find(".active");
|
var $actived_card = this.$el.find(".active");
|
||||||
if (widget.$card.hasClass("active")) {
|
if (widget.$card.hasClass("active")) {
|
||||||
widget.$card.removeClass("active");
|
widget.$card.removeClass("active");
|
||||||
widget.$card.find('.oe_flip_card_front').removeClass("d-none");
|
widget.$card.find(".oe_flip_card_front").removeClass("d-none");
|
||||||
} else {
|
} else {
|
||||||
var self = widget;
|
var self = widget;
|
||||||
widget.defs = [];
|
widget.defs = [];
|
||||||
|
@ -531,10 +569,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
widget._processDynamicFields();
|
widget._processDynamicFields();
|
||||||
$.when(widget.defs).then(function() {
|
$.when(widget.defs).then(function() {
|
||||||
$actived_card.removeClass("active");
|
$actived_card.removeClass("active");
|
||||||
$actived_card.find('.oe_flip_card_front').removeClass("d-none");
|
$actived_card.find(".oe_flip_card_front").removeClass("d-none");
|
||||||
self.$card.addClass("active");
|
self.$card.addClass("active");
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
self.$('.oe_flip_card_front').addClass("d-none");
|
self.$(".oe_flip_card_front").addClass("d-none");
|
||||||
}, 200);
|
}, 200);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -551,15 +589,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
|
||||||
if (typeof prev_widget_index !== "undefined") {
|
if (typeof prev_widget_index !== "undefined") {
|
||||||
// Only check 'back' widgets so there is where the form was created
|
// Only check 'back' widgets so there is where the form was created
|
||||||
for (var index in this.widgets[prev_widget_index].widgets.back) {
|
for (var index in this.widgets[prev_widget_index].widgets.back) {
|
||||||
var widget = this.widgets[prev_widget_index].widgets.back[index];
|
var widget = this.widgets[prev_widget_index].widgets.back[
|
||||||
|
index
|
||||||
|
];
|
||||||
if (widget instanceof ProductPickerQuickCreateForm) {
|
if (widget instanceof ProductPickerQuickCreateForm) {
|
||||||
widget.controller.auto();
|
widget.controller.auto();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return One2ManyProductPickerRenderer;
|
return One2ManyProductPickerRenderer;
|
||||||
});
|
}
|
||||||
|
);
|
||||||
|
|
|
@ -6,7 +6,6 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
var BasicModel = require("web.BasicModel");
|
var BasicModel = require("web.BasicModel");
|
||||||
|
|
||||||
BasicModel.include({
|
BasicModel.include({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Number/String} handle
|
* @param {Number/String} handle
|
||||||
* @param {Object} context
|
* @param {Object} context
|
||||||
|
@ -15,7 +14,8 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
this.localData[handle].context = _.extend(
|
this.localData[handle].context = _.extend(
|
||||||
{},
|
{},
|
||||||
this.localData[handle].context,
|
this.localData[handle].context,
|
||||||
context);
|
context
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +63,7 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
var list = this.localData[listID];
|
var list = this.localData[listID];
|
||||||
var context = _.extend({}, this._getContext(list), options.context);
|
var context = _.extend({}, this._getContext(list), options.context);
|
||||||
|
|
||||||
var position = options?options.position:'top';
|
var position = options ? options.position : "top";
|
||||||
var params = {
|
var params = {
|
||||||
context: context,
|
context: context,
|
||||||
fields: list.fields,
|
fields: list.fields,
|
||||||
|
@ -76,18 +76,15 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
};
|
};
|
||||||
|
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
self._makeDefaultRecord(list.model, params)
|
self._makeDefaultRecord(list.model, params).then(function(recordID) {
|
||||||
.then(function (recordID) {
|
|
||||||
self.setPureVirtual(recordID, true);
|
self.setPureVirtual(recordID, true);
|
||||||
self.updateRecordContext(recordID, {ignore_warning: true});
|
self.updateRecordContext(recordID, {ignore_warning: true});
|
||||||
if (options.data) {
|
if (options.data) {
|
||||||
self._applyChange(
|
self._applyChange(recordID, options.data, params).then(
|
||||||
recordID,
|
function() {
|
||||||
options.data,
|
|
||||||
params
|
|
||||||
).then(function () {
|
|
||||||
d.resolve(self.get(recordID));
|
d.resolve(self.get(recordID));
|
||||||
});
|
}
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
d.resolve(self.get(recordID));
|
d.resolve(self.get(recordID));
|
||||||
}
|
}
|
||||||
|
@ -108,7 +105,7 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
var this_mp = _.clone(this);
|
var this_mp = _.clone(this);
|
||||||
var super_call = this.trigger_up;
|
var super_call = this.trigger_up;
|
||||||
this_mp.trigger_up = function(event_name, data) {
|
this_mp.trigger_up = function(event_name, data) {
|
||||||
if (event_name === 'warning' && data.type === "dialog") {
|
if (event_name === "warning" && data.type === "dialog") {
|
||||||
return; // Do nothing
|
return; // Do nothing
|
||||||
}
|
}
|
||||||
return super_call.apply(this, arguments);
|
return super_call.apply(this, arguments);
|
||||||
|
@ -118,5 +115,4 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -12,17 +12,15 @@ odoo.define("web_widget_one2many_product_picker.BasicView", function (require) {
|
||||||
|
|
||||||
// Add ref to _() -> _t() call
|
// Add ref to _() -> _t() call
|
||||||
var PY_t = new py.PY_def.fromJSON(function() {
|
var PY_t = new py.PY_def.fromJSON(function() {
|
||||||
var args = py.PY_parseArgs(arguments, ['str']);
|
var args = py.PY_parseArgs(arguments, ["str"]);
|
||||||
return py.str.fromJSON(_t(args.str.toJSON()));
|
return py.str.fromJSON(_t(args.str.toJSON()));
|
||||||
});
|
});
|
||||||
|
|
||||||
BasicView.include({
|
BasicView.include({
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
*/
|
*/
|
||||||
_processField: function(viewType, field, attrs) {
|
_processField: function(viewType, field, attrs) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* We need process 'options' attribute to handle translations and
|
* We need process 'options' attribute to handle translations and
|
||||||
* special replacements
|
* special replacements
|
||||||
|
@ -31,15 +29,16 @@ odoo.define("web_widget_one2many_product_picker.BasicView", function (require) {
|
||||||
attrs.widget === "one2many_product_picker" &&
|
attrs.widget === "one2many_product_picker" &&
|
||||||
!_.isObject(attrs.options)
|
!_.isObject(attrs.options)
|
||||||
) {
|
) {
|
||||||
attrs.options = attrs.options ? pyUtils.py_eval(attrs.options, {
|
attrs.options = attrs.options
|
||||||
|
? pyUtils.py_eval(attrs.options, {
|
||||||
_: PY_t,
|
_: PY_t,
|
||||||
|
|
||||||
// Hack: This allow use $number_search out of an string
|
// Hack: This allow use $number_search out of an string
|
||||||
number_search: '$number_search',
|
number_search: "$number_search",
|
||||||
}) : {};
|
})
|
||||||
|
: {};
|
||||||
}
|
}
|
||||||
return this._super(viewType, field, attrs);
|
return this._super(viewType, field, attrs);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -8,8 +8,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
var core = require("web.core");
|
var core = require("web.core");
|
||||||
var field_registry = require("web.field_registry");
|
var field_registry = require("web.field_registry");
|
||||||
var FieldOne2Many = require("web.relational_fields").FieldOne2Many;
|
var FieldOne2Many = require("web.relational_fields").FieldOne2Many;
|
||||||
var One2ManyProductPickerRenderer = require(
|
var One2ManyProductPickerRenderer = require("web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
|
||||||
"web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
|
|
||||||
var tools = require("web_widget_one2many_product_picker.tools");
|
var tools = require("web_widget_one2many_product_picker.tools");
|
||||||
|
|
||||||
var _t = core._t;
|
var _t = core._t;
|
||||||
|
@ -43,10 +42,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
_auto_search_delay: 450,
|
_auto_search_delay: 450,
|
||||||
|
|
||||||
// Model product.product fields
|
// Model product.product fields
|
||||||
search_read_fields: [
|
search_read_fields: ["id", "display_name"],
|
||||||
"id",
|
|
||||||
"display_name",
|
|
||||||
],
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @override
|
* @override
|
||||||
|
@ -58,9 +54,15 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
this.state = record;
|
this.state = record;
|
||||||
|
|
||||||
// Use jquery 'extend' to have a 'deep' merge.
|
// Use jquery 'extend' to have a 'deep' merge.
|
||||||
this.options = $.extend(true, this._getDefaultOptions(), this.attrs.options);
|
this.options = $.extend(
|
||||||
|
true,
|
||||||
|
this._getDefaultOptions(),
|
||||||
|
this.attrs.options
|
||||||
|
);
|
||||||
if (!this.options.search) {
|
if (!this.options.search) {
|
||||||
this.options.search = [[this.options.field_map.name, 'ilike', '$search']];
|
this.options.search = [
|
||||||
|
[this.options.field_map.name, "ilike", "$search"],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
this._searchMode = 0;
|
this._searchMode = 0;
|
||||||
this._searchCategoryNames = [];
|
this._searchCategoryNames = [];
|
||||||
|
@ -92,7 +94,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
};
|
};
|
||||||
if (this.mode === "readonly") {
|
if (this.mode === "readonly") {
|
||||||
this._activeSearchGroup = {
|
this._activeSearchGroup = {
|
||||||
'name': 'main_lines',
|
name: "main_lines",
|
||||||
};
|
};
|
||||||
this._searchContext.activeTest = false;
|
this._searchContext.activeTest = false;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +105,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
* Updates the lines counter badge
|
* Updates the lines counter badge
|
||||||
*/
|
*/
|
||||||
updateBadgeLines: function() {
|
updateBadgeLines: function() {
|
||||||
var records = this.parent_controller.model.get(this.state.id).data[this.name].data;
|
var records = this.parent_controller.model.get(this.state.id).data[
|
||||||
|
this.name
|
||||||
|
].data;
|
||||||
this.$badgeLines.text(records.length);
|
this.$badgeLines.text(records.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -113,13 +117,17 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
}
|
}
|
||||||
var prices = [];
|
var prices = [];
|
||||||
var field_map = this.options.field_map;
|
var field_map = this.options.field_map;
|
||||||
var records = this.parent_controller.model.get(this.state.id).data[this.name].data;
|
var records = this.parent_controller.model.get(this.state.id).data[
|
||||||
|
this.name
|
||||||
|
].data;
|
||||||
if (this.options.show_discount) {
|
if (this.options.show_discount) {
|
||||||
prices = _.map(records, function(line) {
|
prices = _.map(records, function(line) {
|
||||||
return line.data[field_map.product_uom_qty] *
|
return (
|
||||||
|
line.data[field_map.product_uom_qty] *
|
||||||
tools.priceReduce(
|
tools.priceReduce(
|
||||||
line.data[field_map.price_unit],
|
line.data[field_map.price_unit],
|
||||||
line.data[field_map.discount]
|
line.data[field_map.discount]
|
||||||
|
)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
@ -189,7 +197,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
}
|
}
|
||||||
|
|
||||||
this.searchGroups.splice(0, 0, {
|
this.searchGroups.splice(0, 0, {
|
||||||
name: 'all',
|
name: "all",
|
||||||
string: _t("All"),
|
string: _t("All"),
|
||||||
domain: [],
|
domain: [],
|
||||||
order: false,
|
order: false,
|
||||||
|
@ -227,8 +235,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
qweb.render("One2ManyProductPicker.ControlPanelButtons", {
|
qweb.render("One2ManyProductPicker.ControlPanelButtons", {
|
||||||
search_category_names: this._searchCategoryNames,
|
search_category_names: this._searchCategoryNames,
|
||||||
search_mode: this._searchMode,
|
search_mode: this._searchMode,
|
||||||
}
|
})
|
||||||
));
|
);
|
||||||
this.$searchInput = this.$buttons.find(".oe_search_input");
|
this.$searchInput = this.$buttons.find(".oe_search_input");
|
||||||
this.$groups = $(
|
this.$groups = $(
|
||||||
qweb.render("One2ManyProductPicker.ControlPanelGroupButtons", {
|
qweb.render("One2ManyProductPicker.ControlPanelGroupButtons", {
|
||||||
|
@ -252,7 +260,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
return (
|
return (
|
||||||
def &&
|
def &&
|
||||||
def.then(function() {
|
def.then(function() {
|
||||||
if (!self.$el.hasClass("oe_field_one2many_product_picker_maximized")) {
|
if (
|
||||||
|
!self.$el.hasClass("oe_field_one2many_product_picker_maximized")
|
||||||
|
) {
|
||||||
self.$el.addClass("position-relative d-flex flex-column");
|
self.$el.addClass("position-relative d-flex flex-column");
|
||||||
}
|
}
|
||||||
self._addMaximizeButton();
|
self._addMaximizeButton();
|
||||||
|
@ -325,11 +335,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
// to continue
|
// to continue
|
||||||
var domain = this._getFullSearchDomain();
|
var domain = this._getFullSearchDomain();
|
||||||
var soptions = options || {};
|
var soptions = options || {};
|
||||||
var context = _.extend({
|
var context = _.extend(
|
||||||
'active_search_group_name': this._activeSearchGroup.name,
|
{
|
||||||
'active_search_involved_fields': this._searchContext.involvedFields,
|
active_search_group_name: this._activeSearchGroup.name,
|
||||||
'active_test': this._searchContext.activeTest,
|
active_search_involved_fields: this._searchContext.involvedFields,
|
||||||
}, this.value.getContext());
|
active_test: this._searchContext.activeTest,
|
||||||
|
},
|
||||||
|
this.value.getContext()
|
||||||
|
);
|
||||||
|
|
||||||
return $.Deferred(function(d) {
|
return $.Deferred(function(d) {
|
||||||
var limit = soptions.limit || self.options.records_per_page;
|
var limit = soptions.limit || self.options.records_per_page;
|
||||||
|
@ -379,7 +392,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
this._searchContext.activeTest = true;
|
this._searchContext.activeTest = true;
|
||||||
this.doRenderSearchRecords();
|
this.doRenderSearchRecords();
|
||||||
this.$btnLines.removeClass("active");
|
this.$btnLines.removeClass("active");
|
||||||
$btn.parent().find(".active").removeClass("active");
|
$btn.parent()
|
||||||
|
.find(".active")
|
||||||
|
.removeClass("active");
|
||||||
$btn.addClass("active");
|
$btn.addClass("active");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -391,7 +406,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
"position-relative h-100 bg-white oe_field_one2many_product_picker_maximized"
|
"position-relative h-100 bg-white oe_field_one2many_product_picker_maximized"
|
||||||
);
|
);
|
||||||
if (this.$buttons) {
|
if (this.$buttons) {
|
||||||
this.$buttons.find('.dropdown-toggle').popover('update');
|
this.$buttons.find(".dropdown-toggle").popover("update");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -411,8 +426,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
var $target = $(ev.target);
|
var $target = $(ev.target);
|
||||||
this._searchMode = $target.index();
|
this._searchMode = $target.index();
|
||||||
$target.parent().children().removeClass('active');
|
$target
|
||||||
$target.addClass('active');
|
.parent()
|
||||||
|
.children()
|
||||||
|
.removeClass("active");
|
||||||
|
$target.addClass("active");
|
||||||
this.doRenderSearchRecords().then(function() {
|
this.doRenderSearchRecords().then(function() {
|
||||||
self.$searchInput.focus();
|
self.$searchInput.focus();
|
||||||
});
|
});
|
||||||
|
@ -466,12 +484,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
|
|
||||||
// Is a triplet
|
// Is a triplet
|
||||||
if (domain_cloned instanceof Array) {
|
if (domain_cloned instanceof Array) {
|
||||||
|
|
||||||
// Replace right leaf with the current value of the search input
|
// Replace right leaf with the current value of the search input
|
||||||
if (domain_cloned[2] === "$number_search") {
|
if (domain_cloned[2] === "$number_search") {
|
||||||
domain_cloned[2] = Number(this._searchContext.text);
|
domain_cloned[2] = Number(this._searchContext.text);
|
||||||
involved_fields.push({
|
involved_fields.push({
|
||||||
type: 'number',
|
type: "number",
|
||||||
field: domain_cloned[0],
|
field: domain_cloned[0],
|
||||||
oper: domain_cloned[1],
|
oper: domain_cloned[1],
|
||||||
});
|
});
|
||||||
|
@ -479,10 +496,12 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
typeof domain_cloned[2] === "string" &&
|
typeof domain_cloned[2] === "string" &&
|
||||||
domain_cloned[2].includes("$search")
|
domain_cloned[2].includes("$search")
|
||||||
) {
|
) {
|
||||||
domain_cloned[2] = domain_cloned[2]
|
domain_cloned[2] = domain_cloned[2].replace(
|
||||||
.replace(/\$search/, this._searchContext.text);
|
/\$search/,
|
||||||
|
this._searchContext.text
|
||||||
|
);
|
||||||
involved_fields.push({
|
involved_fields.push({
|
||||||
type: 'text',
|
type: "text",
|
||||||
field: domain_cloned[0],
|
field: domain_cloned[0],
|
||||||
oper: domain_cloned[1],
|
oper: domain_cloned[1],
|
||||||
});
|
});
|
||||||
|
@ -507,8 +526,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
var field_name = this.options.field_map.product;
|
var field_name = this.options.field_map.product;
|
||||||
var lines = this.parent_controller.model.get(this.state.id)
|
var lines = this.parent_controller.model.get(this.state.id).data[this.name]
|
||||||
.data[this.name].data;
|
.data;
|
||||||
var ids = _.map(lines, function(line) {
|
var ids = _.map(lines, function(line) {
|
||||||
return line.data[field_name].data.id;
|
return line.data[field_name].data.id;
|
||||||
});
|
});
|
||||||
|
@ -521,13 +540,16 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
*/
|
*/
|
||||||
showLines: function() {
|
showLines: function() {
|
||||||
this._clearSearchInput();
|
this._clearSearchInput();
|
||||||
this.$btnLines.parent().find(".active").removeClass("active");
|
this.$btnLines
|
||||||
|
.parent()
|
||||||
|
.find(".active")
|
||||||
|
.removeClass("active");
|
||||||
this.$btnLines.addClass("active");
|
this.$btnLines.addClass("active");
|
||||||
this._activeSearchGroup = {
|
this._activeSearchGroup = {
|
||||||
'name': 'main_lines',
|
name: "main_lines",
|
||||||
};
|
};
|
||||||
this._searchContext.domain = this._getLinesDomain();
|
this._searchContext.domain = this._getLinesDomain();
|
||||||
this._searchContext.order = [{'name': 'sequence'}, {'name': 'id'}];
|
this._searchContext.order = [{name: "sequence"}, {name: "id"}];
|
||||||
this._searchContext.activeTest = false;
|
this._searchContext.activeTest = false;
|
||||||
this.doRenderSearchRecords();
|
this.doRenderSearchRecords();
|
||||||
},
|
},
|
||||||
|
@ -566,11 +588,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
* @param {DropdownEvent} evt
|
* @param {DropdownEvent} evt
|
||||||
*/
|
*/
|
||||||
_onShowSearchDropdown: function(evt) {
|
_onShowSearchDropdown: function(evt) {
|
||||||
|
|
||||||
// Workaround: This "ensures" a correct dropdown position
|
// Workaround: This "ensures" a correct dropdown position
|
||||||
var offset = $(evt.currentTarget).find(".dropdown-toggle").parent().height();
|
var offset = $(evt.currentTarget)
|
||||||
|
.find(".dropdown-toggle")
|
||||||
|
.parent()
|
||||||
|
.height();
|
||||||
_.defer(function() {
|
_.defer(function() {
|
||||||
$(evt.currentTarget).find(".dropdown-menu")
|
$(evt.currentTarget)
|
||||||
|
.find(".dropdown-menu")
|
||||||
.css("transform", "translate3d(0px, " + offset + "px, 0px)");
|
.css("transform", "translate3d(0px, " + offset + "px, 0px)");
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -593,7 +618,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
{notifyChange: false}
|
{notifyChange: false}
|
||||||
).then(function() {
|
).then(function() {
|
||||||
if (self.options.auto_save) {
|
if (self.options.auto_save) {
|
||||||
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function (rrr) {
|
self.parent_controller
|
||||||
|
.saveRecord(undefined, {stayInEdit: true})
|
||||||
|
.then(function(rrr) {
|
||||||
// Because 'create' generates a new state and we can't know these new id we
|
// Because 'create' generates a new state and we can't know these new id we
|
||||||
// need force update the all the current states.
|
// need force update the all the current states.
|
||||||
self._setValue(
|
self._setValue(
|
||||||
|
@ -640,12 +667,20 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
{notifyChange: false}
|
{notifyChange: false}
|
||||||
).then(function() {
|
).then(function() {
|
||||||
if (self.options.auto_save) {
|
if (self.options.auto_save) {
|
||||||
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
|
self.parent_controller
|
||||||
|
.saveRecord(undefined, {stayInEdit: true})
|
||||||
|
.then(function() {
|
||||||
// Workaround to get updated values
|
// Workaround to get updated values
|
||||||
self.parent_controller.model.reload(self.value.id).then(function (result) {
|
self.parent_controller.model
|
||||||
var new_data = self.parent_controller.model.get(result);
|
.reload(self.value.id)
|
||||||
|
.then(function(result) {
|
||||||
|
var new_data = self.parent_controller.model.get(
|
||||||
|
result
|
||||||
|
);
|
||||||
self.value.data = new_data.data;
|
self.value.data = new_data.data;
|
||||||
self.renderer.updateState(self.value, {force: true});
|
self.renderer.updateState(self.value, {
|
||||||
|
force: true,
|
||||||
|
});
|
||||||
if (evt.data.callback) {
|
if (evt.data.callback) {
|
||||||
evt.data.callback();
|
evt.data.callback();
|
||||||
}
|
}
|
||||||
|
@ -661,9 +696,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
product_picker_modified: true,
|
product_picker_modified: true,
|
||||||
});
|
});
|
||||||
// This will trigger an "state" update
|
// This will trigger an "state" update
|
||||||
this._setValue(
|
this._setValue({
|
||||||
{operation: "UPDATE", id: evt.data.id, data: evt.data.data},
|
operation: "UPDATE",
|
||||||
).then(function () {
|
id: evt.data.id,
|
||||||
|
data: evt.data.data,
|
||||||
|
}).then(function() {
|
||||||
if (evt.data.callback) {
|
if (evt.data.callback) {
|
||||||
evt.data.callback();
|
evt.data.callback();
|
||||||
}
|
}
|
||||||
|
@ -679,7 +716,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
var self = this;
|
var self = this;
|
||||||
this._setValue({operation: "DELETE", ids: [evt.data.id]}).then(function() {
|
this._setValue({operation: "DELETE", ids: [evt.data.id]}).then(function() {
|
||||||
if (self.options.auto_save) {
|
if (self.options.auto_save) {
|
||||||
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
|
self.parent_controller
|
||||||
|
.saveRecord(undefined, {stayInEdit: true})
|
||||||
|
.then(function() {
|
||||||
if (evt.data.callback) {
|
if (evt.data.callback) {
|
||||||
evt.data.callback();
|
evt.data.callback();
|
||||||
}
|
}
|
||||||
|
@ -740,7 +779,6 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Refresh lines count on every change.
|
* Refresh lines count on every change.
|
||||||
*
|
*
|
||||||
|
|
|
@ -45,7 +45,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
.oe_one2many_product_picker_view {
|
.oe_one2many_product_picker_view {
|
||||||
@include make-grid-columns($columns: 24, $breakpoints: $one2many-product-picker-grid-breakpoints);
|
@include make-grid-columns(
|
||||||
|
$columns: 24,
|
||||||
|
$breakpoints: $one2many-product-picker-grid-breakpoints
|
||||||
|
);
|
||||||
|
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
|
@ -58,7 +61,10 @@
|
||||||
user-select: none;
|
user-select: none;
|
||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
perspective: 1000px;
|
perspective: 1000px;
|
||||||
transition: top $one2many-product-picker-transition-3d-time, left $one2many-product-picker-transition-3d-time, width $one2many-product-picker-transition-3d-time, height $one2many-product-picker-transition-3d-time;
|
transition: top $one2many-product-picker-transition-3d-time,
|
||||||
|
left $one2many-product-picker-transition-3d-time,
|
||||||
|
width $one2many-product-picker-transition-3d-time,
|
||||||
|
height $one2many-product-picker-transition-3d-time;
|
||||||
height: $one2many-product-picker-card-min-height;
|
height: $one2many-product-picker-card-min-height;
|
||||||
|
|
||||||
&.blocked {
|
&.blocked {
|
||||||
|
@ -97,11 +103,13 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.o_field_widget, .oe_one2many_product_picker_form_buttons .btn {
|
.o_field_widget,
|
||||||
|
.oe_one2many_product_picker_form_buttons .btn {
|
||||||
transform: scale($one2many-product-picker-zoom-scale);
|
transform: scale($one2many-product-picker-zoom-scale);
|
||||||
margin-bottom: 1.3em !important;
|
margin-bottom: 1.3em !important;
|
||||||
}
|
}
|
||||||
.o_field_widget, .w-100 {
|
.o_field_widget,
|
||||||
|
.w-100 {
|
||||||
width: 100% / $one2many-product-picker-zoom-scale !important;
|
width: 100% / $one2many-product-picker-zoom-scale !important;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +141,9 @@
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: $one2many-product-picker-card-min-height;
|
height: $one2many-product-picker-card-min-height;
|
||||||
transition: transform $one2many-product-picker-transition-3d-time, height $one2many-product-picker-transition-3d-time/2 ease-in-out $one2many-product-picker-transition-3d-time/2;
|
transition: transform $one2many-product-picker-transition-3d-time,
|
||||||
|
height $one2many-product-picker-transition-3d-time/2 ease-in-out
|
||||||
|
$one2many-product-picker-transition-3d-time/2;
|
||||||
transform-style: preserve-3d;
|
transform-style: preserve-3d;
|
||||||
|
|
||||||
.position-absolute {
|
.position-absolute {
|
||||||
|
@ -217,7 +227,9 @@
|
||||||
font-size: 0.95rem;
|
font-size: 0.95rem;
|
||||||
z-index: 0;
|
z-index: 0;
|
||||||
}
|
}
|
||||||
.add_product, .product_qty, .price_unit {
|
.add_product,
|
||||||
|
.product_qty,
|
||||||
|
.price_unit {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,12 +259,12 @@
|
||||||
|
|
||||||
@keyframes productPickerCatchAttention {
|
@keyframes productPickerCatchAttention {
|
||||||
0% {
|
0% {
|
||||||
transform: scale(1.0);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
50% {
|
50% {
|
||||||
transform: scale(1.5);
|
transform: scale(1.5);
|
||||||
}
|
}
|
||||||
100% {
|
100% {
|
||||||
transform: scale(1.0);
|
transform: scale(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,58 +1,83 @@
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.ControlPanelButtons">
|
<t t-name="One2ManyProductPicker.ControlPanelButtons">
|
||||||
<div class="text-center mx-auto">
|
<div class="text-center mx-auto">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<t t-if="search_category_names">
|
<t t-if="search_category_names">
|
||||||
<button class="btn btn-secondary dropdown-toggle" type="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
<button
|
||||||
|
class="btn btn-secondary dropdown-toggle"
|
||||||
|
type="button"
|
||||||
|
data-toggle="dropdown"
|
||||||
|
aria-haspopup="true"
|
||||||
|
aria-expanded="false"
|
||||||
|
>
|
||||||
<i class="fa fa-search" />
|
<i class="fa fa-search" />
|
||||||
</button>
|
</button>
|
||||||
<div class="dropdown-menu">
|
<div class="dropdown-menu">
|
||||||
<t t-foreach="search_category_names" t-as="name">
|
<t t-foreach="search_category_names" t-as="name">
|
||||||
<a t-attf-class="dropdown-item search_mode_option {{name_index == search_mode ? 'active' : ''}}" href="#" t-esc="name" />
|
<a
|
||||||
|
t-attf-class="dropdown-item search_mode_option {{name_index == search_mode ? 'active' : ''}}"
|
||||||
|
href="#"
|
||||||
|
t-esc="name"
|
||||||
|
/>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-else="">
|
<t t-else="">
|
||||||
<button type="button" t-attf-class="btn btn-secondary btn-lg input-group-button">
|
<button
|
||||||
|
type="button"
|
||||||
|
t-attf-class="btn btn-secondary btn-lg input-group-button"
|
||||||
|
>
|
||||||
<i class="fa fa-search" />
|
<i class="fa fa-search" />
|
||||||
</button>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
<input type="search" class="form-control form-control-lg oe_search_input" placeholder="Search..." aria-label="Search..." aria-describedby="btnGroupAddon2" />
|
<input
|
||||||
|
type="search"
|
||||||
|
class="form-control form-control-lg oe_search_input"
|
||||||
|
placeholder="Search..."
|
||||||
|
aria-label="Search..."
|
||||||
|
aria-describedby="btnGroupAddon2"
|
||||||
|
/>
|
||||||
<div class="input-group-append">
|
<div class="input-group-append">
|
||||||
<button type="button" t-attf-class="btn btn-secondary btn-lg input-group-button oe_search_erase">
|
<button
|
||||||
|
type="button"
|
||||||
|
t-attf-class="btn btn-secondary btn-lg input-group-button oe_search_erase"
|
||||||
|
>
|
||||||
<i class="fa fa-eraser" />
|
<i class="fa fa-eraser" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.ControlPanelGroupButtons">
|
<t t-name="One2ManyProductPicker.ControlPanelGroupButtons">
|
||||||
<div class="oe_one2many_product_picker_groups">
|
<div class="oe_one2many_product_picker_groups">
|
||||||
<div class="btn-group" role="group" aria-label="Groups">
|
<div class="btn-group" role="group" aria-label="Groups">
|
||||||
<t t-foreach="groups" t-as="group">
|
<t t-foreach="groups" t-as="group">
|
||||||
<button type="button" t-att-name="group.name" t-attf-class="btn btn-lg btn-secondary rounded-0 border-top-0 {{group.active && 'active' || ''}} oe_btn_search_group" t-att-data-group="group_index">
|
<button
|
||||||
|
type="button"
|
||||||
|
t-att-name="group.name"
|
||||||
|
t-attf-class="btn btn-lg btn-secondary rounded-0 border-top-0 {{group.active && 'active' || ''}} oe_btn_search_group"
|
||||||
|
t-att-data-group="group_index"
|
||||||
|
>
|
||||||
<t t-esc="group.string" />
|
<t t-esc="group.string" />
|
||||||
</button>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<button type="button" class="btn btn-light btn-lg oe_btn_lines">
|
<button type="button" class="btn btn-light btn-lg oe_btn_lines">
|
||||||
Lines
|
Lines
|
||||||
<span class="ml-1 badge badge-light">0</span>
|
<span class="ml-1 badge badge-light">0</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.ButtonMaximize">
|
<t t-name="One2ManyProductPicker.ButtonMaximize">
|
||||||
<button if="product_picker_maximize" class='o_fullscreen btn btn-primary position-absolute border border-dark py-1 px-2'>
|
<button
|
||||||
|
if="product_picker_maximize"
|
||||||
|
class='o_fullscreen btn btn-primary position-absolute border border-dark py-1 px-2'
|
||||||
|
>
|
||||||
<i class='fa fa-expand' />
|
<i class='fa fa-expand' />
|
||||||
</button>
|
</button>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.Total">
|
<t t-name="One2ManyProductPicker.Total">
|
||||||
<div id="product_picker_total" class="text-right">
|
<div id="product_picker_total" class="text-right">
|
||||||
<h2>
|
<h2>
|
||||||
|
@ -61,57 +86,108 @@
|
||||||
</h2>
|
</h2>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.ExtraButtons">
|
<t t-name="One2ManyProductPicker.ExtraButtons">
|
||||||
<div class="w-100 row">
|
<div class="w-100 row">
|
||||||
<button id="productPickerLoadMore" class="btn btn-lg btn-secondary m-auto d-none">Load More</button>
|
<button
|
||||||
|
id="productPickerLoadMore"
|
||||||
|
class="btn btn-lg btn-secondary m-auto d-none"
|
||||||
|
>Load More</button>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.FlipCard">
|
<t t-name="One2ManyProductPicker.FlipCard">
|
||||||
<div class="oe_flip_container p-1 col-12 col-sm-8 col-md-6 col-lg-4 col-xl-3 col-xxl-2">
|
<div
|
||||||
<div t-attf-class="oe_flip_card {{!state && 'disabled' || (auto_save && !is_virtual && !state.data.id && 'blocked') || ''}}">
|
class="oe_flip_container p-1 col-12 col-sm-8 col-md-6 col-lg-4 col-xl-3 col-xxl-2"
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
t-attf-class="oe_flip_card {{!state && 'disabled' || (auto_save && !is_virtual && !state.data.id && 'blocked') || ''}}"
|
||||||
|
>
|
||||||
<div class="oe_flip_card_inner text-center">
|
<div class="oe_flip_card_inner text-center">
|
||||||
<div t-attf-class="oe_flip_card_front p-0 {{(modified && 'border-warning') || (state && !is_virtual && 'border-success') || ''}}">
|
<div
|
||||||
|
t-attf-class="oe_flip_card_front p-0 {{(modified && 'border-warning') || (state && !is_virtual && 'border-success') || ''}}"
|
||||||
|
>
|
||||||
<t t-if="state">
|
<t t-if="state">
|
||||||
<t t-if="!is_virtual">
|
<t t-if="!is_virtual">
|
||||||
<div class="safezone position-absolute m-0 pb-2 pr-2 text-left">
|
<div
|
||||||
<span t-att-data-field="field_map.product_uom_qty" t-attf-data-esc="str({{field_map.product_uom_qty}}) + ' x ' + {{field_map.product_uom}}.data.display_name" t-attf-class="badge {{modified && 'badge-warning' || 'badge-success'}} font-weight-bold rounded-0 mt-0 px-2 py-3 product_qty" />
|
class="safezone position-absolute m-0 pb-2 pr-2 text-left"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
t-att-data-field="field_map.product_uom_qty"
|
||||||
|
t-attf-data-esc="str({{field_map.product_uom_qty}}) + ' x ' + {{field_map.product_uom}}.data.display_name"
|
||||||
|
t-attf-class="badge {{modified && 'badge-warning' || 'badge-success'}} font-weight-bold rounded-0 mt-0 px-2 py-3 product_qty"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<t t-else="">
|
<t t-else="">
|
||||||
<div class="safezone position-absolute m-0 pb-2 pr-2 text-left">
|
<div
|
||||||
<span class="badge badge-primary font-weight-bold rounded-0 mt-0 px-2 py-3 add_product"><i class="fa fa-plus"></i> 1 <t t-esc="state.data[field_map.product_uom].data.display_name"/></span>
|
class="safezone position-absolute m-0 pb-2 pr-2 text-left"
|
||||||
|
>
|
||||||
|
<span
|
||||||
|
class="badge badge-primary font-weight-bold rounded-0 mt-0 px-2 py-3 add_product"
|
||||||
|
><i class="fa fa-plus" /> 1 <t
|
||||||
|
t-esc="state.data[field_map.product_uom].data.display_name"
|
||||||
|
/></span>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
<div class="position-absolute m-0 text-left badge_price">
|
<div class="position-absolute m-0 text-left badge_price">
|
||||||
<t t-if="show_discount">
|
<t t-if="show_discount">
|
||||||
<span t-att-data-field="field_map.discount" t-attf-data-esc="'-' + str({{field_map.discount}}) +'%'" class="badge badge-dark discount_price font-weight-bold rounded-0 mt-1 p-2" />
|
<span
|
||||||
<span t-att-data-field="field_map.price_unit" t-attf-data-esc="'{{monetary('price_unit',true)}}'" class="badge font-weight-bold rounded-0 original_price" />
|
t-att-data-field="field_map.discount"
|
||||||
<span class="badge badge-info price_unit font-weight-bold rounded-0 mt-1 p-2" />
|
t-attf-data-esc="'-' + str({{field_map.discount}}) +'%'"
|
||||||
|
class="badge badge-dark discount_price font-weight-bold rounded-0 mt-1 p-2"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
t-att-data-field="field_map.price_unit"
|
||||||
|
t-attf-data-esc="'{{monetary('price_unit',true)}}'"
|
||||||
|
class="badge font-weight-bold rounded-0 original_price"
|
||||||
|
/>
|
||||||
|
<span
|
||||||
|
class="badge badge-info price_unit font-weight-bold rounded-0 mt-1 p-2"
|
||||||
|
/>
|
||||||
</t>
|
</t>
|
||||||
<t t-else="">
|
<t t-else="">
|
||||||
<span t-att-data-field="field_map.price_unit" t-attf-data-esc="'{{monetary('price_unit',true)}}'" class="badge badge-info price_unit font-weight-bold rounded-0 mt-1 p-2" />
|
<span
|
||||||
|
t-att-data-field="field_map.price_unit"
|
||||||
|
t-attf-data-esc="'{{monetary('price_unit',true)}}'"
|
||||||
|
class="badge badge-info price_unit font-weight-bold rounded-0 mt-1 p-2"
|
||||||
|
/>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
<span data-field="display_name" class="oe_one2many_product_picker_title position-absolute fixed-bottom p-1" data-esc="display_name" />
|
<span
|
||||||
<img alt="" class="img img-fluid" t-att-src="image(state.data[field_map.product].data.id,'image_variant_medium')" t-att-data-src-alt="image(state.data[field_map.product].data.id,'image_variant_big')" />
|
data-field="display_name"
|
||||||
|
class="oe_one2many_product_picker_title position-absolute fixed-bottom p-1"
|
||||||
|
data-esc="display_name"
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
alt=""
|
||||||
|
class="img img-fluid"
|
||||||
|
t-att-src="image(state.data[field_map.product].data.id,'image_variant_medium')"
|
||||||
|
t-att-data-src-alt="image(state.data[field_map.product].data.id,'image_variant_big')"
|
||||||
|
/>
|
||||||
</t>
|
</t>
|
||||||
<t t-else="">
|
<t t-else="">
|
||||||
<span class="oe_one2many_product_picker_title position-absolute fixed-bottom p-1" t-esc="record_search.display_name" />
|
<span
|
||||||
<img alt="" class="img img-fluid" t-att-src="image(record_search.id,'image_variant_medium')" t-att-data-src-alt="image(record_search.id,'image_variant_big')" />
|
class="oe_one2many_product_picker_title position-absolute fixed-bottom p-1"
|
||||||
|
t-esc="record_search.display_name"
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
alt=""
|
||||||
|
class="img img-fluid"
|
||||||
|
t-att-src="image(record_search.id,'image_variant_medium')"
|
||||||
|
t-att-data-src-alt="image(record_search.id,'image_variant_big')"
|
||||||
|
/>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
<div class="oe_flip_card_back">
|
<div class="oe_flip_card_back">
|
||||||
<widget name="product_picker_quick_create_form" t-att-compare-key="field_map.product_uom" />
|
<widget
|
||||||
|
name="product_picker_quick_create_form"
|
||||||
|
t-att-compare-key="field_map.product_uom"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.QuickModifPricePopup">
|
<t t-name="One2ManyProductPicker.QuickModifPricePopup">
|
||||||
<div class="oe_product_picker_quick_modif_price shadow" />
|
<div class="oe_product_picker_quick_modif_price shadow" />
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,18 +1,22 @@
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.QuickCreate.FormButtons">
|
<t t-name="One2ManyProductPicker.QuickCreate.FormButtons">
|
||||||
<div class="oe_one2many_product_picker_form_buttons">
|
<div class="oe_one2many_product_picker_form_buttons">
|
||||||
<t t-if="state == 'new'">
|
<t t-if="state == 'new'">
|
||||||
<button t-attf-class="btn btn-primary oe_record_add">Add</button>
|
<button t-attf-class="btn btn-primary oe_record_add">Add</button>
|
||||||
</t>
|
</t>
|
||||||
<t t-elif="state == 'dirty'">
|
<t t-elif="state == 'dirty'">
|
||||||
<button class="btn btn-success oe_record_change mr-2"><i class="fa fa-check" /></button>
|
<button class="btn btn-success oe_record_change mr-2">
|
||||||
<button class="btn btn-warning oe_record_discard ml-2"><i class="fa fa-times" /></button>
|
<i class="fa fa-check" />
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-warning oe_record_discard ml-2">
|
||||||
|
<i class="fa fa-times" />
|
||||||
|
</button>
|
||||||
</t>
|
</t>
|
||||||
<t t-else="">
|
<t t-else="">
|
||||||
<button class="btn btn-danger oe_record_remove w-100"><i class="fa fa-trash"/> Remove</button>
|
<button class="btn btn-danger oe_record_remove w-100"><i
|
||||||
|
class="fa fa-trash"
|
||||||
|
/> Remove</button>
|
||||||
</t>
|
</t>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,14 +1,18 @@
|
||||||
<template>
|
<template>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.QuickModifPrice.FormButtons">
|
<t t-name="One2ManyProductPicker.QuickModifPrice.FormButtons">
|
||||||
<div class="oe_one2many_product_picker_form_buttons">
|
<div class="oe_one2many_product_picker_form_buttons">
|
||||||
<button class="btn btn-success oe_record_change mr-2"><i class="fa fa-check" /></button>
|
<button class="btn btn-success oe_record_change mr-2">
|
||||||
<button class="btn btn-warning oe_record_discard ml-2"><i class="fa fa-times" /></button>
|
<i class="fa fa-check" />
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-warning oe_record_discard ml-2">
|
||||||
|
<i class="fa fa-times" />
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
<t t-name="One2ManyProductPicker.QuickModifPrice.Price">
|
<t t-name="One2ManyProductPicker.QuickModifPrice.Price">
|
||||||
<div class="text-left"><strong>Price:</strong> <div class="oe_price" /></div>
|
<div class="text-left">
|
||||||
|
<strong>Price:</strong>
|
||||||
|
<div class="oe_price" />
|
||||||
|
</div>
|
||||||
</t>
|
</t>
|
||||||
|
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
/* global QUnit */
|
/* global QUnit */
|
||||||
// Copyright 2020 Tecnativa - Alexandre Díaz
|
// Copyright 2020 Tecnativa - Alexandre Díaz
|
||||||
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
odoo.define('web_widget_one2many_product_picker.widget_tests', function (require) {
|
odoo.define("web_widget_one2many_product_picker.widget_tests", function(require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var FormView = require('web.FormView');
|
var FormView = require("web.FormView");
|
||||||
var testUtils = require('web.test_utils');
|
var testUtils = require("web.test_utils");
|
||||||
|
|
||||||
var createView = testUtils.createView;
|
var createView = testUtils.createView;
|
||||||
|
|
||||||
var getArch = function() {
|
var getArch = function() {
|
||||||
return '<form>' +
|
return (
|
||||||
|
"<form>" +
|
||||||
'<field name="currency_id" invisible="1" />' +
|
'<field name="currency_id" invisible="1" />' +
|
||||||
'<field name="line_ids" widget="one2many_product_picker" options="{\'groups\': [{\'name\': \'Desk\', \'domain\': [(\'name\', \'ilike\', \'%desk%\')], \'order\': {\'name\': \'id\', \'asc\': true}}, {\'name\': \'Chairs\', \'domain\': [(\'name\', \'ilike\', \'%chair%\')]}]}">' +
|
"<field name=\"line_ids\" widget=\"one2many_product_picker\" options=\"{'groups': [{'name': 'Desk', 'domain': [('name', 'ilike', '%desk%')], 'order': {'name': 'id', 'asc': true}}, {'name': 'Chairs', 'domain': [('name', 'ilike', '%chair%')]}]}\">" +
|
||||||
'<kanban>' +
|
"<kanban>" +
|
||||||
'<field name="name" />' +
|
'<field name="name" />' +
|
||||||
'<field name="product_id" />' +
|
'<field name="product_id" />' +
|
||||||
'<field name="price_reduce" />' +
|
'<field name="price_reduce" />' +
|
||||||
|
@ -21,37 +22,87 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
|
||||||
'<field name="foo_id" />' +
|
'<field name="foo_id" />' +
|
||||||
'<field name="product_uom_qty" />' +
|
'<field name="product_uom_qty" />' +
|
||||||
'<field name="product_uom" />' +
|
'<field name="product_uom" />' +
|
||||||
'</kanban>' +
|
"</kanban>" +
|
||||||
'</field>' +
|
"</field>" +
|
||||||
'</form>';
|
"</form>"
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
QUnit.module('Web Widget One2Many Product Picker', {
|
QUnit.module(
|
||||||
|
"Web Widget One2Many Product Picker",
|
||||||
|
{
|
||||||
beforeEach: function() {
|
beforeEach: function() {
|
||||||
this.data = {
|
this.data = {
|
||||||
foo: {
|
foo: {
|
||||||
fields: {
|
fields: {
|
||||||
currency_id: {string: "Currency", type: "many2one", relation: "currency"},
|
currency_id: {
|
||||||
line_ids: {string: "Lines Test", type: "one2many", relation: "line", relation_field: "foo_id"},
|
string: "Currency",
|
||||||
|
type: "many2one",
|
||||||
|
relation: "currency",
|
||||||
|
},
|
||||||
|
line_ids: {
|
||||||
|
string: "Lines Test",
|
||||||
|
type: "one2many",
|
||||||
|
relation: "line",
|
||||||
|
relation_field: "foo_id",
|
||||||
|
},
|
||||||
display_name: {string: "Display Name", type: "char"},
|
display_name: {string: "Display Name", type: "char"},
|
||||||
},
|
},
|
||||||
records: [
|
records: [
|
||||||
{id: 1, line_ids: [1, 2], currency_id: 1, display_name: "FT01"},
|
{
|
||||||
|
id: 1,
|
||||||
|
line_ids: [1, 2],
|
||||||
|
currency_id: 1,
|
||||||
|
display_name: "FT01",
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
line: {
|
line: {
|
||||||
fields: {
|
fields: {
|
||||||
name: {string: "Product Name", type: "string"},
|
name: {string: "Product Name", type: "string"},
|
||||||
product_id: {string: "Product", type: "many2one", relation: "product"},
|
product_id: {
|
||||||
product_uom: {string: "UoM", type: "many2one", relation: "uom"},
|
string: "Product",
|
||||||
|
type: "many2one",
|
||||||
|
relation: "product",
|
||||||
|
},
|
||||||
|
product_uom: {
|
||||||
|
string: "UoM",
|
||||||
|
type: "many2one",
|
||||||
|
relation: "uom",
|
||||||
|
},
|
||||||
product_uom_qty: {string: "Qty", type: "integer"},
|
product_uom_qty: {string: "Qty", type: "integer"},
|
||||||
price_unit: {string: "Product Price", type: "float"},
|
price_unit: {string: "Product Price", type: "float"},
|
||||||
price_reduce: {string: "Product Price Reduce", type: "float"},
|
price_reduce: {
|
||||||
foo_id: {string: "Parent", type: "many2one", relation: "foo"},
|
string: "Product Price Reduce",
|
||||||
|
type: "float",
|
||||||
|
},
|
||||||
|
foo_id: {
|
||||||
|
string: "Parent",
|
||||||
|
type: "many2one",
|
||||||
|
relation: "foo",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
records: [
|
records: [
|
||||||
{id: 1, name: "Large Cabinet", product_id: 1, product_uom: 1, product_uom_qty: 3, price_unit: 9.99, price_reduce: 9.00, foo_id: 1},
|
{
|
||||||
{id: 2, name: "Cabinet with Doors", product_id: 2, product_uom: 1, product_uom_qty: 8, price_unit: 42.99, price_reduce: 40.00, foo_id: 1},
|
id: 1,
|
||||||
|
name: "Large Cabinet",
|
||||||
|
product_id: 1,
|
||||||
|
product_uom: 1,
|
||||||
|
product_uom_qty: 3,
|
||||||
|
price_unit: 9.99,
|
||||||
|
price_reduce: 9.0,
|
||||||
|
foo_id: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "Cabinet with Doors",
|
||||||
|
product_id: 2,
|
||||||
|
product_uom: 1,
|
||||||
|
product_uom_qty: 8,
|
||||||
|
price_unit: 42.99,
|
||||||
|
price_reduce: 40.0,
|
||||||
|
foo_id: 1,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
product: {
|
product: {
|
||||||
|
@ -60,47 +111,60 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
|
||||||
display_name: {string: "Display Name", type: "char"},
|
display_name: {string: "Display Name", type: "char"},
|
||||||
list_price: {string: "Price", type: "float"},
|
list_price: {string: "Price", type: "float"},
|
||||||
image_medium: {string: "Image Medium", type: "binary"},
|
image_medium: {string: "Image Medium", type: "binary"},
|
||||||
uom_category_id: {string: "Category", type: "many2one", relation: "uom_category"},
|
uom_category_id: {
|
||||||
|
string: "Category",
|
||||||
|
type: "many2one",
|
||||||
|
relation: "uom_category",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
records: [
|
records: [
|
||||||
{id: 1, name: "Large Cabinet", display_name: "Large Cabinet", list_price: 9.99, image_medium: "", uom_category_id: 1},
|
{
|
||||||
{id: 2, name: "Cabinet with Doors", display_name: "Cabinet with Doors", list_price: 42.0, image_medium: "", uom_category_id: 1},
|
id: 1,
|
||||||
|
name: "Large Cabinet",
|
||||||
|
display_name: "Large Cabinet",
|
||||||
|
list_price: 9.99,
|
||||||
|
image_medium: "",
|
||||||
|
uom_category_id: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
name: "Cabinet with Doors",
|
||||||
|
display_name: "Cabinet with Doors",
|
||||||
|
list_price: 42.0,
|
||||||
|
image_medium: "",
|
||||||
|
uom_category_id: 1,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
uom_category: {
|
uom_category: {
|
||||||
fields: {
|
fields: {
|
||||||
display_name: {string: "Display Name", type: "char"},
|
display_name: {string: "Display Name", type: "char"},
|
||||||
},
|
},
|
||||||
records: [
|
records: [{id: 1, display_name: "Unit(s)"}],
|
||||||
{id: 1, display_name: "Unit(s)"},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
uom: {
|
uom: {
|
||||||
fields: {
|
fields: {
|
||||||
name: {string: "Name", type: "char"},
|
name: {string: "Name", type: "char"},
|
||||||
},
|
},
|
||||||
records: [
|
records: [{id: 1, name: "Unit(s)"}],
|
||||||
{id: 1, name: "Unit(s)"},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
currency: {
|
currency: {
|
||||||
fields: {
|
fields: {
|
||||||
name: {string: "Name", type: "char"},
|
name: {string: "Name", type: "char"},
|
||||||
symbol: {string: "Symbol", type: "char"},
|
symbol: {string: "Symbol", type: "char"},
|
||||||
},
|
},
|
||||||
records: [
|
records: [{id: 1, name: "Eur", symbol: "€"}],
|
||||||
{id: 1, name: "Eur", symbol: "€"},
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}, function () {
|
},
|
||||||
QUnit.test('Load widget', function (assert) {
|
function() {
|
||||||
|
QUnit.test("Load widget", function(assert) {
|
||||||
assert.expect(4);
|
assert.expect(4);
|
||||||
|
|
||||||
var form = createView({
|
var form = createView({
|
||||||
View: FormView,
|
View: FormView,
|
||||||
model: 'foo',
|
model: "foo",
|
||||||
data: this.data,
|
data: this.data,
|
||||||
arch: getArch(),
|
arch: getArch(),
|
||||||
res_id: 1,
|
res_id: 1,
|
||||||
|
@ -109,28 +173,56 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
|
||||||
index: 0,
|
index: 0,
|
||||||
},
|
},
|
||||||
mockRPC: function(route, args) {
|
mockRPC: function(route, args) {
|
||||||
if (route === '/web/dataset/call_kw/foo/read') {
|
if (route === "/web/dataset/call_kw/foo/read") {
|
||||||
assert.deepEqual(args.args[1], ['currency_id', 'line_ids', 'display_name'],
|
assert.deepEqual(
|
||||||
'should only read "currency_id", "line_ids" and "display_name"');
|
args.args[1],
|
||||||
|
["currency_id", "line_ids", "display_name"],
|
||||||
|
'should only read "currency_id", "line_ids" and "display_name"'
|
||||||
|
);
|
||||||
return $.when(this.data.foo.records);
|
return $.when(this.data.foo.records);
|
||||||
} else if (route === '/web/dataset/call_kw/line/read') {
|
} else if (route === "/web/dataset/call_kw/line/read") {
|
||||||
assert.deepEqual(args.args[1], ['name', 'product_id', 'price_reduce', 'price_unit', 'foo_id', 'product_uom_qty', 'product_uom'],
|
assert.deepEqual(
|
||||||
'should only read "name", "product_id", "price_reduce", "price_unit", "foo_id", "product_uom_qty" and "product_uom"');
|
args.args[1],
|
||||||
|
[
|
||||||
|
"name",
|
||||||
|
"product_id",
|
||||||
|
"price_reduce",
|
||||||
|
"price_unit",
|
||||||
|
"foo_id",
|
||||||
|
"product_uom_qty",
|
||||||
|
"product_uom",
|
||||||
|
],
|
||||||
|
'should only read "name", "product_id", "price_reduce", "price_unit", "foo_id", "product_uom_qty" and "product_uom"'
|
||||||
|
);
|
||||||
return $.when(this.data.line.records);
|
return $.when(this.data.line.records);
|
||||||
} else if (route === '/web/dataset/call_kw/product/search_read') {
|
} else if (
|
||||||
assert.deepEqual(args.kwargs.fields, ['id', 'uom_id', 'display_name', 'uom_category_id', 'image_medium', 'list_price'],
|
route === "/web/dataset/call_kw/product/search_read"
|
||||||
'should only read "id", "uom_id", "display_name", "uom_category_id", "image_medium" and "list_price"');
|
) {
|
||||||
|
assert.deepEqual(
|
||||||
|
args.kwargs.fields,
|
||||||
|
[
|
||||||
|
"id",
|
||||||
|
"uom_id",
|
||||||
|
"display_name",
|
||||||
|
"uom_category_id",
|
||||||
|
"image_medium",
|
||||||
|
"list_price",
|
||||||
|
],
|
||||||
|
'should only read "id", "uom_id", "display_name", "uom_category_id", "image_medium" and "list_price"'
|
||||||
|
);
|
||||||
return $.when(this.data.product.records);
|
return $.when(this.data.product.records);
|
||||||
}
|
}
|
||||||
return this._super.apply(this, arguments);
|
return this._super.apply(this, arguments);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
assert.ok(form.$('.oe_field_one2many_product_picker').is(':visible'),
|
assert.ok(
|
||||||
"should have a visible one2many product picker");
|
form.$(".oe_field_one2many_product_picker").is(":visible"),
|
||||||
|
"should have a visible one2many product picker"
|
||||||
|
);
|
||||||
|
|
||||||
form.destroy();
|
form.destroy();
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,37 +2,77 @@
|
||||||
<odoo>
|
<odoo>
|
||||||
<template id="_assets_backend_helpers" inherit_id="web._assets_backend_helpers">
|
<template id="_assets_backend_helpers" inherit_id="web._assets_backend_helpers">
|
||||||
<xpath expr=".">
|
<xpath expr=".">
|
||||||
<link type="text/css" rel="stylesheet"
|
<link
|
||||||
href="/web_widget_one2many_product_picker/static/src/scss/_variables.scss"/>
|
type="text/css"
|
||||||
|
rel="stylesheet"
|
||||||
|
href="/web_widget_one2many_product_picker/static/src/scss/_variables.scss"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="_assets_bootstrap" inherit_id="web._assets_bootstrap">
|
<template id="_assets_bootstrap" inherit_id="web._assets_bootstrap">
|
||||||
<xpath expr="link[2]">
|
<xpath expr="link[2]">
|
||||||
<link type="text/css" rel="stylesheet" href="/web_widget_one2many_product_picker/static/src/scss/main_variables.scss"/>
|
<link
|
||||||
|
type="text/css"
|
||||||
|
rel="stylesheet"
|
||||||
|
href="/web_widget_one2many_product_picker/static/src/scss/main_variables.scss"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
|
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
|
||||||
<xpath expr="." position="inside">
|
<xpath expr="." position="inside">
|
||||||
<link type="text/css" rel="stylesheet"
|
<link
|
||||||
href="/web_widget_one2many_product_picker/static/src/scss/one2many_product_picker.scss"/>
|
type="text/css"
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/tools.js"></script>
|
rel="stylesheet"
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js"></script>
|
href="/web_widget_one2many_product_picker/static/src/scss/one2many_product_picker.scss"
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js"></script>
|
/>
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_create_form_view.js"></script>
|
<script
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_create_form.js"></script>
|
type="text/javascript"
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js"></script>
|
src="/web_widget_one2many_product_picker/static/src/js/tools.js"
|
||||||
<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
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_model.js"></script>
|
type="text/javascript"
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js"></script>
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/renderer.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_create_form_view.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_create_form.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/basic_view.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/views/basic_model.js"
|
||||||
|
/>
|
||||||
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template id="qunit_suite" name="base_import_tests" inherit_id="web.qunit_suite">
|
<template id="qunit_suite" name="base_import_tests" inherit_id="web.qunit_suite">
|
||||||
<xpath expr="//t[@t-set='head']" position="inside">
|
<xpath expr="//t[@t-set='head']" position="inside">
|
||||||
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/tests/widget_tests.js"></script>
|
<script
|
||||||
|
type="text/javascript"
|
||||||
|
src="/web_widget_one2many_product_picker/static/tests/widget_tests.js"
|
||||||
|
/>
|
||||||
</xpath>
|
</xpath>
|
||||||
</template>
|
</template>
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
Loading…
Reference in New Issue