Laetitia Gangloff
9 years ago
4 changed files with 192 additions and 0 deletions
-
3sql_export_email/__init__.py
-
54sql_export_email/__openerp__.py
-
75sql_export_email/ir_actions.py
-
60sql_export_email/ir_actions_view.xml
@ -0,0 +1,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
|
||||
|
from . import ir_actions |
@ -0,0 +1,54 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Authors: Laetitia Gangloff |
||||
|
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
{ |
||||
|
"name": "SQL export email addon", |
||||
|
"version": "0.1", |
||||
|
"author": "ACSONE SA/NV, Odoo Community Association (OCA)", |
||||
|
"category": "Other", |
||||
|
"website": "http://www.acsone.eu", |
||||
|
"depends": ['email_template', |
||||
|
'sql_export', |
||||
|
'base_export_email', |
||||
|
], |
||||
|
"description": """ |
||||
|
|
||||
|
SQL export email addon |
||||
|
========================= |
||||
|
|
||||
|
Add server action type to send by email a sql export |
||||
|
For this new action type you need to fill the following fields : |
||||
|
- SQL export : it defines the SQL export to use to get the data. |
||||
|
- Template : it is the mail template to send the email. |
||||
|
|
||||
|
Example of use : in a cron for a periodic export of some data |
||||
|
to see the evolution. |
||||
|
|
||||
|
""", |
||||
|
"data": ["ir_actions_view.xml"], |
||||
|
"demo": [], |
||||
|
"test": [], |
||||
|
"active": False, |
||||
|
"license": "AGPL-3", |
||||
|
"installable": True, |
||||
|
"auto_install": False, |
||||
|
"application": False, |
||||
|
} |
@ -0,0 +1,75 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
############################################################################## |
||||
|
# |
||||
|
# Authors: Laetitia Gangloff |
||||
|
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu) |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as |
||||
|
# published by the Free Software Foundation, either version 3 of the |
||||
|
# License, or (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
# |
||||
|
############################################################################## |
||||
|
|
||||
|
from openerp.osv import orm, fields |
||||
|
from openerp.tools.translate import _ |
||||
|
|
||||
|
|
||||
|
class actions_server(orm.Model): |
||||
|
_inherit = "ir.actions.server" |
||||
|
|
||||
|
def __init__(self, pool, cr): |
||||
|
super(actions_server, self).__init__(pool, cr) |
||||
|
# add state 'sql_export_email' |
||||
|
new_state = ('sql_export_email', _('Export SQL data by email')) |
||||
|
if new_state not in self._columns['state'].selection: |
||||
|
self._columns['state'].selection.append(new_state) |
||||
|
return |
||||
|
|
||||
|
_columns = { |
||||
|
'sql_export_id': fields.many2one( |
||||
|
'sql.export', string='SQL export', ondelete='restrict'), |
||||
|
} |
||||
|
|
||||
|
def onchange_state(self, cr, uid, ids, state, context=None): |
||||
|
res = {} |
||||
|
if state == 'sql_export_email': |
||||
|
# model is not used in this type of action, but it is a required |
||||
|
# field, so set the model 'ir.actions.server' |
||||
|
model = self.pool['ir.model'].search( |
||||
|
cr, uid, [('model', '=', 'ir.actions.server')], |
||||
|
context=context) |
||||
|
res['value'] = {'model_id': model[0]} |
||||
|
return res |
||||
|
|
||||
|
def run(self, cr, uid, ids, context=None): |
||||
|
""" |
||||
|
If the state of an action is sql_export_email, |
||||
|
get data related to the sql_export and send the result by email |
||||
|
""" |
||||
|
for action in self.browse(cr, uid, ids, context): |
||||
|
if action.state == 'sql_export_email': |
||||
|
# get data to export |
||||
|
res_id = self.pool['sql.export'].export_sql_query( |
||||
|
cr, uid, [action.sql_export_id.id], |
||||
|
context=context)['res_id'] |
||||
|
data = self.pool['sql.file.wizard'].browse(cr, uid, res_id, |
||||
|
context=context) |
||||
|
if context is None: |
||||
|
context = {} |
||||
|
# data is already encoded in base64 |
||||
|
context['encoded_base_64'] = True |
||||
|
# Prepare a message with the exported data to send with the |
||||
|
# template of the configuration |
||||
|
self._send_email( |
||||
|
cr, uid, action, data['file_name'], data['file'], |
||||
|
context=context) |
||||
|
return super(actions_server, self).run(cr, uid, ids, context=context) |
@ -0,0 +1,60 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="view_server_action_form" model="ir.ui.view"> |
||||
|
<field name="name">Server Action (sql_export_email)</field> |
||||
|
<field name="model">ir.actions.server</field> |
||||
|
<field name="inherit_id" ref="base_export_email.view_server_action_form"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<field name="state" position="attributes"> |
||||
|
<attribute name="on_change">onchange_state(state, context)</attribute> |
||||
|
</field> |
||||
|
<field name="model_id" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible': [('state', '=', 'sql_export_email')]}</attribute> |
||||
|
</field> |
||||
|
<field name="srcmodel_id" position="attributes"> |
||||
|
<attribute name="attrs">{'required': [('state','!=','sql_export_email'), |
||||
|
('state','!=','export_email'), |
||||
|
('state','!=','dummy'), |
||||
|
('state','!=','sms'), |
||||
|
('state','!=','code'), |
||||
|
('state','!=','loop'), |
||||
|
('state','!=','trigger'), |
||||
|
('state','!=','object_copy'), |
||||
|
('state','!=','client_action'), |
||||
|
('state','!=','email'), |
||||
|
('state','!=','sms'), |
||||
|
('state','!=','other')]}</attribute> |
||||
|
</field> |
||||
|
<page string="Export data by email configuration" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible':[('state','!=','export_email'), |
||||
|
('state','!=','sql_export_email')]}</attribute> |
||||
|
</page> |
||||
|
<xpath expr="//page[@string='Export data by email configuration']/group" position='inside'> |
||||
|
<field name ="sql_export_id" attrs="{'required': [('state', '=', 'sql_export_email')], |
||||
|
'invisible': [('state', '!=', 'sql_export_email')]}" /> |
||||
|
</xpath> |
||||
|
<field name="email_template_id" position="attributes"> |
||||
|
<attribute name="attrs">{'required':['|', ('state','=','export_email'), |
||||
|
('state','=','sql_export_email')]}</attribute> |
||||
|
</field> |
||||
|
<field name="export_format" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible':[('state','!=','export_email')], |
||||
|
'required':[('state','=','export_email')]}</attribute> |
||||
|
</field> |
||||
|
<field name="filter_id" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible':[('state','!=','export_email')]}</attribute> |
||||
|
</field> |
||||
|
<field name ="fields_to_export" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible':[('state','!=','export_email')], |
||||
|
'required': [('state', '=', 'export_email'), ('saved_export_id', '=', False)]}</attribute> |
||||
|
</field> |
||||
|
<field name ="saved_export_id" position="attributes"> |
||||
|
<attribute name="attrs">{'invisible':[('state','!=','export_email')], |
||||
|
'required': [('state', '=', 'export_email'), ('fields_to_export', '=', False)]}</attribute> |
||||
|
</field> |
||||
|
|
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue