From e3c175a69c411f41f3e473cfc10f5d8f7d9714fb Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Wed, 12 Jun 2019 19:01:16 +0200 Subject: [PATCH] Migrate sql_export_mail to v9 --- sql_export_mail/README.rst | 64 -------------------- sql_export_mail/__openerp__.py | 8 +-- sql_export_mail/mail_template.xml | 34 +++++------ sql_export_mail/models/sql_export.py | 13 ++-- sql_export_mail/readme/CONFIGURE.rst | 7 +++ sql_export_mail/readme/CONTRIBUTORS.rst | 1 + sql_export_mail/readme/DESCRIPTION.rst | 1 + sql_export_mail/tests/test_sql_query_mail.py | 2 +- 8 files changed, 37 insertions(+), 93 deletions(-) delete mode 100644 sql_export_mail/README.rst create mode 100644 sql_export_mail/readme/CONFIGURE.rst create mode 100644 sql_export_mail/readme/CONTRIBUTORS.rst create mode 100644 sql_export_mail/readme/DESCRIPTION.rst diff --git a/sql_export_mail/README.rst b/sql_export_mail/README.rst deleted file mode 100644 index 31233db35..000000000 --- a/sql_export_mail/README.rst +++ /dev/null @@ -1,64 +0,0 @@ -.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg - :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html - :alt: License: AGPL-3 - -=============== -SQL Export Mail -=============== - -Allow to send the result of a query (made with the module sql_export) by mail. - - -Configuration -============= - -To configure this module, you need to: - -#. Go to the sql query for which you want users to be notified by e-mail. -#. Add users to be notified in the field Users Notified by e-mail. -#. Click on the button create a cron and then configure the cron to run when - you want to. If you already have created a cron for another query, you can - use it again for other queries - -Usage -===== - -.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas - :alt: Try me on Runbot - :target: https://runbot.odoo-community.org/runbot/149/8.0 - -Bug Tracker -=========== - -Bugs are tracked on `GitHub Issues -`_. In case of trouble, please -check there if your issue has already been reported. If you spotted it first, -help us smashing it by providing a detailed and welcomed feedback. - -Credits -======= - -Images ------- - -* Odoo Community Association: `Icon `_. - -Contributors ------------- - -* Florian da Costa - -Maintainer ----------- - -.. image:: https://odoo-community.org/logo.png - :alt: Odoo Community Association - :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. - -To contribute to this module, please visit https://odoo-community.org. diff --git a/sql_export_mail/__openerp__.py b/sql_export_mail/__openerp__.py index 992b0814b..d2b84f565 100644 --- a/sql_export_mail/__openerp__.py +++ b/sql_export_mail/__openerp__.py @@ -1,15 +1,15 @@ # -*- coding: utf-8 -*- -# Copyright 2017 Akretion +# Copyright 2019 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { 'name': 'SQL Export Mail', - 'version': '8.0.1.0.0', + 'version': '9.0.1.0.0', 'author': 'Akretion,Odoo Community Association (OCA)', - 'website': 'http://www.akretion.com', + 'website': 'http://github/oca/server-tools', 'license': 'AGPL-3', 'category': 'Generic Modules/Others', - 'summary': 'Export data in csv file with SQL requests', + 'summary': 'Send csv file generated by sql query by mail.', 'depends': [ 'sql_export', 'mail', diff --git a/sql_export_mail/mail_template.xml b/sql_export_mail/mail_template.xml index db5599c6a..0bb497d32 100644 --- a/sql_export_mail/mail_template.xml +++ b/sql_export_mail/mail_template.xml @@ -1,28 +1,24 @@ - - - + + - - - SQL Export - admin@example.com - ${object.get_email_address_for_template()} - ${object.name or ''} - - - + + SQL Export + admin@example.com + ${object.get_email_address_for_template()} + ${object.name or ''} + + +

You will find the report ${object.name or ''} as an attachment of the mail.

- ]]>
-
+ ]]>
+
-
-
+ + diff --git a/sql_export_mail/models/sql_export.py b/sql_export_mail/models/sql_export.py index 6ee4d04bf..6b0b5a74c 100644 --- a/sql_export_mail/models/sql_export.py +++ b/sql_export_mail/models/sql_export.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright 2017 Akretion +# Copyright 2019 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). from openerp import models, fields, api, _ @@ -47,9 +47,11 @@ class SqlExport(models.Model): 'user_id': SUPERUSER_ID, } cron = self.env['ir.cron'].create(cron_vals) + # We need to pass cron_id in the cron args because a cron is not + # aware of itself in the end method and we need it to find all + # linked sql exports write_vals = {'args': '[[%s]]' % cron.id} cron.write(write_vals) - self.write({'cron_ids': [(4, cron.id)]}) @api.multi @@ -64,17 +66,18 @@ class SqlExport(models.Model): params=params, mode='fetchone') if not res: return - binary = self._execute_sql_request( params=params, mode='stdout', copy_options=self.copy_options) + msg_id = mail_template.send_mail(self.id, force_send=False) + mail = self.env['mail.mail'].browse(msg_id) attach_vals = { 'name': now_time + ' - ' + self.name, 'datas_fname': now_time + ' - ' + self.name + '.csv', 'datas': binary, + 'res_model': 'mail.mail', + 'res_id': mail.id, } attachment = attach_obj.create(attach_vals) - msg_id = mail_template.send_mail(self.id, force_send=False) - mail = self.env['mail.mail'].browse(msg_id) mail.write({'attachment_ids': [(4, attachment.id)]}) @api.model diff --git a/sql_export_mail/readme/CONFIGURE.rst b/sql_export_mail/readme/CONFIGURE.rst new file mode 100644 index 000000000..17ed7c873 --- /dev/null +++ b/sql_export_mail/readme/CONFIGURE.rst @@ -0,0 +1,7 @@ +To configure this module, you need to: + +#. Go to the sql query for which you want users to be notified by e-mail. +#. Add users to be notified in the field Users Notified by e-mail. +#. Click on the button create a cron and then configure the cron to run when + you want to. If you already have created a cron for another query, you can + use it again for other queries diff --git a/sql_export_mail/readme/CONTRIBUTORS.rst b/sql_export_mail/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..0bddb053a --- /dev/null +++ b/sql_export_mail/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Florian da Costa diff --git a/sql_export_mail/readme/DESCRIPTION.rst b/sql_export_mail/readme/DESCRIPTION.rst new file mode 100644 index 000000000..21dae9d88 --- /dev/null +++ b/sql_export_mail/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +Allow to send the result of a query (made with the module sql_export) by mail. diff --git a/sql_export_mail/tests/test_sql_query_mail.py b/sql_export_mail/tests/test_sql_query_mail.py index 45bc2d2d3..0a021e2d6 100644 --- a/sql_export_mail/tests/test_sql_query_mail.py +++ b/sql_export_mail/tests/test_sql_query_mail.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Copyright (C) 2017 Akretion () +# Copyright (C) 2019 Akretion () # @author: Florian da Costa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).