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
Create an account today to enjoy exclusive features and engage with our awesome community!
Înscrie-teRelated Posts | Răspunsuri | Vizualizări | Activitate | |
---|---|---|---|---|
|
2
apr. 21
|
11697 | ||
|
2
iul. 15
|
5153 | ||
|
0
mar. 15
|
4574 | ||
|
1
ian. 21
|
4368 | ||
|
3
sept. 20
|
72324 |