3
0
Fork 0

[IMP] web_widget_one2many_product_picker: black, isort, prettier

13.0
Alexandre D. Díaz 2021-03-16 20:09:18 +01:00
parent 78fdd8580c
commit eb1a53d92a
21 changed files with 1698 additions and 1381 deletions

View File

@ -0,0 +1 @@
../../../../web_widget_one2many_product_picker

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -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,
} }

View File

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

View File

@ -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");
@ -14,7 +12,7 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
* @param {Number} discount * @param {Number} discount
* @returns {Number} * @returns {Number}
*/ */
function priceReduce (price, discount) { function priceReduce(price, discount) {
return price * (1.0 - discount / 100.0); return price * (1.0 - discount / 100.0);
} }
@ -28,20 +26,16 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
* @param {Object} data * @param {Object} data
* @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, data: data,
field_info, currency_field: currency_field,
{ field_digits: true,
data: data, });
currency_field: currency_field,
field_digits: true,
});
} }
return { return {
monetary: monetary, monetary: monetary,
priceReduce: priceReduce, priceReduce: priceReduce,
}; };
}); });

View File

@ -1,6 +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.ProductPickerQuickCreateForm", function ( odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", function(
require require
) { ) {
"use strict"; "use strict";
@ -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;
@ -30,7 +29,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
/** /**
* @override * @override
*/ */
init: function (parent, options) { init: function(parent, options) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.state = options.state; this.state = options.state;
this.main_state = options.main_state; this.main_state = options.main_state;
@ -50,7 +49,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
/** /**
* @override * @override
*/ */
start: function () { start: function() {
var self = this; var self = this;
var def1 = this._super.apply(this, arguments); var def1 = this._super.apply(this, arguments);
var form_arch = this._generateFormArch(); var form_arch = this._generateFormArch();
@ -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,10 +89,10 @@ 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) {
self.controller = controller; self.controller = controller;
self.$el.empty(); self.$el.empty();
self.controller.appendTo(self.$el); self.controller.appendTo(self.$el);
@ -101,7 +101,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
return $.when(def1, def2); return $.when(def1, def2);
}, },
on_attach_callback: function () { on_attach_callback: function() {
if (this.controller) { if (this.controller) {
this.controller.autofocus(); this.controller.autofocus();
} }
@ -111,8 +111,9 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
* @private * @private
* @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);
@ -126,12 +127,12 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
* @private * @private
* @param {CustomEvent} evt * @param {CustomEvent} evt
*/ */
_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,20 +141,30 @@ 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()
var data = {}; ._generateVirtualState({}, this.editContext)
data[self.compareKey] = {operation: 'ADD', id: evt.data.compareValue}; .then(function(state) {
self.basicFieldParams.model._applyChange(state.id, data).then(function () { var data = {};
self.res_id = state.res_id; data[self.compareKey] = {
self.id = state.id; operation: "ADD",
self.start(); id: evt.data.compareValue,
};
self.basicFieldParams.model
._applyChange(state.id, data)
.then(function() {
self.res_id = state.res_id;
self.id = state.id;
self.start();
});
}); });
});
} }
}, },
}); });
widgetRegistry.add("product_picker_quick_create_form", ProductPickerQuickCreateForm); widgetRegistry.add(
"product_picker_quick_create_form",
ProductPickerQuickCreateForm
);
return ProductPickerQuickCreateForm; return ProductPickerQuickCreateForm;
}); });

View File

