Browse Source

Migrate to v12

12.0-mig-module_prototyper_last
Florian da Costa 6 years ago
parent
commit
8a23db0fb9
  1. 16
      sql_export_mail/__manifest__.py
  2. 4
      sql_export_mail/mail_template.xml
  3. 30
      sql_export_mail/models/sql_export.py
  4. 1
      sql_export_mail/tests/__init__.py
  5. 16
      sql_export_mail/tests/test_sql_query_mail.py
  6. 6
      sql_export_mail/views/sql_export_view.xml

16
sql_export_mail/__openerp__.py → sql_export_mail/__manifest__.py

@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'SQL Export Mail',
'version': '9.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)',
'website': 'http://github/oca/server-tools',
'license': 'AGPL-3',
'category': 'Generic Modules/Others',
'version': '12.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',
],
'license': 'AGPL-3',
'data': [
'views/sql_export_view.xml',
'mail_template.xml',
],
'installable': True,
}
}

4
sql_export_mail/mail_template.xml

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<odoo noupdate="1">
<!-- Error Email template -->
<record id="sql_export_mailer" model="mail.template">
@ -20,5 +19,4 @@
]]></field>
</record>
</data>
</odoo>

30
sql_export_mail/models/sql_export.py

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Akretion
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from openerp import models, fields, api, _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp.exceptions import Warning as UserError
from odoo import models, fields, api, _
from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from odoo.exceptions import UserError
from datetime import datetime, timedelta
from openerp import SUPERUSER_ID
from odoo import SUPERUSER_ID
class SqlExport(models.Model):
@ -34,14 +33,13 @@ class SqlExport(models.Model):
def create_cron(self):
self.ensure_one()
nextcall = datetime.now() + timedelta(hours=2)
nextcall_fmt = datetime.strftime(nextcall,
DEFAULT_SERVER_DATETIME_FORMAT)
cron_vals = {
'active': True,
'model': 'sql.export',
'function': '_run_all_sql_export_for_cron',
'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_fmt,
'nextcall': nextcall,
'doall': False,
'numbercall': -1,
'user_id': SUPERUSER_ID,
@ -50,7 +48,9 @@ class SqlExport(models.Model):
# 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}
write_vals = {
'code': 'model._run_all_sql_export_for_cron([%s])' % cron.id
}
cron.write(write_vals)
self.write({'cron_ids': [(4, cron.id)]})
@ -135,10 +135,4 @@ class SqlExport(models.Model):
self.env.context.get('mail_to'))
else:
mail_users = self.mail_user_ids
emails = ''
for user in mail_users:
if emails and user.email:
emails += ',' + user.email
elif user.email:
emails += user.email
return emails
return ','.join([x.email for x in mail_users if x.email])

1
sql_export_mail/tests/__init__.py

@ -1,2 +1 @@
# -*- coding: utf-8 -*-
from . import test_sql_query_mail

16
sql_export_mail/tests/test_sql_query_mail.py

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# 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).
from openerp.tests.common import TransactionCase
from openerp import SUPERUSER_ID
from odoo.tests.common import TransactionCase
from odoo import SUPERUSER_ID
class TestExportSqlQueryMail(TransactionCase):
@ -14,20 +13,17 @@ class TestExportSqlQueryMail(TransactionCase):
self.sql_report_demo = self.env.ref('sql_export.sql_export_partner')
self.sql_report_demo.write({'mail_user_ids': [(4, SUPERUSER_ID)]})
def test_sql_query_create_cron(self):
self.sql_report_demo.create_cron()
self.assertTrue(self.sql_report_demo.cron_ids)
cron = self.sql_report_demo.cron_ids
self.assertEqual(cron.function, '_run_all_sql_export_for_cron')
def test_sql_query_mail(self):
mail_obj = self.env['mail.mail']
mails = mail_obj.search(
[('model', '=', 'sql.export'),
('res_id', '=', self.sql_report_demo.id)])
self.assertFalse(mails)
self.sql_report_demo.send_mail()
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(
[('model', '=', 'sql.export'),
('res_id', '=', self.sql_report_demo.id)])
self.assertTrue(mails)
self.assertTrue(mails.attachment_ids)

6
sql_export_mail/views/sql_export_view.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="sql_export_mail_view_form" model="ir.ui.view">
@ -27,5 +26,4 @@
</field>
</record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save