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

Module: Lunch

Entity: lunch.product

Compute Method: _compute_last_order_date

Inputs Method Outputs
  • product_id
all_orders = self.env['lunch.order'].search([
            ('user_id', '=', self.env.user.id),
            ('product_id', 'in', self.ids),
        ])
mapped_orders = defaultdict(lambda: self.env['lunch.order'])
for order in all_orders:
            mapped_orders[order.product_id] |= order
for product in self:
            if not mapped_orders[product]:
                product.last_order_date = False
            else:
                product.last_order_date = max(mapped_orders[product].mapped('date'))

Back to entity