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 add an independant field in partner categories and show all in partner form ?

By
Anne-Sylvie Burri
on 6/27/13, 6:32 AM 615 views

Hi everybody,

I have to work with partners categories. Here is the situation :

I have 3 levels of categories : "Category", "Subcategory" and "Year". "Category" and "Subcategory" are linked but "Year" is independant.

An example : M. Doe was at "School" (category) in "America" (subcategory) in year 2003. But he is currently following a training in this same "School" in "America" in year 2013.

I have two problems :

  • how to allow one partner to have several times the same category and subcategory ?
  • how to create a new field "Year" which is not linked to the category and subcategory but which must appear in the partner form ? (I think a solution could be to work like "article" in invoice. We can choose many times the same article and we can add other independant data)

I created a new page in the partner form named "Statuts". Now this page shows the module "partner.category". Indeed, I used the following code :

from openerp.osv import fields, osv

class res_partner(osv.osv):
_inherit = 'res.partner'
_order = 'x_nom asc'
_columns = {
    'x_nom': fields.char('Nom',size=64),
    'x_prenom': fields.char('Prenom',size=64),
    'x_category': fields.many2many('res.partner.category','res_partner_category_rel','partner_id','category_id','Statuts'),
    'x_date': fields.selection((('2000','2000'), ('2001','2001'), ('2002','2002'), ('2003','2003'), ('2004','2004'), ('2005','2005'), ('2006','2006'), ('2007','2007'), ('2008','2008'), ('2009','2009'), ('2010','2010'), ('2011','2011'), ('2012','2012'), ('2013','2013')),'Annee'),
}

res_partner()

and :

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_partner_form">
    <field name="name">res.partner.form.inherit</field>
    <field name="model">res.partner</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <data>
            <field name="name" position="after">
                <field name="x_nom"/>
            </field>
            <field name="x_nom" position="after">
                <field name="x_prenom"/>
        </field>
        </data>
    </field>
</record>
<record model="ir.ui.view" id="view_partner_form2">
    <field name="name">res.partner.form.inherit2</field>
    <field name="model">res.partner</field>
    <field name="inherit_id" ref="base.view_partner_form"/>
    <field name="arch" type="xml">
        <notebook position="inside">
            <page string="Statuts">
                <group>
                    <field name="x_category" widget="many2many"/>
                    <field name="x_date" style="width: 30%%"/>
                </group>
            </page>
        </notebook>
    </field>
</record>
</data>
</openerp>

Many thanks in advance for your answer.

JMB

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

0 follower(s)

Stats

Asked: 6/27/13, 6:32 AM
Seen: 615 times
Last updated: 3/16/15, 8:10 AM