javascript - Odoo 销售点:添加按钮以打印不同的收据格式?奥多 13
问题描述
我添加了另一个按钮来打印收据。因此,一个在单击时打印默认收据,另一个打印不同的模板。这是我打印相同收据的代码,我的问题是如何为第二个按钮修改另一个类似于默认模板的模板并进行一些修改。请问有什么帮助吗?谢谢。
odoo.define('pos_print.pos_report', function (require) { "use
strict";
var screens = require('point_of_sale.screens'); console.log("screens
: " + screens)
var gui = require('point_of_sale.gui'); var core =
require('web.core'); var _t = core._t;
screens.ReceiptScreenWidget.include({
renderElement: function() {
var self = this;
this._super();
this.$('.next').click(function(){
if (!self._locked) {
self.click_next();
}
});
this.$('.back').click(function(){
if (!self._locked) {
self.click_back();
}
});
this.$('.button.order-print').click(function(){
if (!self._locked) {
self.print();
}
});
},
}); });
<templates id="point_of_sale.template" xml:space="preserve">
<t t-extend="ReceiptScreenWidget">
<t t-jquery=".button.print" t-operation="after">
<div class="button order-print">
<i class='fa fa-print'></i>
Print POS Order
</div>
</t> </t> </templates>
解决方案
您需要在 ReceiptScreenWidget 中创建新的打印方法:
renderElement: function() {
var self = this;
this._super();
this.$('.next').click(function(){
if (!self._locked) {
self.click_next();
}
});
this.$('.back').click(function(){
if (!self._locked) {
self.click_back();
}
});
this.$('.button.print').click(function(){
if (!self._locked) {
self.print();
}
});
this.$('.button.order-print').click(function(){
// To print new format
if (!self._locked) {
self.myPrint();
}
});
},
myPrint: function () {
// MyNewOrderReceipt is your new receipt template
// YOUR_PARAMS is parameters required in your template
var receipt = QWeb.render('MyNewOrderReceipt', YOUR_PARAMS);
this.pos.proxy.printer.print_receipt(receipt);
this.pos.get_order()._printed = true;
this.lock_screen(false);
},
注意:这是假设您的目标是将新模板直接打印到打印机而不进行预览,如果您想更改收据屏幕,您需要覆盖 ActionButtonWidget。
推荐阅读
- mongodb - 主节点更改后如何使用Nodeport连接MongoDB主节点
- reactjs - React:如何通过单击父 div 来选择子组件中所有列/行的复选框
- arduino - Arduino作为开门者
- javascript - 如何在面向对象的 Javascript 中进行方法链接?
- html - 导航栏中的字幕 + 右对齐项目
- java - 在使用 @Transactional 的 JUnit 测试中未删除实体
- python - 匀称的 .contains() 方法但包括边界?
- windows-10 - .reg 文件问题 - 不更改注册表
- javascript - 由于在 asp.net core / iis express 中缺少 mime 类型,无法加载 javascript
- angular - 如何在 HTML 代码中访问 FormControl 值