
from openerp.osv import orm, fields


class invoice_line(orm.Model):
    _inherit = 'account.invoice.line'

    def _get_child_name(self, cr, uid, ids, name, dict, context=None):
        res = {}
        for line in self.browse(cr, uid, ids, context):
            child_name = ''
            if line.contract_id and line.contract_id.child_id:
                child_name = line.contract_id.child_id.name
            res[line.id] = child_name

        return res

    _columns = {
        'child_name': fields.function(
            _get_child_name, string='Child name', type='char')
    }


from openerp.osv import orm, fields


class invoice_line(orm.Model):
    _inherit = 'account.invoice.line'

    _columns = {
        'child_name': fields.related(
            'contract_id', 'child_name', string='Child name', type='char')
    }

Change child_name to related field.
Change child_name to related field.

  
  from openerp.osv import orm, fields
  
  
  class invoice_line(orm.Model):
      _inherit = 'account.invoice.line'
  
-     def _get_child_name(self, cr, uid, ids, name, dict, context=None):
-         res = {}
-         for line in self.browse(cr, uid, ids, context):
-             child_name = ''
-             if line.contract_id and line.contract_id.child_id:
-                 child_name = line.contract_id.child_id.name
-             res[line.id] = child_name
- 
-         return res
- 
      _columns = {
-         'child_name': fields.function(
+         'child_name': fields.related(
-             _get_child_name, string='Child name', type='char')
+             'contract_id', 'child_name', string='Child name', type='char')
      }
  
Change child_name to related field.
## Code Before:

from openerp.osv import orm, fields


class invoice_line(orm.Model):
    _inherit = 'account.invoice.line'

    def _get_child_name(self, cr, uid, ids, name, dict, context=None):
        res = {}
        for line in self.browse(cr, uid, ids, context):
            child_name = ''
            if line.contract_id and line.contract_id.child_id:
                child_name = line.contract_id.child_id.name
            res[line.id] = child_name

        return res

    _columns = {
        'child_name': fields.function(
            _get_child_name, string='Child name', type='char')
    }

## Instruction:
Change child_name to related field.
## Code After:

from openerp.osv import orm, fields


class invoice_line(orm.Model):
    _inherit = 'account.invoice.line'

    _columns = {
        'child_name': fields.related(
            'contract_id', 'child_name', string='Child name', type='char')
    }
