How to Implement store=True and compute store=False in Odoo?


Overview

In Odoo, computed fields are defined using the compute parameter. The store attribute controls whether the computed value is persisted in the database or calculated dynamically on the fly.


✅ Syntax

computed_field = fields.Char(

    compute='_compute_method',

    store=True or False

)


🔍 store=False (Default)

  • Value is not stored in the database
  • Computation happens each time the field is accessed
  • Cannot be used in:
    • search domains
    • group_by
    • filters in views


🔸 Example


total = fields.Float(

    compute='_compute_total'

    store=False

)

@api.depends('amount', 'tax')

def _compute_total(self):

    for rec in self:

        rec.total = rec.amount + rec.tax


Field total will be computed every time it's accessed.


🔍 store=True

  • Value is stored in the database
  • Computation happens:
    • when the record is created or updated
    • when any @api.depends field changes
  • Can be used in:
    • search domains
    • filters
    • group_by in views
    • performance-optimized reports


Example


total = fields.Float(

    compute='_compute_total'

    store=True

)


@api.depends('amount', 'tax')

def _compute_total(self):

    for rec in self:

        rec.total = rec.amount + rec.tax


Field total is stored, searchable, and usable in filters.



🧠 Realistic Use Case in Odoo


store=False: Use for UI-only or temporary calculations


age_category = fields.Selection(

    compute='_compute_age_category',

    store=False

)


def _compute_age_category(self):

    for rec in self:

        rec.age_category = 'adult' if rec.age > 18 else 'minor'


Used only for display—no need to store.


store=True: Use for reporting, performance, filtering


invoice_count = fields.Integer(

    compute='_compute_invoice_count',

    store=True

)


@api.depends('invoice_ids')

def _compute_invoice_count(self):

    for rec in self:

        rec.invoice_count = len(rec.invoice_ids)


Searchable, fast access, available in smart buttons.



Summary Table


Feature

store=False

store=True

Stored in DB

❌ No

✅ Yes

Recomputed

Every access

On trigger (@api.depends)

Searchable / Filter

❌ No

✅ Yes

Use in group_by

❌ No

✅ Yes

Recommended for

UI display, light data

Reporting, filters, performance