You must use "fields.related" to dclare the parents field in your child object
Then after, you will be able to use this fields where ever you want for that child object (in search for python code or in Xml views):
Here is the code :
Code:
class clients(osv.osv):
_name = 'mymodule.clients'
_columns = {
#field stored in the object
'name': fields.char('Partner Name', size=100, required=True),
'partner_id': fields.integer('Partner ID', readonly=True, required=True),
#field that can be dynamicaly find in the object. here the childs
'maintenances_ids': fields.one2many('mymodule.maintenances', 'partner_id', 'maintenances'), #Define maintenances' Childs
}
clients()
class maintenances(osv.osv):
_name = 'mymodule.maintenances'
_columns = {
#field stored in the object
'name': fields.char('Maintenance Name', size=100, required=True),
'maintenances_id': fields.integer('Maintenance ID', readonly=True, required=True),
'partner_id':fields.many2one('mymodule.clients', 'Clients', required=True), #Define parent Client
#field that can be dynamicaly find in the object here the childs
'product_ids': fields.one2many('mymodule.product', 'maintenances_id', 'Products'), #Define products' Childs
}
maintenances()
class product(osv.osv):
_name = 'mymodule.product'
_columns = {
#field stored in the object
'name': fields.char('Product Name', size=100, required=True),
'product_id': fields.integer('Product ID', readonly=True, required=True),
'maintenances_id':fields.many2one('mymodule.clients', 'Clients', required=True), #Define parent Maintenance
#field that can be dynamicaly find in the object. here the parent (partner_id) folowing by childs (productitem_ids)
'partner_id':fields.related('maintenances_id','partner_id',readonly=True, type='many2one',relation="mymodule.clients",string="Partner",store=False), #Define partner_id which is parent of maintenances_id
'productitem_ids': fields.one2many('mymodule.productitem', 'product_id', 'Product Items'), #Define products' Childs
}
product()
class productitem(osv.osv):
_name = 'mymodule.productitem'
_columns = {
#field stored in the object
'name': fields.char('Product Item Name', size=100, required=True),
'productitem_id': fields.integer('Product Item ID', readonly=True, required=True),
'product_id':fields.many2one('mymodule.product', 'Product', required=True), #Define parent Product
#field that can be dynamicaly find in the object. here the parent (maintenances_id and partner_id)
'maintenances_id':fields.related('product_id','maintenances_id',readonly=True, type='many2one',relation="mymodule.maintenances",string="Maintenance",store=False), #Define maintenances_id which is parent of product_id
'partner_id':fields.related('product_id','maintenances_id','partner_id',readonly=True, type='many2one',relation="mymodule.partner",string="Partner",store=False), #Define partner_id which is parent of maintenances_id which is parent of product_id
}
productitem()