Hello,
I have a Many2one field ( product.product ) and I want to filter it by a given location_id.
Basically when I select the field I want to see only the products with quantity > 0 from a specific location.
How can I achieve this on Odoo 13 CE ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
Hello,
I have a Many2one field ( product.product ) and I want to filter it by a given location_id.
Basically when I select the field I want to see only the products with quantity > 0 from a specific location.
How can I achieve this on Odoo 13 CE ?
Hi,
Try the following code,
from odoo import models, fields
class CustomModel(models.Model):
_name = 'custom.model'
location_id = fields.Many2one('stock.location', string='Location', required=True)
//define default function
def _get_product_domain(self):
domain = [('qty_available', '>', 0)]
if self.location_id:
domain.append(('location_id', '=', self.location_id.id))
return domain
product_id = fields.Many2one('product.product', string='Product', domain=lambda self: self._get_product_domain())
after applying this domain, if you need to add the search filter then you can add the product_id in the filter
Hope it helps
Tạo tài khoản ngay hôm nay để tận hưởng các tính năng độc đáo và tham gia cộng đồng tuyệt vời của chúng tôi!
Đăng kýBài viết liên quan | Trả lời | Lượt xem | Hoạt động | |
---|---|---|---|---|
|
2
thg 4 21
|
11733 | ||
|
2
thg 7 15
|
5166 | ||
|
0
thg 3 15
|
4622 | ||
|
1
thg 1 21
|
4389 | ||
|
3
thg 9 20
|
72348 |