I am very new to Odoo and I am trying to add a simple button to the POS left pane by creating a custom module that extends POS. I have tried several code samples I found on the internet but nothing is working.
I have Odoo 11.0 installed on C:\Program Files (x86)\Odoo 11.0. I created a custome module (rpos) using the scaffold command in C:\User\[username]\Odoo\rpos
Here is my code.
views/templates.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets_backend" name="rpos assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/rpos/static/src/js/rpos.js"></script>
</xpath>
</template>
</odoo>
static/src/js/rpos.js
odoo.rpos = function(instance) {
var module = instance.point_of_sale;
var qweb = instance.web.qweb;
console.log("TEST");
module.PosWidget.include({
build_widgets: function(){
var self = this;
this._super();
cheeseBtn = $qweb.render('cheeseBtn'));
cheeseBtn.appendTo(this.$('.control-buttons'));
this.$('.control-buttons').removeClass('oe_hidden');
}
});
};
static/src/xml/templates.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="cheeseBtn">
<button>Cheese</button>
</t>
</templates>
I am not even sure if my code is being loaded when I run the POS app.
Thanks
/custom-button/manifest.py
{
'name': 'CustomButton',
'summary': '',
'version': '1.0',
'description': """
""",
# 'author': '',
# 'maintainer': '',
# 'contributors': [''],
# 'website': '',
'license': 'AGPL-3',
'category': 'Uncategorized',
'depends': [
'base', 'point_of_sale',
],
'external_dependencies': {
'python': [
],
},
'data': [
'views/templates.xml',
],
'demo': [
],
'js': [
],
'css': [
],
'qweb': [
'static/src/xml/custom_button.xml',
],
'images': [
],
'test': [
],
'installable': True
}
/custom-button/views/templates.xml
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="assets" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/custom-button/static/src/js/custom.js"></script>
</xpath>
</template>
</odoo>
/custom-button/static/src/xml/custom_button.xml
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="CustomButton">
<span class="control-button">
<i class="fa fa-print"></i>
Custom Button
</span>
</t>
</templates>
/custom-button/static/src/js/custom.js
odoo.define('custom-button.custom_button', function (require) {
"use strict";
var core = require('web.core');
var screens = require('point_of_sale.screens');
var gui = require('point_of_sale.gui');
//Custom Code
var CustomButton = screens.ActionButtonWidget.extend({
template: 'CustomButton',
button_click: function(){
var self = this;
self.custom_function();
},
custom_function: function(){
console.log('Hi I am button click of CustomButton');
}
});
screens.define_action_button({
'name': 'custom_button',
'widget': CustomButton,
});
});
screenshot of the custom button in POS screen
https://github.com/minaeid90/Custom-Button
@Mina : Thanks a lot.Your GitHub code is working perfectly.