This question has been flagged

Hi guys,

I've been trying to inherit and extend the POS from Odoo (V8) but I keep running stock. What do I want to do? When the user clicks on a payment method and the screen is show there is a button 'Confirm'. I want to add another button here, which prints a new created QWeb report. So far I've managed to add a new JS file to the web.assets and started to extend the POS. So my code for adding my customer JS file:

<openerp> <data> <!-- Inherit the js template in the module and include js file there. --> <template id="assets_backend_pippa" name="pos_print" inherit_id="web.assets_backend"> <xpath expr="." position="inside"> <script type="text/javascript" src="/my_module_name/static/src/js/pos_button.js"></script> </xpath> </template> </data> </openerp>

the javascript file (pos_button.js):

function openerp_pos_screens(instance, module){ var QWeb = instance.web.qweb, _t = instance.web._t;

module.ReceiptScreenWidget = module.ScreenWidget.extend({ template: 'ReceiptScreenWidget', show_numpad: true, show_leftpane: true, init: function(parent, options) { this._super(parent,options); this.model = options.model; this.user = this.pos.get('user'); this.company = this.pos.get('company'); this.shop_obj = this.pos.get('shop'); }, renderElement: function() { this._super(); this.pos.bind('change:selectedOrder', this.change_selected_order, this); this.change_selected_order(); }, show: function(){ this._super(); var self = this;

this.add_action_button({ label: _t('Print Receipt'), icon: '/pos_print/static/src/img/icons/printer.png', click: function(){ self.print(); }, }); }, close: function(){ this._super(); } }); }

But this gives me the following error in the console:

TypeError: module.ScreenWidget is undefined

So I remain with two questions: 
1) Why am I getting this TypeError? I don't get why it is undefined.
2) How can I pass this part of the code to open up a new custom QWeb report in the POS?

this.add_action_button({ label: _t('Print Receipt'); icon: '/pos_print/static/src/img/icons/printer.png', click: function(){ self.print(); }, });

Update: I managed to get the new button working thanks to Emipro. I'm now trying to call another report lay-out, but this doesn't seem to work. My code:

module.PaymentScreenWidgetInherit=module.PaymentScreenWidget.include({ show:function(){ self=this; this._super(); this.add_action_button({ label: _t('Kasticket'), icon: '/point_of_sale/static/src/img/icons/png48/invoice.png', click: function(){ self.print_report(); }, }); }, //This variable will keep the link to another view. next_screen: 'receipt', print_report:function(){ //This opens the next page (which is the receipt page) this.pos_widget.screen_selector.set_current_screen('receipt'); 

},

refresh: function() { var order = this.pos.get('selectedOrder'); $('.pos-receipt-container', this.$el).html(Qweb.render('PosTicket2',{ widget:this, order: order, orderlines: order.get('orderLines').models, paymentlines: order.get('paymentLines').models, })); },

});

};

This opens a new page but shows the old report lay-out, while it should show the new one I created. My new report code:

<?xml version="1.0" encoding="UTF-8"?> <templates id="template" xml:space="preserve"> <t t-name="PosTicket2"> <div class="pos-sale-ticket"> <div class="pos-center-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' + Date.CultureInfo.formatPatterns.longTime)"/> <t t-esc="order.get('name')"/></div> <br /> <t t-esc="widget.pos.company.name"/><br /> Phone: <t t-esc="widget.pos.company.phone || ''"/><br /> User: <t t-esc="widget.pos.cashier ? widget.pos.cashier.name : widget.pos.user.name"/><br /> Shop: <t t-esc="widget.pos.shop.name"/><br /> <br /> <t t-if="widget.pos.config.receipt_header"> <div style='text-align:center'> <t t-esc="widget.pos.config.receipt_header" /> </div> <br /> </t> </div> </t> </templates>


Thanks, 
Yenthe

Avatar
Discard
Best Answer

This code is working ok, it's based on your code. The thing is that the refresh function of the ReceiptScreenWidget render the original report and that function is called when you call 

this.pos_widget.screen_selector.set_current_screen('receipt');

That's way I put the "no_refresh = true" flag to check if the original refresh function of the ReceiptScreenWidget need to get called or not
Here is the code:

openerp.aa_pippa_pepper_pos = function(instance){

var module = instance.point_of_sale;

var Qweb = instance.web.qweb;

var _t = instance.web._t;

module.PaymentScreenWidget.include({

show:function(){

self=this;

this._super();

this.add_action_button({

label: _t('Kasticket'),

icon: '/point_of_sale/static/src/img/icons/png48/invoice.png',

click: function(){

self.refresh();

},

});

},

refresh: function() {

var order = this.pos.get('selectedOrder');

$('.pos-receipt-container').html(Qweb.render('PosTicket2',{

widget:this,

order: order,

orderlines: order.get('orderLines').models,

paymentlines: order.get('paymentLines').models,

}));

this.pos_widget.receipt_screen.no_refresh = true;

this.pos_widget.screen_selector.set_current_screen('receipt');

this.pos_widget.receipt_screen.no_refresh = false;

},

close: function(){

this._super();

}

});

module.ReceiptScreenWidget.include({

refresh: function() {

if(this.no_refresh){

return

} else{

this._super();

}

},

});

};

--- Update to fix the report template ---

<?xml version="1.0" encoding="UTF-8"?>

<templates id="template" xml:space="preserve">

<t t-name="PosTicket2">

