diff --git a/sql_export_mail/README.rst b/sql_export_mail/README.rst new file mode 100644 index 000000000..d00fbc453 --- /dev/null +++ b/sql_export_mail/README.rst @@ -0,0 +1,84 @@ +=============== +SQL Export Mail +=============== + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/12.0/sql_export_mail + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-12-0/server-tools-12-0-sql_export_mail + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png + :target: https://runbot.odoo-community.org/runbot/149/12.0 + :alt: Try me on Runbot + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Allow to send the result of a query (made with the module sql_export) by mail. + +**Table of contents** + +.. contents:: + :local: + +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 + +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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Akretion + +Contributors +~~~~~~~~~~~~ + +* Florian da Costa + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +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. + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/sql_export_mail/__openerp__.py b/sql_export_mail/__manifest__.py similarity index 60% rename from sql_export_mail/__openerp__.py rename to sql_export_mail/__manifest__.py index d2b84f565..323a031dd 100644 --- a/sql_export_mail/__openerp__.py +++ b/sql_export_mail/__manifest__.py @@ -1,22 +1,20 @@ -# -*- coding: utf-8 -*- -# Copyright 2019 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). - { 'name': 'SQL Export Mail', - 'version': '9.0.1.0.0', - 'author': 'Akretion,Odoo Community Association (OCA)', - 'website': 'http://github/oca/server-tools', - 'license': 'AGPL-3', - 'category': 'Generic Modules/Others', + 'version': '12.0.1.0.0', + 'category': 'Generic Modules', 'summary': 'Send csv file generated by sql query by mail.', + 'author': + "Akretion, Odoo Community Association (OCA)", + 'website': 'https://github.com/OCA/server-tools', 'depends': [ 'sql_export', 'mail', ], + 'license': 'AGPL-3', 'data': [ 'views/sql_export_view.xml', 'mail_template.xml', ], 'installable': True, - } +} diff --git a/sql_export_mail/i18n/fr.po b/sql_export_mail/i18n/fr.po index 483f13599..b308c401e 100644 --- a/sql_export_mail/i18n/fr.po +++ b/sql_export_mail/i18n/fr.po @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * sql_export_mail +# * sql_export_mail # msgid "" msgstr "" @@ -10,47 +10,69 @@ msgstr "" "PO-Revision-Date: 2017-07-18 13:15+0000\n" "Last-Translator: <>\n" "Language-Team: \n" +"Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: \n" "Plural-Forms: \n" #. module: sql_export_mail -#: model:email.template,body_html:sql_export_mail.sql_export_mailer -msgid "\n" -"
\n" +#: model:mail.template,body_html:sql_export_mail.sql_export_mailer +#, fuzzy +#| msgid "" +#| "\n" +#| "
\n" +#| "\n" +#| "

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

\n" +#| "\n" +#| "
\n" +#| " " +msgid "" "\n" -"

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

\n" +"
\n" +"\n" +"

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

\n" "\n" "
\n" -" " -msgstr "\n" -"
\n" +" " +msgstr "" "\n" -"

Vous trouverez le rapport ${object.name or ''} en pièce jointe de ce mail.

\n" +"
\n" +"\n" +"

Vous trouverez le rapport ${object.name or ''} en pièce jointe de ce mail." +"

