[FIX] crm View, onchange, history
bzr revid: tfr@openerp.com-20110208133640-4o0trrfk68yx7vu0
This commit is contained in:
parent
a91c3eb988
commit
6ca06b7027
|
@ -287,7 +287,6 @@ class crm_case(object):
|
|||
if part:
|
||||
addr = self.pool.get('res.partner').address_get(cr, uid, [part], ['contact'])
|
||||
data = {'partner_address_id': addr['contact']}
|
||||
data.update(self.onchange_partner_address_id(cr, uid, ids, addr['contact'])['value'])
|
||||
return {'value': data}
|
||||
|
||||
def onchange_partner_address_id(self, cr, uid, ids, add, email=False):
|
||||
|
|
|
@ -279,7 +279,7 @@ class crm_lead(crm_case, osv.osv):
|
|||
|
||||
if 'stage_id' in vals and vals['stage_id']:
|
||||
stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, vals['stage_id'], context=context)
|
||||
self.history(cr, uid, ids, _('Stage'), details=stage_obj.name)
|
||||
self.history(cr, uid, ids, _("Changed Stage to: ") + stage_obj.name, details=_("Changed Stage to: ") + stage_obj.name)
|
||||
message=''
|
||||
for case in self.browse(cr, uid, ids, context=context):
|
||||
if case.type == 'lead' or context.get('stage_type',False)=='lead':
|
||||
|
|
|
@ -89,7 +89,7 @@
|
|||
<field name="state_id"/>
|
||||
</group>
|
||||
<group colspan="2" col="3">
|
||||
<separator string="Communication History" colspan="4" col="3"/>
|
||||
<separator string="Communication" colspan="4" col="3"/>
|
||||
<field name="email_from" widget="email"/>
|
||||
<newline/>
|
||||
<field name="phone"/>
|
||||
|
@ -99,7 +99,7 @@
|
|||
<field name="mobile"/>
|
||||
<newline/>
|
||||
<separator string="Links" colspan="4" col="3"/>
|
||||
<field name="partner_id" on_change="onchange_partner_id(partner_id, email_from)" string="Customer"/>
|
||||
<field name="partner_id" string="Customer"/>
|
||||
<button
|
||||
name="%(action_crm_lead2partner)d"
|
||||
icon="terp-partner" type="action"
|
||||
|
|
|
@ -166,22 +166,22 @@
|
|||
<field name="date"/>
|
||||
<field name="email_to" size="512"/>
|
||||
<field name="email_cc" size="512"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<field name="name" colspan="4" attrs="{'invisible': [('history', '=', True)]}"/>
|
||||
<field name="display_text" colspan="4" attrs="{'invisible': [('history', '=', False)]}"/>
|
||||
<field name="history" invisible="1"/>
|
||||
</group>
|
||||
<notebook colspan="4">
|
||||
<page string="Details">
|
||||
<group attrs="{'invisible': [('history', '!=', True)]}">
|
||||
<field name="description" colspan="4" nolabel="1" height="250"/>
|
||||
|
||||
<field name="description" colspan="4" nolabel="1"/>
|
||||
<group attrs="{'invisible': [('history', '!=', True)]}">
|
||||
<button colspan="4"
|
||||
string="Reply"
|
||||
name="%(crm.action_crm_send_mail)d"
|
||||
context="{'mail':'reply', 'model': 'crm.lead', 'include_original' : True}"
|
||||
icon="terp-mail-replied" type="action" />
|
||||
</group>
|
||||
<group attrs="{'invisible': [('history', '=', True)]}">
|
||||
<field name="display_text" colspan="4" nolabel="1" height="250"/>
|
||||
</group>
|
||||
|
||||
</page>
|
||||
<page string="Attachments">
|
||||
<field name="attachment_ids" colspan="4" readonly="1" nolabel="1"/>
|
||||
|
|
|
@ -37,7 +37,7 @@ class crm_add_note(osv.osv_memory):
|
|||
attach = [
|
||||
(x.name, base64.decodestring(x.binary)) for x in obj.attachment_ids
|
||||
]
|
||||
case_pool.history(cr, uid, [case], _("Note"), history=False,
|
||||
case_pool.history(cr, uid, [case], self.pool.get('mailgate.message').truncate_data(cr, uid, obj.body, context=context), history=False,
|
||||
details=obj.body, email_from=user_name, attach=attach)
|
||||
|
||||
if obj.state == 'unchanged':
|
||||
|
|
|
@ -37,34 +37,34 @@ class crm_lead2opportunity_partner(osv.osv_memory):
|
|||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
Default get for name, opportunity_ids
|
||||
if there is an exisitng partner link to the lead, find all existing opportunity link with this partnet to merge
|
||||
all information together
|
||||
"""
|
||||
lead_obj = self.pool.get('crm.lead')
|
||||
partner_id = False
|
||||
"""
|
||||
Default get for name, opportunity_ids
|
||||
if there is an exisitng partner link to the lead, find all existing opportunity link with this partnet to merge
|
||||
all information together
|
||||
"""
|
||||
lead_obj = self.pool.get('crm.lead')
|
||||
partner_id = False
|
||||
|
||||
|
||||
res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context)
|
||||
opportunities = res.get('opportunity_ids') or []
|
||||
name = 'convert'
|
||||
if res.get('partner_id'):
|
||||
|
||||
partner_id = res.get('partner_id')
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity')])
|
||||
if ids:
|
||||
name = 'merge'
|
||||
opportunities += ids
|
||||
|
||||
res = super(crm_lead2opportunity_partner, self).default_get(cr, uid, fields, context=context)
|
||||
opportunities = res.get('opportunity_ids') or []
|
||||
name = 'convert'
|
||||
if res.get('partner_id'):
|
||||
|
||||
partner_id = res.get('partner_id')
|
||||
ids = lead_obj.search(cr, uid, [('partner_id', '=', partner_id), ('type', '=', 'opportunity')])
|
||||
if ids:
|
||||
name = 'merge'
|
||||
opportunities += ids
|
||||
|
||||
|
||||
if 'name' in fields:
|
||||
res.update({'name' : name})
|
||||
if 'opportunity_ids' in fields:
|
||||
res.update({'opportunity_ids': opportunities})
|
||||
|
||||
if 'name' in fields:
|
||||
res.update({'name' : name})
|
||||
if 'opportunity_ids' in fields:
|
||||
res.update({'opportunity_ids': opportunities})
|
||||
|
||||
|
||||
return res
|
||||
return res
|
||||
|
||||
def view_init(self, cr, uid, fields, context=None):
|
||||
"""
|
||||
|
@ -99,7 +99,7 @@ Leads Could not convert into Opportunity"))
|
|||
'date_action': time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
}
|
||||
lead.write(vals, context=context)
|
||||
leads.history(cr, uid, [lead], _('Opportunity'), details='Converted to Opportunity', context=context)
|
||||
leads.history(cr, uid, [lead], _('Converted to opportunity'), details='Converted to Opportunity', context=context)
|
||||
if lead.partner_id:
|
||||
msg_ids = [ x.id for x in lead.message_ids]
|
||||
self.pool.get('mailgate.message').write(cr, uid, msg_ids, {
|
||||
|
|
|
@ -7,29 +7,28 @@
|
|||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Convert to Opportunity">
|
||||
<group width="540" height="400">
|
||||
<label string="Are you sure you want to create a partner based on this lead ?" colspan="4"/>
|
||||
<label string="You may have to verify that this partner does not exist already." colspan="4"/>
|
||||
<group colspan="4" col="1" attrs="{'invisible':[('msg','=',False)]}">
|
||||
<field name="msg" colspan="4" nolabel="1" height="50"/>
|
||||
</group>
|
||||
<newline />
|
||||
<field name="action"/>
|
||||
<group attrs="{'invisible':[('action','!=','exist')]}">
|
||||
<field name="partner_id" attrs="{'required': [('action', '=', 'exist')]}"/>
|
||||
</group>
|
||||
<separator string="Convert to Opportunity" colspan="4"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<group col="4" colspan="4" attrs="{'invisible': [('name', '=', 'convert')]}">
|
||||
<separator string="Select Opportunities" colspan="4"/>
|
||||
<field name="opportunity_ids" colspan="4" nolabel="1" height="130"/>
|
||||
|
||||
<group colspan="4" col="1" attrs="{'invisible':[('msg','=',False)]}">
|
||||
<field name="msg" colspan="4" nolabel="1" height="50"/>
|
||||
</group>
|
||||
<separator string="" colspan="4" />
|
||||
<group col="4" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="action_apply" string="Create Opportunity" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
</group>
|
||||
<newline />
|
||||
<field name="action"/>
|
||||
<group attrs="{'invisible':[('action','!=','exist')]}">
|
||||
<field name="partner_id" attrs="{'required': [('action', '=', 'exist')]}"/>
|
||||
</group>
|
||||
<separator string="Convert to Opportunity" colspan="4"/>
|
||||
<field name="name" colspan="4"/>
|
||||
<group col="4" colspan="4" attrs="{'invisible': [('name', '=', 'convert')]}" >
|
||||
<separator string="Select Opportunities" colspan="4" />
|
||||
</group>
|
||||
<field name="opportunity_ids" colspan="4" nolabel="1" attrs="{'invisible': [('name', '=', 'convert')]}"/>
|
||||
|
||||
<separator string="" colspan="4" />
|
||||
<group col="4" colspan="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="action_apply" string="Create Opportunity" type="object" icon="gtk-ok"/>
|
||||
</group>
|
||||
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -40,11 +40,7 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
return False
|
||||
|
||||
def _concat_all(self, attr, ops):
|
||||
result = ''
|
||||
for op in ops:
|
||||
if hasattr(op, attr) and getattr(op, attr):
|
||||
result += ' # ' + getattr(op, attr)
|
||||
return result
|
||||
return ', '.join([getattr(op, attr) for op in ops if hasattr(op, attr) and getattr(op, attr)])
|
||||
|
||||
def action_merge(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
|
@ -53,7 +49,7 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
@param cr: the current row, from the database cursor,
|
||||
@param uid: the current user’s ID for security checks,
|
||||
@param ids: List of Phonecall to Opportunity IDs
|
||||
@param context: A standard dictionary for contextual values
|
||||
@param context: A standard dictionary for contextual valuesn
|
||||
|
||||
@return : Dictionary value for created Opportunity form
|
||||
"""
|
||||
|
@ -89,17 +85,17 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
'state_id' : self._get_first_not_null_id('state_id', op_ids),
|
||||
'description' : self._concat_all('description', op_ids), #not lost
|
||||
'email' : self._get_first_not_null('email', op_ids), # !!
|
||||
'fax' : self._get_first_not_null('fax', op_ids),
|
||||
'mobile' : self._get_first_not_null('mobile', op_ids),
|
||||
'partner_latitude' : hasattr(opp_obj,'partner_latitude') and self._get_first_not_null('partner_latitude', op_ids),
|
||||
'partner_longitude' : hasattr(opp_obj,'partner_longitude') and self._get_first_not_null('partner_longitude', op_ids),
|
||||
'partner_name' : self._get_first_not_null('partner_name', op_ids),
|
||||
'phone' : self._get_first_not_null('phone', op_ids),
|
||||
'probability' : self._get_first_not_null('probability', op_ids),
|
||||
'planned_revenue' : self._get_first_not_null('planned_revenue', op_ids),
|
||||
'street' : self._get_first_not_null('street', op_ids),
|
||||
'street2' : self._get_first_not_null('street2', op_ids),
|
||||
'zip' : self._get_first_not_null('zip', op_ids),
|
||||
'fax' : self._get_first_not_null('fax', op_ids),
|
||||
'mobile' : self._get_first_not_null('mobile', op_ids),
|
||||
'partner_latitude' : hasattr(opp_obj,'partner_latitude') and self._get_first_not_null('partner_latitude', op_ids),
|
||||
'partner_longitude' : hasattr(opp_obj,'partner_longitude') and self._get_first_not_null('partner_longitude', op_ids),
|
||||
'partner_name' : self._get_first_not_null('partner_name', op_ids),
|
||||
'phone' : self._get_first_not_null('phone', op_ids),
|
||||
'probability' : self._get_first_not_null('probability', op_ids),
|
||||
'planned_revenue' : self._get_first_not_null('planned_revenue', op_ids),
|
||||
'street' : self._get_first_not_null('street', op_ids),
|
||||
'street2' : self._get_first_not_null('street2', op_ids),
|
||||
'zip' : self._get_first_not_null('zip', op_ids),
|
||||
|
||||
}
|
||||
|
||||
|
@ -110,9 +106,11 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
for history in opp.message_ids:
|
||||
new_history = message_obj.copy(cr, uid, history.id, default={'res_id': opp.id})
|
||||
#Notification about loss of information
|
||||
details = []
|
||||
subject = ['Merged opportunities :']
|
||||
for opp in op_ids:
|
||||
opp_obj._history(cr, uid, [first_opp], _('Merged from Opportunity: %s : Information lost : [Partner: %s, Stage: %s, Section: %s, Salesman: %s, Category: %s, Channel: %s, City: %s, Company: %s, Country: %s, Email: %s, Phone number: %s, Contact name: %s]')
|
||||
% ( opp.name, opp.partner_id.name or '',
|
||||
subject.append(opp.name)
|
||||
details.append(_('Merged Opportunity: %s\n Partner: %s\n Stage: %s\n Section: %s\n Salesman: %s\n Category: %s\n Channel: %s\n City: %s\n Company: %s\n Country: %s\n Email: %s\n Phone number: %s\n Contact name: %s') % ( opp.name, opp.partner_id.name or '',
|
||||
opp.stage_id.name or '',
|
||||
opp.section_id.name or '',
|
||||
opp.user_id.name or '',
|
||||
|
@ -124,6 +122,10 @@ class crm_merge_opportunity(osv.osv_memory):
|
|||
opp.email or '',
|
||||
opp.phone or '',
|
||||
opp.contact_name or ''))
|
||||
subject = subject[0] + ", ".join(subject[1:])
|
||||
details = "\n\n".join(details)
|
||||
|
||||
opp_obj._history(cr, uid, [first_opp], subject, details=details)
|
||||
|
||||
#data.update({'message_ids' : [(6, 0 ,self._concat_o2m('message_ids', op_ids))]})
|
||||
opp_obj.write(cr, uid, [first_opp.id], data)
|
||||
|
|
|
@ -92,12 +92,13 @@ class mailgate_thread(osv.osv):
|
|||
def history(self, cr, uid, cases, keyword, history=False, subject=None, email=False, details=None, \
|
||||
email_from=False, message_id=False, references=None, attach=None, email_cc=None, \
|
||||
email_bcc=None, email_date=None, context=None):
|
||||
print "histpory",details
|
||||
"""
|
||||
@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 cases: a browse record list
|
||||
@param keyword: Case action keyword e.g.: If case is closed "Close" keyword is used
|
||||
@param keyword: Subject of the history item
|
||||
@param history: Value True/False, If True it makes entry in case History otherwise in Case Log
|
||||
@param email: Email-To / Recipient address
|
||||
@param email_from: Email From / Sender address if any
|
||||
|
@ -141,7 +142,7 @@ class mailgate_thread(osv.osv):
|
|||
'res_id': case.id,
|
||||
'date': time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'message_id': message_id,
|
||||
'description': details or (hasattr(case, 'description') and case.description or False),
|
||||
'description': details,
|
||||
'attachment_ids': [(6, 0, attachments)]
|
||||
}
|
||||
|
||||
|
@ -169,6 +170,8 @@ class mailgate_thread(osv.osv):
|
|||
'message_id': message_id,
|
||||
'attachment_ids': [(6, 0, attachments)]
|
||||
}
|
||||
|
||||
print data
|
||||
obj.create(cr, uid, data, context=context)
|
||||
return True
|
||||
mailgate_thread()
|
||||
|
@ -251,15 +254,7 @@ class mailgate_message(osv.osv):
|
|||
msg_txt += self.truncate_data(cr, uid, message.description, context=context)
|
||||
else:
|
||||
msg_txt = (message.user_id.name or '/') + _(' on ') + format_date_tz(message.date, tz) + ':\n\t'
|
||||
if message.name == _('Opportunity'):
|
||||
msg_txt += _("Converted to Opportunity")
|
||||
elif message.name == _('Note'):
|
||||
msg_txt = (message.user_id.name or '/') + _(' added note on ') + format_date_tz(message.date, tz) + ':\n\t'
|
||||
msg_txt += self.truncate_data(cr, uid, message.description, context=context)
|
||||
elif message.name == _('Stage'):
|
||||
msg_txt += _("Changed Stage to: ") + message.description
|
||||
else:
|
||||
msg_txt += _("Changed Status to: ") + message.name
|
||||
msg_txt += message.name
|
||||
result[message.id] = msg_txt
|
||||
return result
|
||||
|
||||
|
|
Loading…
Reference in New Issue