This question has been flagged
1 Reply
3227 Views

I have created a new model called res.partner.link.category. I have also created a button in the model res.partner, which opens a form to create a new record of res.partner.link.category (I have defined this form too). Everything is fine, but I need one of the fields of the form to have a specific value (to be accurate, the field is partner_id and I want it to value 5 ~when I manage this, I will turn this value to something more logical~). I tried with context, but, by the moment, no results. Here my code:

def create_rplc(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    context['partner_id'] = 5
    data_obj = self.pool.get('ir.model.data')
    data_id = data_obj._get_id(cr, uid, 'res_partner_extended', 'res_partner_link_category_create_form_view')
    view_id = False
    if data_id:
        view_id = data_obj.browse(cr, uid, data_id, context=context).res_id
    return {
        'name': 'Creation',
        'view_type': 'form',
        'view_mode': 'form',
        'views': [(view_id, 'form'),],
        'res_model': 'res.partner.link.category',
        'type': 'ir.actions.act_window',
        'nodestroy': True,
        'target': 'new',
        'flags': {'form': {'action_buttons': True}},
        'context': context,
    }

How can I manage this?

Avatar
Discard
Best Answer

Well.. when you open a new view like this.. you have two choices:
1. open existing record (find the id of record and return in value: {res_id:some_id}
2. create new record with some predefined values ( then first create the record in your method, and apply option1)

you can override _default_get  method for creating new records and add or modify defaults for creating new records.. 

 

hope it helps..

Avatar
Discard
Author

And what about use 'value': {'partner_id': 5}? Shouldn't it work?