Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5033 Lượt xem

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
Ảnh đại diện
Huỷ bỏ

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

Tác giả

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

Câu trả lời hay nhất

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
Ảnh đại diện
Huỷ bỏ
Tác giả

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

Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 7 22
7524
2
thg 4 24
9144
1
thg 3 15
3739
1
thg 5 21
4438
2
thg 1 20
3262