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

Select a field to fill in quick add other than name in many2one

By
Sandy Carter
on 1/15/14, 5:53 PM 1,668 views

I have two models (A and B) with their respective views.

  • Model A has a field named x which is a many2one relation of B.
  • Model B has a field named y which is what interests me.

x is not labeled the same as the name of model B, but the name_get function of B shows me the proper information.

I would like to be able to type in the x field and be able to have the quick add fill in the y field of B, but it only seems to fill in name*.

1
Sandy Carter
On 1/15/14, 5:57 PM

In the xml view of model A, add the following attribute to the x field:

options='{"create_name_field": "y"}'

I found the solution while debugging in javascript in web/static/src/js/view_form.js and found the following function:

add_id: function(id) {},
_create_context: function(name) {
    var tmp = {};
    var field = (this.options || {}).create_name_field;
    if (field === undefined)
        field = "name";
    if (field !== false && name && (this.options || {}).quick_create !== false)
        tmp["default_" + field] = name;
    return tmp;
},

this.options corresponds to the options attribute in the field of and xml view and create_name_field corresponds to a dictionary key.

do you put a example please. thank

wilson zauma
on 3/20/14, 2:04 PM

Here's an example: http://bazaar.launchpad.net/~partner-contact-core-editors/partner-contact-management/7.0/view/head:/base_location/partner_view.xml#L11

Savoir-Faire Linux, Sandy Carter
on 3/20/14, 2:37 PM

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: 1/15/14, 5:53 PM
Seen: 1668 times
Last updated: 3/16/15, 8:10 AM