Перейти к содержимому
Меню
Чтобы взаимодействовать с сообществом, необходимо зарегистрироваться.
Этот вопрос был отмечен
1 Ответить
2114 Представления

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 Ответы Просмотры Активность
2
апр. 23
7583
2
авг. 24
5614
3
сент. 19
4296
2
мар. 25
1511
2
окт. 24
2315