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 access and use partner data inside project module?

By
Yenthe
on 11/14/14, 3:57 AM 901 views

Hey everybody

How can I access data from the res.partner model (for reading, updating, writing, ...) inside my project settings view?

Short question: 
How can I access the model res.partner to read, write, update from it inside the view from 'Project Settings' under the project module?

Long question with a lot of details:

When you click on the project settings, as shown here:


A new menu will open up with the project settings. What I want here are two new tabs. I've managed to add the tabs without any content, looking like this:


What I now want to add is the option to select customers/people from a list and add them in my custom two tabs. I've managed to program this when making a new customer record (in the sale module) but I cannot get this working in the project module.
I want something like this in my project settings view. This example is the view where you make a new customer.
When you click on 'Add an item' you will get a list from all customers which you can select. Like this:


I want to create exactly the same under Project settings but I can't get this working. I've figured out I need to be in project/project.py and project/res_partner_view.xml but I do not know how exactly I should do the model.
If I am not mistaking it should be coded under the class project. Should I inherit res.partner here?

This is the example code I have in my models code from the sale view, which is what I now want to make for project settings.
sale/res_partner.py example:

 

_columns = {
'x_testpersoon': fields.boolean('Testpersoon'),
        'x_geslacht': fields.selection([('M', 'Man / Male / Homme'), ('F', 'Vrouw / Female / Femme')], 'Geslacht'),
        'x_geboortedatum': fields.date('Geboortedatum'),
        'x_opleiding': fields.selection([('Middelbaar', 'Middelbaar / Secondary school / Études secondaires'),
        ('Bachelor', 'Bachelor / Bachelor / Bachelier'), 
        ('Master', 'Master / Master / Master'), 
        ('Universiteit', 'Universiteit / University / Université')], 'Opleiding'),
        'x_beroep': fields.char('Beroep', size=64),
        'x_taal': fields.selection([('NL', 'Nederlands / Dutch / Néerlandais'),
        ('EN', 'Engels / English / Anglais'), 
        ('FR', 'Frans / French / Français')], 'Taal'),
    'session_ids': fields.many2many('res.partner', 'custom_model_multi_customers_to_customer', 'session_id', 'partner_id', string="Sessions"),
        'res_factureren_aan': fields.many2one('res.partner', 'Factureren aan', select=True),
    'x_extra_klanten': fields.many2many('res.partner', 'custom_model_multi_consortium_to_customer', 'session_id_consortium', 'partner_id_consortium',
     string="Consortium"),
}

sale/res_partner_view.xml example:

<notebook>
        <page string="Testpersoon">
        <tree string="Testpersonen">
            <group>
            <field name="x_testpersoon"/>
            <field name="x_geslacht" widget="selection"/>
            <field name="x_geboortedatum"/>
            <field name="x_opleiding" widget="selection"/>
            <field name="x_beroep"/>
            <field name="x_taal" widget="selection"/>
            </group>
        </tree>
        </page>
                            <page string="Externe personen">
                                    <field name="session_ids">
                    <tree string="Gebruikers">
                    <field name="name"/>
                    <field name="phone"/>
                    <field name="email"/>
                                        </tree>
                   </field>
                            </page>
                <page string="Consortium">
                <field name="x_extra_klanten">
                    <tree string="Consortium">
                        <field name="name"/>
                        <field name="phone"/>
                        <field name="email"/>
                    </tree>
                </field>
                </page>
                        </notebook>

 

How can I modify this code to work under project settings in the files project/project.py and project/res_partner_view.xml?

0

Yenthe

--Yenthe--
6676
| 7 7 8
Turnhout, Belgium
--Yenthe--

My Odoo blog: http://www.odoo.yenthevg.com/

My Twitter: https://twitter.com/Yenthe666

Yenthe
On 11/14/14, 5:32 AM

Found the solution myself. I simply had to add the new tables/fields to the colums under the class project and then call the fields in the view. My problem was that I already had a database with the name and some minor errors in the logic.
I didn't need to add res.partner to the inheritance either! This will make the application crash.
The final result:

project/project.py (models):

_columns = {
    'x_external_person_ids': fields.many2many('res.partner', 'custom_model_multi_customers_to_customer2', 'session_id', 'partner_id', string="External"),
    'x_extra_klanten': fields.many2many('res.partner', 'custom_model_multi_consortium_to_customer2', 'session_id_consortium', 'partner_id_consortium',
     string="Consortium"),
}

project/project_view.xml (view):

<page string="Externe personen">
                <label for="x_external_person_ids" string="External persons"/>
                                <field name="x_external_person_ids">
                                    <tree string="Users">
                                        <field name="name"/>
                    <field name="phone"/>
                    <field name="email"/>
                                    </tree>
                                </field>
                            </page>
            <page string="Consortium">
                <label for="x_extra_klanten" string="Consortium project"/>
                <field name="x_extra_klanten">
                     <tree string="Consortium">
                    <field name="name"/>
                    <field name="phone"/>
                    <field name="email"/>
                     </tree>
                </field>
                </page>

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: 11/14/14, 3:57 AM
Seen: 901 times
Last updated: 3/16/15, 8:10 AM