Odoo Help


Onchange value for field many2one type

on 12/23/14, 8:24 AM 1,003 views

For example I have 2 categ_id in Product form (Unit and sparepart). Than I want to add two field selection and many2one type in form Purchase Order like this :


from openerp.osv import osv, fields
class po(osv.osv):
    _inherit = 'purchase.order'
    _columns = {
                'category':fields.selection([('t','Unit'),('s','Sparepart')], 'Division', change_default=True, select=True),
                'product_id':fields.many2one('product.product', string='Product') #, domain=[('categ_id','=',???)]



<?xml version="1.0" encoding="utf-8"?>

<record model="ir.ui.view" id="po_form_view">
    <field name="name">purchase_order</field>
    <field name="model">purchase.order</field>
    <field name="type">form</field>
    <field name="inherit_id" ref="purchase.purchase_order_form"/>
    <field name="arch" type="xml">
        <field name="partner_id" position="after">
            <field name="category" on_change="onchange_categ(category)"/>
            <field name="product_id"/>




The question is : If I choose Unit in field category so value of field Product are Product which categ_id = Unit and if I choose Sparepart so value of field Product are Product which categ_id = Sparepart. How to do it ?

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.


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

1 follower(s)


Asked: 12/23/14, 8:24 AM
Seen: 1003 times
Last updated: 3/16/15, 8:10 AM