@ -1,54 +1,52 @@
// 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";
/** /**
* This file defines the QuickCreateFormView, an extension of the FormView that * This file defines the QuickCreateFormView, an extension of the FormView that
* is used by the RecordQuickCreate in One2ManyProductPicker views. * is used by the RecordQuickCreate in One2ManyProductPicker views.
*/ */
var QuickCreateFormView = require("web.QuickCreateFormView"); var QuickCreateFormView = require("web.QuickCreateFormView");
var BasicModel = require("web.BasicModel"); var BasicModel = require("web.BasicModel");
var core = require("web.core"); var core = require("web.core");
var qweb = core.qweb; var qweb = core.qweb;
BasicModel.include({ BasicModel.include({
_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];
delete values[field_name]; delete values[field_name];
}
delete record.context.ignore_onchanges;
} }
delete record.context.ignore_onchanges; return this._super(values, record, viewType);
} },
return this._super(values, record, viewType); });
},
});
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",
@ -57,7 +55,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
"click .oe_record_discard": "_onClickDiscard", "click .oe_record_discard": "_onClickDiscard",
}), }),
init: function (parent, model, renderer, params) { init: function(parent, model, renderer, params) {
this.compareKey = params.compareKey; this.compareKey = params.compareKey;
this.fieldMap = params.fieldMap; this.fieldMap = params.fieldMap;
this.context = params.context; this.context = params.context;
@ -68,9 +66,12 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
/** /**
* Create or accept changes * Create or accept changes
*/ */
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();
@ -87,7 +88,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* - new: Is a new record * - new: Is a new record
* - dirty: Has changes * - dirty: Has changes
*/ */
_getRecordState: function () { _getRecordState: function() {
var record = this.model.get(this.handle); var record = this.model.get(this.handle);
var state = "record"; var state = "record";
if (this.model.isNew(record.id)) { if (this.model.isNew(record.id)) {
@ -117,15 +118,13 @@ 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(), })
}) );
);
if (this._disabled) { if (this._disabled) {
this._disableQuickCreate(); this._disableQuickCreate();
@ -135,7 +134,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
/** /**
* @private * @private
*/ */
_disableQuickCreate: function () { _disableQuickCreate: function() {
if (!this.$el) { if (!this.$el) {
return; return;
} }
@ -150,8 +149,7 @@ 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");
@ -165,7 +163,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @param {Array[String]} fields_changed * @param {Array[String]} fields_changed
* @returns {Boolean} * @returns {Boolean}
*/ */
_needReloadCard: function (fields_changed) { _needReloadCard: function(fields_changed) {
for (var index in fields_changed) { for (var index in fields_changed) {
var field = fields_changed[index]; var field = fields_changed[index];
if (field === this.fieldMap[this.compareKey]) { if (field === this.fieldMap[this.compareKey]) {
@ -183,7 +181,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private * @private
* @param {ChangeEvent} ev * @param {ChangeEvent} ev
*/ */
_onFieldChanged: function (ev) { _onFieldChanged: function(ev) {
var fields_changed = Object.keys(ev.data.changes); var fields_changed = Object.keys(ev.data.changes);
if (this._needReloadCard(fields_changed)) { if (this._needReloadCard(fields_changed)) {
var field = ev.data.changes[fields_changed[0]]; var field = ev.data.changes[fields_changed[0]];
@ -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 =
@ -237,9 +234,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
/** /**
* @returns {Deferred} * @returns {Deferred}
*/ */
_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();
} }
@ -253,15 +249,15 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
reload: true, reload: true,
savePoint: true, savePoint: true,
viewType: "form", viewType: "form",
}).then(function () { }).then(function() {
var record = self.model.get(self.handle); var record = self.model.get(self.handle);
self.trigger_up("restore_flip_card", { self.trigger_up("restore_flip_card", {
success_callback: function () { success_callback: function() {
self.trigger_up("create_quick_record", { self.trigger_up("create_quick_record", {
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,
@ -269,9 +265,8 @@ 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();
} }
@ -284,10 +279,9 @@ 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();
} }
@ -298,22 +292,21 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
var record = this.model.get(this.handle); var record = this.model.get(this.handle);
this.trigger_up("restore_flip_card", { this.trigger_up("restore_flip_card", {
success_callback: function () { success_callback: function() {
self.trigger_up("update_quick_record", { self.trigger_up("update_quick_record", {
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,
}); });
}, },
_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();
} }
@ -331,7 +324,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
this._updateButtons(); this._updateButtons();
this._enableQuickCreate(); this._enableQuickCreate();
} else { } else {
this.update({}, {reload: false}).then(function () { this.update({}, {reload: false}).then(function() {
self.model.unsetDirty(self.handle); self.model.unsetDirty(self.handle);
self.trigger_up("restore_flip_card"); self.trigger_up("restore_flip_card");
self._updateButtons(); self._updateButtons();
@ -344,7 +337,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickAdd: function (ev) { _onClickAdd: function(ev) {
ev.stopPropagation(); ev.stopPropagation();
this._add(); this._add();
}, },
@ -353,7 +346,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickRemove: function (ev) { _onClickRemove: function(ev) {
ev.stopPropagation(); ev.stopPropagation();
this._remove(); this._remove();
}, },
@ -362,7 +355,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickChange: function (ev) { _onClickChange: function(ev) {
ev.stopPropagation(); ev.stopPropagation();
this._change(); this._change();
}, },
@ -371,34 +364,35 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickDiscard: function (ev) { _onClickDiscard: function(ev) {
ev.stopPropagation(); ev.stopPropagation();
this._discard(); this._discard();
}, },
} }
); );
var ProductPickerQuickCreateFormView = QuickCreateFormView.extend({ var ProductPickerQuickCreateFormView = QuickCreateFormView.extend({
config: _.extend({}, QuickCreateFormView.prototype.config, { config: _.extend({}, QuickCreateFormView.prototype.config, {
Renderer: ProductPickerQuickCreateFormRenderer, Renderer: ProductPickerQuickCreateFormRenderer,
Controller: ProductPickerQuickCreateFormController, Controller: ProductPickerQuickCreateFormController,
}), }),
/** /**
* @override * @override
*/ */
init: function (viewInfo, params) { init: function(viewInfo, params) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.controllerParams.compareKey = params.compareKey; this.controllerParams.compareKey = params.compareKey;
this.controllerParams.fieldMap = params.fieldMap; this.controllerParams.fieldMap = params.fieldMap;
this.controllerParams.context = params.context; this.controllerParams.context = params.context;
this.controllerParams.mainRecordData = params.mainRecordData; this.controllerParams.mainRecordData = params.mainRecordData;
}, },
}); });
return { return {
ProductPickerQuickCreateFormRenderer: ProductPickerQuickCreateFormRenderer, ProductPickerQuickCreateFormRenderer: ProductPickerQuickCreateFormRenderer,
ProductPickerQuickCreateFormController: ProductPickerQuickCreateFormController, ProductPickerQuickCreateFormController: ProductPickerQuickCreateFormController,
ProductPickerQuickCreateFormView: ProductPickerQuickCreateFormView, ProductPickerQuickCreateFormView: ProductPickerQuickCreateFormView,
}; };
}); }
);

View File

@ -1,152 +1,158 @@
// 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;
/**
* This widget render a Form. Used by FieldOne2ManyProductPicker
*/
var ProductPickerQuickModifPriceForm = Widget.extend({
className: "oe_one2many_product_picker_quick_modif_price",
xmlDependencies: [
"/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker_quick_modif_price.xml",
],
/** /**
* @override * This widget render a Form. Used by FieldOne2ManyProductPicker
*/ */
init: function (parent, options) { var ProductPickerQuickModifPriceForm = Widget.extend({
this._super.apply(this, arguments); className: "oe_one2many_product_picker_quick_modif_price",
this.state = options.state; xmlDependencies: [
this.main_state = options.main_state; "/web_widget_one2many_product_picker/static/src/xml/one2many_product_picker_quick_modif_price.xml",
this.node = options.node; ],
this.fields = options.fields;
this.fieldMap = options.fieldMap;
this.searchRecord = options.searchRecord;
this.fieldsInfo = options.fieldsInfo;
this.readonly = options.readonly;
this.basicFieldParams = options.basicFieldParams;
this.canEditPrice = options.canEditPrice;
this.canEditDiscount = options.canEditDiscount;
this.currencyField = options.currencyField;
this.res_id = this.state && this.state.res_id;
this.id = this.state && this.state.id;
this.editContext = {};
},
/** /**
* @override * @override
*/ */
start: function () { init: function(parent, options) {
var self = this; this._super.apply(this, arguments);
var def1 = this._super.apply(this, arguments); this.state = options.state;
var fieldsView = { this.main_state = options.main_state;
arch: this._generateFormArch(), this.node = options.node;
fields: this.fields, this.fields = options.fields;
viewFields: this.fields, this.fieldMap = options.fieldMap;
base_model: this.basicFieldParams.field.relation, this.searchRecord = options.searchRecord;
type: "form", this.fieldsInfo = options.fieldsInfo;
model: this.basicFieldParams.field.relation, this.readonly = options.readonly;
}; this.basicFieldParams = options.basicFieldParams;
this.formView = new ProductPickerQuickModifPriceFormView(fieldsView, { this.canEditPrice = options.canEditPrice;
context: this.main_state.getContext(), this.canEditDiscount = options.canEditDiscount;
fieldMap: this.fieldMap, this.currencyField = options.currencyField;
modelName: this.basicFieldParams.field.relation, this.res_id = this.state && this.state.res_id;
userContext: this.getSession().user_context, this.id = this.state && this.state.id;
ids: this.res_id ? [this.res_id] : [], this.editContext = {};
currentId: this.res_id || undefined, },
mode: this.res_id && this.readonly ? "readonly" : "edit",
recordID: this.id,
index: 0,
parentID: this.basicFieldParams.parentID,
default_buttons: true,
withControlPanel: false,
model: this.basicFieldParams.model,
parentRecordData: this.basicFieldParams.recordData,
currencyField: this.currencyField,
disable_autofocus: true,
});
if (this.id) {
this.basicFieldParams.model.save(this.id, {savePoint: true});
}
var def2 = this.formView.getController(this).then(function (controller) {
self.controller = controller;
self.$el.empty();
self.controller.appendTo(self.$el);
});
return $.when(def1, def2); /**
}, * @override
*/
start: function() {
var self = this;
var def1 = this._super.apply(this, arguments);
var fieldsView = {
arch: this._generateFormArch(),
fields: this.fields,
viewFields: this.fields,
base_model: this.basicFieldParams.field.relation,
type: "form",
model: this.basicFieldParams.field.relation,
};
this.formView = new ProductPickerQuickModifPriceFormView(fieldsView, {
context: this.main_state.getContext(),
fieldMap: this.fieldMap,
modelName: this.basicFieldParams.field.relation,
userContext: this.getSession().user_context,
ids: this.res_id ? [this.res_id] : [],
currentId: this.res_id || undefined,
mode: this.res_id && this.readonly ? "readonly" : "edit",
recordID: this.id,
index: 0,
parentID: this.basicFieldParams.parentID,
default_buttons: true,
withControlPanel: false,
model: this.basicFieldParams.model,
parentRecordData: this.basicFieldParams.recordData,
currencyField: this.currencyField,
disable_autofocus: true,
});
if (this.id) {
this.basicFieldParams.model.save(this.id, {savePoint: true});
}
var def2 = this.formView.getController(this).then(function(controller) {
self.controller = controller;
self.$el.empty();
self.controller.appendTo(self.$el);
});
/** return $.when(def1, def2);
* @override },
*/
destroy: function () {
this._super.apply(this, arguments);
},
on_attach_callback: function () { /**
// Do nothing * @override
}, */
destroy: function() {
this._super.apply(this, arguments);
},
/** on_attach_callback: function() {
* @private // Do nothing
* @returns {String} },
*/
_generateFormArch: function () {
var wanted_field_states = this._getWantedFieldState();
var template =
"<templates><t t-name='One2ManyProductPicker.QuickModifPrice.Form'>";
template += this.basicFieldParams.field.views.form.arch;
template += "</t></templates>";
qweb.add_template(template);
var $arch = $(qweb.render("One2ManyProductPicker.QuickModifPrice.Form", {
field_map: this.fieldMap,
record_search: this.searchRecord,
}));
var field_names = Object.keys(wanted_field_states); /**
var gen_arch = "<form><group>"; * @private
for (var index in field_names) { * @returns {String}
var field_name = field_names[index]; */
var $field = $arch.find("field[name='"+field_name+"']"); _generateFormArch: function() {
var modifiers = var wanted_field_states = this._getWantedFieldState();
$field.attr("modifiers") ? JSON.parse($field.attr("modifiers")) : {}; var template =
modifiers.invisible = false; "<templates><t t-name='One2ManyProductPicker.QuickModifPrice.Form'>";
modifiers.readonly = wanted_field_states[field_name]; template += this.basicFieldParams.field.views.form.arch;
$field.attr("modifiers", JSON.stringify(modifiers)); template += "</t></templates>";
$field.attr("invisible", "0"); qweb.add_template(template);
$field.attr("readonly", wanted_field_states[field_name]?"1":"0"); var $arch = $(
gen_arch += $field[0].outerHTML; qweb.render("One2ManyProductPicker.QuickModifPrice.Form", {
} field_map: this.fieldMap,
gen_arch += "</group></form>"; record_search: this.searchRecord,
return gen_arch; })
}, );
/** var field_names = Object.keys(wanted_field_states);
* This method returns the wanted fields to be displayed in the view. var gen_arch = "<form><group>";
* {field_name: readonly_state} for (var index in field_names) {
* var field_name = field_names[index];
* @private var $field = $arch.find("field[name='" + field_name + "']");
* @returns {Object} var modifiers = $field.attr("modifiers")
*/ ? JSON.parse($field.attr("modifiers"))
_getWantedFieldState: function () { : {};
var wantedFieldState = {}; modifiers.invisible = false;
wantedFieldState[this.fieldMap.discount] = !this.canEditDiscount; modifiers.readonly = wanted_field_states[field_name];
wantedFieldState[this.fieldMap.price_unit] = !this.canEditPrice; $field.attr("modifiers", JSON.stringify(modifiers));
return wantedFieldState; $field.attr("invisible", "0");
}, $field.attr(
}); "readonly",
wanted_field_states[field_name] ? "1" : "0"
);
gen_arch += $field[0].outerHTML;
}
gen_arch += "</group></form>";
return gen_arch;
},
return ProductPickerQuickModifPriceForm; /**
}); * This method returns the wanted fields to be displayed in the view.
* {field_name: readonly_state}
*
* @private
* @returns {Object}
*/
_getWantedFieldState: function() {
var wantedFieldState = {};
wantedFieldState[this.fieldMap.discount] = !this.canEditDiscount;
wantedFieldState[this.fieldMap.price_unit] = !this.canEditPrice;
return wantedFieldState;
},
});
return ProductPickerQuickModifPriceForm;
}
);

View File

@ -1,32 +1,32 @@
// 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";
/** /**
* This file defines the QuickCreateFormView, an extension of the FormView that * This file defines the QuickCreateFormView, an extension of the FormView that
* is used by the RecordQuickCreate in One2ManyProductPicker views. * is used by the RecordQuickCreate in One2ManyProductPicker views.
*/ */
var QuickCreateFormView = require("web.QuickCreateFormView"); var QuickCreateFormView = require("web.QuickCreateFormView");
var core = require("web.core"); var core = require("web.core");
var tools = require("web_widget_one2many_product_picker.tools"); var tools = require("web_widget_one2many_product_picker.tools");
var qweb = core.qweb; var qweb = core.qweb;
var ProductPickerQuickModifPriceFormRenderer = var ProductPickerQuickModifPriceFormRenderer = QuickCreateFormView.prototype.config.Renderer.extend(
QuickCreateFormView.prototype.config.Renderer.extend(
{ {
/** /**
* @override * @override
*/ */
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();
}); });
@ -35,21 +35,22 @@ 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,
}) }
); )
);
}, },
/** /**
* @private * @private
*/ */
_appendPrice: function () { _appendPrice: function() {
this.$el.find(".oe_price").remove(); this.$el.find(".oe_price").remove();
this.$el.append( this.$el.append(
qweb.render("One2ManyProductPicker.QuickModifPrice.Price") qweb.render("One2ManyProductPicker.QuickModifPrice.Price")
@ -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",
@ -69,7 +69,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
/** /**
* @override * @override
*/ */
init: function (parent, model, renderer, params) { init: function(parent, model, renderer, params) {
this.fieldMap = params.fieldMap; this.fieldMap = params.fieldMap;
this.context = params.context; this.context = params.context;
this._super.apply(this, arguments); this._super.apply(this, arguments);
@ -80,9 +80,9 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
/** /**
* @override * @override
*/ */
start: function () { start: function() {
var self = this; var self = this;
return this._super.apply(this, arguments).then(function () { return this._super.apply(this, arguments).then(function() {
self._updatePrice(); self._updatePrice();
}); });
}, },
@ -90,7 +90,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
/** /**
* @override * @override
*/ */
_onFieldChanged: function () { _onFieldChanged: function() {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this._updatePrice(); this._updatePrice();
}, },
@ -98,26 +98,28 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
/** /**
* @private * @private
*/ */
_updatePrice: function () { _updatePrice: function() {
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(
tools.monetary(
price_reduce,
this.getParent().state.fields[this.fieldMap.price_unit],
this.currencyField,
record
)
); );
this.renderer.$el
.find(".oe_price")
.html(
tools.monetary(
price_reduce,
this.getParent().state.fields[this.fieldMap.price_unit],
this.currencyField,
record
)
);
}, },
/** /**
* @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");
@ -129,8 +131,7 @@ 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");
@ -143,7 +144,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickChange: function (ev) { _onClickChange: function(ev) {
var self = this; var self = this;
ev.stopPropagation(); ev.stopPropagation();
this.model.updateRecordContext(this.handle, { this.model.updateRecordContext(this.handle, {
@ -160,7 +161,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
reload: true, reload: true,
savePoint: true, savePoint: true,
viewType: "form", viewType: "form",
}).then(function () { }).then(function() {
self._enableQuickCreate(); self._enableQuickCreate();
var record = self.model.get(self.handle); var record = self.model.get(self.handle);
self.model.unsetDirty(self.handle); self.model.unsetDirty(self.handle);
@ -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", {
@ -188,7 +188,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickDiscard: function (ev) { _onClickDiscard: function(ev) {
ev.stopPropagation(); ev.stopPropagation();
this.model.discardChanges(this.handle, { this.model.discardChanges(this.handle, {
rollback: true, rollback: true,
@ -202,24 +202,25 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
} }
); );
var ProductPickerQuickModifPriceFormView = QuickCreateFormView.extend({ var ProductPickerQuickModifPriceFormView = QuickCreateFormView.extend({
config: _.extend({}, QuickCreateFormView.prototype.config, { config: _.extend({}, QuickCreateFormView.prototype.config, {
Renderer: ProductPickerQuickModifPriceFormRenderer, Renderer: ProductPickerQuickModifPriceFormRenderer,
Controller: ProductPickerQuickModifPriceFormController, Controller: ProductPickerQuickModifPriceFormController,
}), }),
init: function (viewInfo, params) { init: function(viewInfo, params) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
this.controllerParams.fieldMap = params.fieldMap; this.controllerParams.fieldMap = params.fieldMap;
this.controllerParams.context = params.context; this.controllerParams.context = params.context;
this.controllerParams.parentRecordData = params.parentRecordData; this.controllerParams.parentRecordData = params.parentRecordData;
this.controllerParams.currencyField = params.currencyField; this.controllerParams.currencyField = params.currencyField;
}, },
}); });
return { return {
ProductPickerQuickModifPriceFormRenderer: ProductPickerQuickModifPriceFormRenderer, ProductPickerQuickModifPriceFormRenderer: ProductPickerQuickModifPriceFormRenderer,
ProductPickerQuickModifPriceFormController: ProductPickerQuickModifPriceFormController, ProductPickerQuickModifPriceFormController: ProductPickerQuickModifPriceFormController,
ProductPickerQuickModifPriceFormView: ProductPickerQuickModifPriceFormView, ProductPickerQuickModifPriceFormView: ProductPickerQuickModifPriceFormView,
}; };
}); }
);

View File

@ -1,7 +1,7 @@
/* global py */ /* global py */
// 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.One2ManyProductPickerRecord", function ( odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", function(
require require
) { ) {
"use strict"; "use strict";
@ -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;
@ -33,7 +32,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
/** /**
* @override * @override
*/ */
init: function (parent, state, options) { init: function(parent, state, options) {
this._super(parent); this._super(parent);
this.options = options; this.options = options;
this.subWidgets = {}; this.subWidgets = {};
@ -52,44 +51,43 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* *
* @returns {Object} * @returns {Object}
*/ */
generateVirtualState: function () { generateVirtualState: function() {
return this._generateVirtualState().then(this.recreate.bind(this)); return this._generateVirtualState().then(this.recreate.bind(this));
}, },
/** /**
* @override * @override
*/ */
start: function () { start: function() {
return $.when(this._super.apply(this, arguments), this._render()); return $.when(this._super.apply(this, arguments), this._render());
}, },
/** /**
* @override * @override
*/ */
on_attach_callback: function () { on_attach_callback: function() {
_.invoke(this.subWidgets, "on_attach_callback"); _.invoke(this.subWidgets, "on_attach_callback");
}, },
/** /**
* @override * @override
*/ */
on_detach_callback: function () { on_detach_callback: function() {
_.invoke(this.subWidgets, "on_detach_callback"); _.invoke(this.subWidgets, "on_detach_callback");
}, },
/** /**
* @override * @override
*/ */
destroy: function () { destroy: function() {
this.$card.off("") this.$card.off("");
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
/** /**
* @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
@ -104,7 +102,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* *
* @param {Object} state * @param {Object} state
*/ */
recreate: function (state) { recreate: function(state) {
if (state) { if (state) {
this._setState(state); this._setState(state);
} }
@ -127,11 +125,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {String} field_name * @param {String} field_name
* @returns {String} * @returns {String}
*/ */
_getImageUrl: function (product_id, field_name) { _getImageUrl: function(product_id, field_name) {
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
);
}, },
/** /**
@ -140,14 +139,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {String} price_field * @param {String} price_field
*/ */
_getMonetaryFieldValue: function (price_field) { _getMonetaryFieldValue: function(price_field) {
var field_name = this.options.fieldMap[price_field]; var field_name = this.options.fieldMap[price_field];
var price = this.state.data[field_name]; var price = this.state.data[field_name];
return tools.monetary( return tools.monetary(
price, price,
this.state.fields[field_name], this.state.fields[field_name],
this.options.currencyField, this.options.currencyField,
this.state.data); this.state.data
);
}, },
/** /**
@ -155,7 +155,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {String} d a stringified domain * @param {String} d a stringified domain
* @returns {Boolean} the domain evaluted with the current values * @returns {Boolean} the domain evaluted with the current values
*/ */
_computeDomain: function (d) { _computeDomain: function(d) {
return new Domain(d).compute( return new Domain(d).compute(
(this.state || this.getParent().state).evalContext (this.state || this.getParent().state).evalContext
); );
@ -168,8 +168,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {Object} viewState * @param {Object} viewState
* @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,15 +185,15 @@ 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;
}, },
/** /**
* @private * @private
* @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,
}; };
}, },
@ -223,7 +223,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
_getInternalVirtualRecordContext: function () { _getInternalVirtualRecordContext: function() {
var context = {}; var context = {};
context["default_" + this.options.basicFieldParams.relation_field] = context["default_" + this.options.basicFieldParams.relation_field] =
this.options.basicFieldParams.state.id || null; this.options.basicFieldParams.state.id || null;
@ -237,10 +237,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
_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;
@ -252,21 +252,23 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {Object} context * @param {Object} context
* @returns {Object} * @returns {Object}
*/ */
_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, });
});
}, },
_detachAllWidgets: function () { _detachAllWidgets: function() {
_.invoke(this.widgets.front, "on_detach_callback"); _.invoke(this.widgets.front, "on_detach_callback");
_.invoke(this.widgets.back, "on_detach_callback"); _.invoke(this.widgets.back, "on_detach_callback");
this.widgets = { this.widgets = {
@ -278,21 +280,18 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
/** /**
* @override * @override
*/ */
_render: function () { _render: function() {
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);
}, },
@ -304,9 +303,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {jQueryElement} $container * @param {jQueryElement} $container
*/ */
_processWidgetFields: function ($container, widget_list) { _processWidgetFields: function($container, widget_list) {
var self = this; var self = this;
$container.find("field").each(function () { $container.find("field").each(function() {
var $field = $(this); var $field = $(this);
if ($field.parents("widget").length) { if ($field.parents("widget").length) {
return; return;
@ -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(
@ -358,9 +354,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {Class} Widget * @param {Class} Widget
* @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
@ -368,7 +363,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
// that dict being shared between records, we don't modify it // that dict being shared between records, we don't modify it
// in place // in place
var attrs = Object.create(null); var attrs = Object.create(null);
_.each(this.fieldsInfo[field_name], function (value, key) { _.each(this.fieldsInfo[field_name], function(value, key) {
if (_.str.startsWith(key, "t-att-")) { if (_.str.startsWith(key, "t-att-")) {
key = key.slice(6); key = key.slice(6);
value = $field.attr(key); value = $field.attr(key);
@ -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);
@ -396,9 +388,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {jQueryElement} $container * @param {jQueryElement} $container
*/ */
_processWidgets: function ($container, widget_zone) { _processWidgets: function($container, widget_zone) {
var self = this; var self = this;
$container.find("widget").each(function () { $container.find("widget").each(function() {
var $field = $(this); var $field = $(this);
var FieldWidget = widgetRegistry.get($field.attr("name")); var FieldWidget = widgetRegistry.get($field.attr("name"));
var widget = new FieldWidget(self, { var widget = new FieldWidget(self, {
@ -417,9 +409,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
self.widgets[widget_zone].push(widget); self.widgets[widget_zone].push(widget);
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);
}); });
@ -445,7 +438,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {Array[String]} fields * @param {Array[String]} fields
*/ */
_processDynamicFields: function (fields) { _processDynamicFields: function(fields) {
if (!this.state) { if (!this.state) {
return; return;
} }
@ -456,14 +449,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var to_find = []; var to_find = [];
if (!_.isEmpty(fields)) { if (!_.isEmpty(fields)) {
to_find = _.map(fields, function (field) { to_find = _.map(fields, function(field) {
return _.str.sprintf("[data-field=%s]", [field]); return _.str.sprintf("[data-field=%s]", [field]);
}); });
} else { } else {
to_find = ["[data-field]"]; to_find = ["[data-field]"];
} }
this.$el.find(to_find.join()).each(function () { this.$el.find(to_find.join()).each(function() {
var $elm = $(this); var $elm = $(this);
var format_out = $elm.data("esc") || $elm.data("field"); var format_out = $elm.data("esc") || $elm.data("field");
$elm.html( $elm.html(
@ -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"));
} }
} }
} }
@ -491,7 +486,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @returns {String} * @returns {String}
*/ */
_calcPriceReduced: function () { _calcPriceReduced: function() {
var price_reduce = 0; var price_reduce = 0;
var field_map = this.options.fieldMap; var field_map = this.options.fieldMap;
var model = this.options.basicFieldParams.model; var model = this.options.basicFieldParams.model;
@ -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, price_reduce &&
this.state.fields[field_map.price_unit], tools.monetary(
this.options.currencyField, price_reduce,
this.state.data this.state.fields[field_map.price_unit],
this.options.currencyField,
this.state.data
)
); );
}, },
@ -513,39 +512,45 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @returns {Promise} * @returns {Promise}
*/ */
_saveRecord: function () { _saveRecord: function() {
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
stayInEdit: true, .save(record.id, {
reload: true, stayInEdit: true,
savePoint: true, reload: true,
viewType: "form", savePoint: true,
}).then(function () { viewType: "form",
var record = model.get(self.state.id); })
self.trigger_up("create_quick_record", { .then(function() {
id: record.id, var record = model.get(self.state.id);
callback: function () { self.trigger_up("create_quick_record", {
self.$card.find('.o_catch_attention').removeClass('o_catch_attention'); id: record.id,
} callback: function() {
self.$card
.find(".o_catch_attention")
.removeClass("o_catch_attention");
},
});
model.unsetDirty(self.state.id);
}); });
model.unsetDirty(self.state.id);
});
}, },
/** /**
* @private * @private
*/ */
_updateRecord: function () { _updateRecord: function() {
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);
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);
}, },
@ -554,10 +559,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @returns {Promise} * @returns {Promise}
*/ */
_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();
}); });
}, },
@ -578,18 +582,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {Number} amount * @param {Number} amount
* @returns {Promise} * @returns {Promise}
*/ */
_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();
}); });
@ -598,22 +601,22 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
/** /**
* @private * @private
*/ */
_doInteractAnim: function (target, currentTarget) { _doInteractAnim: function(target, currentTarget) {
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");
}); });
}, },
/** /**
* @private * @private
*/ */
_openPriceModifier: function () { _openPriceModifier: function() {
var state_data = this.state && this.state.data; var state_data = this.state && this.state.data;
if (this.options.readOnlyMode || !state_data) { if (this.options.readOnlyMode || !state_data) {
return; return;
@ -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);
}, },
@ -643,16 +647,19 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {ClickEvent} evt * @param {ClickEvent} evt
*/ */
_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) {
@ -689,7 +697,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
/** /**
* @private * @private
*/ */
_onClickDelayedFlipCard: function () { _onClickDelayedFlipCard: function() {
this._clickFlipCardDelayed = false; this._clickFlipCardDelayed = false;
this._clickFlipCardCount = 0; this._clickFlipCardCount = 0;
@ -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"),
}); });
}); });
} }
@ -728,20 +738,20 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {MouseEvent} evt * @param {MouseEvent} evt
*/ */
_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({
@ -768,8 +777,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
height: $currentTarget.height(), height: $currentTarget.height(),
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"));
@ -780,13 +789,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
/** /**
* @private * @private
*/ */
_onRestoreFlipCard: function (evt) { _onRestoreFlipCard: function(evt) {
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();
} }
@ -824,7 +833,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @private * @private
* @param {CustomEvent} evt * @param {CustomEvent} evt
*/ */
_onQuickRecordUpdated: function (evt) { _onQuickRecordUpdated: function(evt) {
this._processDynamicFields(Object.keys(evt.data.changes)); this._processDynamicFields(Object.keys(evt.data.changes));
this.trigger_up("update_subtotal"); this.trigger_up("update_subtotal");
}, },

View File

@ -1,28 +1,28 @@
// 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.BasicModel", function (require) { odoo.define("web_widget_one2many_product_picker.BasicModel", function(require) {
"use strict"; "use strict";
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
*/ */
updateRecordContext: function (handle, context) { updateRecordContext: function(handle, context) {
this.localData[handle].context = _.extend( this.localData[handle].context = _.extend(
{}, {},
this.localData[handle].context, this.localData[handle].context,
context); context
);
}, },
/** /**
* @param {Number/String} id * @param {Number/String} id
* @returns {Boolean} * @returns {Boolean}
*/ */
isPureVirtual: function (id) { isPureVirtual: function(id) {
var data = this.localData[id]; var data = this.localData[id];
return data._virtual || false; return data._virtual || false;
}, },
@ -31,7 +31,7 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
* @param {Number/String} id * @param {Number/String} id
* @param {Boolean} status * @param {Boolean} status
*/ */
setPureVirtual: function (id, status) { setPureVirtual: function(id, status) {
var data = this.localData[id]; var data = this.localData[id];
if (status) { if (status) {
data._virtual = true; data._virtual = true;
@ -43,10 +43,10 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
/** /**
* @param {Number/String} id * @param {Number/String} id
*/ */
unsetDirty: function (id) { unsetDirty: function(id) {
var data = this.localData[id]; var data = this.localData[id];
data._isDirty = false; data._isDirty = false;
this._visitChildren(data, function (r) { this._visitChildren(data, function(r) {
r._isDirty = false; r._isDirty = false;
}); });
}, },
@ -58,12 +58,12 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
* @param {Object} options * @param {Object} options
* @returns {Deferred} * @returns {Deferred}
*/ */
createVirtualRecord: function (listID, options) { createVirtualRecord: function(listID, options) {
var self = this; var self = this;
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,
@ -75,23 +75,20 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
doNotSetDirty: true, doNotSetDirty: true,
}; };
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(recordID, options.data, params).then(
self._applyChange( function() {
recordID,
options.data,
params
).then(function () {
d.resolve(self.get(recordID)); d.resolve(self.get(recordID));
}); }
} else { );
d.resolve(self.get(recordID)); } else {
} d.resolve(self.get(recordID));
}); }
});
}); });
}, },
@ -103,12 +100,12 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
* *
* @override * @override
*/ */
_performOnChange: function (record, fields, viewType) { _performOnChange: function(record, fields, viewType) {
if (record.context && record.context.ignore_warning) { if (record.context && record.context.ignore_warning) {
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);
}, },
}); });
}); });

