Odoo Help

Welcome!

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

0

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

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

0

Bole

--Bole--
2385
| 5 4 6
Zagreb | Karlovac, Croatia
--Bole--

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

Bole
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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