Odoo Hilfe


10 Answers
David Yao
26.03.18, 21:45

Hi all, Thx for the help from Niyas Raphy, I have a much clear picture. I just solved this problem and for people who has the similar problem, hope my answer can help you.

There are 3 keys to solve this problem.

First of all, in my case, what I'm trying to get is a recordset and then find the cost value for each record, sum it up and create a field to store its value (not setting up total_cost column for each record). Secondly, of course, using @api.depends rather than @api.onchange  Thirdly, using update method

This is what my code looks like:


def _compute_amount(self):
    for rec in self:

        money = 0

        for details_rec in rec.cost_line:
            if details_rec.cost_line_cost:
                money = money +  details_rec.cost_line_cost

    self.update({ 'total' : money })


Niyas Raphy

--Niyas Raphy--
| 7 7 11
Wayanad, Kerala, Indien
--Niyas Raphy--

Odoo Techno Functionalist

Feel free to connect :  niyasraphyk@gmail.com

LinkedIn: https://www.linkedin.com/in/niyasraphy/

Happy to help :)

Niyas Raphy
19.03.18, 00:24


The problem seems with the compute function you have wrote, update it like this,


David Yao
19.03.18, 01:17

It seems that it unable to find 'cost_line_cost', it arise a keyerror (KeyError: 'cost_line_cost')

Niyas Raphy
19.03.18, 01:30

Make sure you have got that field in the model

David Yao
19.03.18, 01:49

yes, I have "cost_line_cost " in "costDetails" model, But it is not in the "costSummary" model, does it matter?

David Yao
19.03.18, 02:06

hey, Niyas Raphy, I fixed this keyError by changing @api.depends('cost_line_cost') TO @api.depends('cost_line.cost_line_cost'), but I got a new issue, that is the value is not calculated correctly, all my records showing value 134 at the "total" field/column

Niyas Raphy
19.03.18, 02:47

Yes, it will be like this, you have to add the search condition inside the search,

David Yao
19.03.18, 03:12

For the search domain, I have tried search([('cost_line_cost', '>=', 0)]) OR search([('expense_id', '=', True)]), nothing is changing. And also, my issue is all record's "total" column showing value 134 (even for those don't have "cost_line_cost " value)

David Yao
19.03.18, 03:14

expense_id, I mean cost_id

David Yao
19.03.18, 05:22

hey Niyas Raphy, After I create a new record, the total value becomes 0 (old record's value keeps the same, 134). So, it seems that It goes somewhere else to get the value and doing calculation. but where else it will go? it is defined in the "_compute_amount" method, right? please help me out, thanks!

Fragen Sie
Keep Informed
0 Verfolger
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 eLearning platform and experience all Odoo Apps through learning videos, use cases and quizzes.

Test it now