Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Purchase Stock

Entity: product.product

Compute Method: _compute_monthly_demand

Inputs Method Outputs
  • id
based_on = self.env.context.get("suggest_based_on", "30_days")
start_date, limit_date = self._get_monthly_demand_range(based_on)
move_domain = Domain([
            ('product_id', 'in', self.ids),
            ('state', 'in', ['waiting', 'assigned', 'confirmed', 'partially_available', 'done']),
            ('date', '>=', start_date),
            ('date', '<', limit_date),
        ])
move_domain = Domain.AND([
            move_domain,
            self._get_monthly_demand_moves_location_domain(),
        ])
move_qty_by_products = self.env['stock.move']._read_group(move_domain, ['product_id'], ['product_qty:sum'])
qty_by_product = {product.id: qty for product, qty in move_qty_by_products}
factor = 1
if based_on == "one_year":
            factor = 12
        elif based_on == "three_months" or based_on == "last_year_quarter":
            factor = 3
        elif based_on == "one_week":
            factor = 7 / (365.25 / 12)
for product in self:
            product.monthly_demand = qty_by_product.get(product.id, 0) / factor

Back to entity