Skip to Content
This question has been flagged
1 Reply
6123 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"),
          }
Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Sep 19
2683
0
Mar 15
3442
5
Aug 24
1757
3
May 24
2894
3
Aug 23
42805