|
@ -1,21 +1,10 @@ |
|
|
/****************************************************************************** |
|
|
|
|
|
Point Of Sale - Product Template module for Odoo |
|
|
|
|
|
Copyright (C) 2014-Today Akretion (http://www.akretion.com)
|
|
|
|
|
|
|
|
|
/* Copyright (C) 2014-Today Akretion (https://www.akretion.com) |
|
|
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
|
|
|
@author Sylvain LE GAL (https://twitter.com/legalsylvain)
|
|
|
|
|
|
@author Navarromiguel (https://github.com/navarromiguel)
|
|
|
|
|
|
@author Raphaël Reverdy (https://www.akretion.com)
|
|
|
|
|
|
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify |
|
|
|
|
|
it under the terms of the GNU Affero General Public License as |
|
|
|
|
|
published by the Free Software Foundation, either version 3 of the |
|
|
|
|
|
License, or (at your option) any later version. |
|
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
GNU Affero General Public License for more details. |
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Affero General Public License |
|
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
******************************************************************************/ |
|
|
|
|
|
odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
"use strict"; |
|
|
"use strict"; |
|
|
|
|
|
|
|
@ -42,53 +31,50 @@ odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
variant, displaying an extra scren to select the variant; |
|
|
variant, displaying an extra scren to select the variant; |
|
|
*********************************************************** */ |
|
|
*********************************************************** */ |
|
|
var _render_product_ = screens.ProductListWidget.prototype.render_product; |
|
|
var _render_product_ = screens.ProductListWidget.prototype.render_product; |
|
|
screens.ProductListWidget.include({ |
|
|
|
|
|
|
|
|
|
|
|
init: function(parent, options) { |
|
|
|
|
|
this._super(parent,options); |
|
|
|
|
|
var self = this; |
|
|
|
|
|
// OVERWRITE 'click_product_handler' function to do
|
|
|
|
|
|
// a different behaviour if template with one or many variants
|
|
|
|
|
|
// are selected.
|
|
|
|
|
|
this.click_product_handler = function(event){ |
|
|
|
|
|
var product = self.pos.db.get_product_by_id(this.dataset['productId']); |
|
|
|
|
|
|
|
|
|
|
|
if (product.product_variant_count == 1) { |
|
|
|
|
|
// Normal behaviour, The template has only one variant
|
|
|
|
|
|
options.click_product_action(product); |
|
|
|
|
|
|
|
|
screens.ProductScreenWidget.include({ |
|
|
|
|
|
click_product: function(product) { |
|
|
|
|
|
if (product.product_variant_count > 1) { |
|
|
|
|
|
this.gui.show_popup('select-variant-popup', product.product_tmpl_id); |
|
|
|
|
|
} else { |
|
|
|
|
|
this._super(product); |
|
|
} |
|
|
} |
|
|
else{ |
|
|
|
|
|
// Display for selection all the variants of a template
|
|
|
|
|
|
//self.pos.pos_widget.screen_selector.show_popup('select-variant-popup', product.product_tmpl_id);
|
|
|
|
|
|
self.gui.show_popup('select-variant-popup', product.product_tmpl_id); |
|
|
|
|
|
} |
|
|
} |
|
|
}; |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
screens.ProductListWidget.include({ |
|
|
|
|
|
|
|
|
|
|
|
set_product_list: function(product_list) { |
|
|
/* ************************************************ |
|
|
/* ************************************************ |
|
|
Overload: 'set_product_list' |
|
|
Overload: 'set_product_list' |
|
|
|
|
|
|
|
|
'set_product_list' is a function called before displaying Products. |
|
|
'set_product_list' is a function called before displaying Products. |
|
|
(at the beginning, after a category selection, after a research, etc. |
|
|
(at the beginning, after a category selection, after a research, etc. |
|
|
we just splice all products that are not the 'primary variant' |
|
|
|
|
|
|
|
|
we just remove all products that are not the 'primary variant' |
|
|
*/ |
|
|
*/ |
|
|
set_product_list: function(product_list){ |
|
|
|
|
|
for (var i = product_list.length - 1; i >= 0; i--){ |
|
|
|
|
|
if (!product_list[i].is_primary_variant){ |
|
|
|
|
|
product_list.splice(i, 1); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
this._super(product_list); |
|
|
|
|
|
|
|
|
var list = product_list.filter(function(product) { |
|
|
|
|
|
return product.is_primary_variant; |
|
|
|
|
|
}); |
|
|
|
|
|
this._super(list); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
render_product: function(product){ |
|
|
render_product: function(product){ |
|
|
self = this; |
|
|
|
|
|
|
|
|
var self = this; |
|
|
|
|
|
|
|
|
if (product.product_variant_count == 1){ |
|
|
if (product.product_variant_count == 1){ |
|
|
// Normal Display
|
|
|
// Normal Display
|
|
|
return _render_product_.call(this, product); |
|
|
|
|
|
} |
|
|
|
|
|
else{ |
|
|
|
|
|
|
|
|
return this._super(product); |
|
|
|
|
|
} |
|
|
|
|
|
if (!product.is_primary_variant) { |
|
|
|
|
|
//because screens.js:556: renderElement is called
|
|
|
|
|
|
//once before set_product_list
|
|
|
|
|
|
//So we get product.is_primary_variant
|
|
|
|
|
|
//which are not to be displayed
|
|
|
|
|
|
//
|
|
|
|
|
|
//Here we return mock element for
|
|
|
|
|
|
//products which will not be displayed
|
|
|
|
|
|
return document.createElement('div'); |
|
|
|
|
|
} |
|
|
|
|
|
//TODO reuse upper function
|
|
|
var cached = this.product_cache.get_node(product.id); |
|
|
var cached = this.product_cache.get_node(product.id); |
|
|
if(!cached) { |
|
|
if(!cached) { |
|
|
var image_url = this.get_product_image_url(product); |
|
|
var image_url = this.get_product_image_url(product); |
|
@ -104,7 +90,6 @@ odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
return product_node; |
|
|
return product_node; |
|
|
} |
|
|
} |
|
|
return cached; |
|
|
return cached; |
|
|
} |
|
|
|
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
@ -159,19 +144,17 @@ odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
|
|
|
|
|
|
// Render Variants
|
|
|
// Render Variants
|
|
|
var variant_ids = this.pos.db.template_by_id[product_tmpl_id].product_variant_ids; |
|
|
var variant_ids = this.pos.db.template_by_id[product_tmpl_id].product_variant_ids; |
|
|
var variant_list = []; |
|
|
|
|
|
for (var i = 0, len = variant_ids.length; i < len; i++) { |
|
|
|
|
|
variant_list.push(this.pos.db.get_product_by_id(variant_ids[i])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var variant_list = variant_ids.map(function (variant) { |
|
|
|
|
|
return this.pos.db.get_product_by_id(variant); |
|
|
|
|
|
}, this); |
|
|
this.variant_list_widget.filters = {} |
|
|
this.variant_list_widget.filters = {} |
|
|
this.variant_list_widget.set_variant_list(variant_list); |
|
|
this.variant_list_widget.set_variant_list(variant_list); |
|
|
|
|
|
|
|
|
// Render Attributes
|
|
|
// Render Attributes
|
|
|
var attribute_ids = this.pos.db.attribute_by_template_id(template.id); |
|
|
var attribute_ids = this.pos.db.attribute_by_template_id(template.id); |
|
|
var attribute_list = []; |
|
|
|
|
|
for (var i = 0, len = attribute_ids.length; i < len; i++) { |
|
|
|
|
|
attribute_list.push(this.pos.db.get_product_attribute_by_id(attribute_ids[i])); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var attribute_list = attribute_ids.map(function (attribute) { |
|
|
|
|
|
return this.pos.db.get_product_attribute_by_id(attribute); |
|
|
|
|
|
}, this); |
|
|
this.attribute_list_widget.set_attribute_list(attribute_list, template); |
|
|
this.attribute_list_widget.set_attribute_list(attribute_list, template); |
|
|
|
|
|
|
|
|
if(this.$el){ |
|
|
if(this.$el){ |
|
@ -227,7 +210,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){ |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
filter_variant: function(){ |
|
|
filter_variant: function(){ |
|
|
var value_list = [] |
|
|
|
|
|
|
|
|
var value_list = []; |
|
|
for (var item in this.filters){ |
|
|
for (var item in this.filters){ |
|
|
value_list.push(parseInt(this.filters[item])); |
|
|
value_list.push(parseInt(this.filters[item])); |
|
|
} |
|
|
} |
|
@ -499,25 +482,23 @@ Overload: point_of_sale.PosModel |
|
|
- Load 'name' field of model product.product; |
|
|
- Load 'name' field of model product.product; |
|
|
- Load product.template model; |
|
|
- Load product.template model; |
|
|
*********************************************************** */ |
|
|
*********************************************************** */ |
|
|
var _initialize_ = models.PosModel.prototype.initialize; |
|
|
|
|
|
models.PosModel.prototype.initialize = function(session, attributes){ |
|
|
|
|
|
self = this; |
|
|
|
|
|
// Add the load of the field product_product.name
|
|
|
|
|
|
// that is the name of the template
|
|
|
|
|
|
// Add the load of attribute values
|
|
|
|
|
|
for (var i = 0 ; i < this.models.length; i++){ |
|
|
|
|
|
if (this.models[i].model == 'product.product'){ |
|
|
|
|
|
if (this.models[i].fields.indexOf('name') == -1) { |
|
|
|
|
|
this.models[i].fields.push('name'); |
|
|
|
|
|
} |
|
|
|
|
|
if (this.models[i].fields.indexOf('attribute_value_ids') == -1) { |
|
|
|
|
|
this.models[i].fields.push('attribute_value_ids'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// change product.product call
|
|
|
|
|
|
models.PosModel.prototype.models.some(function (model) { |
|
|
|
|
|
if (model.model !== 'product.product') { |
|
|
|
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
// add name and attribute_value_ids to list of fields
|
|
|
|
|
|
// to fetch for product.product
|
|
|
|
|
|
['name', 'attribute_value_ids'].forEach(function (field) { |
|
|
|
|
|
if (model.fields.indexOf(field) == -1) { |
|
|
|
|
|
model.fields.push(field); |
|
|
} |
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
return true; //exit early the iteration of this.models
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
// Load Product Template
|
|
|
|
|
|
var model = { |
|
|
|
|
|
|
|
|
//Add our new models
|
|
|
|
|
|
models.PosModel.prototype.models.push({ |
|
|
model: 'product.template', |
|
|
model: 'product.template', |
|
|
fields: [ |
|
|
fields: [ |
|
|
'name', |
|
|
'name', |
|
@ -538,11 +519,8 @@ Overload: point_of_sale.PosModel |
|
|
loaded: function(self, templates){ |
|
|
loaded: function(self, templates){ |
|
|
self.db.add_templates(templates); |
|
|
self.db.add_templates(templates); |
|
|
}, |
|
|
}, |
|
|
} |
|
|
|
|
|
this.models.push(model); |
|
|
|
|
|
|
|
|
|
|
|
// Load Product Attribute
|
|
|
|
|
|
model = { |
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
model: 'product.attribute', |
|
|
model: 'product.attribute', |
|
|
fields: [ |
|
|
fields: [ |
|
|
'name', |
|
|
'name', |
|
@ -551,11 +529,8 @@ Overload: point_of_sale.PosModel |
|
|
loaded: function(self, attributes){ |
|
|
loaded: function(self, attributes){ |
|
|
self.db.add_product_attributes(attributes); |
|
|
self.db.add_product_attributes(attributes); |
|
|
}, |
|
|
}, |
|
|
} |
|
|
|
|
|
this.models.push(model); |
|
|
|
|
|
|
|
|
|
|
|
// Load Product Attribute Value
|
|
|
|
|
|
model = { |
|
|
|
|
|
|
|
|
}, |
|
|
|
|
|
{ |
|
|
model: 'product.attribute.value', |
|
|
model: 'product.attribute.value', |
|
|
fields: [ |
|
|
fields: [ |
|
|
'name', |
|
|
'name', |
|
@ -564,10 +539,10 @@ Overload: point_of_sale.PosModel |
|
|
loaded: function(self, values){ |
|
|
loaded: function(self, values){ |
|
|
self.db.add_product_attribute_values(values); |
|
|
self.db.add_product_attribute_values(values); |
|
|
}, |
|
|
}, |
|
|
} |
|
|
|
|
|
this.models.push(model); |
|
|
|
|
|
|
|
|
|
|
|
return _initialize_.call(this, session, attributes); |
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
return { |
|
|
|
|
|
'SelectVariantPopupWidget': SelectVariantPopupWidget, |
|
|
|
|
|
'VariantListWidget': VariantListWidget, |
|
|
|
|
|
'AttributeListWidget': AttributeListWidget, |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
}); |
|
|
}); |