\n" "\n" "
\n" " " #. module: sql_export_mail -#: model:email.template,subject:sql_export_mail.sql_export_mailer +#: model:mail.template,subject:sql_export_mail.sql_export_mailer msgid "${object.name or ''}" msgstr "${object.name or ''}" #. module: sql_export_mail -#: help:sql.export,mail_user_ids:0 -msgid "Add the users who want to receive the report by e-mail. You need to link the sql query with a cron to send mail automatically" -msgstr "Ajoutez les utilisateurs voulant recevoir le rapport par mail. Vous devez ensuite créer une tâche planifiée pour envoyer le mail automatiquement." +#: model:ir.model.fields,help:sql_export_mail.field_sql_export__mail_user_ids +msgid "" +"Add the users who want to receive the report by e-mail. You need to link the " +"sql query with a cron to send mail automatically" +msgstr "" +"Ajoutez les utilisateurs voulant recevoir le rapport par mail. Vous devez " +"ensuite créer une tâche planifiée pour envoyer le mail automatiquement." #. module: sql_export_mail -#: view:sql.export:sql_export_mail.sql_export_mail_view_form +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Create Cron" msgstr "Créer une tâche planfiée" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_cron_ids -#: view:sql.export:sql_export_mail.sql_export_mail_view_form -#: field:sql.export,cron_ids:0 +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__cron_ids +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Crons" msgstr "Tâches planifiées" @@ -60,15 +82,20 @@ msgid "File Not Empty" msgstr "Fichier non vide." #. module: sql_export_mail -#: code:addons/sql_export_mail/models/sql_export.py:126 +#: code:addons/sql_export_mail/models/sql_export.py:124 #, python-format -msgid "It is not possible to execute and send a query automatically by mail if there are parameters to fill" -msgstr "Il n'est pas possible d'exécuter en envoyer le résultat d'une requête par mail si celle-ci contient des paramètres." +msgid "" +"It is not possible to execute and send a query automatically by mail if " +"there are parameters to fill" +msgstr "" +"Il n'est pas possible d'exécuter en envoyer le résultat d'une requête par " +"mail si celle-ci contient des paramètres." #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_mail_condition -#: field:sql.export,mail_condition:0 -msgid "Mail condition" +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_condition +#, fuzzy +#| msgid "Mail condition" +msgid "Mail Condition" msgstr "Condition d'envoi par mail" #. module: sql_export_mail @@ -77,18 +104,17 @@ msgid "SQL export" msgstr "Export SQL" #. module: sql_export_mail -#: code:addons/sql_export_mail/models/sql_export.py:135 +#: code:addons/sql_export_mail/models/sql_export.py:134 #, python-format msgid "The user does not have any e-mail address." msgstr "L'utilisateur selectionné n'a pas d'addresse mail." #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_mail_user_ids -#: field:sql.export,mail_user_ids:0 +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_user_ids msgid "User to notify" msgstr "Utilisateurs à notifier par mail" #. module: sql_export_mail -#: view:sql.export:sql_export_mail.sql_export_mail_view_form +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Users Notified by e-mail" msgstr "Utilisateurs notifiés par mail" diff --git a/sql_export_mail/i18n/sql_export_mail.pot b/sql_export_mail/i18n/sql_export_mail.pot index a27de68f6..4ec87e101 100644 --- a/sql_export_mail/i18n/sql_export_mail.pot +++ b/sql_export_mail/i18n/sql_export_mail.pot @@ -4,10 +4,8 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 8.0\n" +"Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2017-07-18 13:24+0000\n" -"PO-Revision-Date: 2017-07-18 13:24+0000\n" "Last-Translator: <>\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -16,35 +14,34 @@ msgstr "" "Plural-Forms: \n" #. module: sql_export_mail -#: model:email.template,body_html:sql_export_mail.sql_export_mailer +#: model:mail.template,body_html:sql_export_mail.sql_export_mailer msgid "\n" "
\n" "\n" "

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

\n" "\n" "
\n" -" " +" " msgstr "" #. module: sql_export_mail -#: model:email.template,subject:sql_export_mail.sql_export_mailer +#: model:mail.template,subject:sql_export_mail.sql_export_mailer msgid "${object.name or ''}" msgstr "" #. module: sql_export_mail -#: help:sql.export,mail_user_ids:0 +#: model:ir.model.fields,help:sql_export_mail.field_sql_export__mail_user_ids msgid "Add the users who want to receive the report by e-mail. You need to link the sql query with a cron to send mail automatically" msgstr "" #. module: sql_export_mail -#: view:sql.export:sql_export_mail.sql_export_mail_view_form +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Create Cron" msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_cron_ids -#: view:sql.export:sql_export_mail.sql_export_mail_view_form -#: field:sql.export,cron_ids:0 +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__cron_ids +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Crons" msgstr "" @@ -54,15 +51,14 @@ msgid "File Not Empty" msgstr "" #. module: sql_export_mail -#: code:addons/sql_export_mail/models/sql_export.py:126 +#: code:addons/sql_export_mail/models/sql_export.py:124 #, python-format -msgid "It is not possible to execute and send a query automatically by e-mail if there are parameters to fill" +msgid "It is not possible to execute and send a query automatically by mail if there are parameters to fill" msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_mail_condition -#: field:sql.export,mail_condition:0 -msgid "Mail condition" +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_condition +msgid "Mail Condition" msgstr "" #. module: sql_export_mail @@ -71,19 +67,18 @@ msgid "SQL export" msgstr "" #. module: sql_export_mail -#: code:addons/sql_export_mail/models/sql_export.py:135 +#: code:addons/sql_export_mail/models/sql_export.py:134 #, python-format msgid "The user does not have any e-mail address." msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export_mail_user_ids -#: field:sql.export,mail_user_ids:0 +#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_user_ids msgid "User to notify" msgstr "" #. module: sql_export_mail -#: view:sql.export:sql_export_mail.sql_export_mail_view_form +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Users Notified by e-mail" msgstr "" diff --git a/sql_export_mail/mail_template.xml b/sql_export_mail/mail_template.xml index 0bb497d32..d163fc664 100644 --- a/sql_export_mail/mail_template.xml +++ b/sql_export_mail/mail_template.xml @@ -1,24 +1,22 @@ - - + - - - 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 6b0b5a74c..a4478c695 100644 --- a/sql_export_mail/models/sql_export.py +++ b/sql_export_mail/models/sql_export.py @@ -1,12 +1,11 @@ -# -*- coding: utf-8 -*- # Copyright 2019 Akretion # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from openerp import models, fields, api, _ -from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT -from openerp.exceptions import Warning as UserError +from odoo import models, fields, api, _ +from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT +from odoo.exceptions import UserError from datetime import datetime, timedelta -from openerp import SUPERUSER_ID +from odoo import SUPERUSER_ID class SqlExport(models.Model): @@ -34,14 +33,13 @@ class SqlExport(models.Model): def create_cron(self): self.ensure_one() nextcall = datetime.now() + timedelta(hours=2) - nextcall_fmt = datetime.strftime(nextcall, - DEFAULT_SERVER_DATETIME_FORMAT) cron_vals = { 'active': True, - 'model': 'sql.export', - 'function': '_run_all_sql_export_for_cron', + 'model_id': self.env.ref('sql_export.model_sql_export').id, + 'state': 'code', + 'code': 'model._run_all_sql_export_for_cron()', 'name': 'SQL Export : %s' % self.name, - 'nextcall': nextcall_fmt, + 'nextcall': nextcall, 'doall': False, 'numbercall': -1, 'user_id': SUPERUSER_ID, @@ -50,7 +48,9 @@ class SqlExport(models.Model): # 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} + write_vals = { + 'code': 'model._run_all_sql_export_for_cron([%s])' % cron.id + } cron.write(write_vals) self.write({'cron_ids': [(4, cron.id)]}) @@ -135,10 +135,4 @@ class SqlExport(models.Model): self.env.context.get('mail_to')) else: mail_users = self.mail_user_ids - emails = '' - for user in mail_users: - if emails and user.email: - emails += ',' + user.email - elif user.email: - emails += user.email - return emails + return ','.join([x.email for x in mail_users if x.email]) diff --git a/sql_export_mail/static/description/icon.png b/sql_export_mail/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/sql_export_mail/static/description/icon.png differ diff --git a/sql_export_mail/static/description/index.html b/sql_export_mail/static/description/index.html new file mode 100644 index 000000000..b88d51d8e --- /dev/null +++ b/sql_export_mail/static/description/index.html @@ -0,0 +1,431 @@ + + + + + + +SQL Export Mail + + + +
+

