I want to display a value from the child model in the parent model tree view using one2many field in the parent model and computed field. my code
class PurchaseRequest(models.Model):
_name = 'purchase.request'
_description = 'Purchase Request'
estimated_costs = fields.Monetary(
string='Estimated Cost', compute='_compute_estimated_cost',
help='Estimated cost of Purchase Request Line, not propagated to PO.', store=True,
readonly=True)
line_ids = fields.One2many('purchase.request.line', 'request_id',
'Products to Purchase',
readonly=False,
copy=True,
track_visibility='onchange')
@api.multi
@api.depends('line_ids.estimated_cost')
def _compute_estimated_cost(self):
for move in self:
estimated_costs = 0.0
for line in move.line_ids:
estimated_costs = line.estimated_cost
class PurchaseRequestLine(models.Model):
_name = "purchase.request.line"
_description = "Purchase Request Line"
estimated_cost = fields.Monetary(
string='Estimated Cost', currency_field='currency_id', default=0.0,
help='Estimated cost of Purchase Request Line, not propagated to PO.')