From 9b927664db45c4ac5c18950f2e946cb0a118bd16 Mon Sep 17 00:00:00 2001 From: BT-ssteiner Date: Wed, 13 Mar 2024 13:32:02 +0100 Subject: [PATCH 1/2] [IMG] add unit tests added in v15 --- sql_export_mail/tests/test_sql_query_mail.py | 50 ++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/sql_export_mail/tests/test_sql_query_mail.py b/sql_export_mail/tests/test_sql_query_mail.py index 8de0ce9d01..973b8a52c8 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 @@ def setUp(self): 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) From 571bc0e84862722fd2041e37fb2f36cb1698fa7d Mon Sep 17 00:00:00 2001 From: OCA-git-bot Date: Wed, 13 Mar 2024 13:45:23 +0000 Subject: [PATCH 2/2] [BOT] post-merge updates --- README.md | 2 +- sql_export_mail/README.rst | 2 +- sql_export_mail/__manifest__.py | 2 +- sql_export_mail/static/description/index.html | 3 +-- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index eadde17765..e8fde2331b 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ addon | version | maintainers | summary [report_xml](report_xml/) | 16.0.1.1.1 | | Allow to generate XML reports [sql_export](sql_export/) | 16.0.2.1.0 | [![legalsylvain](https://github.com/legalsylvain.png?size=30px)](https://github.com/legalsylvain) | Export data in csv file with SQL requests [sql_export_excel](sql_export_excel/) | 16.0.1.0.1 | | Allow to export a sql query to an excel file. -[sql_export_mail](sql_export_mail/) | 16.0.2.0.0 | [![legalsylvain](https://github.com/legalsylvain.png?size=30px)](https://github.com/legalsylvain) | Send csv file generated by sql query by mail. +[sql_export_mail](sql_export_mail/) | 16.0.2.0.1 | [![legalsylvain](https://github.com/legalsylvain.png?size=30px)](https://github.com/legalsylvain) | Send csv file generated by sql query by mail. [sql_request_abstract](sql_request_abstract/) | 16.0.1.0.0 | [![legalsylvain](https://github.com/legalsylvain.png?size=30px)](https://github.com/legalsylvain) | Abstract Model to manage SQL Requests [//]: # (end addons) diff --git a/sql_export_mail/README.rst b/sql_export_mail/README.rst index 082cfcebc0..d38f3d662c 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:7545ca6358f23ee0f98d8fa0d2610030bdce7d1dc9a2b1e241be5443612fcf1e + !! source digest: sha256:4c0240a987c3a30a7b125286d9656111d9b2d2744838a58a88c4ae05f4b75e9c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/sql_export_mail/__manifest__.py b/sql_export_mail/__manifest__.py index 371758df08..2be2af0618 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": "16.0.2.0.0", + "version": "16.0.2.0.1", "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/static/description/index.html b/sql_export_mail/static/description/index.html index 3c50d3a358..c7cdf40bc6 100644 --- a/sql_export_mail/static/description/index.html +++ b/sql_export_mail/static/description/index.html @@ -1,4 +1,3 @@ - @@ -367,7 +366,7 @@

SQL Export Mail

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:7545ca6358f23ee0f98d8fa0d2610030bdce7d1dc9a2b1e241be5443612fcf1e +!! source digest: sha256:4c0240a987c3a30a7b125286d9656111d9b2d2744838a58a88c4ae05f4b75e9c !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

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.