Help

2

Overriding javascript function does nothing

Avatar
Andrzej

By default Odoo is showing always at least 4 rows with the tree view. As described in this topic:
\https://stackoverflow.com/questions/46468472/tree-view-showing-extra-empty-fields

​I would like to decrease this value to one or two rows. But my custom module changes nothing.

I have this js file odoo\addons\custom_theme\static\src\js\views\list\list_renderer.js:

odoo.define('custom_theme.custom_table_rows', function (require){
"use strict";

//require the module to modify:
var ListRenderer = require(website_sale_delivery.ListRenderer);

//override the method:
ListRenderer.include({
_renderBody: function () {
var $rows = this._renderRows();
while ($rows.length < 1) {
$rows.push(this._renderEmptyRow());
}
return $('<tbody>').append($rows);
}
});
});

And I called it inside xml odoo\addons\custom_theme\views\header.xml:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="Custom_header_theme" inherit_id="web.assets_backend">
<xpath expr=".">
    <script type="text/javascript" src="/custom_theme/static/src/js/views/list/list_renderer.js"></script>
</xpath>
</template>
</data>
</odoo>

Also xml file called inside manifest:

'data': [
# 'security/ir.model.access.csv',
'views/views.xml',
'views/templates.xml',
'views/header.xml',
],

And it does nothing. When I instead modify the js file directly inside source code ("odoo/addons/web/static/src/js/views/list/list_renderer.js") it is working and less rows are appearing. Module as a whole is working because it performs other modifications.

What is wrong?

Avatar
Discard
1 Answer
1
Avatar
Ravi Gadhia
Best Answer

It seems import is wrong

write

var ListRenderer = require('web.ListRenderer');​

instead of 

var ListRenderer = require(website_sale_delivery.ListRenderer);
3 Comments
Avatar
Discard
Avatar
Andrzej
-

Ohh, you are right. I changed it but sadly it still does not work.

Avatar
Ravi Gadhia
-

is there in error in the browser console?

Avatar
Andrzej
-

It is

Failed modules:

"custom_theme.custom_table_rows"

error: ReferenceError: "web is not defined"