Skip to content

Commit

Permalink
update of manual email confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Apr 18, 2013
1 parent 0b06246 commit d78b311
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 71 deletions.
1 change: 1 addition & 0 deletions email_confirmation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
#################################################################################

import mail_mail
import wizard

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
1 change: 1 addition & 0 deletions email_confirmation/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"init_xml": [],
"data": [
"email_confirmation_view.xml",
"wizard/confirmation_view.xml",
],
"demo": [],
"installable": True,
Expand Down
65 changes: 17 additions & 48 deletions email_confirmation/email_confirmation_view.xml
Original file line number Diff line number Diff line change
@@ -1,72 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="view_waiting_mail_tree" model="ir.ui.view">
<field name="name">waiting mail tree</field>
<field name="model">mail.mail</field>
<field name="inherit_id" ref="mail.view_mail_tree"/>
<field name="arch" type="xml">
<field name="author_id" position="after">
<field name="email_to"/>
</field>
</field>
</record>

<record id="view_waiting_mail_form" model="ir.ui.view">
<record id="view_mail_message_form_waiting" model="ir.ui.view">
<field name="name">waiting mail form</field>
<field name="model">mail.mail</field>
<field name="inherit_id" ref="mail.view_mail_form"/>
<field name="model">mail.message</field>
<field name="inherit_id" ref="mail.view_message_form"/>
<field name="arch" type="xml">
<field name="body_html" position="after">
<button name="confirm_mail" string="Confirm Mail" type="object" class="oe_highlight" attrs="{'invisible':[('state','!=','waiting')]}"/>
<field name="body" position="after">
<newline/>
<button name="confirm_mail" string="Confirm Mail" type="object" class="oe_highlight" attrs="{'invisible':[('type','!=','waiting')]}"/>
</field>
</field>
</record>
<record id="view_waiting_mail_search" model="ir.ui.view" >

<record id="view_mail_message_search_waiting" model="ir.ui.view">
<field name="name">waiting mail search</field>
<field name="model">mail.mail</field>
<field name="model">mail.message</field>
<field name="inherit_id" ref="mail.view_message_search"/>
<field name="arch" type="xml">
<search string="Email Search">
<field name="email_from" filter_domain="['|' '|',('email_from','ilike',self), ('email_to','ilike',self), ('subject','ilike',self)]" string="Email"/>
<field name="date"/>
<filter icon="terp-camera_test" name="received" string="Received" domain="[('state','=','received')]"/>
<filter icon="terp-call-start" name="outgoing" string="Outgoing" domain="[('state','=','outgoing')]"/>
<filter icon="terp-check" name="sent" string="Sent" domain="[('state','=','sent')]"/>
<filter icon="terp-gtk-stop" name="exception" string="Failed" domain="[('state','=','exception')]"/>
<filter name="waiting" string="Waiting Confirmation" domain="[('state','=','waiting')]"/>
<separator/>
<filter icon="terp-camera_test" name="type_email" string="Email" domain="[('type','=','email')]"/>
<filter icon="terp-camera_test" name="type_comment" string="Comment" domain="[('type','=','comment')]"/>
<filter icon="terp-camera_test" name="type_notification" string="Notification" domain="[('type','=','notification')]"/>
<group expand="0" string="Extended Filters...">
<field name="author_id"/>
<field name="partner_ids"/>
<field name="model"/>
<field name="res_id"/>
</group>
<group expand="0" string="Group By...">
<filter string="Status" name="status" domain="[]" context="{'group_by':'state'}"/>
<filter string="Author" name="author" context="{'group_by':'author_id'}"/>
<filter string="Thread" name="thread" domain="[]" context="{'group_by':'message_id'}"/>
<filter string="Month" name="month" help="Creation Month" domain="[]" context="{'group_by':'date'}"/>
</group>
</search>
<filter name="emails" position="after">
<filter string="Waiting Emails" name="waiting" domain="[('type', '=', 'waiting')]"/>
</filter>
</field>
</record>


