[IMP]: crm: Apply view_init method in crm

bzr revid: ksa@tinyerp.co.in-20100318101735-0w9qsa4bqw2s93zq
This commit is contained in:
ksa (Open ERP) 2010-03-18 15:47:35 +05:30
parent df1b66d74d
commit 599c2043ae
3 changed files with 164 additions and 124 deletions

View File

@ -31,18 +31,36 @@ class crm_lead2partner(osv.osv_memory):
_columns = {
'action': fields.selection([('exist', 'Link to an existing partner'), \
('create', 'Create a new partner')], \
'Action', required=True),
'Action', required=True),
'partner_id': fields.many2one('res.partner', 'Partner')
}
def view_init(self, cr, uid, fields, context=None):
"""
This function checks for precondition before wizard executes
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
"""
lead_obj = self.pool.get('crm.lead')
rec_ids = context and context.get('active_ids', [])
for lead in lead_obj.browse(cr, uid, rec_ids, context=context):
if lead.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this lead.'))
def _select_partner(self, cr, uid, context=None):
"""
This function Searches for Partner from selected lead.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@return : Partner id if any for selected lead.
"""
@ -55,10 +73,6 @@ class crm_lead2partner(osv.osv_memory):
rec_ids = context and context.get('active_ids', [])
value={}
for lead in lead_obj.browse(cr, uid, rec_ids, context=context):
if lead.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this lead.'))
partner_ids = partner_obj.search(cr, uid, [('name', '=', lead.partner_name or lead.name)])
if not partner_ids and lead.email_from:
address_ids = contact_obj.search(cr, uid, [('email', '=', lead.email_from)])
@ -70,7 +84,7 @@ class crm_lead2partner(osv.osv_memory):
return partner_id
_defaults = {
'action': lambda *a:'exist',
'action': lambda *a:'exist',
'partner_id': _select_partner
}
@ -92,13 +106,13 @@ class crm_lead2partner(osv.osv_memory):
view_id = view_obj.search(cr, uid, [('model', '=', 'crm.lead2partner'), \
('name', '=', 'crm.lead2partner.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.lead2partner',
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.lead2partner',
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
}
@ -123,32 +137,32 @@ class crm_lead2partner(osv.osv_memory):
partner_id = False
contact_id = False
rec_ids = context and context.get('active_ids', [])
for data in self.browse(cr, uid, ids):
for lead in lead_obj.browse(cr, uid, rec_ids):
if data.action == 'create':
partner_id = partner_obj.create(cr, uid, {
'name': lead.partner_name or lead.name,
'user_id': lead.user_id.id,
'comment': lead.description,
'name': lead.partner_name or lead.name,
'user_id': lead.user_id.id,
'comment': lead.description,
})
contact_id = contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': lead.name,
'phone': lead.phone,
'mobile': lead.mobile,
'email': lead.email_from,
'fax': lead.fax,
'title': lead.title,
'function': lead.function and lead.function.id or False,
'street': lead.street,
'street2': lead.street2,
'zip': lead.zip,
'city': lead.city,
'country_id': lead.country_id and lead.country_id.id or False,
'state_id': lead.state_id and lead.state_id.id or False,
'partner_id': partner_id,
'name': lead.name,
'phone': lead.phone,
'mobile': lead.mobile,
'email': lead.email_from,
'fax': lead.fax,
'title': lead.title,
'function': lead.function and lead.function.id or False,
'street': lead.street,
'street2': lead.street2,
'zip': lead.zip,
'city': lead.city,
'country_id': lead.country_id and lead.country_id.id or False,
'state_id': lead.state_id and lead.state_id.id or False,
})
else:
if data.partner_id:
partner_id = data.partner_id.id
@ -184,14 +198,14 @@ class crm_lead2partner(osv.osv_memory):
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value

View File

