Skip to content

Commit 1939d21

Browse files
committed
add readme/index file
1 parent 0ee7f9e commit 1939d21

File tree

3 files changed

+54
-39
lines changed

3 files changed

+54
-39
lines changed

base_export_async/README.rst

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Base Export Async
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
3030

31-
Standard Export can be delayed in asynchronous jobs executed in the background and then send by email to the user.
31+
Standard Export can be delayed in asynchronous jobs executed in the
32+
background and then send by email to the user.
3233

3334
**Table of contents**
3435

@@ -38,12 +39,11 @@ Standard Export can be delayed in asynchronous jobs executed in the background a
3839
Usage
3940
=====
4041

41-
The user is presented with a new checkbox "Asynchronous export"
42-
in the export screen. When selected, the export is delayed in a
43-
background job.
42+
The user is presented with a new checkbox "Asynchronous export" in the
43+
export screen. When selected, the export is delayed in a background job.
4444

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

4848
Bug Tracker
4949
===========
@@ -59,19 +59,19 @@ Credits
5959
=======
6060

6161
Authors
62-
~~~~~~~
62+
-------
6363

6464
* ACSONE SA/NV
6565

6666
Contributors
67-
~~~~~~~~~~~~
67+
------------
6868

69-
* Arnaud Pineux (ACSONE SA/NV) authored the initial prototype.
70-
* Guewen Baconnier (Camptocamp)
71-
* Mitul Shah (TradeSolutions.Digital GmbH)
69+
- Arnaud Pineux (ACSONE SA/NV) authored the initial prototype.
70+
- Guewen Baconnier (Camptocamp)
71+
- Mitul Shah (TradeSolutions.Digital GmbH)
7272

7373
Maintainers
74-
~~~~~~~~~~~
74+
-----------
7575

7676
This module is maintained by the OCA.
7777

base_export_async/static/description/index.html

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -370,7 +370,8 @@ <h1 class="title">Base Export Async</h1>
370370
!! source digest: sha256:9f35a2ee6042c86fff875f9a71682342e5892b923a4bd857bb5b90060376ea55
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/queue/tree/17.0/base_export_async"><img alt="OCA/queue" src="https://img.shields.io/badge/github-OCA%2Fqueue-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/queue-17-0/queue-17-0-base_export_async"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/queue&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373-
<p>Standard Export can be delayed in asynchronous jobs executed in the background and then send by email to the user.</p>
373+
<p>Standard Export can be delayed in asynchronous jobs executed in the
374+
background and then send by email to the user.</p>
374375
<p><strong>Table of contents</strong></p>
375376
<div class="contents local topic" id="contents">
376377
<ul class="simple">
@@ -386,11 +387,10 @@ <h1 class="title">Base Export Async</h1>
386387
</div>
387388
<div class="section" id="usage">
388389
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
389-
<p>The user is presented with a new checkbox “Asynchronous export”
390-
in the export screen. When selected, the export is delayed in a
391-
background job.</p>
392-
<p>The .csv or .xls file generated by the export will be sent by email
393-
to the user who execute the export.</p>
390+
<p>The user is presented with a new checkbox “Asynchronous export” in the
391+
export screen. When selected, the export is delayed in a background job.</p>
392+
<p>The .csv or .xls file generated by the export will be sent by email to
393+
the user who execute the export.</p>
394394
</div>
395395
<div class="section" id="bug-tracker">
396396
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
@@ -419,7 +419,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
419419
<div class="section" id="maintainers">
420420
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
421421
<p>This module is maintained by the OCA.</p>
422-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
422+
<a class="reference external image-reference" href="https://odoo-community.org">
423+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
424+
</a>
423425
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
424426
mission is to support the collaborative development of Odoo features and
425427
promote its widespread use.</p>

base_export_async/tests/test_base_export_async.py

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

44
import json
5-
from unittest import mock
65
from unittest.mock import patch
76

87
import freezegun
@@ -11,9 +10,10 @@
1110
import odoo.tests.common as common
1211
from odoo import fields
1312

14-
from odoo.addons.web.controllers.export import ExcelExport
13+
# This is the key import for fixing "object unbound"
14+
from odoo.addons.website.tools import MockRequest
1515