<record id="action_view_waiting_mail" model="ir.actions.act_window">
<field name="name">Waiting Mail</field>
<field name="res_model">mail.mail</field>
<field name="res_model">mail.message</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="context">{'search_default_waiting': 1, 'search_default_type_email': 1}</field>
<field name="search_view_id" ref="view_waiting_mail_search"/>
<field name="context">{'search_default_waiting': 1}</field>
<field name="search_view_id" ref="view_mail_message_search_waiting"/>
</record>

<menuitem name="Waiting Emails" id="menu_waiting_mail" parent="mail.mail_feeds" sequence="40" action="action_view_waiting_mail" />

</data>
</openerp>

39 changes: 16 additions & 23 deletions email_confirmation/mail_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,35 +21,28 @@
from openerp.osv import fields, osv, orm
from openerp.tools.translate import _

#TODO: For the moment only manual create mail are in "waiting" state ,
# All the automatic mail creation need to be confirm before sending


class mail_mail(orm.Model):
_inherit = 'mail.mail'
class mail_message(orm.Model):
_inherit = 'mail.message'

_columns = {
'state': fields.selection([('outgoing', 'Outgoing'),
('sent', 'Sent'),
('waiting', 'Waiting Confirmation'),
('received', 'Received'),
('exception', 'Delivery Failed'),
('cancel', 'Cancelled'),
], 'Status', readonly=True),
'type': fields.selection([
('email', 'Email'),
('comment', 'Comment'),
('notification', 'System notification'),
('waiting', 'Waiting Confirmation'),
], 'Type',
help="Message type: email for email message, notification for system "\
"message, comment for other messages such as user replies"),
}


def create(self, cr, uid,values, context=None):
print context
print values
values.update({'state': 'waiting'})
print values
new_id = super(mail_mail, self).create(cr, uid, values, context=context)
print new_id
return new_id
def create(self, cr, uid, values, context=None):
values.update({'type': 'waiting'})
return super(mail_message, self).create(cr, uid, values, context=context)

def confirm_mail(self, cr, uid, ids, context=None):
res = self.write(cr, uid, ids[0],{'state':'outgoing'},context=context)
for mail_message_id in ids:
res = self.write(cr, uid, mail_message_id, {'type':'email'}, context=context)
self._notify(cr, uid, mail_message_id, context=context)
return res

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
24 changes: 24 additions & 0 deletions email_confirmation/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2012 Julius Network Solutions SARL <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#################################################################################

import mail_confirmation

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
39 changes: 39 additions & 0 deletions email_confirmation/wizard/confirmation_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>

<record id="view_confirm_waiting_mail_form" model="ir.ui.view">
<field name="name">confirm.mail.message.form</field>
<field name="model">confirm.mail.message</field>
<field name="arch" type="xml">
<form string="Confirm selected Mails" version="7.0">
<header>
<button string="Confirm Mails" name="confirm_mails" type="object" class="oe_highlight"/>
or
<button string="Cancel" class="oe_link" special="cancel"/>
</header>
</form>
</field>
</record>

<record id="action_confirm_waiting_mail" model="ir.actions.act_window">
<field name="name">Confirm Waiting Mails</field>
<field name="res_model">confirm.mail.message</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_confirm_waiting_mail_form"/>
<field name="target">new</field>
</record>

<record model="ir.values" id="confirm_waiting_mail">
<field name="model_id" ref="mail.model_mail_message" />
<field name="name">Confirm Mail</field>
<field name="key2">client_action_multi</field>
<field name="value" eval="'ir.actions.act_window,' + str(ref('action_confirm_waiting_mail'))" />
<field name="key">action</field>
<field name="model">mail.message</field>
</record>

</data>
</openerp>

34 changes: 34 additions & 0 deletions email_confirmation/wizard/mail_confirmation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
#################################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2012 Julius Network Solutions SARL <[email protected]>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#################################################################################

from openerp.osv import fields, orm
from openerp.tools.translate import _

class confirm_mail_message(orm.TransientModel):
_name = "confirm.mail.message"

def confirm_mails(self, cr, uid, ids, context=None):
if context is None:
context = {}
self.pool.get('mail.message').confirm_mail(cr, uid, context.get(('active_ids'), []), context=context)
return {'type': 'ir.actions.act_window_close',}

# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

0 comments on commit d78b311

Please sign in to comment.