This question has been flagged
2 Replies
4717 Views

I've made a custom module for res.partner called "lastname"

If I am in the Customer Form and want to create a new opportunity, I select the "Opportunities" button

Most of the data is automatically populated, except for my custom fields

How do i add this capacity to my custom module?

What would the code be possibly?

Thanks in advance

Avatar
Discard
Best Answer

Hello,

The code that opening the opportunities from the button is defined here, you can see that the button calls an action with name:

%(crm.crm_case_category_act_oppor11)d

which you can find it here , the automatic population of the data comes from the context field:

1) in the button's context you'll find:

 context="{'search_default_partner_id': active_id}" 

this set the default search, so that when you click the button you'll find the search area 'right corner' populated with the partner's name more over if you click create you'll find the partner field populated with this one. [try to delete the search filter and press create, then you will miss the partner].

2) in the action's context you'll find:


 <field name="context">{
'stage_type': 'opportunity',
'default_type': 'opportunity',
'default_user_id': uid
}
</field>

you can set a default value in a field by using 'default_your_field': your_value, in the context dict.

You can edit this context to add the default value of your fields.

* Note: you said that you added some fields to res.partner , but I think you've to add your fields to Opportunity's model to be able to but I think you've to add your fields to Opportunity's model to be able to set the default values to them ....

-Also you can populate it by using an on_change function ...

*BTW I didn't down voted your question ...


I hope this will be helpful 

Avatar
Discard
Best Answer

Hello,

I think this will helpful you.

see crm_lead.py in crm module.

Here in class crm_lead(format_address, osv.osv):

See below method. You can overwrite this method for your custom field.

def on_change_partner_id(self, cr, uid, ids, partner_id, context=None):
print 'onchange partner idddd'
values = {}
if partner_id:
partner = self.pool.get('res.partner').browse(cr, uid, partner_id, context=context)
values = {
'partner_name': partner.parent_id.name if partner.parent_id else partner.name,
'contact_name': partner.name if partner.parent_id else False,
'street': partner.street,
'street2': partner.street2,
'city': partner.city,
'state_id': partner.state_id and partner.state_id.id or False,
'country_id': partner.country_id and partner.country_id.id or False,
'email_from': partner.email,
'phone': partner.phone,
'mobile': partner.mobile,
'fax': partner.fax,
'zip': partner.zip,
}
return {'value': values}
Avatar
Discard