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

[SOLVED] How to create a "create" button in any form?

By
Juan Formoso
on 10/17/14, 12:22 PM 650 views

I am trying to generate a "Create" button in the standard form of partners (res.partner). But I want that if click it, create a object from other model. Let's suppose that I have created a new model called my.model. I want to generate a button in the standard form of partners which opens a standard form to create an object from the model my.model. How can I do 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/21/14, 8:49 AM

Assuming you already created my.model, and defined views for that model,
since your button is visible on form  res.partner , you need to define a method in  res.partner class

in that method you will first call create on my.model like:
mymodel = self.pool.get('my.model')
created_id = mymodel.create(cr, uid, vals ) 
#vals is some values that will appear on created record

and after that you can return the desired view like:

view_ref = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'your_module', 'view_external_id')
view_id = view_ref and view_ref[1] or False
            return {
                'type': 'ir.actions.act_window',
                'name': 'Some name',
                'res_model': 'my.model',
                'res_id': created_id,
                'view_type': 'form',
                'view_mode': 'form',
                'view_id': view_id,
                'target': 'new',
                'nodestroy': True,
                }
 

 

hope it helps.. 
may the source be with you!

Of course it helped me! Thank you so much!

Juan Formoso
on 10/21/14, 11:53 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/17/14, 12:22 PM
Seen: 650 times
Last updated: 3/16/15, 8:10 AM