title: How to make a field computed only if some condition is fulfilled in Odoo 8?
body: <p>Is there any way in Odoo 8 to create a field which is computed only if some condition is fulfilled, otherwise the user will be able to set its value?</p>
  
  <p><strong>Example</strong></p>
  
  <p>I have a model named <code>box</code>, which has a float field named <code>value</code>.</p>
  
  <p>Imagine a box can have several boxes inside, each one which its own value.</p>
  
  <p>So we have a one2many field named <code>child_ids</code> pointing to <code>box</code> and a many2one named <code>parent_id</code> pointig to box too.</p>
  
  <p>Now I want the following behaviour: an user can set the <code>value</code> field of a box which has not any box inside (it means, <code>childs_ids</code> is <em>False</em>), but, if the box has at least one box inside (it means, <code>childs_ids</code> is NOT <em>False</em>), the <code>value</code> field must be computed and it will be the sum of its childs <code>value</code>.</p>
  
  <p>Does anyone have an idea of how to achieve this behaviour?</p>
  
  <p>I put my code, which is not working (the value of <code>value</code> is always being reset to 0):</p>
  
  <pre><code>class box(models.Model):
      _name='box'
  
      @api.one
      @api.depends('child_ids', 'child_ids.value')
      def _compute_value(self):
          if self.child_ids:
              self.value = sum(
                  [child.value for child in self.child_ids])
  
      def _set_value(self):
          pass
  
      parent_id = fields.Many2one(comodel_name='box',
                                  string='Parent Box')
  
      child_ids = fields.One2many(comodel_name='box',
                                  inverse_name='parent_id',
                                  string='Boxes inside')
  
      value = fields.Float(
          string='Value',
          compute='_compute_value',
          inverse='_set_value',
          store=False,
          required=True,
          readonly=True,
          states={'draft':[('readonly',False)]},
      )
  </code></pre>