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.

2

Onchange value for field many2one type

By
Miftah
on 12/23/14, 8:24 AM 812 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 :

Product.py

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','=',???)]
                }
   
po()

 

Product_view.xml

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

<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"/>
        </field>

    <field/>
</record>

</data>
</openerp>

 

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 ?

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: 12/23/14, 8:24 AM
Seen: 812 times
Last updated: 3/16/15, 8:10 AM