Migrate to v12

pull/860/head
Florian da Costa 2019-06-12 19:54:44 +02:00 committed by BT-ssteiner
parent 0f9ad65695
commit 0f8e015530
No known key found for this signature in database
6 changed files with 39 additions and 56 deletions

View File

@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Akretion
# 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': '9.0.1.0.0', 'version': '12.0.1.0.0',
'author': 'Akretion,Odoo Community Association (OCA)', 'category': 'Generic Modules',
'website': 'http://github/oca/server-tools',
'license': 'AGPL-3',
'category': 'Generic Modules/Others',
'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)",
'website': 'https://github.com/OCA/server-tools',
'depends': [ 'depends': [
'sql_export', 'sql_export',
'mail', 'mail',
], ],
'license': 'AGPL-3',
'data': [ 'data': [
'views/sql_export_view.xml', 'views/sql_export_view.xml',
'mail_template.xml', 'mail_template.xml',
], ],
'installable': True, 'installable': True,
} }

View File

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

View File

@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2019 Akretion # Copyright 2019 Akretion
# 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).
from openerp import models, fields, api, _ from odoo import models, fields, api, _
from openerp.tools import DEFAULT_SERVER_DATETIME_FORMAT from odoo.tools import DEFAULT_SERVER_DATETIME_FORMAT
from openerp.exceptions import Warning as UserError from odoo.exceptions import UserError
from datetime import datetime, timedelta from datetime import datetime, timedelta
from openerp import SUPERUSER_ID from odoo import SUPERUSER_ID
class SqlExport(models.Model): class SqlExport(models.Model):
@ -34,14 +33,13 @@ class SqlExport(models.Model):
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)
nextcall_fmt = datetime.strftime(nextcall,
DEFAULT_SERVER_DATETIME_FORMAT)
cron_vals = { cron_vals = {
'active': True, 'active': True,
'model': 'sql.export', 'model_id': self.env.ref('sql_export.model_sql_export').id,
'function': '_run_all_sql_export_for_cron', 'state': 'code',
'code': 'model._run_all_sql_export_for_cron()',
'name': 'SQL Export : %s' % self.name, 'name': 'SQL Export : %s' % self.name,
'nextcall': nextcall_fmt, 'nextcall': nextcall,
'doall': False, 'doall': False,
'numbercall': -1, 'numbercall': -1,
'user_id': SUPERUSER_ID, '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 # 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 # aware of itself in the end method and we need it to find all
# linked sql exports # 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) cron.write(write_vals)
self.write({'cron_ids': [(4, cron.id)]}) self.write({'cron_ids': [(4, cron.id)]})
@ -135,10 +135,4 @@ class SqlExport(models.Model):
self.env.context.get('mail_to')) self.env.context.get('mail_to'))
else: else:
mail_users = self.mail_user_ids mail_users = self.mail_user_ids
emails = '' return ','.join([x.email for x in mail_users if x.email])
for user in mail_users:
if emails and user.email:
emails += ',' + user.email
elif user.email:
emails += user.email
return emails

View File

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

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2019 Akretion (<http://www.akretion.com>) # Copyright (C) 2019 Akretion (<http://www.akretion.com>)
# @author: Florian da Costa # @author: Florian da Costa
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp.tests.common import TransactionCase from odoo.tests.common import TransactionCase
from openerp import SUPERUSER_ID from odoo import SUPERUSER_ID
class TestExportSqlQueryMail(TransactionCase): 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 = self.env.ref('sql_export.sql_export_partner')
self.sql_report_demo.write({'mail_user_ids': [(4, SUPERUSER_ID)]}) 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): def test_sql_query_mail(self):
mail_obj = self.env['mail.mail'] mail_obj = self.env['mail.mail']
mails = mail_obj.search( mails = mail_obj.search(
[('model', '=', 'sql.export'), [('model', '=', 'sql.export'),
('res_id', '=', self.sql_report_demo.id)]) ('res_id', '=', self.sql_report_demo.id)])
self.assertFalse(mails) 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( mails = mail_obj.search(
[('model', '=', 'sql.export'), [('model', '=', 'sql.export'),
('res_id', '=', self.sql_report_demo.id)]) ('res_id', '=', self.sql_report_demo.id)])
self.assertTrue(mails) self.assertTrue(mails)
self.assertTrue(mails.attachment_ids)

View File

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