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

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


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

Fixed it using 

env['stock.quant']._update_available_quantity(record.x_studio_tools,record.x_studio_stock_location,1).
Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 23
7662
2
thg 8 24
5668
3
thg 9 19
4367
2
thg 3 25
1622
2
thg 10 24
2418