Hi all, I'm new to Odoo and working with v11. Currently I got a problem with passing value and calculation.
Here is related coding
.py file:
class costSummary(models.Model):
_name = 'cost.summary'
total = XXXXX
cost_line = fields.One2many('cost.details', inverse_name='cost_id')
class costDetails(models.Model):
_name = 'cost.details'
cost_id = fields.Many2one('cost.summary', ondelete='cascade')
cost_line_id = fields.Char(string="SubExpense")
cost_line_desc = fields.Text(string="SubExpense Description")
cost_line_cost = fields.Float(string='Cost')
xml/view file:
<field name="cost_line_cost" sum="Total cost"/>
Now, I would like to use "total" to store the cost value (the total cost) and display it. But I dont know how to do that. I guess it should be looks like this:
total = fields.Float(store=True, compute='_compute_amount')
@api.depends('cost_line_cost')
def _compute_amount(self):
for rec in self:
rec.total += rec.env['cost.details'].search([]).cost_line_cost
Can anyone please show me how to do it in details? what I missed? any hint will be useful, Thanks a lot!