View File

@ -1,7 +1,7 @@
/* global py */ /* global py */
// 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.BasicView", function (require) { odoo.define("web_widget_one2many_product_picker.BasicView", function(require) {
"use strict"; "use strict";
var core = require("web.core"); var core = require("web.core");
@ -11,18 +11,16 @@ odoo.define("web_widget_one2many_product_picker.BasicView", function (require) {
var _t = core._t; var _t = core._t;
// 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
_: PY_t, ? pyUtils.py_eval(attrs.options, {
_: 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);
}, },
}); });
}); });

View File

@ -1,6 +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.FieldOne2ManyProductPicker", function ( odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", function(
require require
) { ) {
"use strict"; "use strict";
@ -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,24 +42,27 @@ 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
*/ */
init: function (parent, name, record) { init: function(parent, name, record) {
this._super.apply(this, arguments); this._super.apply(this, arguments);
// This is the parent state // This is the parent state
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 = [];
@ -78,7 +80,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @override * @override
*/ */
willStart: function () { willStart: function() {
if (!this.view) { if (!this.view) {
return $.when(); return $.when();
} }
@ -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;
} }
@ -102,28 +104,34 @@ 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);
}, },
updateSubtotalPrice: function () { updateSubtotalPrice: function() {
if (!this.options.show_subtotal) { if (!this.options.show_subtotal) {
return; return;
} }
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 {
prices = _.map(records, function (line) { prices = _.map(records, function(line) {
return ( return (
line.data[field_map.product_uom_qty] * line.data[field_map.product_uom_qty] *
line.data[field_map.price_unit] line.data[field_map.price_unit]
@ -131,7 +139,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
}); });
} }
var total = var total =
_.reduce(prices, function (a, b) { _.reduce(prices, function(a, b) {
return a + b; return a + b;
}) || 0; }) || 0;
total = tools.monetary( total = tools.monetary(
@ -149,7 +157,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @returns {Object} * @returns {Object}
*/ */
getBasicFieldParams: function () { getBasicFieldParams: function() {
return { return {
domain: this.record.getDomain(this.recordParams), domain: this.record.getDomain(this.recordParams),
field: this.field, field: this.field,
@ -166,7 +174,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @override * @override
*/ */
_getRenderer: function () { _getRenderer: function() {
return One2ManyProductPickerRenderer; return One2ManyProductPickerRenderer;
}, },
@ -175,7 +183,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @private * @private
*/ */
_processGroups: function () { _processGroups: function() {
this.searchGroups = []; this.searchGroups = [];
var hasUserActive = false; var hasUserActive = false;
var groups = this.options.groups || []; var groups = this.options.groups || [];
@ -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,
@ -204,9 +212,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @override * @override
*/ */
_renderControlPanel: function () { _renderControlPanel: function() {
var self = this; var self = this;
return this._super.apply(this, arguments).then(function () { return this._super.apply(this, arguments).then(function() {
self.control_panel.update({ self.control_panel.update({
cp_content: { cp_content: {
$buttons: self.$buttons, $buttons: self.$buttons,
@ -219,7 +227,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @override * @override
*/ */
_renderButtons: function () { _renderButtons: function() {
if (this.isReadonly) { if (this.isReadonly) {
return this._super.apply(this, arguments); return this._super.apply(this, arguments);
} }
@ -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", {
@ -244,15 +252,17 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @override * @override
*/ */
_render: function () { _render: function() {
var self = this; var self = this;
var def = this._super.apply(this, arguments); var def = this._super.apply(this, arguments);
// Parent implementation can return 'undefined' :( // Parent implementation can return 'undefined' :(
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();
@ -266,13 +276,13 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @returns {Deferred} * @returns {Deferred}
*/ */
doRenderSearchRecords: function () { doRenderSearchRecords: function() {
var self = this; var self = this;
return $.Deferred(function (d) { return $.Deferred(function(d) {
self._getSearchRecords().then(function () { self._getSearchRecords().then(function() {
self.renderer.$el.scrollTop(0); self.renderer.$el.scrollTop(0);
self.renderer._renderView().then(function (virtualStateDefs) { self.renderer._renderView().then(function(virtualStateDefs) {
virtualStateDefs.then(function () { virtualStateDefs.then(function() {
d.resolve(); d.resolve();
}); });
}); });
@ -285,7 +295,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @private * @private
*/ */
_addMaximizeButton: function () { _addMaximizeButton: function() {
this.$("#product_picker_maximize").remove(); this.$("#product_picker_maximize").remove();
this.$btnMaximize = $(qweb.render("One2ManyProductPicker.ButtonMaximize")); this.$btnMaximize = $(qweb.render("One2ManyProductPicker.ButtonMaximize"));
this.$btnMaximize this.$btnMaximize
@ -298,7 +308,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @private * @private
*/ */
_addTotalsZone: function () { _addTotalsZone: function() {
this.$("#product_picker_total").remove(); this.$("#product_picker_total").remove();
this.$totalZone = $(qweb.render("One2ManyProductPicker.Total")); this.$totalZone = $(qweb.render("One2ManyProductPicker.Total"));
this.$totalZone.appendTo(this.$el); this.$totalZone.appendTo(this.$el);
@ -314,7 +324,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @param {Boolean} merge * @param {Boolean} merge
* @returns {Deferred} * @returns {Deferred}
*/ */
_getSearchRecords: function (options, merge) { _getSearchRecords: function(options, merge) {
var self = this; var self = this;
var arch = this.view.arch; var arch = this.view.arch;
var field_name = this.options.field_map.product; var field_name = this.options.field_map.product;
@ -325,13 +335,16 @@ 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;
var offset = soptions.offset || 0; var offset = soptions.offset || 0;
self._rpc({ self._rpc({
@ -343,7 +356,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
offset: offset, offset: offset,
orderBy: self._searchContext.order, orderBy: self._searchContext.order,
kwargs: {context: context}, kwargs: {context: context},
}).then(function (results) { }).then(function(results) {
if (merge) { if (merge) {
self._searchRecords = _.union( self._searchRecords = _.union(
self._searchRecords || [], self._searchRecords || [],
@ -370,7 +383,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {MouseEvent} evt * @param {MouseEvent} evt
*/ */
_onClickSearchGroup: function (evt) { _onClickSearchGroup: function(evt) {
var $btn = $(evt.target); var $btn = $(evt.target);
var groupIndex = Number($btn.data("group")) || 0; var groupIndex = Number($btn.data("group")) || 0;
this._activeSearchGroup = this.searchGroups[groupIndex]; this._activeSearchGroup = this.searchGroups[groupIndex];
@ -379,26 +392,28 @@ 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");
}, },
/** /**
* @private * @private
*/ */
_onClickMaximize: function () { _onClickMaximize: function() {
this.$el.toggleClass( this.$el.toggleClass(
"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");
} }
}, },
/** /**
* @private * @private
*/ */
_onClickLines: function () { _onClickLines: function() {
this.showLines(); this.showLines();
}, },
@ -406,14 +421,17 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {MouseEvent} ev * @param {MouseEvent} ev
*/ */
_onClickSearchMode: function (ev) { _onClickSearchMode: function(ev) {
var self = this; var self = this;
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()
this.doRenderSearchRecords().then(function () { .children()
.removeClass("active");
$target.addClass("active");
this.doRenderSearchRecords().then(function() {
self.$searchInput.focus(); self.$searchInput.focus();
}); });
}, },
@ -422,7 +440,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @returns {Object} * @returns {Object}
*/ */
_getDefaultOptions: function () { _getDefaultOptions: function() {
return { return {
currency_field: "currency_id", currency_field: "currency_id",
records_per_page: 16, records_per_page: 16,
@ -450,7 +468,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @returns {Array} * @returns {Array}
*/ */
_getFullSearchDomain: function () { _getFullSearchDomain: function() {
this._searchContext.involvedFields = []; this._searchContext.involvedFields = [];
var domain = _.clone(this._searchContext.domain) || []; var domain = _.clone(this._searchContext.domain) || [];
if (this._searchContext.text) { if (this._searchContext.text) {
@ -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],
}); });
@ -502,14 +521,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @returns {Array} * @returns {Array}
*/ */
_getLinesDomain: function () { _getLinesDomain: function() {
if (!this.view) { if (!this.view) {
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;
}); });
return [["id", "in", ids]]; return [["id", "in", ids]];
@ -519,15 +538,18 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* The lines are special data, so we need display it in a other way * The lines are special data, so we need display it in a other way
* that the search results. Use directy in-memory values. * that the search results. Use directy in-memory values.
*/ */
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();
}, },
@ -535,16 +557,16 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @private * @private
*/ */
_clearSearchInput: function () { _clearSearchInput: function() {
this.$searchInput.val(""); this.$searchInput.val("");
this._searchContext.text = ""; this._searchContext.text = "";
}, },
_onKeyPressSearch: function (evt) { _onKeyPressSearch: function(evt) {
if (evt.keyCode === $.ui.keyCode.ENTER) { if (evt.keyCode === $.ui.keyCode.ENTER) {
var self = this; var self = this;
this._searchContext.text = evt.target.value; this._searchContext.text = evt.target.value;
this.doRenderSearchRecords().then(function () { this.doRenderSearchRecords().then(function() {
self.$searchInput.focus(); self.$searchInput.focus();
}); });
} }
@ -553,10 +575,10 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @private * @private
*/ */
_onClickSearchEraser: function () { _onClickSearchEraser: function() {
var self = this; var self = this;
this._clearSearchInput(); this._clearSearchInput();
this.doRenderSearchRecords().then(function () { this.doRenderSearchRecords().then(function() {
self.$searchInput.focus(); self.$searchInput.focus();
}); });
}, },
@ -565,12 +587,15 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @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)
_.defer(function () { .find(".dropdown-toggle")
$(evt.currentTarget).find(".dropdown-menu") .parent()
.height();
_.defer(function() {
$(evt.currentTarget)
.find(".dropdown-menu")
.css("transform", "translate3d(0px, " + offset + "px, 0px)"); .css("transform", "translate3d(0px, " + offset + "px, 0px)");
}); });
}, },
@ -581,7 +606,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {CustomEvent} evt * @param {CustomEvent} evt
*/ */
_onCreateQuickRecord: function (evt) { _onCreateQuickRecord: function(evt) {
evt.stopPropagation(); evt.stopPropagation();
var self = this; var self = this;
this.parent_controller.model.setPureVirtual(evt.data.id, false); this.parent_controller.model.setPureVirtual(evt.data.id, false);
@ -591,20 +616,22 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
this._setValue( this._setValue(
{operation: "ADD", id: evt.data.id}, {operation: "ADD", id: evt.data.id},
{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
// Because 'create' generates a new state and we can't know these new id we .saveRecord(undefined, {stayInEdit: true})
// need force update the all the current states. .then(function(rrr) {
self._setValue( // Because 'create' generates a new state and we can't know these new id we
{operation: "UPDATE", id: evt.data.id}, // need force update the all the current states.
{doNotSetDirty: true} self._setValue(
).then(function () { {operation: "UPDATE", id: evt.data.id},
if (evt.data.callback) { {doNotSetDirty: true}
evt.data.callback(); ).then(function() {
} if (evt.data.callback) {
evt.data.callback();
}
});
}); });
});
} else if (evt.data.callback) { } else if (evt.data.callback) {
evt.data.callback(); evt.data.callback();
} }
@ -615,7 +642,7 @@ 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({operation: "ADD", id: evt.data.id}).then(function () { this._setValue({operation: "ADD", id: evt.data.id}).then(function() {
if (evt.data.callback) { if (evt.data.callback) {
evt.data.callback(); evt.data.callback();
} }
@ -629,7 +656,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {CustomEevent} evt * @param {CustomEevent} evt
*/ */
_onUpdateQuickRecord: function (evt) { _onUpdateQuickRecord: function(evt) {
evt.stopPropagation(); evt.stopPropagation();
var self = this; var self = this;
@ -638,19 +665,27 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
this._setValue( this._setValue(
{operation: "UPDATE", id: evt.data.id, data: evt.data.data}, {operation: "UPDATE", id: evt.data.id, data: evt.data.data},
{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
// Workaround to get updated values .saveRecord(undefined, {stayInEdit: true})
self.parent_controller.model.reload(self.value.id).then(function (result) { .then(function() {
var new_data = self.parent_controller.model.get(result); // Workaround to get updated values
self.value.data = new_data.data; self.parent_controller.model
self.renderer.updateState(self.value, {force: true}); .reload(self.value.id)
if (evt.data.callback) { .then(function(result) {
evt.data.callback(); var new_data = self.parent_controller.model.get(
} result
);
self.value.data = new_data.data;
self.renderer.updateState(self.value, {
force: true,
});
if (evt.data.callback) {
evt.data.callback();
}
});
}); });
});
} else if (evt.data.callback) { } else 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();
} }
@ -674,16 +711,18 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* Handle auto_save when remove a record * Handle auto_save when remove a record
*/ */
_onListRecordRemove: function (evt) { _onListRecordRemove: function(evt) {
evt.stopPropagation(); evt.stopPropagation();
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
if (evt.data.callback) { .saveRecord(undefined, {stayInEdit: true})
evt.data.callback(); .then(function() {
} if (evt.data.callback) {
}); evt.data.callback();
}
});
} else if (evt.data.callback) { } else if (evt.data.callback) {
evt.data.callback(); evt.data.callback();
} }
@ -693,7 +732,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
/** /**
* @private * @private
*/ */
_onUpdateSubtotal: function () { _onUpdateSubtotal: function() {
this.updateSubtotalPrice(); this.updateSubtotalPrice();
}, },
@ -703,7 +742,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* *
* @private * @private
*/ */
_onLoadMore: function () { _onLoadMore: function() {
if (this._isLoading) { if (this._isLoading) {
return; return;
} }
@ -713,7 +752,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
offset: this._searchOffset, offset: this._searchOffset,
}, },
true true
).then(function (records) { ).then(function(records) {
self.renderer.appendSearchRecords(records); self.renderer.appendSearchRecords(records);
}); });
}, },
@ -722,7 +761,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {CustomEvent} evt * @param {CustomEvent} evt
*/ */
_onLoadingRecords: function (evt) { _onLoadingRecords: function(evt) {
this._isLoading = !evt.data.finished; this._isLoading = !evt.data.finished;
this._blockControlPanel(this._isLoading); this._blockControlPanel(this._isLoading);
if (this.renderer) { if (this.renderer) {
@ -734,22 +773,21 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @private * @private
* @param {Boolean} block * @param {Boolean} block
*/ */
_blockControlPanel: function (block) { _blockControlPanel: function(block) {
if (this.$buttons) { if (this.$buttons) {
this.$buttons.find("input,button").attr("disabled", block); this.$buttons.find("input,button").attr("disabled", block);
} }
}, },
/** /**
* Refresh lines count on every change. * Refresh lines count on every change.
* *
* @override * @override
*/ */
_setValue: function (value, options) { _setValue: function(value, options) {
var self = this; var self = this;
return this._super.apply(this, arguments).then(function () { return this._super.apply(this, arguments).then(function() {
self.updateBadgeLines(); self.updateBadgeLines();
self.updateSubtotalPrice(); self.updateSubtotalPrice();
}); });

View File

@ -1,6 +1,6 @@
$one2many-product-picker-grid-breakpoints: map-merge( $one2many-product-picker-grid-breakpoints: map-merge(
$grid-breakpoints, $grid-breakpoints,
( (
xxl: 1440px, xxl: 1440px,
) )
); );

View File

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

View File

@ -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 &amp;&amp; '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 &amp;&amp; '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 &amp;&amp; 'disabled' || (auto_save &amp;&amp; !is_virtual &amp;&amp; !state.data.id &amp;&amp; '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 &amp;&amp; 'disabled' || (auto_save &amp;&amp; !is_virtual &amp;&amp; !state.data.id &amp;&amp; '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 &amp;&amp; 'border-warning') || (state &amp;&amp; !is_virtual &amp;&amp; 'border-success') || ''}}"> <div
t-attf-class="oe_flip_card_front p-0 {{(modified &amp;&amp; 'border-warning') || (state &amp;&amp; !is_virtual &amp;&amp; '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 &amp;&amp; '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 &amp;&amp; '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>

View File

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

View File

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

View File

@ -1,136 +1,228 @@
/* 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 (
'<field name="currency_id" invisible="1" />' + "<form>" +
'<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="currency_id" invisible="1" />' +
'<kanban>' + "<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="name" />' + "<kanban>" +
'<field name="product_id" />' + '<field name="name" />' +
'<field name="price_reduce" />' + '<field name="product_id" />' +
'<field name="price_unit" />' + '<field name="price_reduce" />' +
'<field name="foo_id" />' + '<field name="price_unit" />' +
'<field name="product_uom_qty" />' + '<field name="foo_id" />' +
'<field name="product_uom" />' + '<field name="product_uom_qty" />' +
'</kanban>' + '<field name="product_uom" />' +
'</field>' + "</kanban>" +
'</form>'; "</field>" +
"</form>"
);
}; };
QUnit.module('Web Widget One2Many Product Picker', { QUnit.module(
beforeEach: function () { "Web Widget One2Many Product Picker",
this.data = { {
foo: { beforeEach: function() {
fields: { this.data = {
currency_id: {string: "Currency", type: "many2one", relation: "currency"}, foo: {
line_ids: {string: "Lines Test", type: "one2many", relation: "line", relation_field: "foo_id"}, fields: {
display_name: {string: "Display Name", type: "char"}, currency_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"},
},
records: [
{
id: 1,
line_ids: [1, 2],
currency_id: 1,
display_name: "FT01",
},
],
}, },
records: [ line: {
{id: 1, line_ids: [1, 2], currency_id: 1, display_name: "FT01"}, fields: {
], name: {string: "Product Name", type: "string"},
}, product_id: {
line: { string: "Product",
fields: { type: "many2one",
name: {string: "Product Name", type: "string"}, relation: "product",
product_id: {string: "Product", type: "many2one", relation: "product"}, },
product_uom: {string: "UoM", type: "many2one", relation: "uom"}, product_uom: {
product_uom_qty: {string: "Qty", type: "integer"}, string: "UoM",
price_unit: {string: "Product Price", type: "float"}, type: "many2one",
price_reduce: {string: "Product Price Reduce", type: "float"}, relation: "uom",
foo_id: {string: "Parent", type: "many2one", relation: "foo"}, },
product_uom_qty: {string: "Qty", type: "integer"},
price_unit: {string: "Product Price", type: "float"},
price_reduce: {
string: "Product Price Reduce",
type: "float",
},
foo_id: {
string: "Parent",
type: "many2one",
relation: "foo",
},
},
records: [
{
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,
},
],
}, },
records: [ product: {
{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}, fields: {
{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}, name: {string: "Product name", type: "char"},
], display_name: {string: "Display Name", type: "char"},
}, list_price: {string: "Price", type: "float"},
product: { image_medium: {string: "Image Medium", type: "binary"},
fields: { uom_category_id: {
name: {string : "Product name", type: "char"}, string: "Category",
display_name: {string : "Display Name", type: "char"}, type: "many2one",
list_price: {string: "Price", type: "float"}, relation: "uom_category",
image_medium: {string: "Image Medium", type: "binary"}, },
uom_category_id: {string: "Category", type: "many2one", relation: "uom_category"}, },
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,
},
],
}, },
records: [ uom_category: {
{id: 1, name: "Large Cabinet", display_name: "Large Cabinet", list_price: 9.99, image_medium: "", uom_category_id: 1}, fields: {
{id: 2, name: "Cabinet with Doors", display_name: "Cabinet with Doors", list_price: 42.0, image_medium: "", uom_category_id: 1}, display_name: {string: "Display Name", type: "char"},
], },
}, records: [{id: 1, display_name: "Unit(s)"}],
uom_category: {
fields: {
display_name: {string : "Display Name", type: "char"},
}, },
records: [ uom: {
{id: 1, display_name: "Unit(s)"}, fields: {
], name: {string: "Name", type: "char"},
}, },
uom: { records: [{id: 1, name: "Unit(s)"}],
fields: {
name: {string: "Name", type: "char"},
}, },
records: [ currency: {
{id: 1, name: "Unit(s)"}, fields: {
], name: {string: "Name", type: "char"},
}, symbol: {string: "Symbol", type: "char"},
currency: { },
fields: { records: [{id: 1, name: "Eur", symbol: "€"}],
name: {string: "Name", type: "char"},
symbol: {string: "Symbol", type: "char"},
}, },
records: [ };
{id: 1, name: "Eur", symbol: "€"}, },
],
},
};
}, },
}, function () { function() {
QUnit.test('Load widget', function (assert) { 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,
viewOptions: { viewOptions: {
ids: [1], ids: [1],
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],
return $.when(this.data.foo.records); ["currency_id", "line_ids", "display_name"],
} else if (route === '/web/dataset/call_kw/line/read') { 'should only read "currency_id", "line_ids" and "display_name"'
assert.deepEqual(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.foo.records);
return $.when(this.data.line.records); } else if (route === "/web/dataset/call_kw/line/read") {
} else if (route === '/web/dataset/call_kw/product/search_read') { assert.deepEqual(
assert.deepEqual(args.kwargs.fields, ['id', 'uom_id', 'display_name', 'uom_category_id', 'image_medium', 'list_price'], args.args[1],
'should only read "id", "uom_id", "display_name", "uom_category_id", "image_medium" and "list_price"'); [
return $.when(this.data.product.records); "name",
} "product_id",
return this._super.apply(this, arguments); "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);
} else if (
route === "/web/dataset/call_kw/product/search_read"
) {
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 this._super.apply(this, arguments);
},
});
assert.ok(
form.$(".oe_field_one2many_product_picker").is(":visible"),
"should have a visible one2many product picker"
);
form.destroy();
}); });
}
assert.ok(form.$('.oe_field_one2many_product_picker').is(':visible'), );
"should have a visible one2many product picker");
form.destroy();
});
});
}); });

View File

@ -1,38 +1,78 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8" ?>
<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>