How can I read from a calculated field? In Odoo 9

I have a calculated field in the model called page_price .

Class Page(models.Model):
    page_price = fields.Float(compute='compute_page_price')

    def compute_page_price(self):
        self.page_price = 7  # this value is an example

      

If I show this field in the view it displays 7.

The problem is I am trying to get the value from a different model.

Class Book(models.Model):
  book_price = fields.Float(compute='compute_book_price')

  def compute_book_price(self):
    # page_id has the value of a Page row id
    page_price = self.env['Page'].search([('id', '=', page_id)])[0].page_price
    self.book_price = page_price * 10

      

Here the book_price value is always 0 instead of 70. The
page_price vault inside the compute_book_price function is 0 instead of 7.
Why is this and how can I get the correct value?

Note. If the page_price field is defined as a Float field instead of a calculated field, the result of book_price is 70.

+3


source to share





All Articles