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

I created a server action where when the user clicks it, it will decrement the user's onhand quantity but it won't force save

for record in records:

    location = record.x_studio_stock_location

   

    # Search for the relevant stock.quant record

    quant = env['stock.quant'].search([

        ('location_id', '=', record.x_studio_tools.id)  # Adjust filters as needed

    ], limit=1)


    if quant and quant.location_id == location:

        new_inventory_quantity = quant.inventory_quantity_auto_apply - 1

   

        if new_inventory_quantity < 0:

            raise UserError(f"Inventory quantity cannot be negative for location {location.name}.")

   

        # Update the inventory quantity (this won't save)

        quant.sudo().write({'quantity': new_inventory_quantity})


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

Fixed it using 

env['stock.quant']._update_available_quantity(record.x_studio_tools,record.x_studio_stock_location,1).
อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Can you regenerate the stock_quant table แก้ไขแล้ว
2
เม.ย. 23
7888
2
ส.ค. 24
5815
The Product Creating Multiple Location แก้ไขแล้ว
3
ก.ย. 19
4465
2
มี.ค. 25
1839
2
ต.ค. 24
2605