Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
8465 Lượt xem

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Computed fields are triggered on save (DB write).

Ảnh đại diện
Huỷ bỏ
Tác giả

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

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 15
4301
3
thg 9 24
1462
0
thg 12 23
1378
0
thg 10 21
2988
1
thg 7 21
3753