跳至内容
菜单
此问题已终结
2 回复
5241 查看

I already do the button appears, but I would like it to appear only in my module, can anyone help me?

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-extend="ListView.buttons">
<t t-jquery="button.o_list_button_add" t-operation="after">
<t t-esc="doc_model"/>
<t t-if="doc_model in ['manifestation.recipient']">
<button class="btn btn-default btn_import_nfe" type="button">Importar Notas Sefaz</button>
</t>
</t>
</t>
</templates>
形象
丢弃
最佳答案

Alright, so if you made the button appear, I am assuming you create the .xml file and imported it on your qweb list of your module's manifest.

Next, you need to create the .js function that will call the function you want.

That's an example I have:

odoo.define('sale.order', function (require) {
"use strict";

var Model = require("web.rpc");
var ListController = require('web.ListController');

ListController.include({

renderButtons: function () {
this._super.apply(this, arguments);
if (this.$buttons) {
let importButton = this.$buttons.find(".oe_import_last_sales");
importButton && importButton.click(this.proxy("importLastSalesAction"));
}
},

importLastSalesAction: function () {
//implement your click logic here
Model.query({
model: "res.company",
method: "cron_sale",
args: [{}]
}).then(function (data) {
});
}

});
});


Where ".oe_import_last_sales" is the class I added to the qweb button. In your case I guess it will be be ".btn_import_nfe". Then, on my example, the "importLastSalesAction" function calls the method cron_sale, defined under the "res.company" module.

You JS code isn't known by Odoo yet, so next you have got to import it. That can be done by creating another .xml file with the following content:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="assets_backend" name="product_template assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<script type="text/javascript" src="/vtex_connector/static/src/js/import_last_sales.js"></script>
</xpath>
</template>
</data>
</odoo>

Where the src prorperty on the script tag is the path of your .js

You then have to import the .xml file on your manifest data list, upgrade your module and everything should be working.

Boa sorte!

形象
丢弃
编写者 最佳答案


形象
丢弃
相关帖文 回复 查看 活动
1
2月 21
3502
0
6月 20
2329
0
5月 22
3134
1
3月 22
13119
5
3月 20
3492