SQL Export Mail

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runbot

+

Allow to send the result of a query (made with the module sql_export) by mail.

+

Table of contents

+ +
+

Configuration

+

To configure this module, you need to:

+
    +
  1. Go to the sql query for which you want users to be notified by e-mail.
  2. +
  3. Add users to be notified in the field Users Notified by e-mail.
  4. +
  5. 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
  6. +
+
+
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Akretion
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/sql_export_mail/tests/__init__.py b/sql_export_mail/tests/__init__.py index 1d119c788..8d5f08c3f 100644 --- a/sql_export_mail/tests/__init__.py +++ b/sql_export_mail/tests/__init__.py @@ -1,2 +1 @@ -# -*- coding: utf-8 -*- from . import test_sql_query_mail diff --git a/sql_export_mail/tests/test_sql_query_mail.py b/sql_export_mail/tests/test_sql_query_mail.py index 0a021e2d6..e028b4960 100644 --- a/sql_export_mail/tests/test_sql_query_mail.py +++ b/sql_export_mail/tests/test_sql_query_mail.py @@ -1,10 +1,9 @@ -# -*- coding: utf-8 -*- # Copyright (C) 2019 Akretion () # @author: Florian da Costa # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from openerp.tests.common import TransactionCase -from openerp import SUPERUSER_ID +from odoo.tests.common import TransactionCase +from odoo import SUPERUSER_ID class TestExportSqlQueryMail(TransactionCase): @@ -14,20 +13,17 @@ class TestExportSqlQueryMail(TransactionCase): self.sql_report_demo = self.env.ref('sql_export.sql_export_partner') self.sql_report_demo.write({'mail_user_ids': [(4, SUPERUSER_ID)]}) - def test_sql_query_create_cron(self): - self.sql_report_demo.create_cron() - self.assertTrue(self.sql_report_demo.cron_ids) - cron = self.sql_report_demo.cron_ids - self.assertEqual(cron.function, '_run_all_sql_export_for_cron') - def test_sql_query_mail(self): mail_obj = self.env['mail.mail'] mails = mail_obj.search( [('model', '=', 'sql.export'), ('res_id', '=', self.sql_report_demo.id)]) self.assertFalse(mails) - self.sql_report_demo.send_mail() + self.sql_report_demo.create_cron() + self.assertTrue(self.sql_report_demo.cron_ids) + self.sql_report_demo.cron_ids.method_direct_trigger() mails = mail_obj.search( [('model', '=', 'sql.export'), ('res_id', '=', self.sql_report_demo.id)]) self.assertTrue(mails) + self.assertTrue(mails.attachment_ids) diff --git a/sql_export_mail/views/sql_export_view.xml b/sql_export_mail/views/sql_export_view.xml index a2f0fe781..93a94c5b9 100644 --- a/sql_export_mail/views/sql_export_view.xml +++ b/sql_export_mail/views/sql_export_view.xml @@ -1,6 +1,5 @@ - - + @@ -27,5 +26,4 @@ - - +