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

Module: Product Pricelist Margin

Entity: product.pricelist.item

Compute Method: _compute_margin

Inputs Method Outputs
  • applied_on
  • product_tmpl_id
  • min_quantity
  • product_tmpl_id.uom_id
  • currency_id
  • currency_id.rounding
  • product_tmpl_id.taxes_id
  • cost
  • margin
current_company = self.env.company
for item in self:
            if (
                item.applied_on not in ("1_product", "0_product_variant")
                or not item.product_tmpl_id
            ):
                item.margin = 0
                item.margin_percent = 0
                continue

            price = item._compute_price(
                item.product_tmpl_id,
                item.min_quantity,
                item.product_tmpl_id.uom_id,
                fields.Datetime.now(),
            )

            if float_is_zero(price, precision_rounding=item.currency_id.rounding):
                item.margin = 0
                item.margin_percent = 0
                continue

            res = item.product_tmpl_id.taxes_id.filtered(
                lambda t: t.company_id and t.company_id == current_company
            ).compute_all(
                price,
                item.currency_id,
                product=item.product_tmpl_id,
            )

            price_vat_excl = res["total_excluded"]

            cost = self.env.user.company_id.currency_id._convert(
                item.cost, item.currency_id
            )

            item.margin = price_vat_excl - cost
            item.margin_percent = float_round(
                price_vat_excl and (item.margin / price_vat_excl) * 100,
                self.env["decimal.precision"].precision_get("Product Unit of Measure"),
            )

Back to entity