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

Module: SRM

Entity: crm.lead

Compute Method: _compute_purchase_amount_total

Inputs Method Outputs
  • company_currency
  • id
amount_per_lead = defaultdict(float)
for lead, currency, company, date_order, amount in self.env[
            "purchase.order"
        ]._read_group(
            domain=Domain.AND(
                [
                    self._get_purchase_order_lead_domain(),
                    self._get_lead_purchase_order_domain(),
                ]
            ),
            groupby=["opportunity_id", "currency_id", "company_id", "date_order:day"],
            aggregates=["amount_untaxed:sum"],
        ):
            company_currency = lead.company_currency or self.env.company.currency_id
            amount_per_lead[lead.id] += currency._convert(
                amount,
                company_currency,
                company,
                date_order or fields.Date.context_today(self),
            )
for lead in self:
            lead.purchase_amount_total = amount_per_lead.get(lead.id, 0.0)

Back to entity