Se rendre au contenu
Odoo Menu
  • Se connecter
  • Essai gratuit
  • Applications
    Finance
    • Comptabilité
    • Facturation
    • Notes de frais
    • Feuilles de calcul (BI)
    • Documents
    • Signature
    Ventes
    • CRM
    • Ventes
    • PdV Boutique
    • PdV Restaurant
    • Abonnements
    • Location
    Sites web
    • Site Web
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Chaîne d'approvisionnement
    • Inventaire
    • Fabrication
    • PLM
    • Achats
    • Maintenance
    • Qualité
    Ressources Humaines
    • Employés
    • Recrutement
    • Congés
    • Évaluations
    • Recommandations
    • Parc automobile
    Marketing
    • Marketing Social
    • E-mail Marketing
    • SMS Marketing
    • Événements
    • Marketing Automation
    • Sondages
    Services
    • Projet
    • Feuilles de temps
    • Services sur Site
    • Assistance
    • Planification
    • Rendez-vous
    Productivité
    • Discussion
    • Validations
    • Internet des Objets
    • VoIP
    • Connaissances
    • WhatsApp
    Applications tierces Odoo Studio Plateforme Cloud d'Odoo
  • Industries
    Commerce de détail
    • Librairie
    • Magasin de vêtements
    • Magasin de meubles
    • Épicerie
    • Quincaillerie
    • Magasin de jouets
    Food & Hospitality
    • Bar et Pub
    • Restaurant
    • Fast-food
    • Maison d’hôtes
    • Distributeur de boissons
    • Hôtel
    Immobilier
    • Agence immobilière
    • Cabinet d'architecture
    • Construction
    • Gestion immobilière
    • Jardinage
    • Association de copropriétaires
    Consultance
    • Cabinet d'expertise comptable
    • Partenaire Odoo
    • Agence Marketing
    • Cabinet d'avocats
    • Aquisition de talents
    • Audit & Certification
    Fabrication
    • Textile
    • Métal
    • Meubles
    • Alimentation
    • Brewery
    • Cadeaux d'entreprise
    Santé & Fitness
    • Club de sports
    • Opticien
    • Salle de fitness
    • Praticiens bien-être
    • Pharmacie
    • Salon de coiffure
    Trades
    • Bricoleur
    • Matériel informatique et support
    • Systèmes photovoltaïques
    • Cordonnier
    • Services de nettoyage
    • Services CVC
    Autres
    • Organisation à but non lucratif
    • Agence environnementale
    • Location de panneaux d'affichage
    • Photographie
    • Leasing de vélos
    • Revendeur de logiciel
    Browse all Industries
  • Communauté
    Apprenez
    • Tutoriels
    • Documentation
    • Certifications
    • Formation
    • Blog
    • Podcast
    Renforcer l'éducation
    • Programme éducatif
    • Business Game Scale-Up!
    • Rendez-nous visite
    Obtenir le logiciel
    • Téléchargement
    • Comparez les éditions
    • Versions
    Collaborer
    • Github
    • Forum
    • Événements
    • Traductions
    • Devenez partenaire
    • Services for Partners
    • Enregistrer votre cabinet comptable
    Nos Services
    • Trouver un partenaire
    • Trouver un comptable
    • Rencontrer un conseiller
    • Services de mise en œuvre
    • Références clients
    • Assistance
    • Mises à niveau
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obtenir une démonstration
  • Tarification
  • Aide

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilité
  • Inventaire
  • PoS
  • Projet
  • MRP
All apps
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Vous devez être inscrit pour interagir avec la communauté.
Toutes les publications Personnes Badges
Étiquettes (Voir toutl)
odoo accounting v14 pos v15
À propos de ce forum
Aide

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

S'inscrire

Recevez une notification lorsqu'il y a de l'activité sur ce poste

Cette question a été signalée
javascriptinheritancepoint_of_salebackbone.jsodoo8
13 Réponses
24018 Vues
Avatar
Yenthe Van Ginneken (Mainframe Monkey)

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

3
Avatar
Ignorer
Avatar
Axel Mendoza
Meilleure réponse

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>


6
Avatar
Ignorer
Yenthe Van Ginneken (Mainframe Monkey)
Auteur

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?

Axel Mendoza

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

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

Excellent answer, upvoted & accepted! Thank you Axel.

Avatar
Emipro Technologies Pvt. Ltd.
Meilleure réponse

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>

   },

});

};



1
Avatar
Ignorer
Yenthe Van Ginneken (Mainframe Monkey)
Auteur

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 Van Ginneken (Mainframe Monkey)
Auteur

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

Emipro Technologies Pvt. Ltd.

Can you tell your purpose for having a new screen?

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

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

Emipro Technologies Pvt. Ltd.

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

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

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

Emipro Technologies Pvt. Ltd.

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.

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

@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 Van Ginneken (Mainframe Monkey)
Auteur

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

Emipro Technologies Pvt. Ltd.

What error you are facing here?

Yenthe Van Ginneken (Mainframe Monkey)
Auteur

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

Vous appréciez la discussion ? Ne vous contentez pas de lire, rejoignez-nous !

Créez un compte dès aujourd'hui pour profiter de fonctionnalités exclusives et échanger avec notre formidable communauté !

S'inscrire
Publications associées Réponses Vues Activité
Extend a specific popup widget
javascript point_of_sale backbone.js
Avatar
0
févr. 19
6830
Inherit POS Javascript function in Odoo 10 Résolu
javascript inheritance point_of_sale odoo10.0
Avatar
Avatar
1
avr. 18
11430
Add a field and update the value in odoo pos orderline Odoo 11 Résolu
javascript inheritance point_of_sale odoo odoo11
Avatar
Avatar
1
juil. 21
16873
(SOLVED) JavaScript: How to add a QR code in POS Receipt?
javascript point_of_sale
Avatar
0
août 23
4048
Change onclick kanban project view (JS file)
javascript inheritance
Avatar
Avatar
1
mars 22
7659
Communauté
  • Tutoriels
  • Documentation
  • Forum
Open Source
  • Téléchargement
  • Github
  • Runbot
  • Traductions
Services
  • Hébergement Odoo.sh
  • Assistance
  • Migration
  • Développements personnalisés
  • Éducation
  • Trouver un comptable
  • Trouver un partenaire
  • Devenez partenaire
À propos
  • Notre société
  • Actifs de la marque
  • Contactez-nous
  • Emplois
  • Événements
  • Podcast
  • Blog
  • Clients
  • Informations légales • Confidentialité
  • Sécurité.
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo est une suite d'applications open source couvrant tous les besoins de votre entreprise : CRM, eCommerce, Comptabilité, Inventaire, Point de Vente, Gestion de Projet, etc.

Le positionnement unique d'Odoo est d'être à la fois très facile à utiliser et totalement intégré.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now