コンテンツへスキップ
メニュー
この質問にフラグが付けられました
1 返信
6832 ビュー

I have problem is, i can't add function for my custom button to print reciept in POS

Here my js code: 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 Widget = require('web.Widget');

var ajax = require('web.ajax');

var qweb = core.qweb;
ajax.loadXML('/POS/static/src/xml/custom_pos.xml', qweb);
});


And here is my POS/static/src/xml/custom_pos.xml:


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

<t t-name="PaymentScreenWidget" t-extend="PaymentScreenWidget">
<t t-jquery='.payment-buttons' t-operation='append'>
<span class="control-button">
<i class="fa fa-print"></i>
Custom Button
</span>
</t>
</t>
</templates >

And here my xml in views


<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="demo_example_ext_js" name="Demo Example Ext Js" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/POS/static/src/js/pos.js"></script>
</xpath>
</template>
</odoo>

How can i add function print reciept for my custom button, just like "Print Reciept" have already in POS when you click Validate Button?

アバター
破棄
最善の回答

Hi,

You can load XML from  __manifest__.py file

'qweb': ['static/src/xml/*.xml'],


then, custom_pos.xml


<?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>
</templates>

load JS :-
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/POS/static/src/js/pos_test.js"/>
</xpath>
</template>
</data>
</odoo>

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 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(){
var order = this.pos.get_order();
console.log("order")
// Render receipt screen and can print function

}
});

});

Thanks
アバター
破棄
著作者

Hi Niyas,

If my custom_pos.xml update like exaclty what you say, my custom button didnt show.

著作者

Hi Niyas,

I solve that problem, can you spend a little time to help me about this?

著作者

My custom button will have exactly what "Print Receipt" button do ( in Validate screens ). So that, Can I write js code the same with that "Print Receipt" button?

関連投稿 返信 ビュー 活動
9
6月 23
12857
2
1月 22
3717
2
12月 21
7650
0
6月 21
1811
0
2月 21
2394