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

I'm using the following code to get the quantity of a product based on two warehouses I already created:

product = self.env['product.product'].browse(PRODUCT_ID)

product_wh_1_qt = product.with_context({'warehouse': WAREHOUSE_ID_1}).qty_available
product_wh_2_qt= product.with_context({'warehouse': WAREHOUSE_ID_2}).qty_available
but something odd happens: the first result is right but the second result is the same as the first result (but it should not be because quantities are different in warehouses)

If I change the order qnd do this:

product_wh_2_qt = product.with_context({'warehouse': WAREHOUSE_ID_2}).qty_available
product_wh_1_qt= product.with_context({'warehouse': WAREHOUSE_ID_1}).qty_available
again the first result is right but the second one is the same as first one. any ideas how to fix?

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

Hi,

Try like this,

product_wh_2_qt = product.with_context({'warehouse': WAREHOUSE_ID_2}).qty_available
product_wh_1_qt = product.with_context({}, warehouse=WAREHOUSE_ID_1).qty_available

For more see: Odoo ORM


# current context is {'key1': True}
r2 = records.with_context({}, key2=True)
# -> r2._context is {'key2': True}
r2 = records.with_context(key2=True)
# -> r2._context is {'key1': True, 'key2': True}


Thanks

Ảnh đại diện
Huỷ bỏ
Tác giả

thanks a lot

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

Hi @niyas, both the lines are coming same value only for multiple warehouses..!!! 

Any solution..??

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 6 16
2775
2
thg 12 20
2870
Inventory Đã xử lý
2
thg 5 25
1238
2
thg 5 25
800
2
thg 4 25
1705