Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
5035 Näkymät

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
Hylkää

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

Tekijä

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

Paras vastaus

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
Hylkää
Tekijä

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

Tekijä

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

Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
heinäk. 22
7525
2
huhtik. 24
9145
1
maalisk. 15
3741
1
toukok. 21
4439
2
tammik. 20
3262