[MIG] sql_export_mail: Migration to 14.0

pull/672/head
hkapatel 2021-06-15 17:07:19 +05:30 committed by Sylvain LE GAL
parent f7585a5b92
commit 647d954584
5 changed files with 5 additions and 27 deletions

View File

@ -1,15 +1,12 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{ {
"name": "SQL Export Mail", "name": "SQL Export Mail",
"version": "12.0.1.0.0", "version": "14.0.1.0.0",
"category": "Generic Modules", "category": "Generic Modules",
"summary": "Send csv file generated by sql query by mail.", "summary": "Send csv file generated by sql query by mail.",
"author": "Akretion, Odoo Community Association (OCA)", "author": "Akretion, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/server-tools", "website": "https://github.com/OCA/server-tools",
"depends": [ "depends": ["sql_export", "mail"],
"sql_export",
"mail",
],
"license": "AGPL-3", "license": "AGPL-3",
"data": [ "data": [
"views/sql_export_view.xml", "views/sql_export_view.xml",

View File

@ -19,17 +19,6 @@ msgstr ""
#. module: sql_export_mail #. module: sql_export_mail
#: model:mail.template,body_html:sql_export_mail.sql_export_mailer #: model:mail.template,body_html:sql_export_mail.sql_export_mailer
#, fuzzy #, fuzzy
#| msgid ""
#| "\n"
#| "<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-"
#| "serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; "
#| "\">\n"
#| "\n"
#| "<p>You will find the report ${object.name or ''} as an attachment of the "
#| "mail.</p>\n"
#| "\n"
#| "</div>\n"
#| " "
msgid "" msgid ""
"\n" "\n"
"<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-" "<div style=\"font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-"
@ -94,7 +83,6 @@ msgstr ""
#. module: sql_export_mail #. module: sql_export_mail
#: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_condition #: model:ir.model.fields,field_description:sql_export_mail.field_sql_export__mail_condition
#, fuzzy #, fuzzy
#| msgid "Mail condition"
msgid "Mail Condition" msgid "Mail Condition"
msgstr "Condition d'envoi par mail" msgstr "Condition d'envoi par mail"

View File

@ -5,7 +5,6 @@ from datetime import datetime, timedelta
from odoo import SUPERUSER_ID, _, api, fields, models from odoo import SUPERUSER_ID, _, api, fields, models
from odoo.exceptions import UserError from odoo.exceptions import UserError
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
class SqlExport(models.Model): class SqlExport(models.Model):
@ -28,7 +27,6 @@ class SqlExport(models.Model):
[("not_empty", "File Not Empty")], default="not_empty" [("not_empty", "File Not Empty")], default="not_empty"
) )
@api.multi
def create_cron(self): def create_cron(self):
self.ensure_one() self.ensure_one()
nextcall = datetime.now() + timedelta(hours=2) nextcall = datetime.now() + timedelta(hours=2)
@ -51,11 +49,9 @@ class SqlExport(models.Model):
cron.write(write_vals) cron.write(write_vals)
self.write({"cron_ids": [(4, cron.id)]}) self.write({"cron_ids": [(4, cron.id)]})
@api.multi
def send_mail(self, params=None): def send_mail(self, params=None):
self.ensure_one() self.ensure_one()
mail_template = self.env.ref("sql_export_mail.sql_export_mailer") mail_template = self.env.ref("sql_export_mail.sql_export_mailer")
now_time = datetime.strftime(datetime.now(), DEFAULT_SERVER_DATETIME_FORMAT)
attach_obj = self.env["ir.attachment"] attach_obj = self.env["ir.attachment"]
if self.mail_condition == "not_empty": if self.mail_condition == "not_empty":
res = self._execute_sql_request(params=params, mode="fetchone") res = self._execute_sql_request(params=params, mode="fetchone")
@ -78,8 +74,7 @@ class SqlExport(models.Model):
msg_id = mail_template.send_mail(self.id, force_send=False) msg_id = mail_template.send_mail(self.id, force_send=False)
mail = self.env["mail.mail"].browse(msg_id) mail = self.env["mail.mail"].browse(msg_id)
attach_vals = { attach_vals = {
"name": now_time + " - " + self.name, "name": filename,
"datas_fname": filename,
"datas": binary, "datas": binary,
"res_model": "mail.mail", "res_model": "mail.mail",
"res_id": mail.id, "res_id": mail.id,
@ -115,7 +110,6 @@ class SqlExport(models.Model):
else: else:
export.send_mail() export.send_mail()
@api.multi
@api.constrains("field_ids", "mail_user_ids") @api.constrains("field_ids", "mail_user_ids")
def check_no_parameter_if_sent_by_mail(self): def check_no_parameter_if_sent_by_mail(self):
for export in self: for export in self:
@ -127,7 +121,6 @@ class SqlExport(models.Model):
) )
) )
@api.multi
@api.constrains("mail_user_ids") @api.constrains("mail_user_ids")
def check_mail_user(self): def check_mail_user(self):
for export in self: for export in self:
@ -135,7 +128,6 @@ class SqlExport(models.Model):
if not user.email: if not user.email:
raise UserError(_("The user does not have any e-mail address.")) raise UserError(_("The user does not have any e-mail address."))
@api.multi
def get_email_address_for_template(self): def get_email_address_for_template(self):
""" """
Called from mail template Called from mail template

View File

@ -1 +1,2 @@
* Florian da Costa <florian.dacosta@akretion.com> * Florian da Costa <florian.dacosta@akretion.com>
* Helly kapatel <helly.kapatel@initos.com>

View File

@ -30,7 +30,7 @@
<field <field
name="cron_ids" name="cron_ids"
nolabel="1" nolabel="1"
domain="[('function', '=', '_run_all_sql_export_for_cron')]" domain="[('model_id', '=', 'sql.export')]"
groups="base.group_system" groups="base.group_system"
/> />
</group> </group>