[IMP]: CRM Ergonomy Improvement blueprint: Modifications for removing simple wizard and put osv_memory wizard instead of it ,for onchange issue in CRM

bzr revid: rpa@tinyerp.com-20091029112713-p7ozeg2ni2x92xbj
This commit is contained in:
rpa (Open ERP) 2009-10-29 16:57:13 +05:30
parent 337c086db0
commit c4919b57df
4 changed files with 71 additions and 85 deletions

View File

@ -1039,5 +1039,43 @@ class crm_email_history(osv.osv):
_order = 'id desc'
crm_email_history()
class crm_email_add_cc_wizard(osv.osv_memory):
_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),
}
def change_email(self, cr, uid, ids, user, partner):
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={}):
email = self.read(cr, uid, ids[0])['email']
if not context:
return {}
history_line = self.pool.get('crm.case.history').browse(cr, uid, context['active_id'])
crm_case = self.pool.get('crm.case')
case_id = history_line.log_id.case_id.id
crm_case.write(cr, uid, case_id, {'email_cc' : email})
return {}
crm_email_add_cc_wizard()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -239,11 +239,37 @@
</record>
<menuitem action="crm_case_rule-act" id="menu_crm_case_rule-act" parent="crm.next_id_51"/>
<wizard string="Add a CC"
model="crm.case"
menu = "False"
name="crm.case.email.add_cc"
id="wizard_crm_case_email_add_cc"/>
<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"/>
<separator string="Test" 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>
<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 -->
<record id="crm_case_log_tree-view" model="ir.ui.view">
@ -395,8 +421,8 @@
<field name="email"/>
<field name="canal_id"/>
<button
string="Add a CC"
name="%(wizard_crm_case_email_add_cc)d"
string="Add a CC"
name="%(action_view_crm_email_add_cc_wizard)d"
icon="gtk-add" type="action"/>
</group>
<newline/>

View File

@ -23,7 +23,6 @@ import crm_wizard
import wizard_crm_send_email
import wizard_crm_new_send_email
import wizard_fetch_mail
import wizard_add_cc
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,77 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2009 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/>.
#
##############################################################################
import time
import wizard
import osv
import pooler
cc_form = '''<?xml version="1.0"?>
<form string="Add a CC">
<field name="send_to"/>
<newline/>
<field name="user_id" attrs="{'readonly' : [('send_to','!=','user')], 'required' : [('send_to','=','user')]}"/>
<field name="partner_id" attrs="{'readonly' : [('send_to','!=','partner')], 'required' : [('send_to','=','partner')]}"/>/>
<field name="email"/>
</form>'''
#on_change="change_email(user_id, partner_id)"
cc_fields = {
'send_to' : {'string' : 'Send to', 'type' : 'selection', 'required' :True, \
'selection' :[('user','User'),('partner','Partner'),('email','Email Address')], \
'default' : 'email'},
'user_id' : {'string' : 'User', 'type' : 'many2one', 'relation' : 'res.users'},
'partner_id' : {'string' : 'Partner', 'type' : 'many2one', 'relation' : 'res.partner'},
'email' : {'string' : 'Email', 'type' : 'char', 'size' : 24},
}
#def change_email(self, cr, uid, data, context):
# return {}
def email_cc_add(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
history_line = pool.get('crm.case.history').browse(cr, uid, data['id'])
crm_case = pool.get('crm.case')
case_id = history_line.log_id.case_id.id
crm_case.write(cr, uid, case_id, {'email_cc' : data['form']['email']})
#TODO: send the latest email to the email adderss
return {}
class wizard_add_cc(wizard.interface):
states = {
'init' : {
'actions' : [],
'result' : {'type' : 'form', 'arch' : cc_form, 'fields' :cc_fields,\
'state' :[('end','Cancel', 'gtk-cancel'),('add','Ok', 'gtk-go-forward' )]}
},
'add' : {
'actions' : [email_cc_add],
'result' : {'type' : 'state', 'state' : 'end'}
}
}
wizard_add_cc('crm.case.email.add_cc')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: