Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie

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
Awatar
Odrzuć

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

Autor

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

Najlepsza odpowiedź

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
Awatar
Odrzuć
Autor

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

Autor

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

Powiązane posty Odpowiedzi Widoki Czynność
3
lip 22
7524
2
kwi 24
9144
1
mar 15
3739
1
maj 21
4438
2
sty 20
3262