I need to get products available quantity from odoo stock.
There are several models I stock_quant, stock_move, stock_location.
What I am trying to achieve are two things:
Can anyone please guide me?
multiple quantity is used when the product must be ordered in multiple units because your supplier does not sell single units for instance, or because you want to. the unit specified on the product form.
Forecasted quantity = Onhand quantity - outgoing shipment product quantity + incoming shipment product quantity.
Clicking on Product Category we can find the product categories listed out. These are the pre-configured product categories. The categories here are consumables, expenses, Rental, Internal, Saleable, Deliveries, etc.
Functional Odoo 15. Product packaging is a valuable tool both for business and the client. The company can reduce shipping charges, delivery charges, and many more and help sell products at a low margin. For the customer, it is worth their money, and they have the opportunity to gain a discount.
Stock related fields are defines in products (functional field) and directly from the product you can get the stock for all warehouses / locations or for individual location / warehouse.
Example:
For all warehouses / locations
product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.qty_available
For individual location / warehouse (WAREHOUSE_ID / LOCATION_ID should be replaced by actual id)
product = self.env['product.product'].browse(PRODUCT_ID)
available_qty = product.with_context({'warehouse' : WAREHOUSE_ID}).qty_available
available_qty = product.with_context({'location' : LOCATION_ID}).qty_available
Other fields are also there.
Forecasted Stock => virtual_available
Incoming Stock => incoming
Outgoing Stock => outgoing
You can access all those fields in similar manner. If you will not pass any warehouse / location in context then it will returns the stock of the all warehouses together.
For more details you may refer product.py in stock module.
Solution:
@api.onchange('product_id','source_location')
def product_qty_location_check(self):
if self.product_id and self.source_location:
product = self.product_id
available_qty = product.with_context({'location' : self.source_location.id}).qty_available
print available_qty
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With