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

how I can change product quantity on hand by code?

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

you can try ths way:

from odoo import api, models

class ProductQuantityUpdate(models.Model):
_inherit = 'product.product'

def change_quantity(self, new_quantity):
for product in self:
product.write({'qty_available': new_quantity})

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

I try it and it's not work

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

Hi,

Easy method for the same from the code and ui is to make an inventory adjustment on particular location with needed value.

Thanks

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

is the method is action_update_quantity_on_hand ?
I try it but I had error
can you write the code to implement the method

feel free to update the question with the tried code and error you received

Tác giả

product = self.enve['product.product'].search([('id','=',product_id.id)])
product.qty_available = 100
product.action_update_quantity_on_hand ()
I have no change in this try and no error

as i suggested in answer, try simulating the same code execution of inventory adjustment with stock.quant model

Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 8 25
2902
3
thg 7 24
2345
3
thg 2 25
4148
0
thg 5 24
46
1
thg 4 24
3704