Browse Source

Migrate sql_export_mail to v9

pull/1604/head
Florian da Costa 5 years ago
parent
commit
e3c175a69c
  1. 64
      sql_export_mail/README.rst
  2. 8
      sql_export_mail/__openerp__.py
  3. 34
      sql_export_mail/mail_template.xml
  4. 13
      sql_export_mail/models/sql_export.py
  5. 7
      sql_export_mail/readme/CONFIGURE.rst
  6. 1
      sql_export_mail/readme/CONTRIBUTORS.rst
  7. 1
      sql_export_mail/readme/DESCRIPTION.rst
  8. 2
      sql_export_mail/tests/test_sql_query_mail.py

64
sql_export_mail/README.rst

@ -1,64 +0,0 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
===============
SQL Export Mail
===============
Allow to send the result of a query (made with the module sql_export) by mail.
Configuration
=============
To configure this module, you need to:
#. Go to the sql query for which you want users to be notified by e-mail.
#. Add users to be notified in the field Users Notified by e-mail.
#. Click on the button create a cron and then configure the cron to run when
you want to. If you already have created a cron for another query, you can
use it again for other queries
Usage
=====
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/8.0
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/server-tools/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.
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------
* Florian da Costa <florian.dacosta@akretion.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
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.
To contribute to this module, please visit https://odoo-community.org.

8
sql_export_mail/__openerp__.py

@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Akretion
# Copyright 2019 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'SQL Export Mail',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'http://www.akretion.com',
'website': 'http://github/oca/server-tools',
'license': 'AGPL-3',
'category': 'Generic Modules/Others',
'summary': 'Export data in csv file with SQL requests',
'summary': 'Send csv file generated by sql query by mail.',
'depends': [
'sql_export',
'mail',

34
sql_export_mail/mail_template.xml

@ -1,28 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 Akretion (http://www.akretion.com/)
The licence is in the file __openerp__.py
-->
<openerp>
<data noupdate="1">
<odoo>
<data noupdate="1">
<!-- Error Email template -->
<record id="sql_export_mailer" model="email.template">
<field name="name">SQL Export</field>
<field name="email_from">admin@example.com</field>
<field name="email_to">${object.get_email_address_for_template()}</field>
<field name="subject">${object.name or ''}</field>
<field name="model_id" ref="sql_export.model_sql_export"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<!-- Error Email template -->
<record id="sql_export_mailer" model="mail.template">
<field name="name">SQL Export</field>
<field name="email_from">admin@example.com</field>
<field name="email_to">${object.get_email_address_for_template()}</field>
<field name="subject">${object.name or ''}</field>
<field name="model_id" ref="sql_export.model_sql_export"/>
<field name="auto_delete" eval="True"/>
<field name="body_html"><![CDATA[
<div style="font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); background-color: #FFF; ">
<p>You will find the report ${object.name or ''} as an attachment of the mail.</p>
</div>
]]></field>
</record>
]]></field>
</record>
</data>
</openerp>
</data>
</odoo>

13
sql_export_mail/models/sql_export.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Akretion
# Copyright 2019 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api, _
@ -47,9 +47,11 @@ class SqlExport(models.Model):
'user_id': SUPERUSER_ID,
}
cron = self.env['ir.cron'].create(cron_vals)
# 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
write_vals = {'args': '[[%s]]' % cron.id}
cron.write(write_vals)
self.write({'cron_ids': [(4, cron.id)]})
@api.multi
@ -64,17 +66,18 @@ class SqlExport(models.Model):
params=params, mode='fetchone')
if not res:
return
binary = self._execute_sql_request(
params=params, mode='stdout', copy_options=self.copy_options)
msg_id = mail_template.send_mail(self.id, force_send=False)
mail = self.env['mail.mail'].browse(msg_id)
attach_vals = {
'name': now_time + ' - ' + self.name,
'datas_fname': now_time + ' - ' + self.name + '.csv',
'datas': binary,
'res_model': 'mail.mail',
'res_id': mail.id,
}
attachment = attach_obj.create(attach_vals)
msg_id = mail_template.send_mail(self.id, force_send=False)
mail = self.env['mail.mail'].browse(msg_id)
mail.write({'attachment_ids': [(4, attachment.id)]})
@api.model

7
sql_export_mail/readme/CONFIGURE.rst

@ -0,0 +1,7 @@
To configure this module, you need to:
#. Go to the sql query for which you want users to be notified by e-mail.
#. Add users to be notified in the field Users Notified by e-mail.
#. Click on the button create a cron and then configure the cron to run when
you want to. If you already have created a cron for another query, you can
use it again for other queries

1
sql_export_mail/readme/CONTRIBUTORS.rst

@ -0,0 +1 @@
* Florian da Costa <florian.dacosta@akretion.com>

1
sql_export_mail/readme/DESCRIPTION.rst

@ -0,0 +1 @@
Allow to send the result of a query (made with the module sql_export) by mail.

2
sql_export_mail/tests/test_sql_query_mail.py

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Akretion (<http://www.akretion.com>)
# Copyright (C) 2019 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

Loading…
Cancel
Save