diff --git a/setup/sql_export_mail/odoo/addons/sql_export_mail b/setup/sql_export_mail/odoo/addons/sql_export_mail new file mode 120000 index 000000000..2c1bd4889 --- /dev/null +++ b/setup/sql_export_mail/odoo/addons/sql_export_mail @@ -0,0 +1 @@ +../../../../sql_export_mail \ No newline at end of file diff --git a/setup/sql_export_mail/setup.py b/setup/sql_export_mail/setup.py new file mode 100644 index 000000000..28c57bb64 --- /dev/null +++ b/setup/sql_export_mail/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) 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/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/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, [])])]}" /> </button> @@ -21,21 +20,27 @@ attrs="{'invisible': [('cron_ids', '=', [(6, False, [])])]}" /> </field> - <group name="parameters" position="after"> - <group groups="sql_request_abstract.group_sql_request_user"> - <group string="Users Notified by e-mail"> - <field name="mail_user_ids" nolabel="1" /> - </group> - <group string="Crons" groups="base.group_system"> - <field + <page name="page_sql" position="after"> + <page name="page_mail" string="Mail"> + <group string="Users Notified by e-mail"> + <field + name="mail_user_ids" + nolabel="1" + widget="many2many_tags" + colspan="2" + /> + </group> + <group string="Crons"> + <field name="cron_ids" nolabel="1" + colspan="2" domain="[('model_id', '=', 'sql.export')]" - groups="base.group_system" /> - </group> - </group> - </group> + </group> + + </page> + </page> </field> </record>