问题描述
https://apps.odoo.com/apps/modules/12.0/pos_multi_variant/#loempia-comments
我已使用此应用程序在 pos 的弹出窗口上显示产品的变体
我不得不修改代码以使其工作,因为它的 odoo 12 并且我正在将它安装在 odoo13 上
发生的事情是主要产品出现在弹出窗口中,产品屏幕上排列着变体
有什么建议可以解决这个问题吗?
谢谢
静态 > js 文件
odoo.define('pos_multi_variant.ProductPopup',function (require)
{ "使用严格";
var PosBaseWidget = require('point_of_sale.BaseWidget');
var gui = require('point_of_sale.gui');
var models = require('point_of_sale.models');
var core = require('web.core');
var screens = require('point_of_sale.screens');
var PopupWidget = require('point_of_sale.popups');
var Widget = require("web.Widget");
var QWeb = core.qweb;
var rpc = require('web.rpc');
var _t = require('web.core')._t;
models.load_models([
{ model: 'variants.tree',fields: ["pos_active","value","attribute","variants_id","extra_price"],loaded: function(self,variants_tree)
{ self.variant_tree = variants_tree;
_.each(variants_tree,function(item)
{ self.item = item;
});
}
},{ model: 'product.attribute.value',fields: ["id","name"],values)
{ self.values = values;
}
}]);
var super_models = models.PosModel.prototype.models;
models.load_fields('product.product','pos_variants');
models.load_fields('product.product','variant_line_ids');
var _super_orderline = models.Orderline.prototype;
models.Orderline = models.Orderline.extend
({ initialize: function(attr,options)
{ _super_orderline.initialize.call(this,attr,options);
this.product_variants = this.product_variants || [];
},init_from_JSON: function(json)
{ _super_orderline.init_from_JSON.apply(this,arguments);
this.product_variants = json.product_variants || [];
},export_as_JSON: function ()
{ var json = _super_orderline.export_as_JSON.apply(this,arguments);
json.product_variants = this.product_variants || [];
return json;
},});
var ProductPopUp = PopupWidget.extend
({ template: 'ProductPopUp',init: function(parent,options)
{ this._super(parent,options);
this.options = {};
this.pos_reference = "";
},show: function(options)
{ this._super(options);
this.render_list(options);
},events:
{ 'click .button.cancel': 'click_cancel','click .button.confirm': 'click_confirm','click .product': 'click_variant',},click_variant:function(e)
{ var order = this.self.pos.get('selectedOrder')
var self = e.currentTarget
var action = $(self).find('.action').text();
var categories = []
var category = $(self).find('.action').data('category');
$('.product-img').find('.variant-selected').each(function ()
{ if($(this).data('category') == category)
{ $(this).text("").removeClass('variant-selected');
$(self).find('.action').text("Selected").addClass('variant-selected');
}
});
$(self).find('.action').text("Selected").addClass('variant-selected');
var add = $(self).find('.extra-price').text().substr(1).slice(0,-2);
var type = $(self).find('.variants').text();
$(self).find('.variant-selected').attr('data-price',add);
$(self).find('.variant-selected').attr('data-type',type);
},render_list:function(options)
{ this.list = options.list
this.image_url = options.image_url
this.pos_reference = options.data
this.variant_values = options.values
this.self = options.self
var AddError = "variants are not added";
var ActiveError = "No active variants "
var NotActive = 0;
var AttributeNumbers = []
var pushed = []
for (var i = 0; i < this.list.length; i++)
{ if(this.list[i].pos_active == false)
{ NotActive += 1
}
if(this.list.length == NotActive)
{ $("#notify").append(ActiveError);
}
if(this.list[i].pos_active == true)
{ if (!pushed.includes(this.list[i].attribute[0]))
{ var temp = {};
temp.id = this.list[i].attribute[0];
temp.name = this.list[i].attribute[1]
pushed.push(this.list[i].attribute[0])
AttributeNumbers.push(temp)
}
}
}
var tag = "<div class='"+i+"'>";
for ( var i in AttributeNumbers)
{ tag += "<h2 class='tag'>"+AttributeNumbers[i].name+"</h2>";
for (var attr = 0; attr < this.list.length; attr++)
{ if (AttributeNumbers[i].id == this.list[attr].attribute[0])
{ var values = this.list[attr].value.length
for(var j = 0; j < values; j++)
{ if(this.list[attr].extra_price)
{ var price = '+'+this.format_currency(this.list[attr].extra_price)}
else
{ var price = '+'+this.format_currency(0.00)}
for(var k=0; k < this.variant_values.length; k++)
{ if((this.variant_values[k].id == this.list[attr].value[j]) && this.list[attr].pos_active == true)
{ var rows ="<article class='product'>" +
"<div class='product-img'>"+
"<img src='"+this.image_url+"'/>" +
"<span class='extra-price'>"+price+"</span>"+
"<h2 class='action' data-price='' data-type='' data-category='"+AttributeNumbers[i].name+"'></h2>"+
"<span class='variants'>"+this.variant_values[k].name+"</span>"+
"</div>"+
"</article>"
tag += rows
}
}
}
}
}
}
tag += "</div>"
$("#notify").append(tag);
if(!(this.pos_reference.variant_line_ids.length>0))
{ $("#notify").append(AddError);
}
},click_cancel: function()
{ var order = this.self.pos.get('selectedOrder').selected_orderline.product_variants = []
this.gui.close_popup();
},click_confirm: function()
{ var price = 0.00
var order = this.self.pos.get('selectedOrder');
var selected_orderline = order.selected_orderline
$('.product-img').find('.variant-selected').each(function ()
{ price += parseFloat($(this).data('price'))
var variant = order.selected_orderline.product_variants
variant.push
({ 'extra_price': $(this).data('price'),'type': $(this).data('type'),})
});
selected_orderline.price_manually_set = true;
selected_orderline.price += price
selected_orderline.trigger('change',selected_orderline);
this.gui.close_popup();
}
});
gui.define_popup({name:'ProductSelection',widget: ProductPopUp});
screens.ProductScreenWidget.include
({ click_product: function(product)
{ var image_url = this.get_product_image(product.id);
var self = this;
var variant_tree = this.pos.variant_tree
var list = []
var values = this.pos.values
for(var i = 0; i < variant_tree.length; i++)
{ if(variant_tree[i].variants_id[0] == product.product_tmpl_id)
{ list.push(variant_tree[i]); }
}
if(product.to_weight && this.pos.config.iface_electronic_scale)
{ this.gui.show_screen('scale',{product: product});}
else if(product.pos_variants)
{ this.pos.get_order().add_product(product);
this.gui.show_popup('ProductSelection',{ 'title': product.display_name,data: product,image_url: image_url,list: list,values: values,self: self
});
}
else
{ this.pos.get_order().add_product(product); }
},get_product_image: function(product)
{ return window.location.origin + '/web/image?model=product.product&field=image_medium&id='+product; }
});
});
这是静态的 > xml
<?xml version="1.0" encoding="UTF-8"?>
<t t-extend="Product" name="ProductStockWidget">
<t t-jquery="div.product-img" t-operation="replace">
<div class="product-img">
<img t-att-src='image_url' alt="Product image"/>
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.get_price(pricelist,1),'Product Price')"/>
</span>
<t t-if="product.pos_variants">
<span class="variant">Multi-variant</span>
</t>
</t>
<t t-if="product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.get_price(pricelist,'Product Price')"/>
</span>
<t t-if="product.pos_variants">
<span class="variant">Multi-variant</span>
</t>
</t>
</div>
</t>
</t>
<t t-extend="Orderline">
<t t-jquery="ul.info-list" t-operation="append">
<div class="variant-orderline">
<t t-foreach="line.product_variants" t-as="item">
<li>
<em>
<t t-esc="item.type" />:
</em>
at
<t t-esc="widget.format_currency(item.extra_price)"/>
</li>
</t>
</div>
</t>
</t>
<t t-extend="PosTicket">
<t t-jquery="tr[t-foreach*='orderlines'][t-as*='orderline']" t-operation="append">
<tr t-foreach="orderline.product_variants" t-as="variant">
<div>
<td t-esc="variant.type" style="padding-left:15px;"/>
<td style="text-align: left;" t-esc="widget.format_currency(variant.extra_price)"/>
</div>
</tr>
</t>
</t>
这是静态的 > xml
<?xml version="1.0" encoding="UTF-8"?>
<t t-extend="Product" name="ProductStockWidget">
<t t-jquery="div.product-img" t-operation="replace">
<div class="product-img">
<img t-att-src='image_url' alt="Product image"/>
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.get_price(pricelist,'Product Price')"/>
</span>
<t t-if="product.pos_variants">
<span class="variant">Multi-variant</span>
</t>
</t>
</div>
</t>
</t>
<t t-extend="Orderline">
<t t-jquery="ul.info-list" t-operation="append">
<div class="variant-orderline">
<t t-foreach="line.product_variants" t-as="item">
<li>
<em>
<t t-esc="item.type" />:
</em>
at
<t t-esc="widget.format_currency(item.extra_price)"/>
</li>
</t>
</div>
</t>
</t>
<t t-extend="PosTicket">
<t t-jquery="tr[t-foreach*='orderlines'][t-as*='orderline']" t-operation="append">
<tr t-foreach="orderline.product_variants" t-as="variant">
<div>
<td t-esc="variant.type" style="padding-left:15px;"/>
<td style="text-align: left;" t-esc="widget.format_currency(variant.extra_price)"/>
</div>
</tr>
</t>
</t>
视图> xml
<?xml version="1.0" encoding="UTF-8"?>
<t t-extend="Product" name="ProductStockWidget">
<t t-jquery="div.product-img" t-operation="replace">
<div class="product-img">
<img t-att-src='image_url' alt="Product image"/>
<t t-if="!product.to_weight">
<span class="price-tag">
<t t-esc="widget.format_currency(product.get_price(pricelist,'Product Price')"/>
</span>
<t t-if="product.pos_variants">
<span class="variant">Multi-variant</span>
</t>
</t>
</div>
</t>
</t>
<t t-extend="Orderline">
<t t-jquery="ul.info-list" t-operation="append">
<div class="variant-orderline">
<t t-foreach="line.product_variants" t-as="item">
<li>
<em>
<t t-esc="item.type" />:
</em>
at
<t t-esc="widget.format_currency(item.extra_price)"/>
</li>
</t>
</div>
</t>
</t>
<t t-extend="PosTicket">
<t t-jquery="tr[t-foreach*='orderlines'][t-as*='orderline']" t-operation="append">
<tr t-foreach="orderline.product_variants" t-as="variant">
<div>
<td t-esc="variant.type" style="padding-left:15px;"/>
<td style="text-align: left;" t-esc="widget.format_currency(variant.extra_price)"/>
</div>
</tr>
</t>
</t>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)