[MIG] account_financial_report: Migration to 16.0

This commit is contained in:
David Ramia
2022-12-20 14:25:50 +01:00
committed by chaule97
parent 0e20eeb133
commit 4de4c3d2b1
23 changed files with 289 additions and 318 deletions

View File

@@ -1,3 +1,6 @@
a {
color: #00337b;
}
.act_as_table {
display: table !important;
background-color: white;

View File

@@ -1,37 +0,0 @@
// Method is available here https://github.com/odoo/odoo/blob/15.0/addons/web/static/src/webclient/actions/action_service.js#L981
// TO DO: Check for implement this action inherit
// odoo.define("account_financial_report.ReportActionManager", function (require) {
// "use strict";
//
// const ActionManager = require("web.ActionManager");
// require("web.ReportActionManager");
//
// ActionManager.include({
// /**
// * @override
// */
// _executeReportClientAction: function (action, options) {
// const MODULE_NAME = "account_financial_report";
//
// // When 'report_action' is called from the backend, Odoo hardcodes the action tag.
// // We have to make a hack to use our own report controller.
// if (action.report_name.startsWith(`${MODULE_NAME}.`)) {
// const urls = this._makeReportUrls(action);
// const clientActionOptions = _.extend({}, options, {
// context: action.context,
// data: action.data,
// display_name: action.display_name,
// name: action.name,
// report_file: action.report_file,
// report_name: action.report_name,
// report_url: urls.html,
// });
// return this.doAction(
// "account_financial_report.client_action",
// clientActionOptions
// );
// }
// return this._super.apply(this, arguments);
// },
// });
// });

View File

@@ -1,58 +0,0 @@
odoo.define("account_financial_report.client_action", function (require) {
"use strict";
var ReportAction = require("report.client_action");
var core = require("web.core");
var QWeb = core.qweb;
const AFRReportAction = ReportAction.extend({
start: function () {
return this._super.apply(this, arguments).then(() => {
this.$buttons = $(
QWeb.render(
"account_financial_report.client_action.ControlButtons",
{}
)
);
this.$buttons.on("click", ".o_report_print", this.on_click_print);
this.$buttons.on("click", ".o_report_export", this.on_click_export);
this.controlPanelProps.cp_content = {
$buttons: this.$buttons,
};
this._controlPanelWrapper.update(this.controlPanelProps);
});
},
on_click_export: function () {
const action = {
type: "ir.actions.report",
report_type: "xlsx",
report_name: this._get_xlsx_name(this.report_name),
report_file: this._get_xlsx_name(this.report_file),
data: this.data,
context: this.context,
display_name: this.title,
};
return this.do_action(action);
},
/**
* @param {String} str
* @returns {String}
*/
_get_xlsx_name: function (str) {
if (!_.isString(str)) {
return str;
}
const parts = str.split(".");
return `a_f_r.report_${parts[parts.length - 1]}_xlsx`;
},
});
core.action_registry.add("account_financial_report.client_action", AFRReportAction);
return AFRReportAction;
});

View File

@@ -0,0 +1,38 @@
/** @odoo-module **/
import {ReportAction} from "@web/webclient/actions/reports/report_action";
import {patch} from "web.utils";
const MODULE_NAME = "account_financial_report";
patch(ReportAction.prototype, "account_financial_report.ReportAction", {
setup() {
this._super.apply(this, arguments);
this.isAccountFinancialReport = this.props.report_name.startsWith(
`${MODULE_NAME}.`
);
},
export() {
this.action.doAction({
type: "ir.actions.report",
report_type: "xlsx",
report_name: this._get_xlsx_name(this.props.report_name),
report_file: this._get_xlsx_name(this.props.report_file),
data: this.props.data || {},
context: this.props.context || {},
display_name: this.title,
});
},
/**
* @param {String} str
* @returns {String}
*/
_get_xlsx_name(str) {
if (!_.isString(str)) {
return str;
}
const parts = str.split(".");
return `a_f_r.report_${parts[parts.length - 1]}_xlsx`;
},
});

View File

@@ -1,17 +1,19 @@
<template>
<!-- Buttons of the Control Panel -->
<t t-name="account_financial_report.client_action.ControlButtons">
<div class="o_report_buttons">
<t
t-name="info.ReportAction"
t-inherit="web.ReportAction"
t-inherit-mode="extension"
owl="1"
>
<xpath expr="//button" position="after">
<button
t-if="isAccountFinancialReport"
t-on-click="export"
type="button"
class="btn btn-primary o_report_print"
title="Print"
>Print</button>
<button
type="button"
class="btn btn-secondary o_report_export"
class="btn btn-secondary"
title="Export"
>Export</button>
</div>
</xpath>
</t>
</template>