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

I have got a dropdown showing lot numbers in Manufacturing picking operations. The problem is I do not want to show the lot numbers having no product i.e. 0 quantity. I have created another selection field and populated the lot numbers dynamically, however I am getting a list attribute error while populating dropdown:

AttributeError: 'list' object has no attribute 'get'

Here is the model selection field and code to populate it:

@api.onchange('location_id')
def _fetch_non_empty_lots(self):
 lots = [] 
 quants = self.env['stock.quant'].search([('location_id.id','=',self.location_id.id), 
 ('product_id.id', '=', self.product_id.id), ('quantity', '>', 0)]) 
 for quant in quants: 
    lots.append((str(quant.lot_id.id),str(quant.lot_id.display_name)))
 return lots 
x_lot_id = fields.Selection(selection="_fetch_non_empty_lots", name="Non Empty Lots")
## declare field

When the list is empty, there is no error. When there is non-empty lot then I am getting the eror. Ineed some assistance.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Try removing the .id on your search parameters for the 'stock.quant' recordsets.

Like this:

quants = self.env['stock.quant'].search([('location_id','=',self.location_id.id), 
 ('product_id', '=', self.product_id.id), ('quantity', '>', 0)])
Ảnh đại diện
Huỷ bỏ
Tác giả

it doesn't work .. the issue is with what I am returning i.e. list

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 12 22
23816
1
thg 10 19
5605
1
thg 8 19
3597
3
thg 11 23
17134
0
thg 11 23
2098