Odoo Help


How to detect stock location based on warehouse_id?

Paulo Matos‏
on 10/16/14, 7:57 AM 971 views

Hi all,

I need your help on setting the location_id value below, based on the warehouse_id on the same code.

class sale_order_line(osv.osv):
    _inherit = 'sale.order.line'
    _columns = {
        'warehouse_id': fields.many2one('stock.warehouse',

        'location_id': HOW TO DETECT BASED ON THE warehouse_id above?


I need to add the location of type "stock" from where products are sold and from where I can calculate the forecasted stock value.

Can anyone help me please?

Thank you very much






You can define fields.related and then you can use that field as you want. To defind location_id based on the warehouse_id you can define it as like below,

'location_id' : fields.related('warehouse_id','lot_stock_id',type='many2one',relation='stock.location',readonly=True,store=True,string="Stock Location")

I hope it will help you.

Thank you very much Emipro. It solved my problem.

ThinkOpen Solutions (Angola), Paulo Matos‏
on 10/21/14, 3:19 AM

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

1 follower(s)


Asked: 10/16/14, 7:57 AM
Seen: 971 times
Last updated: 3/16/15, 8:10 AM