Odoo Help

Welcome!

This community 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.

0

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

By
E.M.
on 2/14/16, 7:40 AM 607 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, 
  digits_compute=dp.get_precision('Account'), 
  string='Untaxed Amount',
              store={
                    '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),
              },
  multi='sums', 
  help="The amount without tax.", 
  track_visibility='always'),


Thanks

1

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


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

Hello,

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.

E.M.
on 2/14/16, 8:53 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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