Odoo Help


How to return domain on on_change?

on 6/29/13, 4:48 AM 2,585 views

I have a one2many field in product form to keep unique serial numbers of the product. All serial numbers are linked to a location. This location can belong to any warehouse and can be at nth number in hierarchy.

While creating a sale order , after selecting product in sale order line. I need to select available serial numbers of the selected product in sale order sub line. Here I need a domain such a way that only serial number should be shown in sale order sub line which exist in the selected shop's warehouse.

I need to apply domain on 'unique_code' in 'sale_granite_line' class class structure is given below.

How to return domain on the same? Any help would be appreciated. Thank You.

class sale_order_line(osv.osv):



class sale_granite_line(osv.osv):



class product_product(osv.osv):


          'product_serial_lines':fields.one2many('product.serial.lines','product_id','Product Serial Lines'),

class product_serial_lines(osv.osv):


          'name':fields.char('Serial No'),
--Ahmed M.Elmubarak--

Ahmed M.Elmubarak
On 6/29/13, 5:49 AM

Hello, I faced same problem and solved it by:

1- adding form fields you want to the context of the one2many field like this

 <field name = "name_ids"  context = "{'stock_id': your warehouser field name}">

2- adding on_change function to the sale_grantie_line model

3- on the tree/ from view of the sale_grantie_line within the one2many field add an on_change to the sale_line_id and I suggest you'll pass sale_line_id to function , just add context to your argrument like this

 <field name = "name_ids"  context = "{'stock_id': your warehouser field name}">
    <tree string = "string" editable = "bottom">
       <field name = "sale_line_id" on_change = "on_change_id(sale_line_id,context)"/>
       <field name = "unique_code"/>

4- now on on_change function check the context for your warehouse id and do your calculations for your domain and return a domain for unique_code field

return {'domain': {'unique_code': your_domain}}

I hope this could help you...


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

0 follower(s)


Asked: 6/29/13, 4:48 AM
Seen: 2585 times
Last updated: 3/16/15, 8:10 AM