Skip to content

Commit 7f59164

Browse files
[MIG] base_export_async: Migration to 17.0
1 parent 3faab6c commit 7f59164

16 files changed

Lines changed: 114 additions & 78 deletions

File tree

base_export_async/README.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,15 @@ Contributors
6868

6969
- Arnaud Pineux (ACSONE SA/NV) authored the initial prototype.
7070
- Guewen Baconnier (Camptocamp)
71+
- Stéphane Mangin (ACSONE SA/NV)
72+
73+
Other credits
74+
-------------
75+
76+
The migration of this module from 16.0 to 17.0 was financially supported
77+
by:
78+
79+
- ACSONE SA/NV (https://www.acsone.eu/)
7180

7281
Maintainers
7382
-----------

base_export_async/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"name": "Base Export Async",
66
"summary": "Asynchronous export with job queue",
7-
"version": "16.0.1.2.0",
7+
"version": "17.0.1.0.0",
88
"license": "AGPL-3",
99
"author": "ACSONE SA/NV, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/queue",
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo noupdate="1">
3-
<record id="attachment_ttl" model="ir.config_parameter">
4-
<field name="key">attachment.ttl</field>
5-
<field name="value">7</field>
6-
</record>
3+
<record id="attachment_ttl" model="ir.config_parameter">
4+
<field name="key">attachment.ttl</field>
5+
<field name="value">7</field>
6+
</record>
77
</odoo>

base_export_async/data/cron.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo>
3-
<record id="to_delete_attachment" model="ir.cron">
4-
<field name="name">Delete Generated Exports</field>
5-
<field name="model_id" ref="model_delay_export" />
6-
<field name="state">code</field>
7-
<field name="code">model.cron_delete()</field>
8-
<field name='interval_number'>1</field>
9-
<field name='interval_type'>days</field>
10-
<field name="numbercall">-1</field>
11-
</record>
3+
<record id="to_delete_attachment" model="ir.cron">
4+
<field name="name">Delete Generated Exports</field>
5+
<field name="model_id" ref="model_delay_export" />
6+
<field name="state">code</field>
7+
<field name="code">model.cron_delete()</field>
8+
<field name='interval_number'>1</field>
9+
<field name='interval_type'>days</field>
10+
<field name="numbercall">-1</field>
11+
</record>
1212
</odoo>
Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<odoo noupdate="1">
3-
<record id="delay_export_mail_template" model="mail.template">
4-
<field name="name">Delay Export</field>
5-
<field
3+
<record id="delay_export_mail_template" model="mail.template">
4+
<field name="name">Delay Export</field>
5+
<field
66
name="subject"
77
>Export {{ object.model_description }} {{ datetime.date.today() }}</field>
8-
<field name="model_id" ref="base_export_async.model_delay_export" />
9-
<field name="auto_delete" eval="True" />
10-
<field name="body_html" type="html">
11-
<p>Your export is available <a
8+
<field name="model_id" ref="base_export_async.model_delay_export" />
9+
<field name="auto_delete" eval="True" />
10+
<field name="body_html" type="html">
11+
<p>Your export is available <a
1212
t-attf-href="{{ object.url }}"
1313
target="_blank"
1414
>here</a>.</p>
15-
<p>It will be automatically deleted the <t
16-
t-out="object.expiration_date"
17-
/>.</p>
18-
<br />
19-
<p>
20-
<span
15+
<p>It will be automatically deleted the <t t-out="object.expiration_date" />.</p>
16+
<br />
17+
<p>
18+
<span
2119
style="color: #808080;"
2220
>This is an automated message please do not reply.</span>
23-
</p>
24-
</field>
25-
</record>
21+
</p>
22+
</field>
23+
</record>
2624
</odoo>

base_export_async/models/delay_export.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,19 @@
77

88
from dateutil.relativedelta import relativedelta
99

10-
from odoo import _, api, fields, models
10+
from odoo import _, api, fields, http, models
1111
from odoo.exceptions import UserError
1212

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

1515

16+
class FakeRequest:
17+
def __init__(self, env):
18+
self.env = env
19+
self.context = env.context
20+
self.session = {}
21+
22+
1623
class DelayExport(models.Model):
1724
_name = "delay.export"
1825
_description = "Asynchronous Export"
@@ -28,7 +35,13 @@ def delay_export(self, data):
2835
params = json.loads(data.get("data"))
2936
if not self.env.user.email:
3037
raise UserError(_("You must set an email address to your user."))
31-
self.with_delay().export(params)
38+
39+
# Push a fake request into Odoo's local stack
40+
http._request_stack.push(FakeRequest(self.env))
41+
try:
42+
self.with_delay().export(params)
43+
finally:
44+
http._request_stack.pop()
3245

3346
@api.model
3447
def _get_file_content(self, params):
@@ -58,11 +71,8 @@ def _get_file_content(self, params):
5871
columns_headers = [val["label"].strip() for val in fields_name]
5972

6073
if export_format == "csv":
61-
csv = CSVExport()
62-
return csv.from_data(columns_headers, import_data)
63-
else:
64-
xls = ExcelExport()
65-
return xls.from_data(columns_headers, import_data)
74+
return CSVExport().from_data(columns_headers, import_data)
75+
return ExcelExport().from_data(columns_headers, import_data)
6676

6777
@api.model
6878
def export(self, params):
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Arnaud Pineux (ACSONE SA/NV) authored the initial prototype.
22
- Guewen Baconnier (Camptocamp)
3+
- Stéphane Mangin (ACSONE SA/NV)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The migration of this module from 16.0 to 17.0 was financially supported by:
2+
3+
- ACSONE SA/NV (<https://www.acsone.eu/>)
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Standard Export can be delayed in asynchronous jobs executed in the
2-
background and then send by email to the user.
1+
Standard Export can be delayed in asynchronous jobs executed in the background and then
2+
send by email to the user.

base_export_async/readme/USAGE.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
The user is presented with a new checkbox "Asynchronous export" in the
2-
export screen. When selected, the export is delayed in a background job.
1+
The user is presented with a new checkbox "Asynchronous export" in the export screen.
2+
When selected, the export is delayed in a background job.
33

4-
The .csv or .xls file generated by the export will be sent by email to
5-
the user who execute the export.
4+
The .csv or .xls file generated by the export will be sent by email to the user who
5+
execute the export.

0 commit comments

Comments
 (0)