i want to override a ReceiptScreen method from point_of_sale module.
var ReceiptScreenWidget = ScreenWidget.extend...
gui.define_screen({name:'receipt', widget: ReceiptScreenWidget});
In order to do this, i've created my own module but i don't know what steps follow to change the ReceiptScreenWidget.print() function.
Here is the screens.js that contains the Widget.Function that i want to override. (search for: ReceiptScreenWidget)
I tried to follow this example but the code is from Odoo 8 or 9 so i couldn't make it work.
*Odoo version: 10
JS
odoo.define('your_module_name.filename', function (require) {
"use strict";
var gui = require('point_of_sale.gui');
var screens = require('point_of_sale.screens');
var core = require('web.core');
var QWeb = core.qweb;
var _t = core._t;
screens.ReceiptScreenWidget.include({
print: function() {
// Your code
},
});
});
XML to add JS
<?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="/your_module_name/static/js/filename.js"></script>
</xpath>
</template>
</odoo>
Add that xml in __manifest__.py
{
...
...
'data': [
...
'views/above_xml_filename.xml',
],
....
}
Related
How in custom module change text 'Add an item' to 'Add new row"?
Any simple solution?
Hello Pointer,
Using odoo 8
Try this below code,
your_module_name/view/custome_file_include.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!-- Include External/Custom/Own JS File. And Order Maintain. -->
<script type="text/javascript" src="/your_module_name/static/src/js/custome_file_include.js"></script>
<script type="text/javascript" src="/your_module_name/static/src/js/custome_view_form.js"></script>
</xpath>
</template>
</data>
</openerp>
your_module_name/src/js/custome_file_include.js
openerp.fm_sale_order_ext_ept = function(instance) {
change_tree_view_add_item_name(instance);
}
your_module_name/src/js/custome_view_form.js
function change_tree_view_add_item_name(instance) {
instance.web.form.AddAnItemList.include({
pad_table_to: function (count) {
if (!this.view.is_action_enabled('create') || this.is_readonly()) {
this._super(count);
return;
}
this._super(count > 0 ? count - 1 : 0);
var self = this;
var columns = _(this.columns).filter(function (column) {
return column.invisible !== '1';
}).length;
if (this.options.selectable) { columns++; }
if (this.options.deletable) { columns++; }
var $cell = $('<td>', {
colspan: columns,
'class': this._add_row_class || ''
}).html(
$('<a>', {href: '#'}).text(_t("Add new row"))
.mousedown(function () {
// FIXME: needs to be an official API somehow
if (self.view.editor.is_editing()) {
self.view.__ignore_blur = true;
}
})
.click(function (e) {
e.preventDefault();
e.stopPropagation();
// FIXME: there should also be an API for that one
if (self.view.editor.form.__blur_timeout) {
clearTimeout(self.view.editor.form.__blur_timeout);
self.view.editor.form.__blur_timeout = false;
}
self.view.ensure_saved().done(function () {
self.view.do_add_record();
});
}));
var $padding = this.$current.find('tr:not([data-id]):first');
var $newrow = $('<tr>').append($cell);
if ($padding.length) {
$padding.replaceWith($newrow);
} else {
this.$current.replaceWith($newrow)
}
}
});
}
Using odoo9
First we create new module and given below is file structure of new module.
Module_Name
static
src
js
File_Name.js
views
File_Name.xml
__openerp__.py
Module_Name->views->File_Name.xml
Now we add the custome js in base odoo 9 module so we are create xml file and inherit base file and add our custome js,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="assets_backend" name="account assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<!-- Include External/Custom/Own JS File. And Order Maintain. -->
<script type="text/javascript" src="/Module_Name/static/src/js/File_Name.js"></script>
</xpath>
</template>
</data>
</openerp>
Module_Name->static->src->js->File_Name.js
Now we are inherit base form_relation_widget.js js and modify this method,
odoo.define('Module_Name.File_Name', function (require) {
"use strict";
var core = require('web.core');
var ListView = require('web.ListView');
var _t = core._t;
var _lt = core._lt;
// Include "web.form_relational"
var form_relational = require('web.form_relational');
// Include X2ManyList Functionality and Modify X2ManyList Functionality
var form_relational = form_relational.X2ManyList.include({
pad_table_to: function (count) {
if (!this.view.is_action_enabled('create') || this.view.x2m.get('effective_readonly')) {
this._super(count);
return;
}
this._super(count > 0 ? count - 1 : 0);
var self = this;
var columns = _(this.columns).filter(function (column) {
return column.invisible !== '1';
}).length;
if (this.options.selectable) { columns++; }
if (this.options.deletable) { columns++; }
var $cell = $('<td>', {
colspan: columns,
'class': 'oe_form_field_x2many_list_row_add'
}).append(
$('<a>', {href: '#'}).text(_t("Add new row"))
.click(function (e) {
e.preventDefault();
e.stopPropagation();
// FIXME: there should also be an API for that one
if (self.view.editor.form.__blur_timeout) {
clearTimeout(self.view.editor.form.__blur_timeout);
self.view.editor.form.__blur_timeout = false;
}
self.view.save_edition().done(function () {
self.view.do_add_record();
});
}));
var $padding = this.$current.find('tr:not([data-id]):first');
var $newrow = $('<tr>').append($cell);
if ($padding.length) {
$padding.replaceWith($newrow);
} else {
this.$current.replaceWith($newrow);
}
},
});
});
Module_Name->openerp.py
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Module Name',
'version': '1.0',
'category': '',
'sequence': 1,
'summary': '',
'description': """ Give the Description of Module """,
'website': '',
'depends': ['web'],
'data': [
'views/File_Name.xml'
],
'demo': [],
'css': [],
'js' : [],
'installable': True,
'auto_install': False,
'application': True,
}
odoo_v9->web->static->src->js->views->form_relation_widget.js
Add X2ManyList : X2ManyList this line in base js (odoo9 module) form_relation_widget.js
return {
FieldMany2ManyTags: FieldMany2ManyTags,
AbstractManyField: AbstractManyField,
X2ManyList : X2ManyList, ////Add this line in this file
};
I hope my answer is helpful.
If any query so comment please.
An option could be that you enter on debug mode.
Then, go to Configuration -> Application Terms -> Synchronize Terms. In the dropdown Language, select English and wait until finish.
Go to Translated Terms, in the search field write "Add an item" and replace the text that is in Translation Value column.
It's worth say, this change will stored in the DB and all one2many relations will be affected.
This string is provided by JavaScript code. So you have to extend the js widget to change the name.
I need override in below function ASC to DESC
render: function (messages, options) {
clearTimeout(this.auto_render_timeout);
var self = this;
var msgs = _.map(messages, this._preprocess_message.bind(this));
if (this.options.display_order === ORDER.ASC) {
msgs.reverse();
}
Source code: https://postimg.org/image/9mxw6ksy7/67729f63/
You need to replace the function and then call _super(). Include your method in the class which implements this function. A similar question is posted HERE with a specific implementation which has been tested. My below example has not been tested fully. Remember to install your addon and update it to see your changes.
}
'name': "asc_desc",
'summary': """
Short (1 phrase/line) summary of the module's purpose, used as
subtitle on modules listing or apps.openerp.com""",
'description': """
Long description of module's purpose
""",
'author': "My Company",
'website': "http://www.yourcompany.com",
# Categories can be used to filter modules in modules listing
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list
'category': 'Uncategorized',
'version': '0.1',
# any module necessary for this one to work correctly
'depends': ['base'],
# always loaded
'data': [
# 'security/ir.model.access.csv',
'views.xml',
'templates.xml',
'javascript_import.xml',
],
# only loaded in demonstration mode
'demo': [
'demo.xml',
],
}
javascript_import.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<template id="assets_backend_asc_desc" name="assets_backend_asc_desc" inherit_id="web.assets_backend">
<xpath expr="script[last()]" position="after">
<script type="text/javascript" src="/asc_desc/static/src/js/asc.js"></script>
</xpath>
</template>
</data>
</openerp>
asc.js
odoo.define('asc_desc.ChatThread', function(require){
"use strict"
var core = require('web.core');
var QWeb = core.qweb;
var thread = require('mail.ChatThread');
var ORDER = {
DESC: -1,
ASC: 1,
}
thread.include({
render: function (messages, options) {
console.log("TEST");
var msgs = _.map(messages, this._preprocess_message.bind(this));
if (this.options.display_order === ORDER.DESC) {
msgs.reverse();
}
options = _.extend({}, this.options, options);
// Hide avatar and info of a message if that message and the previous
// one are both comments wrote by the same author at the same minute
var prev_msg;
_.each(msgs, function (msg) {
if (!prev_msg || (Math.abs(msg.date.diff(prev_msg.date)) > 60000) || prev_msg.message_type !== 'comment' || msg.message_type !== 'comment' || (prev_msg.author_id[0] !== msg.author_id[0])) {
msg.display_author = true;
} else {
msg.display_author = !options.squash_close_messages;
}
prev_msg = msg;
});
this.$el.html(QWeb.render('mail.ChatThread', {
messages: msgs,
options: options,
ORDER: ORDER,
}));
},
});
});
Ensure you include the file declaring your js in your __openerp__.py file.
In my Yii web application, Google chart is not working. I am getting all values by renderpartial method. But, the pie chart is not displayed.
My code is,
<div class="content">
<div id="graph" style="width:300px;height:300px ">
</div>
</div>
<script type="text/javascript" src="https://www.google.com/jsapi">
// Load the Visualization API and the piechart package.
google.load("visualization", "1", { packages: ["corechart"] });
// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(createPIE);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function createPIE() {
var options = {
title: 'Fees Allocation',
colors: ['#888', 'orange','red'],
is3D: true
};
// Create our data table.
var data = google.visualization.arrayToDataTable([
['Total Amount', <?php echo $amount;?>],
['Collected', <?php echo $collected;?>],
['Due', <?php echo $due;?>]]);
var chart = new google.visualization.PieChart(document.getElementById('graph'));
chart.draw(data, options);
}
</script>
Please help me.
There are few mistakes in your code please try below code
<?php
$amount = 20;
$collected = 50;
$due = 30;
?>
<div class="content">
<div id="graph" style="width:300px;height:300px">
</div>
</div>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
// Load the Visualization API and the piechart package.
google.charts.load("current", { packages: ["corechart"] });
// Set a callback to run when the Google Visualization API is loaded.
google.charts.setOnLoadCallback(createPIE);
// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function createPIE() {
var options = {
title: 'Fees Allocation',
colors: ['#888', 'orange','red'],
is3D: true
};
// Create our data table.
var data = google.visualization.arrayToDataTable([
['status', 'Amount'],
['Total Amount', <?php echo $amount;?>],
['Collected', <?php echo $collected;?>],
['Due', <?php echo $due;?>]]);
var chart = new google.visualization.PieChart(document.getElementById('graph'));
chart.draw(data, options);
}
</script>
Checkout this fiddle : https://jsfiddle.net/xoevL26z/
How do I enable live suggestions with reading from my odata Service for a single cell in my table?
oTable.addColumn(new sap.ui.table.Column({
template : new sap.m.Input({
value : column, // also works, its dynamic
textAlign : sap.ui.core.TextAlign.Center,
inputType : Text,
type : sap.m.InputType.Text,
showSuggestion : true,
liveChange : function() {
if (this.getValue().length > 0) {
var oModel = new sap.ui.model.json.JSONModel();
var value = this.getValue();
var serviceUrl = "/sap/opu/odata/SAP/XXXX_SRV/SuggestionsSet/?$filter=startswith(Key,'" + value + "')";
oModel.loadData(serviceUrl, null, false, "GET", false, false, null);
this.destroySuggestionItems();
for (var i = 0; i < oModel.oData.d.results.length; i++) {
this.addSuggestionItem(new sap.ui.core.Item({
text: oModel.oData.d.results[i].Key,
}));
} // everything seems fine, but no Suggestion opens..
}
},
}),
visible : true,
}));
See the explored example.
However, in your case the model is an ODataModel, but that does not really matter...
As you can see in the examples's code you can also use
showSuggestion="true"
suggest="handleSuggest"
suggestionItems="{/ProductCollection}"
In the handler you then do this (copied from the example as well):
handleSuggest: function(oEvent) {
var sTerm = oEvent.getParameter("suggestValue");
var aFilters = [];
if (sTerm) {
aFilters.push(new Filter("Name", sap.ui.model.FilterOperator.StartsWith, sTerm));
}
oEvent.getSource().getBinding("suggestionItems").filter(aFilters);
}
Basically you
- create one or more filters
- get the binding for the suggestionItems aggregation
- call .filter(...) on the binding and pass the filter(s)
There is no need to code that stuff manually (i.e. GET request etc.).
Here is a runninh example for you (run via jsbin), see below.
In your case all you do is bind to
suggestionItems="{path:'/SuggestionSet', templateShareable:false}">
In the handleSuggest handler you would then get the the value for the Key property of the SuggestionSet that belongs to current/corresponding input field in order to instantiate a new Filter. You could get the Key from the BindingContext I guess...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SAPUI5 single file template | nabisoft</title>
<script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-theme="sap_bluecrystal"
data-sap-ui-libs="sap.m"
data-sap-ui-bindingSyntax="complex"
data-sap-ui-compatVersion="edge"
data-sap-ui-preload="async"></script>
<!-- use "sync" or change the code below if you have issues -->
<!-- XMLView -->
<script id="myXmlView" type="ui5/xmlview">
<mvc:View
controllerName="MyController"
xmlns="sap.m"
xmlns:core="sap.ui.core"
xmlns:mvc="sap.ui.core.mvc">
<Table
id="myTable"
growing="true"
growingThreshold="10"
growingScrollToLoad="true"
busyIndicatorDelay="0">
<columns>
<Column>
<Text text="Customer ID"/>
</Column>
<Column>
<Text text="Company Name"/>
</Column>
</columns>
<items>
<!-- filled via bindItems() in controller -->
</items>
</Table>
</mvc:View>
</script>
<!-- XML Fragment -->
<script id="myXMLFragment" type="ui5/fragment">
<core:FragmentDefinition
xmlns="sap.m"
xmlns:core="sap.ui.core">
<ColumnListItem type="Active">
<cells>
<ObjectIdentifier title="{CustomerID}"/>
<Input
value="{CompanyName}"
showSuggestion="true"
suggest="handleSuggest"
suggestionItems="{path:'/Customers', templateShareable:false}">
<suggestionItems>
<core:Item text="{CompanyName}" />
</suggestionItems>
</Input>
</cells>
</ColumnListItem>
</core:FragmentDefinition>
</script>
<script>
sap.ui.getCore().attachInit(function () {
"use strict";
//### Controller ###
sap.ui.controller("MyController", {
onInit : function () {
this.getView().setModel(
new sap.ui.model.odata.v2.ODataModel("https://cors-anywhere.herokuapp.com/services.odata.org/V2/Northwind/Northwind.svc/", {
json : true,
useBatch : false
})
);
var sPath = "/Customers";
var oTable = this.byId("myTable");
var oTemplate = sap.ui.xmlfragment({
fragmentContent : jQuery("#myXMLFragment").html()
});
oTable.bindItems(sPath, oTemplate, null /*oSorter*/, null /*aFilters*/);
},
handleSuggest: function(oEvent) {
var sTerm = oEvent.getParameter("suggestValue");
var aFilters = [];
if (sTerm) {
aFilters.push(new Filter("CompanyName", sap.ui.model.FilterOperator.StartsWith, sTerm));
}
oEvent.getSource().getBinding("suggestionItems").filter(aFilters);
}
});
//### THE APP: place the XMLView somewhere into DOM ###
sap.ui.xmlview({
viewContent : jQuery("#myXmlView").html()
}).placeAt("content");
});
</script>
</head>
<body class="sapUiBody">
<div id="content"></div>
</body>
</html>
I need to make some customizations in the PoS module in Odoo 8.
For this i have created a module call "cus_pos". With this code i extended the interface:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-extend="PosWidget">
<t t-jquery="div.pos-leftpane > div.window > div:last" t-operation="after">
<div class="payment-lines">
<div class="paymentline selected">
<!-- trigger an error <t t-esc="widget.get_list_salespersons()" /> -->
<div class="paymentline-name"> Salesperson: </div>
<select id="salesperson-select" class="paymentline-input">
</select>
</div>
</div>
</t>
</t>
</templates>
But when i try to extend the widget "PosWidget", to add a method to populate the select "salesperson-select", i get this error "Error: QWeb2 - template['PosWidget']: Runtime Error: TypeError: dict.widget.get_list_salespersons is not a function".
To extend the "PosWidget" i had tried this strategies:
One:
openerp.cus_pos = function(instance) {
template: 'PosWidget',
var module = instance.point_of_sale;
module.PosWidget = module.PosWidget.extend({
get_list_salespersons: function() {
console.log("Hurray!!!");
}
});
}
Two:
function openerp_pos_salesperson(instance, module) { //module is instance.point_of_sale
var module = instance.point_of_sale;
var QWeb = instance.web.qweb;
_t = instance.web._t;
module.SalePersonWidget = module.PosWidget.include({
template: 'PosWidget',
get_list_salespersons: function() {
console.log("Hurray!!!");
}
});
}
Three:
function openerp_pos_saleperson(instance, module) { //module is instance.point_of_sale
var module = instance.point_of_sale;
var QWeb = instance.web.qweb;
_t = instance.web._t;
module.SalePersonWidget = module.PosWidget.include({
template: 'PosWidget',
get_list_salespersons: function() {
console.log("Hurray!!!");
}
});
}
(function() {
var _super = window.openerp.point_of_sale;
window.openerp.point_of_sale = function(instance) {
_super(instance);
var module = instance.point_of_sale;
openerp_pos_vendedor(instance,module);
}
})();
Four:
openerp.cus_pos = function(instance) {
var module = instance.point_of_sale;
var _super_ = module.PosWidget.prototype.get_list_salespersons;
module.PosWidget.prototype.get_list_salespersons = function() {
console.log("Hurray!!!");
_super_.call(this);
};
};
Searching for some documentation i found http://thierry-godin.developpez.com/openerp/tutorial-module-creation-pos-modification-english-version/#LI but is outdated.
Any help on my question would be a great help. Many Thanks
Yes Thierry Godin wrote things about V7, but a lot of things are obsolete now in V8.
you should check new V8 modules in OCA on gitHub / OCA / POS
You can too take a look on the Odoo Forum.
After that, if you're still blocked I can check your problem.
There is 2 ways to overload existing Odoo POS :
https://github.com/OCA/pos/blob/8.0/pos_product_template/static/src/js/ppt.js#L74
https://github.com/OCA/pos/blob/8.0/pos_product_template/static/src/js/ppt.js#L109
(It depends of the kind of objects.)
BTW, what is the objective of your module ?
Kind regards.