Odoo Help


Understanding old API, what does store in fields.function actually do?

on 2/14/16, 7:40 AM 1,070 views

I would like to understand when this field changes. It is part of sale.py model.

I have added a field "global discount" to sale.order model and  I would like amount_untaxed to change when field "global discount" changes, what should I do?

'amount_untaxed': fields.function(_amount_all_wrapper, 
  string='Untaxed Amount',
                    'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),
     'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),
  help="The amount without tax.", 


Ahmed M.Elmubarak
On 2/14/16, 8:50 AM


The store keyword used to enhance the performance; since the functional field will be computed each time it'll be visible to the user.

without the store keyword [store=False], the functional field will not be stored in the database [e.g you can just access it by a browse record].

If you use store=True [the default is False]; your functional field will be stored in the DB and will be calculated for just one time.

- To tell the server when to recompute this filed you'll use a dictionary as

store={'model_name': (trigger_ids, [trigger_fields], priority), ...}

as in your example:

'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line'], 10),

the means: the field amount_untaxed will be recomputed whenever there is a changes in the 'order_line' field of the sale.order and

'sale.order.line': (_get_order, ['price_unit', 'tax_id', 'discount', 'product_uom_qty'], 10),

To recompute the field whenever there is a changes in the fields: 'price_unit', 'tax_id', 'discount', 'product_uom_qty' of the sale.order.line ...

the _get_order function: will return the [id] of parent sale order of the sale.order.line

For your question, I think you need to update the line as:

 'sale.order': (lambda self, cr, uid, ids, c={}: ids, ['order_line', 'global_discount'], 10),

I hope this could helps ...

It really helps, I managed to discover that adding global_discount triggered the field update, but I did not manage to fully understand how it fully worked. Your explanation is comprehensive and clear, thanks a lot.

on 2/14/16, 8:53 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/14/16, 7:40 AM
Seen: 1070 times
Last updated: 2/14/16, 8:52 AM