This question has been flagged

We need to be able to query the number of a given product currently in quotations. In other words, take inventory of a given SKU, and get a number back which is the total no. of them currently in active (not cancelled) quotations.

I understand that Odoo's logic is to count inventory once it is on a sales order. But for our needs, we also need to be able to get a quick take of how many are in quotations.

What database model/field do I need to look for here?

I've looked around and cannot seem to find it - even in developer mode.

Perhaps I'm missing it.  

Avatar
Discard
Best Answer

Hello Hibou,

I wrote this script within a scheduled action and seems to work:

internal_reference = "DESK0004"

sale_order_lines_quantity = sum(

  env["sale.order.line"].search

  (

    ["&", ("product_id.default_code", "=", internal_reference), ("order_id.state", "=", "draft")]

  ).mapped("product_uom_qty")

)


raise Warning(sale_order_lines_quantity)


The idea behind it is that you are searching for all sales orders lines where the order_id (related sales order) is in the draft stage (quotation). You then search on the product_id.default_code to check that the sales order line is the product you are looking for. You then map by the quantity and get the sum. 

I hope this helps.

Thanks, 

Avatar
Discard