<div class="pos-sale-ticket">

<div class="pos-center-align"><t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate + ' ' +

Date.CultureInfo.formatPatterns.longTime)"/> <t t-esc="order.get('name')"/></div>

<br />

<t t-esc="widget.pos.company.name"/><br />

Phone: <t t-esc="widget.pos.company.phone || ''"/><br />

User: <t t-esc="widget.pos.cashier ? widget.pos.cashier.name : widget.pos.user.name"/><br />

Shop: <t t-esc="widget.pos.shop.name"/><br />

<br />

<t t-if="widget.pos.config.receipt_header">

<div style='text-align:center'>

<t t-esc="widget.pos.config.receipt_header" />

</div>

<br />

</t>

<table class='receipt-orderlines'>

<colgroup>

<col width='50%' />

<col width='25%' />

<col width='25%' />

</colgroup>

<tr t-foreach="orderlines" t-as="orderline">

<td>

<t t-esc="orderline.get_product().display_name"/>

<t t-if="orderline.get_discount() > 0">

<div class="pos-disc-font">

With a <t t-esc="orderline.get_discount()"/>% discount

</div>

</t>

</td>

<td class="pos-right-align">

<t t-esc="orderline.get_quantity_str_with_unit()"/>

</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(orderline.get_display_price())"/>

</td>

</tr>

</table>

<br />

<table class='receipt-total'>

<tr>

<td>Subtotal:</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(order.getSubtotal())"/>

</td>

</tr>

<t t-foreach="order.getTaxDetails()" t-as="taxdetail">

<tr>

<td><t t-esc="taxdetail.name" /></td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(taxdetail.amount)" />

</td>

</tr>

</t>

<tr>

<td>Discount:</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(order.getDiscountTotal())"/>

</td>

</tr>

<tr class="emph">

<td>Total:</td>

<td class="pos-right-align">

<t t-esc="widget.format_currency(order.getTotalTaxIncluded())"/>

</td>

</tr>

</table>

</div>

</t>

</templates>


Avatar
Discard
Author

Thanks Axel, a step closer! The thing is, I've now extended my custom ticket since it should show the prices too. So I added a line: but when I now run the JS I will get the error 'Error: QWeb2 - template['PosTicket2']: Runtime Error: TypeError: dict.order.get_subtotal is not a function' so I'm missing something in the JS that gets the get_subtotal but I'm not sure how to call it.. Think you could give me a helping hand there too?

Update the code to see what is the error now with the get_subtotal function

Author

Excellent answer, upvoted & accepted! Thank you Axel.

Best Answer

Here in your pos_button.js file

For initializing a function in ".js" file you need to do following:

In your case your module name is "my_module_name" which we can see from your ".js" declaration in web.asset.

Now, why do you want to define new "ReceiptScreenWidget", because it already there provided in core module 'point_of_sale'

Try Following:

openerp.my_module_name = function(instance){
     var module = instance.point_of_sale;
     var Qweb = instance.web.qweb;
     var _t =    instance.web._t;
   

module.PaymentScreenWidgetInherit=module.PaymentScreenWidget.include({ 

    show:function(){

                self=this;

                this._super();

                this.add_action_button({

                                    label: _t('NA'),

                                    icon: '/point_of_sale/static/src/img/icons/png48/go-previous.png',

                                   click: function(){

                                                    self.myclick();

                                    },

                });

    },

    myclick:function(){

              alert('My Button Click');

             <<your code for loading qweb template goes here>

   },

});

};



Avatar
Discard
Author

Thanks for the great answer Emipro! I've added a line in the JS like this: this.pos_widget.screen_selector.set_current_screen(this.next_screen); which is opening a new view, the default ticket screen. How do I now create another view/report that should be opened in place of the receipt screen? :s

Author

I've added my code as how it looks now, I did some attemps.

Can you tell your purpose for having a new screen?

Author

The default ticket that is printed in the screen (when you click on the payment method and then on confirm shows you the dialog to print the report but also shows the report inline. I want a second view which shows another version of this ticket in the browser. See: http://i.imgur.com/2iUI5MY.png

Do you want to keep the old version of the report? If no then I suggest copy whole template of that report version in your xml file and keep the 'same name of the template' and just do the changes you want, so it will load with whatever changes you made. In this case you don't need to add any new button. OR you can create your own new template and in js file you need to override the code where it prints the old version of the report and change the template name with yours new template name. Hope this helps !!.

Author

@Emipro I do need the old ticket lay-out. So I need two buttons next to eachother that both link to another QWeb report. How exactly should I link my second button to the QWeb report then?

Actually, when you click on confirm button pos makes the order 'paid' and shows you the reciept. I don't know while showing new qweb template do you want to confirm the order or not. If not than, in your case you need to create new screen inherited from 'ScreenWidget'. Then from the code shown above in function 'myclick' you need to show that new screen rendering your new qweb template. For rendering the qweb template, you can just search around in core module how the old report is rendered and check it.

Author

@Emipro I'm talking about the button 'Validate', not 'Invoice'. My new button (named 'Kasticket') should do exactly the same functionalities as 'Validate', the only difference is that it should show another QWeb report. I can't find any working way to show another QWeb report though..

Author

@Emipro I've updated my code again and added in my template for the new QWeb report.

What error you are facing here?

Author

The new QWeb report is not shown in the ticket view, it is always the old (default) QWeb report