Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
589 views
in Technique[技术] by (71.8m points)

javascript - Odoo Point Of Sale : Add button to print a different receipt format? Odoo 13

I added another button to print receipt.So, one that prints the default receipt when clicked and another that prints a different template. Here is my code which print the same receipt , my question is how to modify for the second button another template similar to the default with some modifications. Any help please? Thanks.

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>
question from:https://stackoverflow.com/questions/65876445/odoo-point-of-sale-add-button-to-print-a-different-receipt-format-odoo-13

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you need to create new print method in 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);
},

note: this is assuming you are aiming to print the new template directly to printer without preview, if you want to change the receipt screen you need to override ActionButtonWidget.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...