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

Can't get Compute field to work?

By
Yakito
on 2/28/15, 10:29 PM 1,057 views

Hi, 

I am learning how to use the compute field under Odoo v8. The example in the docs looks clear and it seems pretty easy, but no mather what I do it doesn't seem to get triggered.

This is the most basic example I am testing which is not working for some reason:

        'total_units': fields.char(compute='_compute_total',string='Number of Units'),
    

    @api.one
    def _compute_total(self):
        print "Show this if triggered"
        self.total_units = 23

For this basic example I was looking to see a '23' on the total_units field, but nothing happens.

Shouldn't _compute_total be triggered each time the tree view is opened? What I am missing?

Any help will be appreciated,

Thanks

0

tolstoj

--tolstoj--
899
| 6 5 8
Germany
--tolstoj--

hi

tolstoj
On 3/1/15, 4:45 AM

Computed fields are triggered on save (DB write).

Hi, thanks. I read in the docs that "computed fields are not stored by default, they are computed and returned when requested. Setting store=True will store them in the database and automatically enable searching" So my understanding was that I can run a compute field if I need results "on the fly". if this is not the case, what type of field can I use to get results on the fly under V8? Thanks so much for your help

Yakito
on 3/1/15, 8:31 AM

You can overwrite read method of your model and change return value for desired field.

tolstoj
on 3/1/15, 11:40 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/28/15, 10:29 PM
Seen: 1057 times
Last updated: 3/16/15, 8:10 AM