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.

1

How to return domain on on_change?

By
Yogesh
on 6/29/13, 4:48 AM 1,968 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):

_inherit="sale.order.line"

_columns={
          'sub_order_lines':fields.one2many('sale.granite.line','sale_line_id','Size'),
          }

class sale_granite_line(osv.osv):

_name='sale.granite.line'

_columns={
          'sale_line_id':fields.many2one('sale.order.line'),
          'unique_code':fields.many2one('product.serial.lines','Code',required=True),
          }

class product_product(osv.osv):

_inherit="product.product"

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

class product_serial_lines(osv.osv):

_name='product.serial.lines'

_columns={
          'name':fields.char('Serial No'),
          'product_id':fields.many2one('product.product','Product',ondelete="cascade"),
          'product_location':fields.many2one('stock.location','Location',required=True,ondelete="cascade"),
          }
2

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--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"/>
    </tree>

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...

Thanks...

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

0 follower(s)

Stats

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