我需要覆盖Javascript方法,并严格要求此方法:
有人可以解释我该怎么做吗?
答案 0 :(得分:3)
要通过添加创建新模块来覆盖javascript
方法,请按照以下步骤操作:
在your_js_file_name.js
文件夹中创建一个static/src/js
,并将其添加到assets_backend
模板中。
<template id="assets_backend" name="hr assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/folder_name/static/src/js/your_js_file_name.js"></script>
</xpath>
</template>
在your_js_file_name.js
文件中定义一个新模块,就像在account
模块中一样,可以使用相同的名称,但请确保它以文件夹名称(technical name
您的module
,例如account, sale, product...etc
):
// just for debugin when you log in Odoo you should see this message
// if you don't see it this means that the js file is not loaded yet
// you need to make sure you upgrade the module the xml file that extend the assets_backed is in the manifest.
console.log('my ReconciliationRenderer is loaded);
odoo.define('folder_name.ReconciliationRenderer', function (require) {
"use strict";
var ReconciliationRenderer = require('account.ReconciliationRenderer');
// you need to require any thing is used inside the code of the method too
var qweb = core.qweb; // like Qweb
// override the method update of LineRenderer class
ReconciliationRenderer.LineRenderer.include({
update: function (state) {
// you can call the original method using this
this._super(state);
}
});
});
对于大多数Javascript
方法,应该这样做。希望这能给您和您应该做什么的想法