Skip to content

Commit 4301da4

Browse files
committed
[IMP] sql_export_mail, add partner as export email recipient
1 parent 67ded10 commit 4301da4

File tree

4 files changed

+51
-7
lines changed

4 files changed

+51
-7
lines changed

sql_export_mail/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
22
{
33
"name": "SQL Export Mail",
4-
"version": "16.0.2.0.2",
4+
"version": "16.0.2.1.0",
55
"category": "Generic Modules",
66
"summary": "Send csv file generated by sql query by mail.",
77
"author": "Akretion,GRAP,Odoo Community Association (OCA)",

sql_export_mail/models/sql_export.py

+35-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ class SqlExport(models.Model):
1919
help="Add the users who want to receive the report by e-mail. You "
2020
"need to link the sql query with a cron to send mail automatically",
2121
)
22+
mail_partner_ids = fields.Many2many(
23+
"res.partner",
24+
"mail_partner_sqlquery_rel",
25+
"sql_id",
26+
"partner_id",
27+
help="Add the partners who wants to receive the report by e-mail. You "
28+
"need to link the sql query with a cron to send a mail automatically",
29+
)
2230
cron_ids = fields.Many2many(
2331
"ir.cron",
2432
"cron_sqlquery_rel",
@@ -138,13 +146,38 @@ def check_mail_user(self):
138146
if not user.email:
139147
raise UserError(_("The user does not have any e-mail address."))
140148

149+
@api.constrains("mail_partner_ids")
150+
def check_mail_partner(self):
151+
for export in self:
152+
if "%(company_id)s" in export.query or "%(user_id)s" in export.query:
153+
raise UserError(
154+
_(
155+
"A query that uses the company_id or user_id parameter "
156+
"cannot be directly sent to a partner."
157+
)
158+
)
159+
for partner in export.mail_partner_ids:
160+
if not partner.email:
161+
raise UserError(_("The partner does not have any e-mail address."))
162+
141163
def get_email_address_for_template(self):
142164
"""
143-
Called from mail template
165+
Called from mail template.
166+
Collects email addresses from both users and partners.
144167
"""
145168
self.ensure_one()
146169
if self.env.context.get("mail_to"):
147170
mail_users = self.env["res.users"].browse(self.env.context.get("mail_to"))
171+
mail_partners = []
148172
else:
149173
mail_users = self.mail_user_ids
150-
return ",".join([x.email for x in mail_users if x.email])
174+
mail_partners = self.mail_partner_ids
175+
176+
email_addresses = []
177+
for user in mail_users:
178+
if user.email:
179+
email_addresses.append(user.email)
180+
for partner in mail_partners:
181+
if partner.email:
182+
email_addresses.append(partner.email)
183+
return ",".join(email_addresses)

sql_export_mail/static/description/index.html

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88

99
/*
1010
:Author: David Goodger (goodger@python.org)
11-
: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 $
1212
:Copyright: This stylesheet has been placed in the public domain.
1313
1414
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1516
1617
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1718
customize this style sheet.
@@ -274,7 +275,7 @@
274275
margin-left: 2em ;
275276
margin-right: 2em }
276277

277-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
278279
pre.code, code { background-color: #eeeeee }
279280
pre.code .comment, code .comment { color: #5C6576 }
280281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -300,7 +301,7 @@
300301
span.pre {
301302
white-space: pre }
302303

303-
span.problematic {
304+
span.problematic, pre.problematic {
304305
color: red }
305306

306307
span.section-subtitle {
@@ -421,7 +422,9 @@ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
421422
<div class="section" id="maintainers">
422423
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
423424
<p>This module is maintained by the OCA.</p>
424-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
425+
<a class="reference external image-reference" href="https://odoo-community.org">
426+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
427+
</a>
425428
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
426429
mission is to support the collaborative development of Odoo features and
427430
promote its widespread use.</p>

sql_export_mail/views/sql_export_view.xml

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
colspan="2"
3232
/>
3333
</group>
34+
<group string="Partners Notified by e-mail">
35+
<field
36+
name="mail_partner_ids"
37+
nolabel="1"
38+
widget="many2many_tags"
39+
colspan="2"
40+
/>
41+
</group>
3442
<group string="Crons" groups="base.group_system">
3543
<field
3644
name="cron_ids"

0 commit comments

Comments
 (0)