[IMP] web_widget_one2many_product_picker: black, isort, prettier

pull/1858/head
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).
{
'name': 'Web Widget One2Many Product Picker',
'summary': 'Widget to select products on one2many fields',
'version': '12.0.2.3.0',
'category': 'Website',
'author': "Tecnativa, "
"Odoo Community Association (OCA)",
'website': 'https://www.tecnativa.com',
'license': 'AGPL-3',
'depends': [
'product',
],
'data': [
'templates/assets.xml',
],
'qweb': [
'static/src/xml/one2many_product_picker.xml',
],
'installable': True,
'auto_install': False,
"name": "Web Widget One2Many Product Picker",
"summary": "Widget to select products on one2many fields",
"version": "12.0.2.3.0",
"category": "Website",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://www.tecnativa.com",
"license": "AGPL-3",
"depends": ["product",],
"data": ["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):
_inherit = 'product.product'
_inherit = "product.product"
image_variant_medium = fields.Binary(
"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"
"or product image medium, limited to 512x512px.",
)
image_variant_big = fields.Binary(
"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"
"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):
for record in self:
if record.image_variant:
@ -28,8 +28,9 @@ class ProductProduct(models.Model):
record.image_variant,
return_big=False,
return_small=False,
avoid_resize_medium=True)
record.image_variant_medium = resized_images['image_medium']
avoid_resize_medium=True,
)
record.image_variant_medium = resized_images["image_medium"]
record.image_variant_big = record.image_variant
else:
record.image_variant_medium = record.product_tmpl_id.image_medium

View File

@ -1,8 +1,6 @@
// Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker.tools", function (
require
) {
odoo.define("web_widget_one2many_product_picker.tools", function(require) {
"use strict";
var field_utils = require("web.field_utils");
@ -29,10 +27,7 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
* @returns {String}
*/
function monetary(value, field_info, currency_field, data) {
return field_utils.format.monetary(
value,
field_info,
{
return field_utils.format.monetary(value, field_info, {
data: data,
currency_field: currency_field,
field_digits: true,
@ -43,5 +38,4 @@ odoo.define("web_widget_one2many_product_picker.tools", function (
monetary: monetary,
priceReduce: priceReduce,
};
});

View File

@ -8,9 +8,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
var core = require("web.core");
var Widget = require("web.Widget");
var widgetRegistry = require("web.widget_registry");
var ProductPickerQuickCreateFormView = require(
"web_widget_one2many_product_picker.ProductPickerQuickCreateFormView"
).ProductPickerQuickCreateFormView;
var ProductPickerQuickCreateFormView = require("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView")
.ProductPickerQuickCreateFormView;
var qweb = core.qweb;
@ -70,7 +69,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
var refinedContext = _.extend(
{},
this.main_state.getContext(),
this.nodeContext);
this.nodeContext
);
_.extend(refinedContext, this.editContext);
this.formView = new ProductPickerQuickCreateFormView(fieldsView, {
context: refinedContext,
@ -89,7 +89,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
model: this.basicFieldParams.model,
mainRecordData: this.getParent().getParent().state,
});
// if (this.id) {
// If (this.id) {
// this.basicFieldParams.model.save(this.id, {savePoint: true});
// }
var def2 = this.formView.getController(this).then(function(controller) {
@ -112,7 +112,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
* @returns {String}
*/
_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 += "</t></templates>";
qweb.add_template(template);
@ -128,10 +129,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
*/
_onReloadView: function(evt) {
this.editContext = {
'ignore_onchanges': [this.compareKey],
'base_record_id': evt.data.baseRecordID || null,
'base_record_res_id': evt.data.baseRecordResID || null,
'base_record_compare_value': evt.data.baseRecordCompareValue || null,
ignore_onchanges: [this.compareKey],
base_record_id: evt.data.baseRecordID || null,
base_record_res_id: evt.data.baseRecordResID || null,
base_record_compare_value: evt.data.baseRecordCompareValue || null,
};
if (evt.data.baseRecordCompareValue === evt.data.compareValue) {
@ -140,10 +141,17 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
this.start();
} else {
var self = this;
this.getParent()._generateVirtualState({}, this.editContext).then(function (state) {
this.getParent()
._generateVirtualState({}, this.editContext)
.then(function(state) {
var data = {};
data[self.compareKey] = {operation: 'ADD', id: evt.data.compareValue};
self.basicFieldParams.model._applyChange(state.id, data).then(function () {
data[self.compareKey] = {
operation: "ADD",
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();
@ -153,7 +161,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateForm", f
},
});
widgetRegistry.add("product_picker_quick_create_form", ProductPickerQuickCreateForm);
widgetRegistry.add(
"product_picker_quick_create_form",
ProductPickerQuickCreateForm
);
return ProductPickerQuickCreateForm;
});

View File

@ -1,8 +1,8 @@
// Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView", function (
require
) {
odoo.define(
"web_widget_one2many_product_picker.ProductPickerQuickCreateFormView",
function(require) {
"use strict";
/**
@ -20,7 +20,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
_applyOnChange: function(values, record, viewType) {
var vt = viewType || record.viewType;
// 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;
for (var index in ignore_changes) {
var field_name = ignore_changes[index];
@ -32,23 +32,21 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
},
});
var ProductPickerQuickCreateFormRenderer =
QuickCreateFormView.prototype.config.Renderer.extend(
var ProductPickerQuickCreateFormRenderer = QuickCreateFormView.prototype.config.Renderer.extend(
{
/**
* @override
*/
start: function() {
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);
},
}
);
var ProductPickerQuickCreateFormController =
QuickCreateFormView.prototype.config.Controller.extend(
var ProductPickerQuickCreateFormController = QuickCreateFormView.prototype.config.Controller.extend(
{
events: _.extend({}, QuickCreateFormView.prototype.events, {
"click .oe_record_add": "_onClickAdd",
@ -70,7 +68,10 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
*/
auto: function() {
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;
}
var state = this._getRecordState();
@ -118,11 +119,9 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private
*/
_updateButtons: function() {
this.$el.find(
".oe_one2many_product_picker_form_buttons").remove();
this.$el.find(".oe_one2many_product_picker_form_buttons").remove();
this.$el.find(".o_form_view").append(
qweb.render(
"One2ManyProductPicker.QuickCreate.FormButtons", {
qweb.render("One2ManyProductPicker.QuickCreate.FormButtons", {
state: this._getRecordState(),
})
);
@ -151,7 +150,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
* @private
*/
_enableQuickCreate: function() {
// Allows to create again
this._disabled = false;
this.$el.removeClass("o_disabled");
@ -197,17 +195,16 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
compareValue: new_value,
};
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];
if (typeof old_value === 'object') {
if (typeof old_value === "object") {
old_value = old_value.data.id;
}
reload_values.baseRecordID = record.id;
reload_values.baseRecordResID = record.ref;
reload_values.baseRecordCompareValue = old_value;
} else {
reload_values.baseRecordID =
record.context.base_record_id;
reload_values.baseRecordID = record.context.base_record_id;
reload_values.baseRecordResID =
record.context.base_record_res_id;
reload_values.baseRecordCompareValue =
@ -239,7 +236,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
*/
_add: function() {
if (this._disabled) {
// Don't do anything if we are already creating a record
return $.Deferred();
}
@ -261,7 +257,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
id: record.id,
});
self.model.unsetDirty(self.handle);
//self._updateButtons();
// Self._updateButtons();
self._enableQuickCreate();
},
block: true,
@ -271,7 +267,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
_remove: function() {
if (this._disabled) {
// Don't do anything if we are already creating a record
return $.Deferred();
}
@ -287,7 +282,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
_change: function() {
var self = this;
if (this._disabled) {
// Don't do anything if we are already creating a record
return $.Deferred();
}
@ -303,7 +297,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
id: record.id,
});
self.model.unsetDirty(self.handle);
//self._updateButtons();
// Self._updateButtons();
self._enableQuickCreate();
},
block: true,
@ -313,7 +307,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
_discard: function() {
var self = this;
if (this._disabled) {
// Don't do anything if we are already creating a record
return $.Deferred();
}
@ -401,4 +394,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickCreateFormView
ProductPickerQuickCreateFormController: ProductPickerQuickCreateFormController,
ProductPickerQuickCreateFormView: ProductPickerQuickCreateFormView,
};
});
}
);

View File

@ -1,15 +1,14 @@
// Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm", function (
require
) {
odoo.define(
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm",
function(require) {
"use strict";
var core = require("web.core");
var Widget = require("web.Widget");
var ProductPickerQuickModifPriceFormView = require(
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView"
).ProductPickerQuickModifPriceFormView;
var ProductPickerQuickModifPriceFormView = require("web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView")
.ProductPickerQuickModifPriceFormView;
var qweb = core.qweb;
@ -110,23 +109,29 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
template += this.basicFieldParams.field.views.form.arch;
template += "</t></templates>";
qweb.add_template(template);
var $arch = $(qweb.render("One2ManyProductPicker.QuickModifPrice.Form", {
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>";
for (var index in field_names) {
var field_name = field_names[index];
var $field = $arch.find("field[name='" + field_name + "']");
var modifiers =
$field.attr("modifiers") ? JSON.parse($field.attr("modifiers")) : {};
var modifiers = $field.attr("modifiers")
? JSON.parse($field.attr("modifiers"))
: {};
modifiers.invisible = false;
modifiers.readonly = wanted_field_states[field_name];
$field.attr("modifiers", JSON.stringify(modifiers));
$field.attr("invisible", "0");
$field.attr("readonly", wanted_field_states[field_name]?"1":"0");
$field.attr(
"readonly",
wanted_field_states[field_name] ? "1" : "0"
);
gen_arch += $field[0].outerHTML;
}
gen_arch += "</group></form>";
@ -149,4 +154,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
});
return ProductPickerQuickModifPriceForm;
});
}
);

View File

@ -1,8 +1,8 @@
// Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView", function (
require
) {
odoo.define(
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceFormView",
function(require) {
"use strict";
/**
@ -16,8 +16,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
var qweb = core.qweb;
var ProductPickerQuickModifPriceFormRenderer =
QuickCreateFormView.prototype.config.Renderer.extend(
var ProductPickerQuickModifPriceFormRenderer = QuickCreateFormView.prototype.config.Renderer.extend(
{
/**
* @override
@ -25,7 +24,8 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
start: function() {
var self = this;
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() {
self._appendPrice();
self._appendButtons();
@ -36,13 +36,14 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
* @private
*/
_appendButtons: function() {
this.$el.find(
".oe_one2many_product_picker_form_buttons").remove();
this.$el.find(".oe_one2many_product_picker_form_buttons").remove();
this.$el.append(
qweb.render(
"One2ManyProductPicker.QuickModifPrice.FormButtons", {
"One2ManyProductPicker.QuickModifPrice.FormButtons",
{
mode: this.mode,
})
}
)
);
},
@ -58,8 +59,7 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
}
);
var ProductPickerQuickModifPriceFormController =
QuickCreateFormView.prototype.config.Controller.extend(
var ProductPickerQuickModifPriceFormController = QuickCreateFormView.prototype.config.Controller.extend(
{
events: _.extend({}, QuickCreateFormView.prototype.events, {
"click .oe_record_change": "_onClickChange",
@ -102,8 +102,11 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
var record = this.model.get(this.handle);
var price_reduce = tools.priceReduce(
record.data[this.fieldMap.price_unit],
record.data[this.fieldMap.discount]);
this.renderer.$el.find(".oe_price").html(
record.data[this.fieldMap.discount]
);
this.renderer.$el
.find(".oe_price")
.html(
tools.monetary(
price_reduce,
this.getParent().state.fields[this.fieldMap.price_unit],
@ -117,7 +120,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
* @private
*/
_disableQuickCreate: function() {
// Ensures that the record won't be created twice
this._disabled = true;
this.$el.addClass("o_disabled");
@ -130,7 +132,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
* @private
*/
_enableQuickCreate: function() {
// Allows to create again
this._disabled = false;
this.$el.removeClass("o_disabled");
@ -173,7 +174,6 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
this.getParent().destroy();
}
} else {
// If is a "normal" record, update it
var record = this.model.get(this.handle);
this.trigger_up("update_quick_record", {
@ -222,4 +222,5 @@ odoo.define("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm
ProductPickerQuickModifPriceFormController: ProductPickerQuickModifPriceFormController,
ProductPickerQuickModifPriceFormView: ProductPickerQuickModifPriceFormView,
};
});
}
);

View File

@ -11,9 +11,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var Domain = require("web.Domain");
var widgetRegistry = require("web.widget_registry");
var tools = require("web_widget_one2many_product_picker.tools");
var ProductPickerQuickModifPriceForm = require(
"web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm");
var FieldManagerMixin = require('web.FieldManagerMixin');
var ProductPickerQuickModifPriceForm = require("web_widget_one2many_product_picker.ProductPickerQuickModifPriceForm");
var FieldManagerMixin = require("web.FieldManagerMixin");
var qweb = core.qweb;
var _t = core._t;
@ -81,7 +80,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @override
*/
destroy: function() {
this.$card.off("")
this.$card.off("");
this._super.apply(this, arguments);
},
@ -89,7 +88,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @override
*/
update: function(record) {
// Detach the widgets because the record will empty its $el, which
// will remove all event handlers on its descendants, and we want
// to keep those handlers alive as we will re-use these widgets
@ -131,7 +129,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
return _.str.sprintf(
"/web/image/product.product/%d/%s",
product_id,
field_name);
field_name
);
},
/**
@ -147,7 +146,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
price,
this.state.fields[field_name],
this.options.currencyField,
this.state.data);
this.state.data
);
},
/**
@ -169,7 +169,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @param {Object} recordSearch
*/
_setState: function(viewState, recordSearch) {
// No parent = product_pricker widget destroyed
// So this is a 'zombie' record. Destroy it!
if (!this.getParent()) {
@ -186,7 +185,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
this.recordSearch = recordSearch;
}
var model = this.options.basicFieldParams.model;
this.is_virtual = this.state && model.isPureVirtual(this.state.id) || false;
this.is_virtual =
(this.state && model.isPureVirtual(this.state.id)) || false;
},
/**
@ -194,7 +194,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @returns {Object}
*/
_getQWebContext: function() {
// Using directly the 'model record' instead of the state because
// the state it's a parsed version of this record that doesn't
// contains the '_virtual' attribute.
@ -202,7 +201,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var record = model.get(this.state.id);
return {
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),
compute_domain: this._computeDomain.bind(this),
state: this.state,
@ -212,7 +212,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
show_discount: this.options.showDiscount,
is_virtual: this.is_virtual,
modified: record && record.context.product_picker_modified,
active_model: '',
active_model: "",
auto_save: this.options.autoSave,
};
},
@ -240,7 +240,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
_getInternalVirtualRecordData: function() {
var data = {};
data[this.options.fieldMap.product] = {
operation: 'ADD',
operation: "ADD",
id: this.recordSearch.id,
};
return data;
@ -255,12 +255,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
_generateVirtualState: function(data, context) {
var model = this.options.basicFieldParams.model;
var scontext = _.extend(
{}, this._getInternalVirtualRecordContext(), context);
{},
this._getInternalVirtualRecordContext(),
context
);
// Force qty to 1.0 to launch correct onchanges
scontext[`default_${this.options.fieldMap.product_uom_qty}`] = 1.0;
var sdata = _.extend({}, this._getInternalVirtualRecordData(), data);
return model.createVirtualRecord(
this.options.basicFieldParams.value.id, {
return model.createVirtualRecord(this.options.basicFieldParams.value.id, {
data: sdata,
context: scontext,
});
@ -282,17 +284,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
this._detachAllWidgets();
this.defs = [];
this._replaceElement(
qweb.render(
"One2ManyProductPicker.FlipCard",
this._getQWebContext()
)
qweb.render("One2ManyProductPicker.FlipCard", this._getQWebContext())
);
this.$el.data("renderer_widget_index", this.options.renderer_widget_index);
this.$card = this.$(".oe_flip_card");
this.$front = this.$(".oe_flip_card_front");
this.$back = this.$(".oe_flip_card_back");
this._processWidgetFields(this.$front);
this._processWidgets(this.$front, 'front');
this._processWidgets(this.$front, "front");
this._processDynamicFields();
return $.when.apply(this, this.defs);
},
@ -314,27 +313,24 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var field_name = $field.attr("name");
var field_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
// even if it is not specified in the view.
if (field_widget || self.fields[field_name].type === "many2many") {
var widget = self.subWidgets[field_name];
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
widget.reset(self.state);
$field.replaceWith(widget.$el);
} 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;
if (Widget) {
widget = self._processWidget($field, field_name, Widget);
self.subWidgets[field_name] = widget;
} else if (config.debug) {
// the widget is not implemented
// The widget is not implemented
$field.replaceWith(
$("<span>", {
text: _.str.sprintf(
@ -359,8 +355,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
* @returns {Widget} the widget instance
*/
_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
// we here replace those attrs in the dict of attrs of the state
// by their evaluted value, to make it transparent from the
@ -379,10 +374,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
attrs: attrs,
data: this.state.data,
});
var widget = new Widget(
this, field_name,
this.getParent().state,
options);
var widget = new Widget(this, field_name, this.getParent().state, options);
var def = widget.replace($field);
if (def.state() === "pending") {
this.defs.push(def);
@ -419,7 +411,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var def = widget
._widgetRenderAndInsert(function() {
// Do nothing
}).then(function () {
})
.then(function() {
widget.$el.addClass("o_widget");
$field.replaceWith(widget.$el);
});
@ -475,13 +468,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var field_map = this.options.fieldMap;
if (state_data) {
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);
if (has_discount) {
this.$el.find(".price_unit").html(this._calcPriceReduced());
} else {
this.$el.find(".price_unit").html(
this._getMonetaryFieldValue("price_unit"));
this.$el
.find(".price_unit")
.html(this._getMonetaryFieldValue("price_unit"));
}
}
}
@ -499,13 +494,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
if (record && record.data[field_map.discount]) {
price_reduce = tools.priceReduce(
record.data[field_map.price_unit],
record.data[field_map.discount]);
record.data[field_map.discount]
);
}
return price_reduce && tools.monetary(
return (
price_reduce &&
tools.monetary(
price_reduce,
this.state.fields[field_map.price_unit],
this.options.currencyField,
this.state.data
)
);
},
@ -517,18 +516,22 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var self = this;
var model = this.options.basicFieldParams.model;
var record = model.get(this.state.id);
return model.save(record.id, {
return model
.save(record.id, {
stayInEdit: true,
reload: true,
savePoint: true,
viewType: "form",
}).then(function () {
})
.then(function() {
var record = model.get(self.state.id);
self.trigger_up("create_quick_record", {
id: record.id,
callback: function() {
self.$card.find('.o_catch_attention').removeClass('o_catch_attention');
}
self.$card
.find(".o_catch_attention")
.removeClass("o_catch_attention");
},
});
model.unsetDirty(self.state.id);
});
@ -544,8 +547,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
this.trigger_up("update_quick_record", {
id: record.id,
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);
},
@ -557,7 +562,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
_addProduct: function() {
var self = this;
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 changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
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;
this.$card.addClass("blocked");
return model.notifyChanges(
record.id,
changes
).then(function () {
return model.notifyChanges(record.id, changes).then(function() {
self._saveRecord();
});
},
@ -581,15 +585,14 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
_incProductQty: function(amount) {
var self = this;
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 changes = _.pick(record.data, this.options.fieldMap.product_uom_qty);
changes[this.options.fieldMap.product_uom_qty] += amount;
return model.notifyChanges(
record.id,
changes
).then(function () {
return model.notifyChanges(record.id, changes).then(function() {
self._processDynamicFields();
self._lazyUpdateRecord();
});
@ -602,11 +605,11 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var $target = $(target);
var $currentTarget = $(currentTarget);
var $img = $currentTarget.find(".oe_flip_card_front img");
$target.addClass('o_catch_attention');
$img.addClass('oe_product_picker_catch_attention');
$img.on('animationend', function () {
$img.removeClass('oe_product_picker_catch_attention');
$img.off('animationend');
$target.addClass("o_catch_attention");
$img.addClass("oe_product_picker_catch_attention");
$img.on("animationend", function() {
$img.removeClass("oe_product_picker_catch_attention");
$img.off("animationend");
});
},
@ -632,7 +635,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
currencyField: this.options.currencyField,
});
this.$modifPricePopup = $(
qweb.render("One2ManyProductPicker.QuickModifPricePopup"));
qweb.render("One2ManyProductPicker.QuickModifPricePopup")
);
this.$modifPricePopup.appendTo($(".o_main_content"));
modif_price_form.attachTo(this.$modifPricePopup);
},
@ -645,14 +649,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
*/
_onClickFlipCard: function(evt) {
// 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;
}
var $target = $(evt.target);
if (!this.options.readOnlyMode) {
if (
$target.hasClass('add_product') ||
$target.parents('.add_product').length
$target.hasClass("add_product") ||
$target.parents(".add_product").length
) {
if (!this.is_adding_product) {
this.is_adding_product = true;
@ -661,13 +668,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
}
return;
} else if (
$target.hasClass('product_qty') ||
$target.parents('.product_qty').length
$target.hasClass("product_qty") ||
$target.parents(".product_qty").length
) {
this._incProductQty(1);
this._doInteractAnim(evt.target, evt.currentTarget);
return;
} else if ($target.hasClass('safezone')) {
} else if ($target.hasClass("safezone")) {
// Do nothing on safe zones
return;
}
@ -675,7 +682,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
if (!this._clickFlipCardDelayed) {
this._clickFlipCardDelayed = setTimeout(
this._onClickDelayedFlipCard.bind(this, evt),
this._click_card_delayed_time);
this._click_card_delayed_time
);
}
++this._clickFlipCardCount;
if (this._clickFlipCardCount >= 2) {
@ -704,21 +712,23 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
this.defs = [];
if (!this.widgets.back.length) {
this._processWidgetFields(this.$back);
this._processWidgets(this.$back, 'back');
this._processWidgets(this.$back, "back");
}
this._processDynamicFields();
$.when(this.defs).then(function() {
var $actived_card = self.$el.parent().find(".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.on('transitionend', function () {
self.$card.on("transitionend", function() {
self.$front.addClass("d-none");
self.$card.off('transitionend');
self.$card.off("transitionend");
});
self.trigger_up("record_flip", {
widget_index: self.$el.data("renderer_widget_index"),
prev_widget_index: $actived_card.parent().data("renderer_widget_index"),
prev_widget_index: $actived_card
.parent()
.data("renderer_widget_index"),
});
});
}
@ -731,17 +741,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
_onDblClickDelayedFlipCard: function(evt) {
var $target = $(evt.target);
if (
$target.hasClass('badge_price') ||
$target.parents('.badge_price').length
$target.hasClass("badge_price") ||
$target.parents(".badge_price").length
) {
this._openPriceModifier();
} else {
var $currentTarget = $(evt.currentTarget);
var $img = $currentTarget.find(".oe_flip_card_front img");
var cur_img_src = $img.attr("src");
if ($currentTarget.hasClass('oe_flip_card_maximized')) {
$currentTarget.removeClass('oe_flip_card_maximized');
$currentTarget.on('transitionend', function () {
if ($currentTarget.hasClass("oe_flip_card_maximized")) {
$currentTarget.removeClass("oe_flip_card_maximized");
$currentTarget.on("transitionend", function() {
$currentTarget.css({
position: "",
top: "",
@ -750,14 +760,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
height: "",
zIndex: "",
});
$currentTarget.off('transitionend');
$currentTarget.off("transitionend");
});
} else {
var $actived_card = this.$el.parent().find(".active");
if ($actived_card[0] !== $currentTarget[0]) {
$actived_card.removeClass("active");
$actived_card.find('.oe_flip_card_front')
.removeClass("d-none");
$actived_card.find(".oe_flip_card_front").removeClass("d-none");
}
var offset = $currentTarget.offset();
$currentTarget.css({
@ -769,7 +778,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
zIndex: 50,
});
_.defer(function() {
$currentTarget.addClass('oe_flip_card_maximized');
$currentTarget.addClass("oe_flip_card_maximized");
});
}
$img.attr("src", $img.data("srcAlt"));
@ -784,9 +793,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
var self = this;
this.$card.removeClass("active");
this.$front.removeClass("d-none");
if (this.$card.hasClass('oe_flip_card_maximized')) {
this.$card.removeClass('oe_flip_card_maximized');
this.$card.on('transitionend', function () {
if (this.$card.hasClass("oe_flip_card_maximized")) {
this.$card.removeClass("oe_flip_card_maximized");
this.$card.on("transitionend", function() {
self.$card.css({
position: "",
top: "",
@ -795,7 +804,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRecord", fu
height: "",
zIndex: "",
});
self.$card.off('transitionend');
self.$card.off("transitionend");
if (evt.data.success_callback) {
evt.data.success_callback();
}

View File

@ -1,28 +1,26 @@
// Copyright 2020 Tecnativa - Alexandre Díaz
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer", function (
require
) {
odoo.define(
"web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
function(require) {
"use strict";
var core = require("web.core");
var BasicRenderer = require("web.BasicRenderer");
var One2ManyProductPickerRecord = require(
"web_widget_one2many_product_picker.One2ManyProductPickerRecord");
var ProductPickerQuickCreateForm = require(
"web_widget_one2many_product_picker.ProductPickerQuickCreateForm");
var One2ManyProductPickerRecord = require("web_widget_one2many_product_picker.One2ManyProductPickerRecord");
var ProductPickerQuickCreateForm = require("web_widget_one2many_product_picker.ProductPickerQuickCreateForm");
var qweb = core.qweb;
/* This is the renderer of the main widget */
var One2ManyProductPickerRenderer = BasicRenderer.extend({
className: 'oe_one2many_product_picker_view',
className: "oe_one2many_product_picker_view",
events: {
'click #productPickerLoadMore': '_onClickLoadMore',
"click #productPickerLoadMore": "_onClickLoadMore",
},
custom_events: {
'record_flip': '_onRecordFlip',
record_flip: "_onRecordFlip",
},
DELAY_GET_RECORDS: 150,
@ -35,7 +33,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
this._super.apply(this, arguments);
this.widgets = [];
this.recordOptions = _.extend({}, params.record_options, {
viewType: 'One2ManyProductPicker',
viewType: "One2ManyProductPicker",
});
// Workaround: Odoo initilize this class so we need do this to
@ -52,7 +50,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
*/
on_attach_callback: function() {
this._isInDom = true;
_.invoke(this.widgets, 'on_attach_callback');
_.invoke(this.widgets, "on_attach_callback");
},
/**
@ -60,7 +58,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
*/
on_detach_callback: function() {
this._isInDom = false;
_.invoke(this.widgets, 'on_detach_callback');
_.invoke(this.widgets, "on_detach_callback");
},
/**
@ -160,8 +158,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
// create a 'pure virtual' record again.
for (var index_destroy in to_destroy) {
var widget_destroyed = to_destroy[index_destroy];
var widget_product_id = widget_destroyed.state
.data[this.options.field_map.product].data.id;
var widget_product_id =
widget_destroyed.state.data[this.options.field_map.product].data
.id;
var found = false;
// If already exists a widget for the product don't try create a new one
for (var eb = this.widgets.length - 1; eb >= 0; --eb) {
@ -169,7 +168,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
if (
widget &&
widget.state &&
widget.state.data[this.options.field_map.product].data.id === widget_product_id
widget.state.data[this.options.field_map.product].data
.id === widget_product_id
) {
found = true;
break;
@ -182,14 +182,19 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
for (var eb = new_states.length - 1; eb >= 0; --eb) {
var state = new_states[eb];
if (
state.data[this.options.field_map.product].data.id === widget_product_id
state.data[this.options.field_map.product].data.id ===
widget_product_id
) {
new_state_id = state.id;
break;
}
}
var search_record = _.find(this.search_data, {id: widget_product_id});
var new_search_record = _.extend({}, search_record, {__id: new_state_id});
var search_record = _.find(this.search_data, {
id: widget_product_id,
});
var new_search_record = _.extend({}, search_record, {
__id: new_state_id,
});
var search_record_index = widget_destroyed.$el.index();
defs.push(
this.appendSearchRecords(
@ -216,7 +221,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
* @returns {Deferred}
*/
_updateStateRecords: function(old_states) {
// States to remove
var states_to_destroy = [];
for (var index in old_states) {
@ -248,7 +252,6 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
for (var e = this.widgets.length - 1; e >= 0; --e) {
var widget = this.widgets[e];
if (!widget || !widget.state) {
// Already processed widget (deleted)
continue;
}
@ -257,9 +260,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
exists = true;
break;
} else if (
widget.recordSearch.id === state.data[this.options.field_map.product].data.id
widget.recordSearch.id ===
state.data[this.options.field_map.product].data.id
) {
// Is a new record
search_record_index = widget.$el.index();
search_record = widget.recordSearch;
@ -268,7 +271,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
// Remove "pure virtual" records that have the same product that the new record
if (
widget.is_virtual &&
widget.state.data[this.options.field_map.product].data.id === state.data[this.options.field_map.product].data.id
widget.state.data[this.options.field_map.product].data
.id ===
state.data[this.options.field_map.product].data.id
) {
to_destroy.push(widget);
delete this.widgets[e];
@ -279,8 +284,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
// Need add a new one?
if (!exists && search_record_index !== -1) {
var new_search_record = _.extend({}, search_record, {__id: state.id});
defs.push(this.appendSearchRecords([new_search_record], false, true, search_record_index)[0]);
var new_search_record = _.extend({}, search_record, {
__id: state.id,
});
defs.push(
this.appendSearchRecords(
[new_search_record],
false,
true,
search_record_index
)[0]
);
}
}
@ -298,8 +312,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
this.$recordsContainer = $("<DIV/>", {
class: "w-100 row",
});
this.$extraButtonsContainer = $(qweb.render("One2ManyProductPicker.ExtraButtons"));
this.$btnLoadMore = this.$extraButtonsContainer.find("#productPickerLoadMore");
this.$extraButtonsContainer = $(
qweb.render("One2ManyProductPicker.ExtraButtons")
);
this.$btnLoadMore = this.$extraButtonsContainer.find(
"#productPickerLoadMore"
);
this.search_data = this._sort_search_data(this.search_data);
return $.Deferred(function(d) {
var defs = self.appendSearchRecords(self.search_data, true);
@ -308,7 +326,9 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
self.$el.empty();
self.$el.append(self.$recordsContainer);
self.$el.append(self.$extraButtonsContainer);
self.showLoadMore(self.last_search_data_count >= self.options.records_per_page);
self.showLoadMore(
self.last_search_data_count >= self.options.records_per_page
);
if (self._isInDom) {
_.invoke(self.widgets, "on_attach_callback");
}
@ -334,9 +354,13 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
}
}
}
var sorted_datas = _.chain(datas).sortBy('_order_value').map(function(item) {
return _.omit(item, '_order_value');
}).value().reverse();
var sorted_datas = _.chain(datas)
.sortBy("_order_value")
.map(function(item) {
return _.omit(item, "_order_value");
})
.value()
.reverse();
return sorted_datas;
}
return datas;
@ -361,7 +385,8 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
var state_record = this.state.data[index_data];
var field = state_record.data[field_name];
if (
(typeof field === "object" && field.data.id === record_search.id) ||
(typeof field === "object" &&
field.data.id === record_search.id) ||
field === record_search.id
) {
records.push(
@ -423,10 +448,15 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
* @param {Boolean} no_process_records
* @param {Number} position
*/
_appendSearchRecords: function (search_records, no_process_records, position) {
_appendSearchRecords: function(
search_records,
no_process_records,
position
) {
var self = this;
var processed_records =
no_process_records?search_records:this._processSearchRecords(search_records);
var processed_records = no_process_records
? search_records
: this._processSearchRecords(search_records);
_.each(processed_records, function(search_record) {
var state_data = self._getRecordDataById(search_record.__id);
var widget_options = self._getRecordOptions(search_record);
@ -450,13 +480,16 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
// At this point the widget will use the existing state (line) or
// the search data. Using search data instead of waiting for
// simulated state gives a low FCP time.
var def = ProductPickerRecord.appendTo(self.$recordsContainer)
.then(function (widget, widget_position) {
var def = ProductPickerRecord.appendTo(self.$recordsContainer).then(
function(widget, widget_position) {
if (typeof widget_position !== "undefined") {
var $elm = this.$el.find("> div > div:nth("+widget_position+")");
var $elm = this.$el.find(
"> div > div:nth(" + widget_position + ")"
);
widget.$el.insertAfter($elm);
}
}.bind(self, ProductPickerRecord, position));
}.bind(self, ProductPickerRecord, position)
);
if (def.state() === "pending") {
self.defs.push(def);
}
@ -479,7 +512,12 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
* @param {Number} position
* @returns {Array[Deferred]}
*/
appendSearchRecords: function (search_records, no_attach_widgets, no_process_records, position) {
appendSearchRecords: function(
search_records,
no_attach_widgets,
no_process_records,
position
) {
var self = this;
this.trigger_up("loading_records");
this.defs = [];
@ -522,7 +560,7 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
var $actived_card = this.$el.find(".active");
if (widget.$card.hasClass("active")) {
widget.$card.removeClass("active");
widget.$card.find('.oe_flip_card_front').removeClass("d-none");
widget.$card.find(".oe_flip_card_front").removeClass("d-none");
} else {
var self = widget;
widget.defs = [];
@ -531,10 +569,10 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
widget._processDynamicFields();
$.when(widget.defs).then(function() {
$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");
setTimeout(function() {
self.$('.oe_flip_card_front').addClass("d-none");
self.$(".oe_flip_card_front").addClass("d-none");
}, 200);
});
}
@ -551,15 +589,17 @@ odoo.define("web_widget_one2many_product_picker.One2ManyProductPickerRenderer",
if (typeof prev_widget_index !== "undefined") {
// Only check 'back' widgets so there is where the form was created
for (var index in this.widgets[prev_widget_index].widgets.back) {
var widget = this.widgets[prev_widget_index].widgets.back[index];
var widget = this.widgets[prev_widget_index].widgets.back[
index
];
if (widget instanceof ProductPickerQuickCreateForm) {
widget.controller.auto();
}
}
}
}
},
});
return One2ManyProductPickerRenderer;
});
}
);

View File

@ -6,7 +6,6 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
var BasicModel = require("web.BasicModel");
BasicModel.include({
/**
* @param {Number/String} handle
* @param {Object} context
@ -15,7 +14,8 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
this.localData[handle].context = _.extend(
{},
this.localData[handle].context,
context);
context
);
},
/**
@ -63,7 +63,7 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
var list = this.localData[listID];
var context = _.extend({}, this._getContext(list), options.context);
var position = options?options.position:'top';
var position = options ? options.position : "top";
var params = {
context: context,
fields: list.fields,
@ -76,18 +76,15 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
};
return $.Deferred(function(d) {
self._makeDefaultRecord(list.model, params)
.then(function (recordID) {
self._makeDefaultRecord(list.model, params).then(function(recordID) {
self.setPureVirtual(recordID, true);
self.updateRecordContext(recordID, {ignore_warning: true});
if (options.data) {
self._applyChange(
recordID,
options.data,
params
).then(function () {
self._applyChange(recordID, options.data, params).then(
function() {
d.resolve(self.get(recordID));
});
}
);
} else {
d.resolve(self.get(recordID));
}
@ -108,7 +105,7 @@ odoo.define("web_widget_one2many_product_picker.BasicModel", function (require)
var this_mp = _.clone(this);
var super_call = this.trigger_up;
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 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);
},
});
});

View File

@ -12,17 +12,15 @@ odoo.define("web_widget_one2many_product_picker.BasicView", function (require) {
// Add ref to _() -> _t() call
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()));
});
BasicView.include({
/**
* @override
*/
_processField: function(viewType, field, attrs) {
/**
* We need process 'options' attribute to handle translations and
* special replacements
@ -31,15 +29,16 @@ odoo.define("web_widget_one2many_product_picker.BasicView", function (require) {
attrs.widget === "one2many_product_picker" &&
!_.isObject(attrs.options)
) {
attrs.options = attrs.options ? pyUtils.py_eval(attrs.options, {
attrs.options = attrs.options
? pyUtils.py_eval(attrs.options, {
_: PY_t,
// Hack: This allow use $number_search out of an string
number_search: '$number_search',
}) : {};
number_search: "$number_search",
})
: {};
}
return this._super(viewType, field, attrs);
},
});
});

View File

@ -8,8 +8,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
var core = require("web.core");
var field_registry = require("web.field_registry");
var FieldOne2Many = require("web.relational_fields").FieldOne2Many;
var One2ManyProductPickerRenderer = require(
"web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
var One2ManyProductPickerRenderer = require("web_widget_one2many_product_picker.One2ManyProductPickerRenderer");
var tools = require("web_widget_one2many_product_picker.tools");
var _t = core._t;
@ -43,10 +42,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
_auto_search_delay: 450,
// Model product.product fields
search_read_fields: [
"id",
"display_name",
],
search_read_fields: ["id", "display_name"],
/**
* @override
@ -58,9 +54,15 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
this.state = record;
// 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) {
this.options.search = [[this.options.field_map.name, 'ilike', '$search']];
this.options.search = [
[this.options.field_map.name, "ilike", "$search"],
];
}
this._searchMode = 0;
this._searchCategoryNames = [];
@ -92,7 +94,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
};
if (this.mode === "readonly") {
this._activeSearchGroup = {
'name': 'main_lines',
name: "main_lines",
};
this._searchContext.activeTest = false;
}
@ -103,7 +105,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* Updates the lines counter badge
*/
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);
},
@ -113,13 +117,17 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
}
var prices = [];
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) {
prices = _.map(records, function(line) {
return line.data[field_map.product_uom_qty] *
return (
line.data[field_map.product_uom_qty] *
tools.priceReduce(
line.data[field_map.price_unit],
line.data[field_map.discount]
)
);
});
} else {
@ -189,7 +197,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
}
this.searchGroups.splice(0, 0, {
name: 'all',
name: "all",
string: _t("All"),
domain: [],
order: false,
@ -227,8 +235,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
qweb.render("One2ManyProductPicker.ControlPanelButtons", {
search_category_names: this._searchCategoryNames,
search_mode: this._searchMode,
}
));
})
);
this.$searchInput = this.$buttons.find(".oe_search_input");
this.$groups = $(
qweb.render("One2ManyProductPicker.ControlPanelGroupButtons", {
@ -252,7 +260,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
return (
def &&
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._addMaximizeButton();
@ -325,11 +335,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
// to continue
var domain = this._getFullSearchDomain();
var soptions = options || {};
var context = _.extend({
'active_search_group_name': this._activeSearchGroup.name,
'active_search_involved_fields': this._searchContext.involvedFields,
'active_test': this._searchContext.activeTest,
}, this.value.getContext());
var context = _.extend(
{
active_search_group_name: this._activeSearchGroup.name,
active_search_involved_fields: this._searchContext.involvedFields,
active_test: this._searchContext.activeTest,
},
this.value.getContext()
);
return $.Deferred(function(d) {
var limit = soptions.limit || self.options.records_per_page;
@ -379,7 +392,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
this._searchContext.activeTest = true;
this.doRenderSearchRecords();
this.$btnLines.removeClass("active");
$btn.parent().find(".active").removeClass("active");
$btn.parent()
.find(".active")
.removeClass("active");
$btn.addClass("active");
},
@ -391,7 +406,7 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
"position-relative h-100 bg-white oe_field_one2many_product_picker_maximized"
);
if (this.$buttons) {
this.$buttons.find('.dropdown-toggle').popover('update');
this.$buttons.find(".dropdown-toggle").popover("update");
}
},
@ -411,8 +426,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
ev.preventDefault();
var $target = $(ev.target);
this._searchMode = $target.index();
$target.parent().children().removeClass('active');
$target.addClass('active');
$target
.parent()
.children()
.removeClass("active");
$target.addClass("active");
this.doRenderSearchRecords().then(function() {
self.$searchInput.focus();
});
@ -466,12 +484,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
// Is a triplet
if (domain_cloned instanceof Array) {
// Replace right leaf with the current value of the search input
if (domain_cloned[2] === "$number_search") {
domain_cloned[2] = Number(this._searchContext.text);
involved_fields.push({
type: 'number',
type: "number",
field: domain_cloned[0],
oper: domain_cloned[1],
});
@ -479,10 +496,12 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
typeof domain_cloned[2] === "string" &&
domain_cloned[2].includes("$search")
) {
domain_cloned[2] = domain_cloned[2]
.replace(/\$search/, this._searchContext.text);
domain_cloned[2] = domain_cloned[2].replace(
/\$search/,
this._searchContext.text
);
involved_fields.push({
type: 'text',
type: "text",
field: domain_cloned[0],
oper: domain_cloned[1],
});
@ -507,8 +526,8 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
return [];
}
var field_name = this.options.field_map.product;
var lines = this.parent_controller.model.get(this.state.id)
.data[this.name].data;
var lines = this.parent_controller.model.get(this.state.id).data[this.name]
.data;
var ids = _.map(lines, function(line) {
return line.data[field_name].data.id;
});
@ -521,13 +540,16 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
*/
showLines: function() {
this._clearSearchInput();
this.$btnLines.parent().find(".active").removeClass("active");
this.$btnLines
.parent()
.find(".active")
.removeClass("active");
this.$btnLines.addClass("active");
this._activeSearchGroup = {
'name': 'main_lines',
name: "main_lines",
};
this._searchContext.domain = this._getLinesDomain();
this._searchContext.order = [{'name': 'sequence'}, {'name': 'id'}];
this._searchContext.order = [{name: "sequence"}, {name: "id"}];
this._searchContext.activeTest = false;
this.doRenderSearchRecords();
},
@ -566,11 +588,14 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
* @param {DropdownEvent} evt
*/
_onShowSearchDropdown: function(evt) {
// Workaround: This "ensures" a correct dropdown position
var offset = $(evt.currentTarget).find(".dropdown-toggle").parent().height();
var offset = $(evt.currentTarget)
.find(".dropdown-toggle")
.parent()
.height();
_.defer(function() {
$(evt.currentTarget).find(".dropdown-menu")
$(evt.currentTarget)
.find(".dropdown-menu")
.css("transform", "translate3d(0px, " + offset + "px, 0px)");
});
},
@ -593,7 +618,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
{notifyChange: false}
).then(function() {
if (self.options.auto_save) {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function (rrr) {
self.parent_controller
.saveRecord(undefined, {stayInEdit: true})
.then(function(rrr) {
// Because 'create' generates a new state and we can't know these new id we
// need force update the all the current states.
self._setValue(
@ -640,12 +667,20 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
{notifyChange: false}
).then(function() {
if (self.options.auto_save) {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
self.parent_controller
.saveRecord(undefined, {stayInEdit: true})
.then(function() {
// Workaround to get updated values
self.parent_controller.model.reload(self.value.id).then(function (result) {
var new_data = self.parent_controller.model.get(result);
self.parent_controller.model
.reload(self.value.id)
.then(function(result) {
var new_data = self.parent_controller.model.get(
result
);
self.value.data = new_data.data;
self.renderer.updateState(self.value, {force: true});
self.renderer.updateState(self.value, {
force: true,
});
if (evt.data.callback) {
evt.data.callback();
}
@ -661,9 +696,11 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
product_picker_modified: true,
});
// This will trigger an "state" update
this._setValue(
{operation: "UPDATE", id: evt.data.id, data: evt.data.data},
).then(function () {
this._setValue({
operation: "UPDATE",
id: evt.data.id,
data: evt.data.data,
}).then(function() {
if (evt.data.callback) {
evt.data.callback();
}
@ -679,7 +716,9 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
var self = this;
this._setValue({operation: "DELETE", ids: [evt.data.id]}).then(function() {
if (self.options.auto_save) {
self.parent_controller.saveRecord(undefined, {stayInEdit: true}).then(function () {
self.parent_controller
.saveRecord(undefined, {stayInEdit: true})
.then(function() {
if (evt.data.callback) {
evt.data.callback();
}
@ -740,7 +779,6 @@ odoo.define("web_widget_one2many_product_picker.FieldOne2ManyProductPicker", fun
}
},
/**
* Refresh lines count on every change.
*

View File

@ -45,7 +45,10 @@
}
.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;
@ -58,7 +61,10 @@
user-select: none;
background-color: transparent;
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;
&.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);
margin-bottom: 1.3em !important;
}
.o_field_widget, .w-100 {
.o_field_widget,
.w-100 {
width: 100% / $one2many-product-picker-zoom-scale !important;
}
}
@ -133,7 +141,9 @@
position: relative;
width: 100%;
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;
.position-absolute {
@ -217,7 +227,9 @@
font-size: 0.95rem;
z-index: 0;
}
.add_product, .product_qty, .price_unit {
.add_product,
.product_qty,
.price_unit {
cursor: pointer;
}
}
@ -247,12 +259,12 @@
@keyframes productPickerCatchAttention {
0% {
transform: scale(1.0);
transform: scale(1);
}
50% {
transform: scale(1.5);
}
100% {
transform: scale(1.0);
transform: scale(1);
}
}

View File

@ -1,58 +1,83 @@
<template>
<t t-name="One2ManyProductPicker.ControlPanelButtons">
<div class="text-center mx-auto">
<div class="input-group">
<div class="input-group-prepend">
<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" />
</button>
<div class="dropdown-menu">
<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>
</div>
</t>
<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" />
</button>
</t>
</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">
<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" />
</button>
</div>
</div>
</div>
</t>
<t t-name="One2ManyProductPicker.ControlPanelGroupButtons">
<div class="oe_one2many_product_picker_groups">
<div class="btn-group" role="group" aria-label="Groups">
<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" />
</button>
</t>
</div>
<button type="button" class="btn btn-light btn-lg oe_btn_lines">
Lines
<span class="ml-1 badge badge-light">0</span>
</button>
</div>
</t>
<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' />
</button>
</t>
<t t-name="One2ManyProductPicker.Total">
<div id="product_picker_total" class="text-right">
<h2>
@ -61,57 +86,108 @@
</h2>
</div>
</t>
<t t-name="One2ManyProductPicker.ExtraButtons">
<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>
</t>
<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 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_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 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="!is_virtual">
<div 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
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>
</t>
<t t-else="">
<div 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"></i> 1 <t t-esc="state.data[field_map.product_uom].data.display_name"/></span>
<div
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>
</t>
<div class="position-absolute m-0 text-left badge_price">
<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 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" />
<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
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-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>
</div>
<span 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')" />
<span
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-else="">
<span 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')" />
<span
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>
</div>
<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>
</t>
<t t-name="One2ManyProductPicker.QuickModifPricePopup">
<div class="oe_product_picker_quick_modif_price shadow" />
</t>
</template>

View File

@ -1,18 +1,22 @@
<template>
<t t-name="One2ManyProductPicker.QuickCreate.FormButtons">
<div class="oe_one2many_product_picker_form_buttons">
<t t-if="state == 'new'">
<button t-attf-class="btn btn-primary oe_record_add">Add</button>
</t>
<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-warning oe_record_discard ml-2"><i class="fa fa-times" /></button>
<button class="btn btn-success oe_record_change mr-2">
<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-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>
</div>
</t>
</template>

View File

@ -1,14 +1,18 @@
<template>
<t t-name="One2ManyProductPicker.QuickModifPrice.FormButtons">
<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-warning oe_record_discard ml-2"><i class="fa fa-times" /></button>
<button class="btn btn-success oe_record_change mr-2">
<i class="fa fa-check" />
</button>
<button class="btn btn-warning oe_record_discard ml-2">
<i class="fa fa-times" />
</button>
</div>
</t>
<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>
</template>

View File

@ -1,19 +1,20 @@
/* global QUnit */
// Copyright 2020 Tecnativa - Alexandre Díaz
// 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";
var FormView = require('web.FormView');
var testUtils = require('web.test_utils');
var FormView = require("web.FormView");
var testUtils = require("web.test_utils");
var createView = testUtils.createView;
var getArch = function() {
return '<form>' +
return (
"<form>" +
'<field name="currency_id" invisible="1" />' +
'<field name="line_ids" widget="one2many_product_picker" options="{\'groups\': [{\'name\': \'Desk\', \'domain\': [(\'name\', \'ilike\', \'%desk%\')], \'order\': {\'name\': \'id\', \'asc\': true}}, {\'name\': \'Chairs\', \'domain\': [(\'name\', \'ilike\', \'%chair%\')]}]}">' +
'<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%')]}]}\">" +
"<kanban>" +
'<field name="name" />' +
'<field name="product_id" />' +
'<field name="price_reduce" />' +
@ -21,37 +22,87 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
'<field name="foo_id" />' +
'<field name="product_uom_qty" />' +
'<field name="product_uom" />' +
'</kanban>' +
'</field>' +
'</form>';
"</kanban>" +
"</field>" +
"</form>"
);
};
QUnit.module('Web Widget One2Many Product Picker', {
QUnit.module(
"Web Widget One2Many Product Picker",
{
beforeEach: function() {
this.data = {
foo: {
fields: {
currency_id: {string: "Currency", type: "many2one", relation: "currency"},
line_ids: {string: "Lines Test", type: "one2many", relation: "line", relation_field: "foo_id"},
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"},
{
id: 1,
line_ids: [1, 2],
currency_id: 1,
display_name: "FT01",
},
],
},
line: {
fields: {
name: {string: "Product Name", type: "string"},
product_id: {string: "Product", type: "many2one", relation: "product"},
product_uom: {string: "UoM", type: "many2one", relation: "uom"},
product_id: {
string: "Product",
type: "many2one",
relation: "product",
},
product_uom: {
string: "UoM",
type: "many2one",
relation: "uom",
},
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"},
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.00, foo_id: 1},
{id: 2, name: "Cabinet with Doors", product_id: 2, product_uom: 1, product_uom_qty: 8, price_unit: 42.99, price_reduce: 40.00, foo_id: 1},
{
id: 1,
name: "Large Cabinet",
product_id: 1,
product_uom: 1,
product_uom_qty: 3,
price_unit: 9.99,
price_reduce: 9.0,
foo_id: 1,
},
{
id: 2,
name: "Cabinet with Doors",
product_id: 2,
product_uom: 1,
product_uom_qty: 8,
price_unit: 42.99,
price_reduce: 40.0,
foo_id: 1,
},
],
},
product: {
@ -60,47 +111,60 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
display_name: {string: "Display Name", type: "char"},
list_price: {string: "Price", type: "float"},
image_medium: {string: "Image Medium", type: "binary"},
uom_category_id: {string: "Category", type: "many2one", relation: "uom_category"},
uom_category_id: {
string: "Category",
type: "many2one",
relation: "uom_category",
},
},
records: [
{id: 1, name: "Large Cabinet", display_name: "Large Cabinet", list_price: 9.99, image_medium: "", uom_category_id: 1},
{id: 2, name: "Cabinet with Doors", display_name: "Cabinet with Doors", list_price: 42.0, image_medium: "", uom_category_id: 1},
{
id: 1,
name: "Large Cabinet",
display_name: "Large Cabinet",
list_price: 9.99,
image_medium: "",
uom_category_id: 1,
},
{
id: 2,
name: "Cabinet with Doors",
display_name: "Cabinet with Doors",
list_price: 42.0,
image_medium: "",
uom_category_id: 1,
},
],
},
uom_category: {
fields: {
display_name: {string: "Display Name", type: "char"},
},
records: [
{id: 1, display_name: "Unit(s)"},
],
records: [{id: 1, display_name: "Unit(s)"}],
},
uom: {
fields: {
name: {string: "Name", type: "char"},
},
records: [
{id: 1, name: "Unit(s)"},
],
records: [{id: 1, name: "Unit(s)"}],
},
currency: {
fields: {
name: {string: "Name", type: "char"},
symbol: {string: "Symbol", type: "char"},
},
records: [
{id: 1, name: "Eur", symbol: "€"},
],
records: [{id: 1, name: "Eur", symbol: "€"}],
},
};
},
}, function () {
QUnit.test('Load widget', function (assert) {
},
function() {
QUnit.test("Load widget", function(assert) {
assert.expect(4);
var form = createView({
View: FormView,
model: 'foo',
model: "foo",
data: this.data,
arch: getArch(),
res_id: 1,
@ -109,28 +173,56 @@ odoo.define('web_widget_one2many_product_picker.widget_tests', function (require
index: 0,
},
mockRPC: function(route, args) {
if (route === '/web/dataset/call_kw/foo/read') {
assert.deepEqual(args.args[1], ['currency_id', 'line_ids', 'display_name'],
'should only read "currency_id", "line_ids" and "display_name"');
if (route === "/web/dataset/call_kw/foo/read") {
assert.deepEqual(
args.args[1],
["currency_id", "line_ids", "display_name"],
'should only read "currency_id", "line_ids" and "display_name"'
);
return $.when(this.data.foo.records);
} else if (route === '/web/dataset/call_kw/line/read') {
assert.deepEqual(args.args[1], ['name', 'product_id', 'price_reduce', 'price_unit', 'foo_id', 'product_uom_qty', 'product_uom'],
'should only read "name", "product_id", "price_reduce", "price_unit", "foo_id", "product_uom_qty" and "product_uom"');
} else if (route === "/web/dataset/call_kw/line/read") {
assert.deepEqual(
args.args[1],
[
"name",
"product_id",
"price_reduce",
"price_unit",
"foo_id",
"product_uom_qty",
"product_uom",
],
'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"');
} 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");
assert.ok(
form.$(".oe_field_one2many_product_picker").is(":visible"),
"should have a visible one2many product picker"
);
form.destroy();
});
});
}
);
});

View File

@ -2,37 +2,77 @@
<odoo>
<template id="_assets_backend_helpers" inherit_id="web._assets_backend_helpers">
<xpath expr=".">
<link type="text/css" rel="stylesheet"
href="/web_widget_one2many_product_picker/static/src/scss/_variables.scss"/>
<link
type="text/css"
rel="stylesheet"
href="/web_widget_one2many_product_picker/static/src/scss/_variables.scss"
/>
</xpath>
</template>
<template id="_assets_bootstrap" inherit_id="web._assets_bootstrap">
<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>
</template>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link type="text/css" rel="stylesheet"
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/tools.js"></script>
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/record.js"></script>
<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 type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_create_form.js"></script>
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/One2ManyProductPicker/quick_modif_price_form_view.js"></script>
<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 type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/views/basic_model.js"></script>
<script type="text/javascript" src="/web_widget_one2many_product_picker/static/src/js/widgets/field_one2many_product_picker.js"></script>
<link
type="text/css"
rel="stylesheet"
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/tools.js"
/>
<script
type="text/javascript"
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>
</template>
<template id="qunit_suite" name="base_import_tests" inherit_id="web.qunit_suite">
<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>
</template>
</odoo>