From 6ecad7a5ba94f757975ab005f5b2671516456258 Mon Sep 17 00:00:00 2001 From: Sylvain LE GAL Date: Wed, 26 Oct 2022 16:24:25 +0200 Subject: [PATCH] [MIG] sql_export_mail from OCA/server-tools 14.0 to OCA/reporting-engine 16.0 branch - Update views, regarding changes in sql_export module - Add prepare function for cron vals --- sql_export_mail/README.rst | 25 +++++--- sql_export_mail/__manifest__.py | 14 +++-- sql_export_mail/{ => data}/mail_template.xml | 0 sql_export_mail/i18n/sql_export_mail.pot | 58 ++++--------------- sql_export_mail/models/sql_export.py | 27 +++++---- sql_export_mail/static/description/index.html | 11 ++-- sql_export_mail/views/sql_export_view.xml | 29 ++++++---- 7 files changed, 75 insertions(+), 89 deletions(-) rename sql_export_mail/{ => data}/mail_template.xml (100%) diff --git a/sql_export_mail/README.rst b/sql_export_mail/README.rst index 89058c698..ba67e1e68 100644 --- a/sql_export_mail/README.rst +++ b/sql_export_mail/README.rst @@ -13,14 +13,14 @@ SQL Export Mail .. |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/14.0/sql_export_mail - :alt: OCA/server-tools +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github + :target: https://github.com/OCA/reporting-engine/tree/16.0/sql_export_mail + :alt: OCA/reporting-engine .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-tools-14-0/server-tools-14-0-sql_export_mail + :target: https://translation.odoo-community.org/projects/reporting-engine-16-0/reporting-engine-16-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/14.0 + :target: https://runbot.odoo-community.org/runbot/143/16.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -46,10 +46,10 @@ To configure this module, you need to: Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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 `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -60,6 +60,7 @@ Authors ~~~~~~~ * Akretion +* GRAP Contributors ~~~~~~~~~~~~ @@ -80,6 +81,14 @@ 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. +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/reporting-engine `_ 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/__manifest__.py b/sql_export_mail/__manifest__.py index 278d42817..e6768b832 100644 --- a/sql_export_mail/__manifest__.py +++ b/sql_export_mail/__manifest__.py @@ -1,16 +1,20 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). { "name": "SQL Export Mail", - "version": "14.0.1.0.0", + "version": "16.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"], + "author": "Akretion,GRAP,Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "website": "https://github.com/OCA/reporting-engine", + "depends": [ + "mail", + "sql_export", + ], "license": "AGPL-3", "data": [ "views/sql_export_view.xml", - "mail_template.xml", + "data/mail_template.xml", ], "installable": True, } diff --git a/sql_export_mail/mail_template.xml b/sql_export_mail/data/mail_template.xml similarity index 100% rename from sql_export_mail/mail_template.xml rename to sql_export_mail/data/mail_template.xml diff --git a/sql_export_mail/i18n/sql_export_mail.pot b/sql_export_mail/i18n/sql_export_mail.pot index 68bf42e1e..35aba27fe 100644 --- a/sql_export_mail/i18n/sql_export_mail.pot +++ b/sql_export_mail/i18n/sql_export_mail.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 14.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" @@ -37,31 +37,6 @@ msgid "" " sql query with a cron to send mail automatically" msgstr "" -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__assigned_attachment_ids -msgid "Assigned Attachments" -msgstr "" - -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__changeset_change_ids -msgid "Changeset Changes" -msgstr "" - -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__changeset_ids -msgid "Changesets" -msgstr "" - -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__count_pending_changeset_changes -msgid "Count Pending Changeset Changes" -msgstr "" - -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__count_pending_changesets -msgid "Count Pending Changesets" -msgstr "" - #. module: sql_export_mail #: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form msgid "Create Cron" @@ -73,22 +48,13 @@ msgstr "" msgid "Crons" msgstr "" -#. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__display_name -msgid "Display Name" -msgstr "" - #. module: sql_export_mail #: model:ir.model.fields.selection,name:sql_export_mail.selection__sql_export__mail_condition__not_empty msgid "File Not Empty" msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__id -msgid "ID" -msgstr "" - -#. module: sql_export_mail +#. odoo-python #: code:addons/sql_export_mail/models/sql_export.py:0 #, python-format msgid "" @@ -97,8 +63,8 @@ msgid "" msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export____last_update -msgid "Last Modified on" +#: model_terms:ir.ui.view,arch_db:sql_export_mail.sql_export_mail_view_form +msgid "Mail" msgstr "" #. module: sql_export_mail @@ -106,27 +72,23 @@ msgstr "" msgid "Mail Condition" msgstr "" +#. module: sql_export_mail +#: model:mail.template,name:sql_export_mail.sql_export_mailer +msgid "SQL Export" +msgstr "" + #. module: sql_export_mail #: model:ir.model,name:sql_export_mail.model_sql_export msgid "SQL export" msgstr "" #. module: sql_export_mail -#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__smart_search -msgid "Smart Search" -msgstr "" - -#. module: sql_export_mail +#. odoo-python #: code:addons/sql_export_mail/models/sql_export.py:0 #, 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__user_can_see_changeset -msgid "User Can See Changeset" -msgstr "" - #. module: sql_export_mail #: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_user_ids msgid "User to notify" diff --git a/sql_export_mail/models/sql_export.py b/sql_export_mail/models/sql_export.py index d3529c638..c30d2d4d2 100644 --- a/sql_export_mail/models/sql_export.py +++ b/sql_export_mail/models/sql_export.py @@ -27,21 +27,23 @@ class SqlExport(models.Model): [("not_empty", "File Not Empty")], default="not_empty" ) - def create_cron(self): + def _prepare_cron_mail(self): self.ensure_one() - nextcall = datetime.now() + timedelta(hours=2) - cron_vals = { + return { "active": True, "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, + "nextcall": datetime.now() + timedelta(hours=2), "doall": False, "numbercall": -1, "user_id": SUPERUSER_ID, } - cron = self.env["ir.cron"].create(cron_vals) + + def create_cron(self): + self.ensure_one() + cron = self.env["ir.cron"].create(self._prepare_cron_mail()) # 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 @@ -51,24 +53,25 @@ class SqlExport(models.Model): def send_mail(self, params=None): self.ensure_one() + params = params or {} mail_template = self.env.ref("sql_export_mail.sql_export_mailer") attach_obj = self.env["ir.attachment"] if self.mail_condition == "not_empty": res = self._execute_sql_request(params=params, mode="fetchone") if not res: return - ctx = self.env.context.copy() - if params: - if "user_id" in params: - ctx["force_user"] = params["user_id"] - if "company_id" in params: - ctx["force_company"] = params["company_id"] + wizard = self.env["sql.file.wizard"].create( { "sql_export_id": self.id, } ) - wizard.with_context(ctx).export_sql() + if "user_id" in params: + wizard = wizard.with_context(force_user=params["user_id"]) + if "company_id" in params: + wizard = wizard.with_context(force_company=params["company_id"]) + + wizard.export_sql() binary = wizard.binary_file filename = wizard.file_name msg_id = mail_template.send_mail(self.id, force_send=False) diff --git a/sql_export_mail/static/description/index.html b/sql_export_mail/static/description/index.html index 680790e0e..e6288135f 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. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> -

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

+

Beta License: AGPL-3 OCA/reporting-engine 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

@@ -395,10 +395,10 @@ use it again for other queries

Bug Tracker

-

Bugs are tracked on GitHub Issues. +

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.

+feedback.

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

@@ -407,6 +407,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Authors

  • Akretion
  • +
  • GRAP
@@ -423,7 +424,9 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

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.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/reporting-engine 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/views/sql_export_view.xml b/sql_export_mail/views/sql_export_view.xml index 7645c5c44..487bad1d9 100644 --- a/sql_export_mail/views/sql_export_view.xml +++ b/sql_export_mail/views/sql_export_view.xml @@ -11,7 +11,6 @@ name="create_cron" string="Create Cron" type="object" - groups="base.group_system" attrs="{'invisible': ['|', ('state', '=', 'draft'), ('mail_user_ids', '=', [(6, False, [])])]}" /> @@ -21,21 +20,27 @@ attrs="{'invisible': [('cron_ids', '=', [(6, False, [])])]}" /> - - - - - - - + + + + + + - - - + + + +