我希望你能帮助我,我已经使用了odoo .v8,我正在研究Point of Sale模块,而且我要继承一些打印方法,一切都很好直到我重新定义 validate_order 我在客户端收到此错误:
Uncaught ReferenceError: QWeb is not defined
这是我的代码如何重新定义 validate_order 方法:
function openerp_tpv_screens(instance, module){
var Qweb = instance.web.qweb;
var _t = instance.web._t;
module.PaymentScreenWidget=module.PaymentScreenWidget.extend({
validate_order: function(options) {
var self = this;
options = options || {};
var currentOrder = this.pos.get('selectedOrder');
if(currentOrder.get('orderLines').models.length === 0){
this.pos_widget.screen_selector.show_popup('error',{
'message': _t('Empty Order'),
'comment': _t('There must be at least one product in your order before it can be validated'),
});
return;
}
var plines = currentOrder.get('paymentLines').models;
for (var i = 0; i < plines.length; i++) {
if (plines[i].get_type() === 'bank' && plines[i].get_amount() < 0) {
this.pos_widget.screen_selector.show_popup('error',{
'message': _t('Negative Bank Payment'),
'comment': _t('You cannot have a negative amount in a Bank payment. Use a cash payment method to return money to the customer.'),
});
return;
}
}
if(!this.is_paid()){
return;
}
// The exact amount must be paid if there is no cash payment method defined.
if (Math.abs(currentOrder.getTotalTaxIncluded() - currentOrder.getPaidTotal()) > 0.00001) {
var cash = false;
for (var i = 0; i < this.pos.cashregisters.length; i++) {
cash = cash || (this.pos.cashregisters[i].journal.type === 'cash');
}
if (!cash) {
this.pos_widget.screen_selector.show_popup('error',{
message: _t('Cannot return change without a cash payment method'),
comment: _t('There is no cash payment method available in this point of sale to handle the change.\n\n Please pay the exact amount or add a cash payment method in the point of sale configuration'),
});
return;
}
}
if (this.pos.config.iface_cashdrawer) {
this.pos.proxy.open_cashbox();
}
if(options.invoice){
// deactivate the validation button while we try to send the order
this.pos_widget.action_bar.set_button_disabled('validation',true);
this.pos_widget.action_bar.set_button_disabled('invoice',true);
this.pos_widget.action_bar.set_button_disabled('invoice_03',true);
var invoiced = this.pos.push_and_invoice_order(currentOrder);
invoiced.fail(function(error){
if(error === 'error-no-client' || error === 'error-generic-client'){
self.pos_widget.screen_selector.show_popup('error',{
message: _t('An anonymous order cannot be invoiced'),
comment: _t('Please select a client for this order. This can be done by clicking the order tab'),
});
}else if(error === 'error-no-generic-client'){
self.pos_widget.screen_selector.show_popup('error',{
message: _t('An anonymous order cannot be invoiced'),
comment: _t('No se debe seleccionar un Cliente Genérico.'),
});
}else{
self.pos_widget.screen_selector.show_popup('error',{
message: _t('The order could not be sent'),
comment: _t('Check your internet connection and try again.'),
});
}
self.pos_widget.action_bar.set_button_disabled('validation',false);
self.pos_widget.action_bar.set_button_disabled('invoice',false);
self.pos_widget.action_bar.set_button_disabled('invoice_03',false);
});
invoiced.done(function(){
self.pos_widget.action_bar.set_button_disabled('validation',false);
self.pos_widget.action_bar.set_button_disabled('invoice',false);
self.pos_widget.action_bar.set_button_disabled('invoice_03',false);
self.pos.get('selectedOrder').destroy();
});
}else{
this.pos.push_order(currentOrder)
if(this.pos.config.iface_print_via_proxy){
var receipt = currentOrder.export_for_printing();
this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',{
receipt: receipt, widget: self,
}));
this.pos.get('selectedOrder').destroy(); //finish order and go back to scan screen
}else{
this.pos_widget.screen_selector.set_current_screen(this.next_screen);
}
}
// hide onscreen (iOS) keyboard
setTimeout(function(){
document.activeElement.blur();
$("input").blur();
},250);
},
});
给我错误的具体行是:
this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',{
receipt: receipt, widget: self,
}));`
Qweb未定义错误但我做了:var Qweb = instance.web.qweb;
感谢您的时间。
答案 0 :(得分:0)
尝试在对象中传递渲染的模板,并在代码中调用此对象。之后,如果它不起作用,请检查 __ openerp __。py 文件。在那个检查你的Qweb模板的路径应该是这样的:
'qweb': ['static/src/xml/pos.xml']
之后不要忘记在xml文件中检查你的js文件路径,它应该是这样的:
<template id="assets_backend" name="pos assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/module_name/static/src/js/file_name.js"></script>
</template>
再次运行并检查天气错误是否已解决。