This question has been flagged

Hey! In stock.warehouse.orderpoint we have a field for minimum quantity. I want that field in my product.template model to. So that whatever minimum quantity is defined in the "Reorder rule" that value must be in the separate field in my form/tree view of product.template.

I am trying to use related field but it makes me select the record to fetch the value and i dont want that. Value must come by itself without any selection at all. Below are my related fields


re_order = fields.Many2one('stock.warehouse.orderpoint',string = 'Reorder', store=True)

min_qty = fields.Float(related='re_order.product_min_qty',string = 'Minimum Quantity', store=True)
Some help would be nice. Thanks in advance
Avatar
Discard

Do you want to modify it from product.template or just for viewing?

Author

I just want to view that field in product template tree view for each product. Kindly help i'll be very thankful

Best Answer

You can use computed field as below: 

min_qty = fields.Float(compute='_get_min_qty', string='Minimum Quantity')
def _get_min_qty(self):
for prod_tml in self:
product = self.env['product.product'].search([('product_tmpl_id','=',prod_tml.id)])
product_reorder = self.env['stock.warehouse.orderpoint'].search([('product_id','=',product.id)],limit=1)
if product_reorder:
prod_tml.min_qty= product_reorder.product_min_qty
Avatar
Discard
Author

Hey man Thank you so much, This worked like a char,. Just one question y i am not able to inherit and add this working field in tree view it is giving this error

" ValueError: Expected singleton: product.product(10, 11, 12)".

Author

ok this is fixed to i just had to put an else and use @api.depends and multi. Thanks