[REF]: crm: Separated osv_memory wizard for add cc from crm.py into wizard folder

bzr revid: rpa@tinyerp.com-20100323114455-hdla4728nv6cyx69
This commit is contained in:
rpa (Open ERP)
2010-03-23 17:14:55 +05:30
parent a57bd96bea
commit c184f21599
6 changed files with 160 additions and 111 deletions
+1
View File
@@ -74,6 +74,7 @@ between mails and Open ERP.""",
'wizard/crm_partner_to_opportunity_view.xml',
'wizard/crm_send_email_view.xml',
'wizard/crm_email_add_cc_view.xml',
'crm_wizard.xml',
'crm_view.xml',
-74
View File
@@ -894,80 +894,6 @@ class crm_case_history(osv.osv):
crm_case_history()
class crm_email_add_cc_wizard(osv.osv_memory):
""" Email Add CC"""
_name = "crm.email.add.cc"
_description = "Email Add CC"
_columns = {
'name': fields.selection([('user', 'User'), ('partner', 'Partner'),\
('email', 'Email Address')], 'Send to', required=True),
'user_id': fields.many2one('res.users', "User"),
'partner_id': fields.many2one('res.partner', "Partner"),
'email': fields.char('Email', size=32),
'subject': fields.char('Subject', size=32),
}
def change_email(self, cr, uid, ids, user, partner):
""" @param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Mail’s IDs
"""
if (not partner and not user):
return {'value': {'email': False}}
email = False
if partner:
addr = self.pool.get('res.partner').address_get(cr, uid, [partner], ['contact'])
if addr:
email = self.pool.get('res.partner.address').read(cr, uid, addr['contact'] , ['email'])['email']
elif user:
addr = self.pool.get('res.users').read(cr, uid, user, ['address_id'])['address_id']
if addr:
email = self.pool.get('res.partner.address').read(cr, uid, addr[0] , ['email'])['email']
return {'value': {'email': email}}
def add_cc(self, cr, uid, ids, context={}):
""" @param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of create menu’s IDs
@param context: A standard dictionary for contextual values
"""
data = self.read(cr, uid, ids[0])
email = data['email']
subject = data['subject']
if not context:
return {}
history_line = self.pool.get('crm.case.history').browse(cr, uid, context['active_id'])
model = history_line.log_id.model_id.model
model_pool = self.pool.get(model)
case = model_pool.browse(cr, uid, history_line.log_id.res_id)
body = history_line.description.replace('\n', '\n> ')
flag = tools.email_send(
case.user_id.address_id.email,
[case.email_from],
subject or '[' + str(case.id) + '] ' + case.name,
model_pool.format_body(body),
email_cc = [email],
openobject_id = str(case.id),
subtype = "html"
)
if flag:
model_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + ',' + email or email})
else:
raise osv.except_osv(_('Email Fail!'), ("Lastest Email is not sent successfully"))
return {}
crm_email_add_cc_wizard()
class users(osv.osv):
_inherit = 'res.users'
-35
View File
@@ -194,41 +194,6 @@
<field name="view_id" ref="crm_case_section_view_tree"/>
</record>
<!-- CRM Email Add CC Form View -->
<record id="view_crm_email_add_cc_wizard" model="ir.ui.view">
<field name="name">Add CC</field>
<field name="model">crm.email.add.cc</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Add CC">
<field name="name"/>
<field name="subject"/>
<separator string="" colspan="4"/>
<newline/>
<field name="user_id"
attrs="{ 'required' : [('name','=','user')]}"
on_change="change_email(user_id, partner_id)"/>
<field name="partner_id"
attrs="{'required' : [('name','=','partner')]}"
on_change="change_email(user_id, partner_id)"/>
<field name="email"/>
<button name="add_cc" string="Ok" type="object" icon="gtk-go-forward"/>
</form>
</field>
</record>
<!-- CRM Email Add CC Action -->
<record id="action_view_crm_email_add_cc_wizard" model="ir.actions.act_window">
<field name="name">Add CC</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">crm.email.add.cc</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<!-- Cases Tree View -->
<record id="crm_case_log_tree-view" model="ir.ui.view">
+1 -2
View File
@@ -20,7 +20,7 @@
##############################################################################
import crm_send_email
import wizard_history_event
import crm_email_add_cc
import crm_lead_to_partner
import crm_lead_to_opportunity
@@ -34,6 +34,5 @@ import crm_phonecall_to_meeting
import crm_phonecall_to_opportunity
import crm_partner_to_opportunity
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+106
View File
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# 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 osv import osv, fields
from tools.translate import _
import tools
class crm_email_add_cc_wizard(osv.osv_memory):
""" Email Add CC"""
_name = "crm.email.add.cc"
_description = "Email Add CC"
_columns = {
'name': fields.selection([('user', 'User'), ('partner', 'Partner'), \
('email', 'Email Address')], 'Send to', required=True),
'user_id': fields.many2one('res.users', "User"),
'partner_id': fields.many2one('res.partner', "Partner"),
'email': fields.char('Email', size=32),
'subject': fields.char('Subject', size=32),
}
def on_change_email(self, cr, uid, ids, user, partner):
""" @param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of Mail’s IDs
"""
if (not partner and not user):
return {'value': {'email': False}}
email = False
if partner:
addr = self.pool.get('res.partner').address_get(cr, uid, [partner], ['contact'])
if addr:
email = self.pool.get('res.partner.address').read(cr, uid, addr['contact'] , ['email'])['email']
elif user:
addr = self.pool.get('res.users').read(cr, uid, user, ['address_id'])['address_id']
if addr:
email = self.pool.get('res.partner.address').read(cr, uid, addr[0] , ['email'])['email']
return {'value': {'email': email}}
def add_cc(self, cr, uid, ids, context={}):
"""
Adds CC value in case
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current user’s ID for security checks,
@param ids: List of create menu’s IDs
@param context: A standard dictionary for contextual values
"""
data = self.read(cr, uid, ids[0])
email = data['email']
subject = data['subject']
if not context:
return {}
history_line = self.pool.get('crm.case.history').browse(cr, uid, context['active_id'])
model = history_line.log_id.model_id.model
model_pool = self.pool.get(model)
case = model_pool.browse(cr, uid, history_line.log_id.res_id)
body = history_line.description.replace('\n', '\n> ')
if not case.email_from:
raise osv.except_osv(_('Warning!'), ('No email Address defined for this case..'))
if not email:
raise osv.except_osv(_('Warning!'), ('Please Specify email address..'))
flag = tools.email_send(
case.user_id.address_id.email,
[case.email_from],
subject or '[' + str(case.id) + '] ' + case.name,
model_pool.format_body(body),
email_cc = [email],
openobject_id = str(case.id),
subtype = "html"
)
if flag:
model_pool.write(cr, uid, case.id, {'email_cc' : case.email_cc and case.email_cc + ',' + email or email})
else:
raise osv.except_osv(_('Email Fail!'), ("Lastest Email is not sent successfully"))
return {}
crm_email_add_cc_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
@@ -0,0 +1,52 @@
<openerp>
<data>
<!-- CRM Email Add CC Form View -->
<record id="view_crm_email_add_cc_wizard" model="ir.ui.view">
<field name="name">Add CC</field>
<field name="model">crm.email.add.cc</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Add CC">
<field name="name" width="200" />
<field name="subject" width="200" />
<separator colspan="4" string="" />
<group col="2" colspan="2" attrs="{ 'invisible' : [('name','!=','user')]}">
<field name="user_id"
attrs="{ 'required' : [('name','=','user')]}"
on_change="on_change_email(user_id, partner_id)" />
</group>
<newline />
<group col="2" colspan="2"
attrs="{ 'invisible' : [('name','!=','partner')]}">
<field name="partner_id"
attrs="{'required' : [('name','=','partner')]}"
on_change="on_change_email(user_id, partner_id)" />
</group>
<newline />
<field name="email" attrs="{ 'required' : [('name','=','email')]}" />
<newline />
<separator colspan="4" string="" />
<group col="2" colspan="4">
<label string="" />
<button name="add_cc" string="_Add"
type="object" icon="gtk-ok" />
</group>
</form>
</field>
</record>
<!-- CRM Email Add CC Action -->
<record id="action_view_crm_email_add_cc_wizard" model="ir.actions.act_window">
<field name="name">Add CC</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">crm.email.add.cc</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</data>
</openerp>