Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to inherit the POS to add a new print button and QWeb report?

By
Yenthe
on 12/17/15, 3:37 AM 2,607 views

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

1

Axel Mendoza

--Axel Mendoza--
10308
| 7 7 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full time employee trying to understand what to do an how

Reach me at aekroft@gmail.com

Axel Mendoza
On 12/22/15, 5:31 PM

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>


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?

Yenthe
on 12/23/15, 3:05 AM

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

Axel Mendoza
on 12/23/15, 3:09 AM

Excellent answer, upvoted & accepted! Thank you Axel.

Yenthe
on 12/23/15, 4:23 AM
1

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 12/17/15, 6:31 AM

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>

   },

});

};



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

Yenthe
on 12/17/15, 7:36 AM

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

Yenthe
on 12/17/15, 7:54 AM

Can you tell your purpose for having a new screen?

Emipro Technologies Pvt. Ltd.
on 12/17/15, 9:27 AM

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

Yenthe
on 12/17/15, 9:57 AM

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 !!.

Emipro Technologies Pvt. Ltd.
on 12/18/15, 12:26 AM

@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?

Yenthe
on 12/18/15, 1:53 AM

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.

Emipro Technologies Pvt. Ltd.
on 12/18/15, 8:16 AM

@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..

Yenthe
on 12/18/15, 9:44 AM

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

Yenthe
on 12/18/15, 10:05 AM

What error you are facing here?

Emipro Technologies Pvt. Ltd.
on 12/19/15, 7:52 AM

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

Yenthe
on 12/19/15, 10:46 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 12/17/15, 3:37 AM
Seen: 2607 times
Last updated: 12/23/15, 4:22 AM