Browse Source

[MIG] pos_product_template

pull/411/head
Hugo Santos 6 years ago
committed by Wolfgang Pichler
parent
commit
5938b32017
  1. 5
      pos_product_template/README.rst
  2. 1
      pos_product_template/__init__.py
  3. 3
      pos_product_template/__manifest__.py
  4. 39
      pos_product_template/static/src/js/ppt.js
  5. 4
      pos_product_template/static/src/xml/ppt.xml
  6. 11
      pos_product_template/view/view.xml

5
pos_product_template/README.rst

@ -30,7 +30,7 @@ You will see one article instead of all the variants.
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/pos/10.0
:target: https://runbot.odoo-community.org/runbot/pos/11.0
Known issues / Roadmap Known issues / Roadmap
@ -43,7 +43,7 @@ Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/issues>`_. In case of trouble, please
<https://github.com/OCA/pos/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first, check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback. help us smash it by providing detailed and welcomed feedback.
@ -62,6 +62,7 @@ Contributors
* Navarromiguel (https://github.com/navarromiguel) * Navarromiguel (https://github.com/navarromiguel)
* Damendieta (https://github.com/damendieta) * Damendieta (https://github.com/damendieta)
* Raphaël Reverdy (https://akretion.com) * Raphaël Reverdy (https://akretion.com)
* Hugo Santos (https://factorlibre.com)
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.

1
pos_product_template/__init__.py

@ -1,4 +1,3 @@
# -*- encoding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Point Of Sale - Product Template module for Odoo # Point Of Sale - Product Template module for Odoo

3
pos_product_template/__manifest__.py

@ -1,7 +1,6 @@
# -*- encoding: utf-8 -*-
{ {
'name': 'POS - Product Template', 'name': 'POS - Product Template',
'version': '10.0.1.0.1',
'version': '11.0.1.0.0',
'category': 'Point Of Sale', 'category': 'Point Of Sale',
'author': "Akretion,Odoo Community Association (OCA)", 'author': "Akretion,Odoo Community Association (OCA)",
'summary': 'Manage Product Template in Front End Point Of Sale', 'summary': 'Manage Product Template in Front End Point Of Sale',

39
pos_product_template/static/src/js/ppt.js

@ -60,7 +60,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
render_product: function(product){ render_product: function(product){
var self = this; var self = this;
if (product.product_variant_count == 1){
if (product.product_variant_count === 1){
// Normal Display // Normal Display
return this._super(product); return this._super(product);
} }
@ -219,7 +219,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
var variant = this.variant_list[index]; var variant = this.variant_list[index];
var found = true; var found = true;
for (var i = 0; i < value_list.length; i++){ for (var i = 0; i < value_list.length; i++){
found = found && (variant.attribute_value_ids.indexOf(value_list[i]) != -1);
found = found && (variant.attribute_value_ids.indexOf(value_list[i]) !== -1);
} }
if (found){ if (found){
this.filter_variant_list.push(variant); this.filter_variant_list.push(variant);
@ -228,6 +228,17 @@ odoo.define("pos_product_template.pos_product_template", function(require){
this.renderElement(); this.renderElement();
}, },
_get_active_pricelist: function(){
var current_order = this.pos.get_order();
var current_pricelist = this.pos.default_pricelist;
if (current_order) {
current_pricelist = current_order.pricelist;
}
return current_pricelist;
},
set_variant_list: function(variant_list){ set_variant_list: function(variant_list){
this.variant_list = variant_list; this.variant_list = variant_list;
this.filter_variant_list = variant_list; this.filter_variant_list = variant_list;
@ -235,7 +246,9 @@ odoo.define("pos_product_template.pos_product_template", function(require){
}, },
render_variant: function(variant){ render_variant: function(variant){
var current_pricelist = this._get_active_pricelist();
var variant_html = QWeb.render('VariantWidget', { var variant_html = QWeb.render('VariantWidget', {
pricelist: current_pricelist,
widget: this, widget: this,
variant: variant, variant: variant,
}); });
@ -247,7 +260,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
renderElement: function() { renderElement: function() {
var self = this; var self = this;
var el_html = openerp.qweb.render(this.template, {widget: this});
var el_html = core.qweb.render(this.template, {widget: this});
var el_node = document.createElement('div'); var el_node = document.createElement('div');
el_node.innerHTML = el_html; el_node.innerHTML = el_html;
el_node = el_node.childNodes[1]; el_node = el_node.childNodes[1];
@ -335,7 +348,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
var subproduct_list = this.pos.db.get_product_by_value_and_products(value.id, product_list); var subproduct_list = this.pos.db.get_product_by_value_and_products(value.id, product_list);
var variant_qty = subproduct_list.length; var variant_qty = subproduct_list.length;
// Hide product attribute value if there is no product associated to it // Hide product attribute value if there is no product associated to it
if (variant_qty != 0) {
if (variant_qty !== 0) {
var value_node = this.render_value(value, variant_qty); var value_node = this.render_value(value, variant_qty);
value_node.addEventListener('click', this.click_set_attribute_handler); value_node.addEventListener('click', this.click_set_attribute_handler);
list_container.appendChild(value_node); list_container.appendChild(value_node);
@ -358,7 +371,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
renderElement: function() { renderElement: function() {
var self = this; var self = this;
var el_html = openerp.qweb.render(this.template, {widget: this});
var el_html = core.qweb.render(this.template, {widget: this});
var el_node = document.createElement('div'); var el_node = document.createElement('div');
el_node.innerHTML = el_html; el_node.innerHTML = el_html;
el_node = el_node.childNodes[1]; el_node = el_node.childNodes[1];
@ -399,7 +412,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
get_product_by_value_and_products: function(value_id, products){ get_product_by_value_and_products: function(value_id, products){
var list = []; var list = [];
for (var i = 0, len = products.length; i < len; i++) { for (var i = 0, len = products.length; i < len; i++) {
if (products[i].attribute_value_ids.indexOf(value_id) != -1){
if (products[i].attribute_value_ids.indexOf(value_id) !== -1){
list.push(products[i]); list.push(products[i]);
} }
} }
@ -432,7 +445,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
var attribute_ids = []; var attribute_ids = [];
for (var i = 0; i < value_ids.length; i++){ for (var i = 0; i < value_ids.length; i++){
var value = this.product_attribute_value_by_id[value_ids[i]]; var value = this.product_attribute_value_by_id[value_ids[i]];
if (attribute_ids.indexOf(value.attribute_id[0])==-1){
if (attribute_ids.indexOf(value.attribute_id[0])===-1){
attribute_ids.push(value.attribute_id[0]); attribute_ids.push(value.attribute_id[0]);
} }
} }
@ -449,12 +462,12 @@ odoo.define("pos_product_template.pos_product_template", function(require){
for (var j = 0; j <templates[i].product_variant_ids.length; j++){ for (var j = 0; j <templates[i].product_variant_ids.length; j++){
var product = this.product_by_id[templates[i].product_variant_ids[j]] var product = this.product_by_id[templates[i].product_variant_ids[j]]
for (var k = 0; k < product.attribute_value_ids.length; k++){ for (var k = 0; k < product.attribute_value_ids.length; k++){
if (attribute_value_ids.indexOf(product.attribute_value_ids[k])==-1){
if (attribute_value_ids.indexOf(product.attribute_value_ids[k])===-1){
attribute_value_ids.push(product.attribute_value_ids[k]); attribute_value_ids.push(product.attribute_value_ids[k]);
} }
} }
product.product_variant_count = templates[i].product_variant_count; product.product_variant_count = templates[i].product_variant_count;
product.is_primary_variant = (j==0);
product.is_primary_variant = (j===0);
} }
this.template_by_id[templates[i].id].attribute_value_ids = attribute_value_ids; this.template_by_id[templates[i].id].attribute_value_ids = attribute_value_ids;
} }
@ -490,7 +503,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
// add name and attribute_value_ids to list of fields // add name and attribute_value_ids to list of fields
// to fetch for product.product // to fetch for product.product
['name', 'attribute_value_ids'].forEach(function (field) { ['name', 'attribute_value_ids'].forEach(function (field) {
if (model.fields.indexOf(field) == -1) {
if (model.fields.indexOf(field) === -1) {
model.fields.push(field); model.fields.push(field);
} }
}); });
@ -498,7 +511,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
}); });
//Add our new models //Add our new models
models.PosModel.prototype.models.push({
models.load_models([{
model: 'product.template', model: 'product.template',
fields: [ fields: [
'name', 'name',
@ -513,7 +526,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
];}, ];},
context: function(self){ context: function(self){
return { return {
pricelist: self.pricelist.id,
pricelist: self.pricelists[0].id,
display_default_code: false, display_default_code: false,
};}, };},
loaded: function(self, templates){ loaded: function(self, templates){
@ -539,7 +552,7 @@ odoo.define("pos_product_template.pos_product_template", function(require){
loaded: function(self, values){ loaded: function(self, values){
self.db.add_product_attribute_values(values); self.db.add_product_attribute_values(values);
}, },
});
}]);
return { return {
'SelectVariantPopupWidget': SelectVariantPopupWidget, 'SelectVariantPopupWidget': SelectVariantPopupWidget,
'VariantListWidget': VariantListWidget, 'VariantListWidget': VariantListWidget,

4
pos_product_template/static/src/xml/ppt.xml

@ -101,12 +101,12 @@
<div class="variant-header"> <div class="variant-header">
<t t-if="!variant.to_weight"> <t t-if="!variant.to_weight">
<span class="price-tag"> <span class="price-tag">
<t t-esc="widget.format_currency(variant.price,'Product Price')"/>
<t t-esc="widget.format_currency(variant.get_price(pricelist, 1), 'Product Price')"/>
</span> </span>
</t> </t>
<t t-if="variant.to_weight"> <t t-if="variant.to_weight">
<span class="price-tag"> <span class="price-tag">
<t t-esc="widget.format_currency(variant.price,'Product Price')+'/Kg'"/>
<t t-esc="widget.format_currency(variant.get_price(pricelist, 1), 'Product Price')+'/Kg'"/>
</span> </span>
</t> </t>
</div> </div>

11
pos_product_template/view/view.xml

@ -3,17 +3,12 @@
@author Sylvain LE GAL (https://twitter.com/legalsylvain) @author Sylvain LE GAL (https://twitter.com/legalsylvain)
License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). --> License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). -->
<odoo> <odoo>
<!-- Add: JS Files -->
<template id="assets_backend" name="point_of_sale assets2" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_product_template/static/src/js/ppt.js"></script>
</xpath>
</template>
<!-- Add: CSS Files -->
<template id="index" name="pos_product_template assets" inherit_id="point_of_sale.assets"> <template id="index" name="pos_product_template assets" inherit_id="point_of_sale.assets">
<xpath expr="//link[@id='pos-stylesheet']" position="after"> <xpath expr="//link[@id='pos-stylesheet']" position="after">
<link rel="stylesheet" href="/pos_product_template/static/src/css/ppt.css" id="pos_product_template-stylesheet"/> <link rel="stylesheet" href="/pos_product_template/static/src/css/ppt.css" id="pos_product_template-stylesheet"/>
</xpath> </xpath>
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_product_template/static/src/js/ppt.js"></script>
</xpath>
</template> </template>
</odoo> </odoo>
Loading…
Cancel
Save