Odoo Help

1

How to properly update one column value to be showed in another with fields.related?

By
Tomas Parnarauskas
on 6/4/13, 6:20 AM 2,284 views

Hello, I'm trying to create module, that would add new field in res.partner object and that same field would be related with res.company. To be specific it is company_registry field. So it should work like this: if company_registry field is entered in res.company, it updates that field in res.partner too (to res.partner resource that is the same as res.company resource). I wanted to make it the same as res.partner.vat field is behaving. You enter vat code in company and it automatically appears at res.partner.

1
Tomas Parnarauskas
On 6/4/13, 6:23 AM

It could be done like this:

__init__.py:

import res_partner
import res_company

__openerp__.py:

{
    'name': 'Company code',
    'version': '1.0',
    'depends': ['base_vat'],
    'author': 'Oerp',
    'description': """
Address Book
==========================================

Adds new field code in partners object. 

    """,
    'website': '',
    'category': 'base',
    'demo': [],
    'test': [],
    'data': ['res_partner_view.xml'
    ],
    'auto_install': False,
    'installable': True,
}

res_partner.py:

from openerp.osv import osv, fields

class res_partner(osv.osv):
    _name = 'res.partner'
    _inherit = 'res.partner'
    _columns = {
        'company_registry': fields.char('Company Registry', help="Registry code of company", size=64)
    }
res_partner()

res_company.py:

from openerp.osv import osv, fields

class res_company(osv.osv):
    _name = 'res.company'
    _inherit = 'res.company'
    _columns = {
        'company_registry': fields.related('partner_id', 'company_registry', string="Company Registry", type="char", size=64)
    }
res_company()

res_partner_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
    <record id="view_partner_form1" model="ir.ui.view">
        <field name="name">re.partner.vat.inherit1</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base_vat.view_partner_form"/>
        <field name="arch" type="xml">
            <label for="vat" position="before"> 
                <field name="company_registry" placeholder="e.g. 300341211" class="oe_inline"/>
            </label>
        </field>            
    </record>
</data>
</openerp>

About This Community

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

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)

Stats

Asked: 6/4/13, 6:20 AM
Seen: 2284 times
Last updated: 10/29/15, 1:34 AM