Skip to content

Commit 54abd51

Browse files
committed
Fix failing checks
1 parent 5ff8e46 commit 54abd51

File tree

6 files changed

+132
-111
lines changed

6 files changed

+132
-111
lines changed

base_export_async/__manifest__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
{
5-
'name': 'Base Export Async',
6-
'summary': 'Asynchronous export with job queue',
7-
'version': '17.0.1.0.0',
8-
'license': 'AGPL-3',
9-
'author': 'ACSONE SA/NV, Odoo Community Association (OCA)',
10-
'website': 'https://github.com/OCA/queue',
11-
'depends': ['web', 'queue_job'],
12-
'data': [
5+
"name": "Base Export Async",
6+
"summary": "Asynchronous export with job queue",
7+
"version": "17.0.1.0.0",
8+
"license": "AGPL-3",
9+
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
10+
"website": "https://github.com/OCA/queue",
11+
"depends": ["web", "queue_job"],
12+
"data": [
1313
# added this additional rule as when the export happens from queue job module
1414
# there is no user is there, which was causing an issue when fetching res.currency
15-
'security/ir.model.access.csv',
16-
'security/ir_rule.xml',
17-
'data/config_parameter.xml',
18-
'data/cron.xml',
19-
'data/mail_template.xml',
15+
"security/ir.model.access.csv",
16+
"security/ir_rule.xml",
17+
"data/config_parameter.xml",
18+
"data/cron.xml",
19+
"data/mail_template.xml",
2020
],
21-
'demo': [],
22-
'assets': {
23-
'web.assets_backend': [
24-
'base_export_async/static/src/xml/base.xml',
25-
'base_export_async/static/src/js/list_controller.esm.js',
26-
'base_export_async/static/src/js/data_export.esm.js',
21+
"demo": [],
22+
"assets": {
23+
"web.assets_backend": [
24+
"base_export_async/static/src/xml/base.xml",
25+
"base_export_async/static/src/js/list_controller.esm.js",
26+
"base_export_async/static/src/js/data_export.esm.js",
2727
],
2828
},
29-
'installable': True,
29+
"installable": True,
3030
}

base_export_async/models/delay_export.py

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,67 @@
77

88
from dateutil.relativedelta import relativedelta
99

10-
from odoo import _, api, fields, models, SUPERUSER_ID
11-
from odoo.http import request
10+
from odoo import SUPERUSER_ID, _, api, fields, models
1211
from odoo.exceptions import UserError
12+
from odoo.http import request
1313

1414
from odoo.addons.web.controllers.export import CSVExport, ExcelExport
1515

1616

1717
class DelayExport(models.Model):
18-
_name = 'delay.export'
19-
_description = 'Asynchronous Export'
18+
_name = "delay.export"
19+
_description = "Asynchronous Export"
2020

21-
user_ids = fields.Many2many('res.users', string='Users', index=True)
21+
user_ids = fields.Many2many("res.users", string="Users", index=True)
2222
model_description = fields.Char()
2323
url = fields.Char()
2424
expiration_date = fields.Date()
2525

2626
@api.model
2727
def delay_export(self, data):
2828
"""Delay the export, called from js"""
29-
params = json.loads(data.get('data'))
29+
params = json.loads(data.get("data"))
3030
if not self.env.user.email:
31-
raise UserError(_('You must set an email address to your user.'))
31+
raise UserError(_("You must set an email address to your user."))
3232
self.with_delay().export(params)
3333

3434
@api.model
3535
def _get_file_content(self, params):
36-
export_format = params.get('format')
36+
export_format = params.get("format")
3737

3838
items = operator.itemgetter(
39-
'model', 'fields', 'ids', 'domain', 'import_compat', 'context', 'user_ids'
39+
"model", "fields", "ids", "domain", "import_compat", "context", "user_ids"
4040
)(params)
4141
(model_name, fields_name, ids, domain, import_compat, context, user_ids) = items
4242

43-
model = self.env[model_name].sudo().with_context(
44-
import_compat=import_compat, **context
43+
model = (
44+
self.env[model_name]
45+
.sudo()
46+
.with_context(import_compat=import_compat, **context)
4547
)
4648
records = model.browse(ids) or model.search(
4749
domain, offset=0, limit=False, order=False
4850
)
4951

5052
if not model._is_an_ordinary_table():
51-
fields_name = [field for field in fields_name if field['name'] != 'id']
53+
fields_name = [field for field in fields_name if field["name"] != "id"]
5254

53-
field_names = [f['name'] for f in fields_name]
54-
import_data = records.export_data(field_names).get('datas', [])
55+
field_names = [f["name"] for f in fields_name]
56+
import_data = records.export_data(field_names).get("datas", [])
5557

5658
if import_compat:
5759
columns_headers = field_names
5860
else:
59-
columns_headers = [val['label'].strip() for val in fields_name]
61+
columns_headers = [val["label"].strip() for val in fields_name]
6062

6163
# Patch: ensure request.env is set with a valid uid before triggering ExportXlsxWriter
62-
if export_format != 'csv':
63-
if not hasattr(request, 'env') or request.env.uid is None:
64-
request.env = api.Environment(self.env.cr, SUPERUSER_ID, self.env.context)
64+
if export_format != "csv":
65+
if not hasattr(request, "env") or request.env.uid is None:
66+
request.env = api.Environment(
67+
self.env.cr, SUPERUSER_ID, self.env.context
68+
)
6569

66-
if export_format == 'csv':
70+
if export_format == "csv":
6771
csv = CSVExport()
6872
return csv.from_data(columns_headers, import_data)
6973
else:
@@ -79,7 +83,7 @@ def export(self, params):
7983
* format: csv/excel
8084
* model: model to export
8185
* fields: list of fields to export, a list of dict:
82-
[{'label': '', 'name': ''}]
86+
[{"label": "", "name": ""}]
8387
* ids: list of ids to export
8488
* domain: domain for the export
8589
* context: context for the export (language, ...)
@@ -88,62 +92,62 @@ def export(self, params):
8892
"""
8993
content = self._get_file_content(params)
9094

91-
items = operator.itemgetter('model', 'context', 'format', 'user_ids')(params)
95+
items = operator.itemgetter("model", "context", "format", "user_ids")(params)
9296
model_name, context, export_format, user_ids = items
93-
users = self.env['res.users'].browse(user_ids)
97+
users = self.env["res.users"].browse(user_ids)
9498

95-
export_record = self.sudo().create({'user_ids': [(6, 0, users.ids)]})
99+
export_record = self.sudo().create({"user_ids": [(6, 0, users.ids)]})
96100

97-
name = '{}.{}'.format(model_name, export_format)
98-
attachment = self.env['ir.attachment'].create(
101+
name = f"{model_name}.{export_format}"
102+
attachment = self.env["ir.attachment"].create(
99103
{
100-
'name': name,
101-
'datas': base64.b64encode(content),
102-
'type': 'binary',
103-
'res_model': self._name,
104-
'res_id': export_record.id,
104+
"name": name,
105+
"datas": base64.b64encode(content),
106+
"type": "binary",
107+
"res_model": self._name,
108+
"res_id": export_record.id,
105109
}
106110
)
107111

108-
url = '{}/web/content/ir.attachment/{}/datas/{}?download=true'.format(
109-
self.env['ir.config_parameter'].sudo().get_param('web.base.url'),
112+
url = "{}/web/content/ir.attachment/{}/datas/{}?download=true".format(
113+
self.env["ir.config_parameter"].sudo().get_param("web.base.url"),
110114
attachment.id,
111115
attachment.name,
112116
)
113117

114118
time_to_live = (
115-
self.env['ir.config_parameter'].sudo().get_param('attachment.ttl', 7)
119+
self.env["ir.config_parameter"].sudo().get_param("attachment.ttl", 7)
116120
)
117121
date_today = fields.Date.today()
118122
expiration_date = fields.Date.to_string(
119123
date_today + relativedelta(days=+int(time_to_live))
120124
)
121125

122-
odoo_bot = self.sudo().env.ref('base.partner_root')
126+
odoo_bot = self.sudo().env.ref("base.partner_root")
123127
email_from = odoo_bot.email
124128
model_description = self.env[model_name]._description
125129
export_record.write(
126130
{
127-
'url': url,
128-
'expiration_date': expiration_date,
129-
'model_description': model_description,
131+
"url": url,
132+
"expiration_date": expiration_date,
133+
"model_description": model_description,
130134
}
131135
)
132136

133-
self.env.ref('base_export_async.delay_export_mail_template').send_mail(
137+
self.env.ref("base_export_async.delay_export_mail_template").send_mail(
134138
export_record.id,
135139
email_values={
136-
'email_from': email_from,
137-
'reply_to': email_from,
138-
'recipient_ids': [(6, 0, users.mapped('partner_id').ids)],
140+
"email_from": email_from,
141+
"reply_to": email_from,
142+
"recipient_ids": [(6, 0, users.mapped("partner_id").ids)],
139143
},
140144
)
141145

142146
@api.model
143147
def cron_delete(self):
144148
time_to_live = (
145-
self.env['ir.config_parameter'].sudo().get_param('attachment.ttl', 7)
149+
self.env["ir.config_parameter"].sudo().get_param("attachment.ttl", 7)
146150
)
147151
date_today = fields.Date.today()
148152
date_to_delete = date_today + relativedelta(days=-int(time_to_live))
149-
self.search([('create_date', '<=', date_to_delete)]).unlink()
153+
self.search([("create_date", "<=", date_to_delete)]).unlink()

base_export_async/static/description/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
413413
<ul class="simple">
414414
<li>Arnaud Pineux (ACSONE SA/NV) authored the initial prototype.</li>
415415
<li>Guewen Baconnier (Camptocamp)</li>
416+
<li>Mitul Shah (TradeSolutions.Digital GmbH)</li>
416417
</ul>
417418
</div>
418419
<div class="section" id="maintainers">

base_export_async/static/src/js/data_export.esm.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {ExportDataDialog} from "@web/views/view_dialogs/export_data_dialog";
44
import {patch} from "@web/core/utils/patch";
5-
import { useService } from "@web/core/utils/hooks";
5+
import {useService} from "@web/core/utils/hooks";
66

77
patch(ExportDataDialog.prototype, {
88
setup() {

base_export_async/static/src/js/list_controller.esm.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
/** @odoo-module **/
22

33

4-
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
4+
import {AlertDialog} from "@web/core/confirmation_dialog/confirmation_dialog";
55
import {ListController} from "@web/views/list/list_controller";
66
import {_t} from "@web/core/l10n/translation";
77
import {download} from "@web/core/network/download";
88
import {patch} from "@web/core/utils/patch";
9-
import { useService } from "@web/core/utils/hooks";
9+
import {useService} from "@web/core/utils/hooks";
1010

1111
patch(ListController.prototype, {
1212
setup() {
1313
super.setup();
14-
this.uiService = useService('ui');
15-
this.orm = useService('orm');
14+
this.uiService = useService("ui");
15+
this.orm = useService("orm");
1616
},
1717
async downloadExport(fields, import_compat, format, async = false) {
1818
let ids = false;
@@ -52,7 +52,9 @@ patch(ListController.prototype, {
5252
this.orm.call("delay.export", "delay_export", args).then(function () {
5353
self.uiService.unblock();
5454
self.model.dialog.add(AlertDialog, {
55-
body: _t("You will receive the export file by email as soon as it is finished."),
55+
body: _t(
56+
"You will receive the export file by email as soon as it is finished."
57+
),
5658
});
5759
});
5860
} else {

0 commit comments

Comments
 (0)