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 Return Domain for One2many Product ID Field in Purchase Order Form

By
Miftah
on 12/27/14, 11:09 PM 1,335 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 :

purchase_order.py

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)
                }
   
po()


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

    <field/>
</record>

</data>
</openerp>

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) ?

1
Miftah
On 12/29/14, 5:43 AM

Hi Maniganda..

I have try your code, but it didn't work. Can you give me more spesifik coding? Thanks before

1

Maniganda

--Maniganda--
1038
| 5 7 7
Bangalore, India
--Maniganda--
Maniganda
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}

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/27/14, 11:09 PM
Seen: 1335 times
Last updated: 7/10/15, 10:49 AM