Odoo Help


Onchange Return Domain for One2many Product ID Field in Purchase Order Form

on 12/27/14, 11:09 PM 1,949 views

I have 2 product category (Unit and Sparepart). Then I want to add division field with selection type in form Purchase Order like this :


from openerp.osv import osv, fields
class po(osv.osv):
    _inherit = 'purchase.order'
    _columns = {
                'division':fields.selection([('t','Unit'),('s','Sparepart')], 'Division', change_default=True, select=True)


<?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="division" on_change="onchange_division(division)"/>



The Issue is : I want if I choose Unit in division field so domain for Product field are Product which categ_id = 'Unit' and if I choose Sparepart so domain for Product field are Product which categ_id = 'Sparepart'. How to do it (with onchange method) ?

On 12/29/14, 3:33 AM

HI you can build the domain in onchange_event

you can check the value of division field in onchange. based on the values build the domain and return the output

return {'value':your_value,'domain':your_domain}

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/27/14, 11:09 PM
Seen: 1949 times
Last updated: 6/7/17, 2:41 AM