I have created a custom module where there is a field related to product
. When the user checkout the product in the custom module, I want to decrease the quantity of product in the override create method. How to achieve this?
Finally, I found the solution code
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.env.company.id)], limit=1
)
self.env['stock.quant'].with_context(inventory_mode=True).create({
'product_id': product_id,
'location_id': warehouse.lot_stock_id.id,
'inventory_quantity': new_quantity,
})