Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5515 Lượt xem

Am using ' create_uid' field in crm.phonecall model, which is a many to one field.

when i convert that phonecall to opportunity using 'convert to opportunity' button.

I want the data in create_uid to be transfered to a custom field in 'crm.lead' model (this model holds the code for opportunity).

thanks in advance

 

 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Dear roshan,

try this,,,,

def convert_opportunity in crm_phonecall.py as follows,

def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False,cr_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        #cr_cr = self.pool.get('crm.user')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):            
            #cr_id=cr_cr.browse(cr, uid, call.create_uid, context=context)
            if not cr_id:
                cr_id= call.create_uid and call.create_uid.id or False  
            if not partner_id:
                partner_id = call.partner_id and call.partner_id.id or False                              
            if partner_id:
                address_id = partner.address_get(cr, uid, [partner_id])['default']
                if address_id:
                    default_contact = partner.browse(cr, uid, address_id, context=context)
            opportunity_id = opportunity.create(cr, uid, {
                            'name': opportunity_summary or call.name,
                            'activity':call.activity,
                            'planned_revenue': planned_revenue,
                            'probability': probability,
                            'partner_id': partner_id or False,
                            'mobile': default_contact and default_contact.mobile,
                            'section_id': call.section_id and call.section_id.id or False,
                            'description': call.description or False,
                            'priority': call.priority,
                            'type': 'opportunity',
                            'phone': call.partner_phone or False,
                            'email_from': default_contact and default_contact.email,
                            'created_by':cr_id,
                        })
            vals = {
                'partner_id': partner_id,
                'opportunity_id': opportunity_id,
                'state': 'done',
            }
            self.write(cr, uid, [call.id], vals, context=context)
            opportunity_dict[call.id] = opportunity_id
        return opportunity_dict

Then create a field in crm_lead.py as follows,

        'created_by':fields.many2one('res.users', 'Created By', ondelete='set null', track_visibility='onchange',select=True),

Then add the field in crm_lead_view.xml to view this..

hope this helps,,,

 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Dear roshan,

try this,,,,

def convert_opportunity in crm_phonecall.py as follows,

def convert_opportunity(self, cr, uid, ids, opportunity_summary=False, partner_id=False,cr_id=False, planned_revenue=0.0, probability=0.0, context=None):
        partner = self.pool.get('res.partner')
        opportunity = self.pool.get('crm.lead')
        #cr_cr = self.pool.get('crm.user')
        opportunity_dict = {}
        default_contact = False
        for call in self.browse(cr, uid, ids, context=context):            
            #cr_id=cr_cr.browse(cr, uid, call.create_uid, context=context)
            if not cr_id:
                cr_id= call.create_uid and call.create_uid.id or False  
            if not partner_id:
                partner_id = call.partner_id and call.partner_id.id or False                              
            if partner_id:
                address_id = partner.address_get(cr, uid, [partner_id])['default']
                if address_id:
                    default_contact = partner.browse(cr, uid, address_id, context=context)
            opportunity_id = opportunity.create(cr, uid, {
                            'name': opportunity_summary or call.name,
                            'activity':call.activity,
                            'planned_revenue': planned_revenue,
                            'probability': probability,
                            'partner_id': partner_id or False,
                            'mobile': default_contact and default_contact.mobile,
                            'section_id': call.section_id and call.section_id.id or False,
                            'description': call.description or False,
                            'priority': call.priority,
                            'type': 'opportunity',
                            'phone': call.partner_phone or False,
                            'email_from': default_contact and default_contact.email,
                            'created_by':cr_id,
                        })
            vals = {
                'partner_id': partner_id,
                'opportunity_id': opportunity_id,
                'state': 'done',
            }
            self.write(cr, uid, [call.id], vals, context=context)
            opportunity_dict[call.id] = opportunity_id
        return opportunity_dict

Then create a field in crm_lead.py as follows,

        'created_by':fields.many2one('res.users', 'Created By', ondelete='set null', track_visibility='onchange',select=True),

Then add the field in crm_lead_view.xml to view this..

hope this helps,,,

 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 9 23
4302
1
thg 2 19
14212
1
thg 7 24
1549
2
thg 6 18
12295
0
thg 3 15
4289