@ -40,6 +40,23 @@ class crm_phonecall2opportunity(osv.osv_memory):
return {'type':'ir.actions.act_window_close'}
def view_init(self, cr, uid, fields, context=None):
"""
This function checks for precondition before wizard executes
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
"""
record_id = context and context.get('active_id', False) or False
case = phonecall_obj.browse(cr, uid, record_id, context=context)
if case.state in ['done', 'cancel']:
raise osv.except_osv(_("Warning"), _("Closed/Cancelled Phone \
Call Could not convert into Opportunity"))
def action_apply(self, cr, uid, ids, context=None):
"""
This converts Phonecall to Opportunity and opens Phonecall view
@ -56,60 +73,55 @@ class crm_phonecall2opportunity(osv.osv_memory):
opp_obj = self.pool.get('crm.opportunity')
phonecall_obj = self.pool.get('crm.phonecall')
case = phonecall_obj.browse(cr, uid, record_id, context=context)
data_obj = self.pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
if case.state in ['done', 'cancel']:
raise osv.except_osv(_("Warning"), _("Closed/Cancelled Phone \
Call Could not convert into Opportunity"))
else:
data_obj = self.pool.get('ir.model.data')
result = data_obj._get_id(cr, uid, 'crm', 'view_crm_case_opportunities_filter')
res = data_obj.read(cr, uid, result, ['res_id'])
id2 = data_obj._get_id(cr, uid, 'crm', 'crm_case_form_view_oppor')
id3 = data_obj._get_id(cr, uid, 'crm', 'crm_case_tree_view_oppor')
if id2:
id2 = data_obj.browse(cr, uid, id2, context=context).res_id
if id3:
id3 = data_obj.browse(cr, uid, id3, context=context).res_id
for this in self.browse(cr, uid, ids, context=context):
new_opportunity_id = opp_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': this.partner_id and this.partner_id.id or False,
'section_id': case.section_id and case.section_id.id or False,
'description': case.description or False,
'phonecall_id': case.id,
'priority': case.priority,
'phone': case.partner_phone or False,
})
new_opportunity = opp_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id.id,
'opportunity_id' : new_opportunity_id,
}
phonecall_obj.write(cr, uid, [case.id], vals)
phonecall_obj.case_close(cr, uid, [case.id])
opp_obj.case_open(cr, uid, [new_opportunity_id])
for this in self.browse(cr, uid, ids, context=context):
new_opportunity_id = opp_obj.create(cr, uid, {
'name': this.name,
'planned_revenue': this.planned_revenue,
'probability': this.probability,
'partner_id': this.partner_id and this.partner_id.id or False,
'section_id': case.section_id and case.section_id.id or False,
'description': case.description or False,
'phonecall_id': case.id,
'priority': case.priority,
'phone': case.partner_phone or False,
})
new_opportunity = opp_obj.browse(cr, uid, new_opportunity_id)
vals = {
'partner_id': this.partner_id.id,
'opportunity_id' : new_opportunity_id,
}
phonecall_obj.write(cr, uid, [case.id], vals)
phonecall_obj.case_close(cr, uid, [case.id])
opp_obj.case_open(cr, uid, [new_opportunity_id])
value = {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.opportunity',
'res_id': int(new_opportunity_id),
'view_id': False,
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
value = {
'name': _('Opportunity'),
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'crm.opportunity',
'res_id': int(new_opportunity_id),
'view_id': False,
'views': [(id2, 'form'), (id3, 'tree'), (False, 'calendar'), (False, 'graph')],
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value
_columns = {
'name' : fields.char('Opportunity Summary', size=64, required=True, select=1),
'probability': fields.float('Success Probability'),
'planned_revenue': fields.float('Expected Revenue'),
'partner_id': fields.many2one('res.partner', 'Partner'),
'name' : fields.char('Opportunity Summary', size=64, required=True, select=1),
'probability': fields.float('Success Probability'),
'planned_revenue': fields.float('Expected Revenue'),
'partner_id': fields.many2one('res.partner', 'Partner'),
}
def default_get(self, cr, uid, fields, context=None):
@ -127,7 +139,7 @@ Call Could not convert into Opportunity"))
if record_id:
phonecall = self.pool.get('crm.phonecall').browse(cr, uid, record_id, context=context)
res = {
'name': phonecall.name,
'name': phonecall.name,
'partner_id': phonecall.partner_id and phonecall.partner_id.id or False
}
return res

View File

@ -31,18 +31,36 @@ class crm_phonecall2partner(osv.osv_memory):
_columns = {
'action': fields.selection([('exist', 'Link to an existing partner'), \
('create', 'Create a new partner')], \
'Action', required=True),
'Action', required=True),
'partner_id': fields.many2one('res.partner', 'Partner')
}
def view_init(self, cr, uid, fields, context=None):
"""
This function checks for precondition before wizard executes
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
"""
phonecall_obj = self.pool.get('crm.phonecall')
rec_ids = context and context.get('active_ids', [])
for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
if phonecall.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this phonecall.'))
def _select_partner(self, cr, uid, context=None):
"""
This function Searches for Partner from selected phonecall.
@param self: The object pointer
@param cr: the current row, from the database cursor,
@param uid: the current users ID for security checks,
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@param fields: List of fields for default value
@param context: A standard dictionary for contextual values
@return : Partner id if any for selected phonecall.
"""
@ -56,10 +74,6 @@ class crm_phonecall2partner(osv.osv_memory):
value = {}
for phonecall in phonecall_obj.browse(cr, uid, rec_ids, context=context):
if phonecall.partner_id:
raise osv.except_osv(_('Warning !'),
_('A partner is already defined on this phonecall.'))
partner_ids = partner_obj.search(cr, uid, [('name', '=', phonecall.name or phonecall.name)])
if not partner_ids and phonecall.email_from:
address_ids = contact_obj.search(cr, uid, [('email', '=', phonecall.email_from)])
@ -71,7 +85,7 @@ class crm_phonecall2partner(osv.osv_memory):
return partner_id
_defaults = {
'action': lambda *a:'exist',
'action': lambda *a:'exist',
'partner_id': _select_partner
}
@ -93,13 +107,13 @@ class crm_phonecall2partner(osv.osv_memory):
view_id = view_obj.search(cr, uid, [('model', '=', 'crm.phonecall2partner'), \
('name', '=', 'crm.phonecall2partner.view')])
return {
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.phonecall2partner',
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
'view_mode': 'form',
'view_type': 'form',
'view_id': view_id or False,
'res_model': 'crm.phonecall2partner',
'context': context,
'type': 'ir.actions.act_window',
'target': 'new',
}
@ -124,21 +138,21 @@ class crm_phonecall2partner(osv.osv_memory):
contact_id = False
rec_ids = context and context.get('active_ids', [])
for data in self.browse(cr, uid, ids):
for phonecall in phonecall_obj.browse(cr, uid, rec_ids):
if data.action == 'create':
partner_id = partner_obj.create(cr, uid, {
'name': phonecall.name or phonecall.name,
'user_id': phonecall.user_id.id,
'comment': phonecall.description,
'name': phonecall.name or phonecall.name,
'user_id': phonecall.user_id.id,
'comment': phonecall.description,
})
contact_id = contact_obj.create(cr, uid, {
'partner_id': partner_id,
'name': phonecall.name,
'phone': phonecall.partner_phone,
'partner_id': partner_id,
'name': phonecall.name,
'phone': phonecall.partner_phone,
})
else:
if data.partner_id:
partner_id = data.partner_id.id
@ -174,14 +188,14 @@ class crm_phonecall2partner(osv.osv_memory):
res = mod_obj.read(cr, uid, result, ['res_id'])
value = {
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'domain': "[]",
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'res.partner',
'res_id': partner_ids and int(partner_ids[0]) or False,
'view_id': False,
'context': context,
'type': 'ir.actions.act_window',
'search_view_id': res['res_id']
}
return value