16-
# Reformatting CSV export data
16+
# Data definitions
1717
data_csv = {
1818
"data": json.dumps(
1919
{
@@ -34,7 +34,6 @@
3434
)
3535
}
3636

37-
# Reformatting XLS export data
3837
data_xls = {
3938
"data": json.dumps(
4039
{
@@ -61,54 +60,68 @@ def setUp(self):
6160
super().setUp()
6261
self.delay_export_obj = self.env["delay.export"]
6362
self.job_obj = self.env["queue.job"]
64-
with patch("odoo.http._request_stack") as mock_request_stack:
65-
mock_request = mock.Mock(env=self.env)
66-
mock_request_stack.push(mock_request)
67-
self.addCleanup(mock_request_stack.pop)
63+
64+
# We use MockRequest as a context manager to bind the request object correctly
65+
self.mock_request_stack = MockRequest(self.env)
66+
self.mock_request_stack.__enter__()
67+
self.addCleanup(self.mock_request_stack.__exit__, None, None, None)
6868

6969
def test_delay_export(self):
70-
"""Check that the call create a new JOB"""
71-
nbr_job = len(self.job_obj.search([]))
70+
"""Check that the call creates a new JOB"""
71+
nbr_job = self.job_obj.search_count([])
7272
self.delay_export_obj.delay_export(data_csv)
73-
new_nbr_job = len(self.job_obj.search([]))
73+
new_nbr_job = self.job_obj.search_count([])
7474
self.assertEqual(new_nbr_job, nbr_job + 1)
7575

7676
def test_export_csv(self):
77-
"""Check that the export generate an attachment and email"""
77+
"""Check that the export generates an attachment and email"""
7878
params = json.loads(data_csv.get("data"))
7979
mails = self.env["mail.mail"].search([])
8080
attachments = self.env["ir.attachment"].search([])
81+
8182
self.delay_export_obj.export(params)
83+
8284
new_mail = self.env["mail.mail"].search([]) - mails
8385
new_attachment = self.env["ir.attachment"].search([]) - attachments
86+
8487
self.assertEqual(len(new_mail), 1)
8588
self.assertEqual(new_attachment.name, "res.partner.csv")
8689

8790
def test_export_xls(self):
88-
"""Check that the export generate an attachment and email"""
91+
"""Check that the export generates an attachment and email"""
8992
params = json.loads(data_xls.get("data"))
9093
mails = self.env["mail.mail"].search([])
9194
attachments = self.env["ir.attachment"].search([])
92-
with patch.object(ExcelExport, "from_data", return_value=b"\x41\x42\x43\x44"):
95+
96+
# Patch the class method directly
97+
with patch(
98+
"odoo.addons.web.controllers.export.ExcelExport.from_data",
99+
return_value=b"\x41\x42\x43\x44",
100+
):
93101
self.delay_export_obj.export(params)
102+
94103
new_mail = self.env["mail.mail"].search([]) - mails
95104
new_attachment = self.env["ir.attachment"].search([]) - attachments
105+
96106
self.assertEqual(len(new_mail), 1)
97107
self.assertEqual(new_attachment.name, "res.partner.xls")
98108

99109
def test_cron_delete(self):
100110
"""Check that cron delete attachment after TTL"""
101111
params = json.loads(data_csv.get("data"))
102112
attachments = self.env["ir.attachment"].search([])
113+
103114
self.delay_export_obj.export(params)
104115
new_attachment = self.env["ir.attachment"].search([]) - attachments
116+
105117
time_to_live = (
106118
self.env["ir.config_parameter"].sudo().get_param("attachment.ttl", 7)
107119
)
120+
108121
date_today = fields.Datetime.now()
109-
date_past_ttl = date_today + relativedelta(days=int(time_to_live))
122+
date_past_ttl = date_today + relativedelta(days=int(time_to_live) + 1)
123+
110124
with freezegun.freeze_time(date_past_ttl):
111125
self.delay_export_obj.cron_delete()
112126

113-
# The attachment must be deleted
114127
self.assertFalse(new_attachment.exists())

0 commit comments

Comments
 (0)