OCA-git-bot
4 years ago
19 changed files with 805 additions and 1143 deletions
-
1account_financial_report/README.rst
-
1account_financial_report/__manifest__.py
-
1account_financial_report/readme/CONTRIBUTORS.rst
-
258account_financial_report/report/templates/aged_partner_balance.xml
-
269account_financial_report/report/templates/general_ledger.xml
-
14account_financial_report/report/templates/journal_ledger.xml
-
2account_financial_report/report/templates/layouts.xml
-
12account_financial_report/report/templates/open_items.xml
-
348account_financial_report/report/templates/trial_balance.xml
-
127account_financial_report/report/templates/vat_report.xml
-
1account_financial_report/static/description/index.html
-
6account_financial_report/static/src/css/report.css
-
109account_financial_report/static/src/js/account_financial_report_backend.js
-
88account_financial_report/static/src/js/account_financial_report_widgets.js
-
35account_financial_report/static/src/js/action_manager_report.js
-
51account_financial_report/static/src/js/client_action.js
-
58account_financial_report/static/src/js/report.js
-
17account_financial_report/static/src/xml/report.xml
-
78account_financial_report/view/report_template.xml
@ -1,109 +0,0 @@ |
|||
odoo.define("account_financial_report.account_financial_report_backend", function( |
|||
require |
|||
) { |
|||
"use strict"; |
|||
|
|||
var core = require("web.core"); |
|||
var Widget = require("web.Widget"); |
|||
var ControlPanelMixin = require("web.ControlPanelMixin"); |
|||
var ReportWidget = require("account_financial_report.account_financial_report_widget"); |
|||
|
|||
var report_backend = Widget.extend(ControlPanelMixin, { |
|||
// Stores all the parameters of the action.
|
|||
events: { |
|||
"click .o_account_financial_reports_print": "print", |
|||
"click .o_account_financial_reports_export": "export", |
|||
}, |
|||
init: function(parent, action) { |
|||
this.actionManager = parent; |
|||
this.given_context = {}; |
|||
this.odoo_context = action.context; |
|||
this.controller_url = action.context.url; |
|||
if (action.context.context) { |
|||
this.given_context = action.context.context; |
|||
} |
|||
this.given_context.active_id = |
|||
action.context.active_id || action.params.active_id; |
|||
this.given_context.model = action.context.active_model || false; |
|||
this.given_context.ttype = action.context.ttype || false; |
|||
return this._super.apply(this, arguments); |
|||
}, |
|||
willStart: function() { |
|||
return $.when(this.get_html()); |
|||
}, |
|||
set_html: function() { |
|||
var self = this; |
|||
var def = $.when(); |
|||
if (!this.report_widget) { |
|||
this.report_widget = new ReportWidget(this, this.given_context); |
|||
def = this.report_widget.appendTo(this.$el); |
|||
} |
|||
def.then(function() { |
|||
self.report_widget.$el.html(self.html); |
|||
}); |
|||
}, |
|||
start: function() { |
|||
this.set_html(); |
|||
return this._super(); |
|||
}, |
|||
// Fetches the html and is previous report.context if any,
|
|||
// else create it
|
|||
get_html: function() { |
|||
var self = this; |
|||
var defs = []; |
|||
return this._rpc({ |
|||
model: this.given_context.model, |
|||
method: "get_html", |
|||
args: [self.given_context], |
|||
context: self.odoo_context, |
|||
}).then(function(result) { |
|||
self.html = result.html; |
|||
defs.push(self.update_cp()); |
|||
return $.when.apply($, defs); |
|||
}); |
|||
}, |
|||
// Updates the control panel and render the elements that have yet
|
|||
// to be rendered
|
|||
update_cp: function() { |
|||
if (this.$buttons) { |
|||
var status = { |
|||
breadcrumbs: this.actionManager.get_breadcrumbs(), |
|||
cp_content: {$buttons: this.$buttons}, |
|||
}; |
|||
return this.update_control_panel(status); |
|||
} |
|||
}, |
|||
do_show: function() { |
|||
this._super(); |
|||
this.update_cp(); |
|||
}, |
|||
print: function() { |
|||
var self = this; |
|||
this._rpc({ |
|||
model: this.given_context.model, |
|||
method: "print_report", |
|||
args: [this.given_context.active_id, "qweb-pdf"], |
|||
context: self.odoo_context, |
|||
}).then(function(result) { |
|||
self.do_action(result); |
|||
}); |
|||
}, |
|||
export: function() { |
|||
var self = this; |
|||
this._rpc({ |
|||
model: this.given_context.model, |
|||
method: "print_report", |
|||
args: [this.given_context.active_id, "xlsx"], |
|||
context: self.odoo_context, |
|||
}).then(function(result) { |
|||
self.do_action(result); |
|||
}); |
|||
}, |
|||
canBeRemoved: function() { |
|||
return $.when(); |
|||
}, |
|||
}); |
|||
|
|||
core.action_registry.add("account_financial_report_backend", report_backend); |
|||
return report_backend; |
|||
}); |
@ -1,88 +0,0 @@ |
|||
odoo.define("account_financial_report.account_financial_report_widget", function( |
|||
require |
|||
) { |
|||
"use strict"; |
|||
|
|||
var Widget = require("web.Widget"); |
|||
|
|||
var accountFinancialReportWidget = Widget.extend({ |
|||
events: { |
|||
"click .o_account_financial_reports_web_action": "boundLink", |
|||
"click .o_account_financial_reports_web_action_multi": "boundLinkmulti", |
|||
"click .o_account_financial_reports_web_action_monetary": |
|||
"boundLinkMonetary", |
|||
"click .o_account_financial_reports_web_action_monetary_multi": |
|||
"boundLinkMonetarymulti", |
|||
}, |
|||
init: function() { |
|||
this._super.apply(this, arguments); |
|||
}, |
|||
start: function() { |
|||
return this._super.apply(this, arguments); |
|||
}, |
|||
boundLink: function(e) { |
|||
var res_model = $(e.target).data("res-model"); |
|||
var res_id = $(e.target).data("active-id"); |
|||
return this.do_action({ |
|||
type: "ir.actions.act_window", |
|||
res_model: res_model, |
|||
res_id: res_id, |
|||
views: [[false, "form"]], |
|||
target: "current", |
|||
}); |
|||
}, |
|||
boundLinkmulti: function(e) { |
|||
var res_model = $(e.target).data("res-model"); |
|||
var domain = $(e.target).data("domain"); |
|||
if (!res_model) { |
|||
res_model = $(e.target.parentElement).data("res-model"); |
|||
} |
|||
if (!domain) { |
|||
domain = $(e.target.parentElement).data("domain"); |
|||
} |
|||
return this.do_action({ |
|||
type: "ir.actions.act_window", |
|||
name: this._toTitleCase(res_model.split(".").join(" ")), |
|||
res_model: res_model, |
|||
domain: domain, |
|||
views: [ |
|||
[false, "list"], |
|||
[false, "form"], |
|||
], |
|||
target: "current", |
|||
}); |
|||
}, |
|||
boundLinkMonetary: function(e) { |
|||
var res_model = $(e.target.parentElement).data("res-model"); |
|||
var res_id = $(e.target.parentElement).data("active-id"); |
|||
return this.do_action({ |
|||
type: "ir.actions.act_window", |
|||
res_model: res_model, |
|||
res_id: res_id, |
|||
views: [[false, "form"]], |
|||
target: "current", |
|||
}); |
|||
}, |
|||
boundLinkMonetarymulti: function(e) { |
|||
var res_model = $(e.target.parentElement).data("res-model"); |
|||
var domain = $(e.target.parentElement).data("domain"); |
|||
return this.do_action({ |
|||
type: "ir.actions.act_window", |
|||
res_model: res_model, |
|||
domain: domain, |
|||
views: [ |
|||
[false, "list"], |
|||
[false, "form"], |
|||
], |
|||
target: "current", |
|||
}); |
|||
}, |
|||
_toTitleCase: function(str) { |
|||
return str.replace(/\w\S*/g, function(txt) { |
|||
return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase(); |
|||
}); |
|||
}, |
|||
}); |
|||
|
|||
return accountFinancialReportWidget; |
|||
}); |
@ -0,0 +1,35 @@ |
|||
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_file.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); |
|||
}, |
|||
}); |
|||
}); |
@ -0,0 +1,51 @@ |
|||
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._update_control_panel(); |
|||
}); |
|||
}, |
|||
|
|||
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) { |
|||
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; |
|||
}); |
@ -0,0 +1,58 @@ |
|||
odoo.define("account_financial_report.report", function(require) { |
|||
"use strict"; |
|||
|
|||
require("web.dom_ready"); |
|||
const utils = require("report.utils"); |
|||
|
|||
if (window.self === window.top) { |
|||
return; |
|||
} |
|||
|
|||
const web_base_url = $("html").attr("web-base-url"); |
|||
const trusted_host = utils.get_host_from_url(web_base_url); |
|||
const trusted_protocol = utils.get_protocol_from_url(web_base_url); |
|||
const trusted_origin = utils.build_origin(trusted_protocol, trusted_host); |
|||
|
|||
/** |
|||
* Convert a model name to a capitalized title style |
|||
* Example: account.mode.line --> Account Move Line |
|||
* |
|||
* @param {String} str |
|||
* @returns {String} |
|||
*/ |
|||
function toTitleCase(str) { |
|||
return str |
|||
.replaceAll(".", " ") |
|||
.replace( |
|||
/\w\S*/g, |
|||
txt => `${txt.charAt(0).toUpperCase()}${txt.substr(1).toLowerCase()}` |
|||
); |
|||
} |
|||
|
|||
// Allow sending commands to the webclient
|
|||
// `do_action` command with domain
|
|||
$("[res-model][domain]") |
|||
.wrap("<a/>") |
|||
.attr("href", "#") |
|||
.on("click", function(ev) { |
|||
ev.preventDefault(); |
|||
const res_model = $(this).attr("res-model"); |
|||
const action = { |
|||
type: "ir.actions.act_window", |
|||
res_model: res_model, |
|||
domain: $(this).attr("domain"), |
|||
name: toTitleCase(res_model), |
|||
views: [ |
|||
[false, "list"], |
|||
[false, "form"], |
|||
], |
|||
}; |
|||
window.parent.postMessage( |
|||
{ |
|||
message: "report:do_action", |
|||
action: action, |
|||
}, |
|||
trusted_origin |
|||
); |
|||
}); |
|||
}); |
@ -0,0 +1,17 @@ |
|||
<template> |
|||
<!-- Buttons of the Control Panel --> |
|||
<t t-name="account_financial_report.client_action.ControlButtons"> |
|||
<div class="o_report_buttons"> |
|||
<button |
|||
type="button" |
|||
class="btn btn-primary o_report_print" |
|||
title="Print" |
|||
>Print</button> |
|||
<button |
|||
type="button" |
|||
class="btn btn-secondary o_report_export" |
|||
title="Export" |
|||
>Export</button> |
|||
</div> |
|||
</t> |
|||
</template> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue