Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
2 ตอบกลับ
3176 มุมมอง

how I can change product quantity on hand by code?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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})

อวตาร
ละทิ้ง
ผู้เขียน

I try it and it's not work

คำตอบที่ดีที่สุด

Hi,

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

Thanks

อวตาร
ละทิ้ง
ผู้เขียน

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

ผู้เขียน

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
2
ส.ค. 25
2821
3
ก.ค. 24
2251
3
ก.พ. 25
4024
0
พ.ค. 24
46
1
เม.ย. 24
3622