[12.0][MIG] report_csv
parent
94401e10b6
commit
6ca2e17d00
|
@ -1,13 +1,36 @@
|
||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
|
||||||
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
|
|
||||||
:alt: License: AGPL-3
|
|
||||||
|
|
||||||
===============
|
===============
|
||||||
Base report csv
|
Base report csv
|
||||||
===============
|
===============
|
||||||
|
|
||||||
|
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
!! This file is generated by oca-gen-addon-readme !!
|
||||||
|
!! changes will be overwritten. !!
|
||||||
|
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
|
||||||
|
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||||
|
:target: https://odoo-community.org/page/development-status
|
||||||
|
:alt: Beta
|
||||||
|
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
|
||||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
|
:alt: License: AGPL-3
|
||||||
|
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
|
||||||
|
:target: https://github.com/OCA/reporting-engine/tree/12.0/report_csv
|
||||||
|
:alt: OCA/reporting-engine
|
||||||
|
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
|
||||||
|
:target: https://translation.odoo-community.org/projects/reporting-engine-12-0/reporting-engine-12-0-report_csv
|
||||||
|
:alt: Translate me on Weblate
|
||||||
|
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
|
||||||
|
:target: https://runbot.odoo-community.org/runbot/143/12.0
|
||||||
|
:alt: Try me on Runbot
|
||||||
|
|
||||||
|
|badge1| |badge2| |badge3| |badge4| |badge5|
|
||||||
|
|
||||||
This module provides a basic report class to generate csv report.
|
This module provides a basic report class to generate csv report.
|
||||||
|
|
||||||
|
**Table of contents**
|
||||||
|
|
||||||
|
.. contents::
|
||||||
|
:local:
|
||||||
|
|
||||||
Usage
|
Usage
|
||||||
=====
|
=====
|
||||||
|
@ -51,35 +74,42 @@ A report XML record ::
|
||||||
attachment_use="False"
|
attachment_use="False"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
|
||||||
:alt: Try me on Runbot
|
|
||||||
:target: https://runbot.odoo-community.org/runbot/143/11.0
|
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
|
||||||
Bugs are tracked on `GitHub Issues
|
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
|
||||||
<https://github.com/OCA/reporting-engine/issues>`_. In case of trouble, please
|
In case of trouble, please check there if your issue has already been reported.
|
||||||
check there if your issue has already been reported. If you spotted it first,
|
If you spotted it first, help us smashing it by providing a detailed and welcomed
|
||||||
help us smashing it by providing a detailed and welcomed feedback.
|
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_csv%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
|
||||||
|
|
||||||
|
Do not contact contributors directly about support or help with technical issues.
|
||||||
|
|
||||||
Credits
|
Credits
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
Authors
|
||||||
|
~~~~~~~
|
||||||
|
|
||||||
|
* Creu Blanca
|
||||||
|
|
||||||
Contributors
|
Contributors
|
||||||
------------
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
* Enric Tobella <etobella@creublanca.es>
|
* Enric Tobella <etobella@creublanca.es>
|
||||||
|
|
||||||
Maintainer
|
Maintainers
|
||||||
----------
|
~~~~~~~~~~~
|
||||||
|
|
||||||
|
This module is maintained by the OCA.
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/logo.png
|
.. image:: https://odoo-community.org/logo.png
|
||||||
:alt: Odoo Community Association
|
:alt: Odoo Community Association
|
||||||
:target: https://odoo-community.org
|
:target: https://odoo-community.org
|
||||||
|
|
||||||
This module is maintained by the OCA.
|
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
|
mission is to support the collaborative development of Odoo features and
|
||||||
|
promote its widespread use.
|
||||||
|
|
||||||
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
|
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/12.0/report_csv>`_ project on GitHub.
|
||||||
|
|
||||||
To contribute to this module, please visit https://odoo-community.org.
|
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
'Odoo Community Association (OCA)',
|
'Odoo Community Association (OCA)',
|
||||||
'website': "https://github.com/oca/reporting-engine",
|
'website': "https://github.com/oca/reporting-engine",
|
||||||
'category': 'Reporting',
|
'category': 'Reporting',
|
||||||
'version': '11.0.1.0.0',
|
'version': '12.0.1.0.0',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'external_dependencies': {
|
'external_dependencies': {
|
||||||
'python': [
|
'python': [
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
* Enric Tobella <etobella@creublanca.es>
|
||||||
|
* Jaime Arroyo <jaime.arroyo@creublanca.es>
|
|
@ -0,0 +1 @@
|
||||||
|
This module provides a basic report class to generate csv report.
|
|
@ -0,0 +1,38 @@
|
||||||
|
An example of CSV report for partners on a module called `module_name`:
|
||||||
|
|
||||||
|
A python class ::
|
||||||
|
|
||||||
|
from odoo import models
|
||||||
|
|
||||||
|
class PartnerCSV(models.AbstractModel):
|
||||||
|
_name = 'report.report_csv.partner_csv'
|
||||||
|
_inherit = 'report.report_csv.abstract'
|
||||||
|
|
||||||
|
def generate_csv_report(self, writer, data, partners):
|
||||||
|
writer.writeheader()
|
||||||
|
for obj in partners:
|
||||||
|
writer.writerow({
|
||||||
|
'name': obj.name,
|
||||||
|
'email': obj.email,
|
||||||
|
})
|
||||||
|
|
||||||
|
def csv_report_options(self):
|
||||||
|
res = super().csv_report_options()
|
||||||
|
res['fieldnames'].append('name')
|
||||||
|
res['fieldnames'].append('email')
|
||||||
|
res['delimiter'] = ';'
|
||||||
|
res['quoting'] = csv.QUOTE_ALL
|
||||||
|
return res
|
||||||
|
|
||||||
|
|
||||||
|
A report XML record ::
|
||||||
|
|
||||||
|
<report
|
||||||
|
id="partner_csv"
|
||||||
|
model="res.partner"
|
||||||
|
string="Print to CSV"
|
||||||
|
report_type="csv"
|
||||||
|
name="module_name.report_name"
|
||||||
|
file="res_partner"
|
||||||
|
attachment_use="False"
|
||||||
|
/>
|
|
@ -16,6 +16,7 @@ except ImportError:
|
||||||
|
|
||||||
class ReportCSVAbstract(models.AbstractModel):
|
class ReportCSVAbstract(models.AbstractModel):
|
||||||
_name = 'report.report_csv.abstract'
|
_name = 'report.report_csv.abstract'
|
||||||
|
_description = 'Abstract Model for CSV reports'
|
||||||
|
|
||||||
def _get_objs_for_report(self, docids, data):
|
def _get_objs_for_report(self, docids, data):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,47 +1,88 @@
|
||||||
// © 2019 Creu Blanca
|
// © 2019 Creu Blanca
|
||||||
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
// License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
odoo.define('report_csv.report', function(require){
|
odoo.define("report_csv.report", function (require) {
|
||||||
'use strict';
|
"use strict";
|
||||||
|
|
||||||
var ActionManager= require('web.ActionManager');
|
var core = require("web.core");
|
||||||
var crash_manager = require('web.crash_manager');
|
var ActionManager = require("web.ActionManager");
|
||||||
var framework = require('web.framework');
|
var crash_manager = require("web.crash_manager");
|
||||||
|
var framework = require("web.framework");
|
||||||
|
var session = require("web.session");
|
||||||
|
var _t = core._t;
|
||||||
|
|
||||||
ActionManager.include({
|
ActionManager.include({
|
||||||
ir_actions_report: function (action, options){
|
|
||||||
var self = this;
|
_downloadReportCSV: function (url, actions) {
|
||||||
var cloned_action = _.clone(action);
|
|
||||||
if (cloned_action.report_type === 'csv') {
|
|
||||||
framework.blockUI();
|
framework.blockUI();
|
||||||
var report_csv_url = 'report/csv/' + cloned_action.report_name;
|
var def = $.Deferred();
|
||||||
|
var type = "csv";
|
||||||
|
var cloned_action = _.clone(actions);
|
||||||
|
|
||||||
if (_.isUndefined(cloned_action.data) ||
|
if (_.isUndefined(cloned_action.data) ||
|
||||||
_.isNull(cloned_action.data) ||
|
_.isNull(cloned_action.data) ||
|
||||||
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)))
|
(_.isObject(cloned_action.data) && _.isEmpty(cloned_action.data)))
|
||||||
{
|
{
|
||||||
if(cloned_action.context.active_ids) {
|
if (cloned_action.context.active_ids) {
|
||||||
report_csv_url += '/' + cloned_action.context.active_ids.join(',');
|
url += "/" + cloned_action.context.active_ids.join(',');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
report_csv_url += '?options=' + encodeURIComponent(JSON.stringify(cloned_action.data));
|
url += "?options=" + encodeURIComponent(JSON.stringify(cloned_action.data));
|
||||||
report_csv_url += '&context=' + encodeURIComponent(JSON.stringify(cloned_action.context));
|
url += "&context=" + encodeURIComponent(JSON.stringify(cloned_action.context));
|
||||||
}
|
}
|
||||||
self.getSession().get_file({
|
|
||||||
url: report_csv_url,
|
var blocked = !session.get_file({
|
||||||
data: {data: JSON.stringify([
|
url: url,
|
||||||
report_csv_url,
|
data: {
|
||||||
cloned_action.report_type
|
data: JSON.stringify([url, type]),
|
||||||
])},
|
},
|
||||||
error: crash_manager.rpc_error.bind(crash_manager),
|
success: def.resolve.bind(def),
|
||||||
success: function (){
|
error: function () {
|
||||||
if(cloned_action && options && !cloned_action.dialog){
|
crash_manager.rpc_error.apply(crash_manager, arguments);
|
||||||
options.on_close();
|
def.reject();
|
||||||
|
},
|
||||||
|
complete: framework.unblockUI,
|
||||||
|
});
|
||||||
|
if (blocked) {
|
||||||
|
// AAB: this check should be done in get_file service directly,
|
||||||
|
// should not be the concern of the caller (and that way, get_file
|
||||||
|
// could return a deferred)
|
||||||
|
var message = _t('A popup window with your report was blocked. You ' +
|
||||||
|
'may need to change your browser settings to allow ' +
|
||||||
|
'popup windows for this page.');
|
||||||
|
this.do_warn(_t('Warning'), message, true);
|
||||||
}
|
}
|
||||||
|
return def;
|
||||||
|
},
|
||||||
|
|
||||||
|
_triggerDownload: function (action, options, type) {
|
||||||
|
var self = this;
|
||||||
|
var reportUrls = this._makeReportUrls(action);
|
||||||
|
if (type === "csv") {
|
||||||
|
return this._downloadReportCSV(reportUrls[type], action).then(function () {
|
||||||
|
if (action.close_on_report_download) {
|
||||||
|
var closeAction = {type: 'ir.actions.act_window_close'};
|
||||||
|
return self.doAction(closeAction, _.pick(options, 'on_close'));
|
||||||
|
} else {
|
||||||
|
return options.on_close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
framework.unblockUI();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
return self._super(action, options);
|
return this._super.apply(this, arguments);
|
||||||
|
},
|
||||||
|
|
||||||
|
_makeReportUrls: function (action) {
|
||||||
|
var reportUrls = this._super.apply(this, arguments);
|
||||||
|
reportUrls.csv = '/report/csv/' + action.report_name;
|
||||||
|
return reportUrls;
|
||||||
|
},
|
||||||
|
|
||||||
|
_executeReportAction: function (action, options) {
|
||||||
|
var self = this;
|
||||||
|
if (action.report_type === 'csv') {
|
||||||
|
return self._triggerDownload(action, options, 'csv');
|
||||||
}
|
}
|
||||||
});
|
return this._super.apply(this, arguments);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue