Skip to Content
Menu
This question has been flagged
2 Replies
5393 Views

I have this XML file for my custom button in POS


<?xml version="1.0" encoding="utf-8"?>
<templates id="template" xml:space="preserve">

<t t-extend="PaymentScreenWidget">
<t t-jquery=".payment-buttons" t-operation="append">
<div class='button js_custom_print'>
<i class='fa fa-print' /> Custom Print
</div>
</t>
</t>
</templates>

And js file is in POS/static/src/js/pos.js


odoo.define('POS.pos', function (require) {
'use strict';

var models = require('point_of_sale.models');
var core = require('web.core');
var screens = require('point_of_sale.screens');
var Widget = require('web.Widget');
var ajax = require('web.ajax');
var qweb = core.qweb;
var PrintBillButtonTicket = screens.ActionButtonWidget.extend({
template: 'PaymentScreenWidget',
print_xml: function(){
var order = this.pos.get('selectedOrder');
if(order.get_orderlines().length > 0){
var receipt = order.export_for_printing();
receipt.bill = true;
this.$('.pos-receipt-container').html(QWeb.render('PosTicket',{
widget:this,
order: order,
receipt: order.export_for_printing(),
orderlines: order.get_orderlines(),
paymentlines: order.get_paymentlines(),
}));
}
},
button_click: function(){

this.print_xml();

},
});
screens.define_action_button({
'name': 'print_billticket',
'widget': PaymentScreenWidget,

});
});

I have error that some module could not be started POS.pos? How can i fixed this to run my function print_xml for my custom button

Avatar
Discard

Show the error log, and the external id you are inheriting. Are you inheriting point_of_sale.assets (<template id="assets" inherit_id="point_of_sale.assets">) to include your js file?

Best Answer

Hi,

I think you are trying to print pos receipt before validating pos order.

(Action button widget is used for adding buttons above numbpad and actionpad widget. You are trying to add payment screen itself in the place of actionpad button.)

Please correct your code like below:

xml file:

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="PaymentScreenWidget">
<t t-jquery="t[t-if='widget.pos.config.module_account']" t-operation="after">
<div class='button js_custom_print'>
<i class='fa fa-print' /> Custom Print
</div>
</t>
</t>

<t t-name="PrintReceiptScreenWidget" t-extend="ReceiptScreenWidget">
<t t-jquery="div.top-content" t-operation="inner">
<span class='button back'>
<i class='fa fa-angle-double-left'></i>
Back
</span>
</t>
</t>
</templates>

js file:

odoo.define('POS.pos', function (require) {
'use strict';

var models = require('point_of_sale.models');
var core = require('web.core');
var screens = require('point_of_sale.screens');
var Widget = require('web.Widget');
var gui = require('point_of_sale.gui');
var ajax = require('web.ajax');

var qweb = core.qweb;

screens.PaymentScreenWidget.include({
renderElement: function() {
var self = this;
this._super();
this.$('.js_custom_print').click(function(){
self.click_custom_print();
});
},
click_custom_print: function(){
this.gui.show_screen('print_receipt');
}
});

var PrintReceiptScreenWidget = screens.ReceiptScreenWidget.extend({
template: 'PrintReceiptScreenWidget',
click_back: function(){
this.gui.show_screen('payment');
},

});
gui.define_screen({name:'print_receipt', widget: PrintReceiptScreenWidget});

});


Thanks

Avatar
Discard
Related Posts Replies Views Activity
9
Jun 23
11126
2
Jan 22
2729
2
Dec 21
6265
0
Jun 21
1005
0
Feb 21
1538