Skip to content

Instantly share code, notes, and snippets.

@tong-odoo
Last active March 13, 2022 09:32
Show Gist options
  • Save tong-odoo/271b8f4d28b9a0f34814695155d19739 to your computer and use it in GitHub Desktop.
Save tong-odoo/271b8f4d28b9a0f34814695155d19739 to your computer and use it in GitHub Desktop.
Create js button and call odoo actions
odoo.define("manila_healthtek_stock_quant_report.InventoryReportListController", function (require) {
"use strict";
var core = require("web.core");
const InventoryReportListController = require("stock.InventoryReportListController");
var qweb = core.qweb;
const InventoryBookReportListController = InventoryReportListController.include({
renderButtons: function ($node) {
this._super.apply(this, arguments);
var $buttonPrint = $(qweb.render("InventoryReport.PrintButtons"));
$buttonPrint.css("margin-right", "3px");
$buttonPrint.on("click", this._onPrintInventoryBook.bind(this));
this.$buttons.prepend($buttonPrint);
},
_onPrintInventoryBook: function () {
const self = this;
this._rpc({
model: "stock.quant",
method: "print_pdf",
args: [[]],
}).then(function (res) {
const reportname = `${res.report_name}?docids=${res.data.join(
","
)}&report_type=qweb-pdf&model_name=stock.quant`;
const action = {
type: "ir.actions.report",
report_type: "qweb-pdf",
report_name: reportname,
report_file: res.report_file,
};
self.do_action(action);
});
},
});
return InventoryBookReportListController;
});
<?xml version="1.0" encoding="utf-8" ?>
<templates id="template" xml:space="preserve">
<button t-name="InventoryReport.PrintButtons" class="btn btn-primary" type="button">Print Inventory Book</button>
</templates>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment