Ir al contenido
Menú
Se marcó esta pregunta
2 Respuestas
6030 Vistas

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
Descartar

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?

Mejor respuesta

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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
9
jun 23
13118
2
ene 22
3895
2
dic 21
7921
0
jun 21
1963
0
feb 21
2586