Skip to Content
Menu
This question has been flagged
2 Replies
4588 Views

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>
Avatar
Discard
Best Answer

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!

Avatar
Discard
Author Best Answer


Avatar
Discard
Related Posts Replies Views Activity
1
Feb 21
2798
0
Jun 20
1582
0
May 22
2015
1
Mar 22
11725
5
Mar 20
2756