首页 > 解决方案 > 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>

标签: javascriptpythonxmlodoo

解决方案


您需要在 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。


推荐阅读