【问题标题】:Odoo Point Of Sale : Add button to print a different receipt format? Odoo 13Odoo 销售点:添加按钮以打印不同的收据格式?奥多 13
【发布时间】:2021-04-28 18:24:37
【问题描述】:

我添加了另一个按钮来打印收据。因此,单击时打印默认收据的按钮和打印不同模板的按钮。这是我打印相同收据的代码,我的问题是如何为第二个按钮修改另一个类似于默认模板的模板并进行一些修改。 请问有什么帮助吗?谢谢。

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>

【问题讨论】:

    标签: javascript python xml odoo


    【解决方案1】:

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

    【讨论】:

    • 我添加了新模板 我将只打印receipt.company.logo ;那么参数'YOUR_PARAMS'应该是什么,你能给我一个例子吗?谢谢。
    • 添加数据时: var receipt = QWeb.render('MyNewOrderReceipt', this.get_receipt_render_env()); ,我得到了这个错误 Uncaught ReferenceError: QWeb is not defined localhost:8069/web/content/849-3c2b99c/… Retraçage :
    • 将此添加到您的 js 文件中: var core = require('web.core'); var QWeb = core.qweb;
    • 'YOUR_PARAMS' 是您在模板中需要的参数,但如果您不需要任何参数,请不要将 YOUR_PARAMS 变量传递给渲染函数,例如 var receipt = QWeb.render( 'MyNewOrderReceipt');
    • 未捕获的错误:QWeb2:找不到模板“MyNewOrderReceipt”localhost:8069/web/content/823-0ffc093/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-09
    • 1970-01-01
    相关资源
    最近更新 更多