Odoo Help


How to open a form with a button and set some of its values?

Juan Formoso
on 10/24/14, 8:53 AM 734 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?




| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 10/24/14, 9:00 AM

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..

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

Juan Formoso
on 10/27/14, 5:39 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 10/24/14, 8:53 AM
Seen: 734 times
Last updated: 3/16/15, 8:10 AM