It is currently Mon May 21, 2012 6:52 pm

All times are UTC + 2 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: How to show a field from a parent class?
PostPosted: Mon Apr 25, 2011 1:33 pm 
Offline

Joined: Fri May 28, 2010 10:33 am
Posts: 409
The idea is:
* to have many clients with many maintenances
(one2many relation)

The need is:
* show a tree view of maintenances group by client

Records of clients class:
* partner_id
* maintenances_ids

Records of maintenances class:
* products_ids
* date_initial
* date_end
* ...

But how to create the tree view showing records of 2 different classes?

Example:

partner | product | date_initial | date_end . . .

Juanjo | maintenance1 | 25/04/2011 | 25/04/2012

Thx, any ideas are welcome.

Juanjo A

_________________
Formación online OpenERP - Programación módulos - Apoyo instalación
http://www.malagatic.com @malagatic


Top
 Profile  
 
 Post subject: Re: How to show a field from a parent class?
PostPosted: Tue Apr 26, 2011 2:15 pm 
Offline

Joined: Fri Nov 06, 2009 7:11 am
Posts: 36
Hello Juanjo A,

JuanjoA wrote:
how to create the tree view showing records of 2 different classes?

Are you familiar with the "PostgreSQL Report" or "Statistical Report" or "Custom Report" of OpenERP?
It displays statistically analyzed data which are in more then one tables and hence classes.
As for example you can see the Sale Analysis Report using : 'Sales/Reporting/Sales Analysis' menu.
This 'Tree View' uses two table's data 'sale_order' and' sale_order_line'.

First you have to define one more class for combining more then one tables' data.
Please go through following link in order to see how actually such class should be written:
http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/sale/report/sale_report.py

JuanjoA wrote:
The need is:
* show a tree view of maintenances group by client

For this you need to define search view.
You can add one button 'Client' (partner_id) in 'Group By...' section in search view and using it you can have maintenances group by client
To develop such "Tree View" with "Search view" :
http://bazaar.launchpad.net/~openerp/openobject-addons/6.0/view/head:/sale/report/sale_report_view.xml (upto line no 133)


Hope this will help you.


Top
 Profile  
 
 Post subject: Re: How to show a field from a parent class?
PostPosted: Wed Apr 27, 2011 9:13 am 
Offline

Joined: Fri May 28, 2010 10:33 am
Posts: 409
@rch thanks, great example the 'Sales/Reporting/Sales Analysis'.

I will try but, can I work without sql, only with python, to do this?

Another idea is the _inherits option. I think this is for get a field from another class.

Thx
Juanjo A.

_________________
Formación online OpenERP - Programación módulos - Apoyo instalación
http://www.malagatic.com @malagatic


Top
 Profile  
 
 Post subject: Re: How to show a field from a parent class?
PostPosted: Mon Jun 06, 2011 5:22 pm 
Offline

Joined: Tue Sep 07, 2010 12:20 pm
Posts: 3
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()




Top
 Profile  
 
 Post subject: Re: How to show a field from a parent class?
PostPosted: Tue Jun 07, 2011 12:34 pm 
Offline

Joined: Fri May 28, 2010 10:33 am
Posts: 409
Thx pronzy, now, I understant the fields.related to acces parent fields on other objects.

Juanjo A.

_________________
Formación online OpenERP - Programación módulos - Apoyo instalación
http://www.malagatic.com @malagatic


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 2 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:

Protected by Anti-Spam ACP