diff --git a/sql_export_mail/README.rst b/sql_export_mail/README.rst index f9da42dec..7297e53db 100644 --- a/sql_export_mail/README.rst +++ b/sql_export_mail/README.rst @@ -7,7 +7,7 @@ SQL Export Mail !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:d827e1e84e845e81a875a56e6dbb22176fb86b3ad685cb5c1105e5a79897dfcb + !! source digest: sha256:e07d45bf05ba7798ba09b99f0a16c60cf70c98dc1819c149bedee8461343721e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -70,6 +70,7 @@ Contributors * Florian da Costa * Helly kapatel +* Solange Steiner Maintainers ~~~~~~~~~~~ diff --git a/sql_export_mail/__manifest__.py b/sql_export_mail/__manifest__.py index 71f4fd01d..16aac573c 100644 --- a/sql_export_mail/__manifest__.py +++ b/sql_export_mail/__manifest__.py @@ -1,7 +1,7 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "SQL Export Mail", - "version": "15.0.2.0.0", + "version": "15.0.1.0.0", "category": "Generic Modules", "summary": "Send csv file generated by sql query by mail.", "author": "Akretion,GRAP,Odoo Community Association (OCA)", diff --git a/sql_export_mail/migrations/16.0.1.0.0/noupdate_changes.xml b/sql_export_mail/migrations/16.0.1.0.0/noupdate_changes.xml deleted file mode 100644 index fe76bd1f4..000000000 --- a/sql_export_mail/migrations/16.0.1.0.0/noupdate_changes.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - {{object.get_email_address_for_template()}} - {{object.name or ''}} - -
- -

You will find the report as an attachment of the mail.

- -
-
-
-
diff --git a/sql_export_mail/migrations/16.0.1.0.0/post-migration.py b/sql_export_mail/migrations/16.0.1.0.0/post-migration.py deleted file mode 100644 index bea37ae39..000000000 --- a/sql_export_mail/migrations/16.0.1.0.0/post-migration.py +++ /dev/null @@ -1,8 +0,0 @@ -from openupgradelib import openupgrade - - -@openupgrade.migrate() -def migrate(env, version): - openupgrade.load_data( - env.cr, "sql_export_mail", "migrations/16.0.1.0.0/noupdate_changes.xml" - ) diff --git a/sql_export_mail/models/sql_export.py b/sql_export_mail/models/sql_export.py index 488b9381d..ef871e70e 100644 --- a/sql_export_mail/models/sql_export.py +++ b/sql_export_mail/models/sql_export.py @@ -118,10 +118,10 @@ class SqlExport(models.Model): else: export.send_mail() - @api.constrains("query_properties_definition", "mail_user_ids") + @api.constrains("field_ids", "mail_user_ids") def check_no_parameter_if_sent_by_mail(self): for export in self: - if export.query_properties_definition and export.mail_user_ids: + if export.field_ids and export.mail_user_ids: raise UserError( _( "It is not possible to execute and send a query " diff --git a/sql_export_mail/readme/CONTRIBUTORS.rst b/sql_export_mail/readme/CONTRIBUTORS.rst index c2183a83d..0a2986268 100644 --- a/sql_export_mail/readme/CONTRIBUTORS.rst +++ b/sql_export_mail/readme/CONTRIBUTORS.rst @@ -1,2 +1,3 @@ * Florian da Costa * Helly kapatel +* Solange Steiner diff --git a/sql_export_mail/static/description/index.html b/sql_export_mail/static/description/index.html index 3756d0c10..28b55bea5 100644 --- a/sql_export_mail/static/description/index.html +++ b/sql_export_mail/static/description/index.html @@ -367,7 +367,7 @@ ul.auto-toc { !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:d827e1e84e845e81a875a56e6dbb22176fb86b3ad685cb5c1105e5a79897dfcb +!! source digest: sha256:e07d45bf05ba7798ba09b99f0a16c60cf70c98dc1819c149bedee8461343721e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/reporting-engine Translate me on Weblate Try me on Runboat

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

@@ -417,6 +417,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
diff --git a/sql_export_mail/tests/test_sql_query_mail.py b/sql_export_mail/tests/test_sql_query_mail.py index 8de0ce9d0..973b8a52c 100644 --- a/sql_export_mail/tests/test_sql_query_mail.py +++ b/sql_export_mail/tests/test_sql_query_mail.py @@ -3,6 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). from odoo import SUPERUSER_ID +from odoo.exceptions import UserError from odoo.tests.common import TransactionCase @@ -13,15 +14,58 @@ class TestExportSqlQueryMail(TransactionCase): self.sql_report_demo.write({"mail_user_ids": [(4, SUPERUSER_ID)]}) def test_sql_query_mail(self): - mail_obj = self.env["mail.mail"] - mails = mail_obj.search( + """Check the general execution""" + self.check_before_change() + self.check_execution() + + def test_not_able_add_user(self): + """if there are field_ids, mail_user_ids can not be set""" + sql_report_demo_with_partner = self.env.ref( + "sql_export.sql_export_partner_with_variables" + ) + with self.assertRaises(UserError): + sql_report_demo_with_partner.write( + {"mail_user_ids": [(4, self.env.ref("base.user_demo").id)]} + ) + + def test_sql_query_mail_company(self): + """Check the general execution with %(company_id)s""" + self.check_before_change() + self.sql_report_demo.write( + { + "mail_user_ids": [(4, self.env.ref("base.user_demo").id)], + "query": """SELECT name, street + FROM res_partner where company_id = %(company_id)s""", + } + ) + self.check_execution() + + def test_sql_query_mail_company_user(self): + """Check the general execution with %(company_id)s and %(user_id)s)""" + self.check_before_change() + self.sql_report_demo.write( + { + "mail_user_ids": [(4, self.env.ref("base.user_demo").id)], + "query": """SELECT name, street FROM res_partner + where company_id = %(company_id)s and id in ( + select partner_id from res_users where id = %(user_id)s)""", + } + ) + self.check_execution() + + def check_before_change(self): + """Check if there are no mails before changing the sql report""" + mails = self.env["mail.mail"].search( [("model", "=", "sql.export"), ("res_id", "=", self.sql_report_demo.id)] ) self.assertFalse(mails) + + def check_execution(self): + """Check if the cron could be created and the mail sending is working""" 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( + mails = self.env["mail.mail"].search( [("model", "=", "sql.export"), ("res_id", "=", self.sql_report_demo.id)] ) self.assertTrue(mails) diff --git a/sql_export_mail/views/sql_export_view.xml b/sql_export_mail/views/sql_export_view.xml index 9a9b7aea9..a4da55690 100644 --- a/sql_export_mail/views/sql_export_view.xml +++ b/sql_export_mail/views/sql_export_view.xml @@ -21,8 +21,8 @@ groups="base.group_system" /> - - + + - - + +