Skip to Content
Menu
This question has been flagged
1 Reply
11179 Views

i have domain filter code for many2one field. this is working fine for many2one field so i wanted 'area_id' i.e hindu_data_super class should be in many2many or please let me know how can i select multiple item in one field...

class hindu_desh(osv.Model):

_name="hindu.desh"

_description="Define districts"

_columns={ 'name':fields.char('District Name',size=64,required=True) }

hindu_desh()

class hindu_state(osv.Model):

_name="hindu.state"

_description="Define sub districts"

_columns={ 'name':fields.char('Sub District Name',size=64,required=True), 'hindu_state_id': fields.many2one('hindu.desh','District Name',select=True,required=True,ondelete="restrict") }

hindu_state()

class hindu_dist(osv.Model):

_name="hindu.dist"

_description="Define areas"

_columns={ 'name':fields.char('Area Name',size=64,required=True),

#'area_type': fields.selection(area_type_lov,'Area Type',required=True),

'hindu_state_id':fields.many2one('hindu.state','Sub District Name',size=64,required=True),

'district_id':fields.related('hindu_state_id','hindu_state_id',readonly=True,type='many2one',relation='hindu.desh',string='District Name'),

}

hindu_dist()

class hindu_data_super(osv.Model):

_name = "hindu.data.super"

_description = "Area of Registration Super"

_columns = {

'district_id' : fields.many2one('hindu.desh','District', select=True, required=True, ondelete="restrict"),

'hindu_state_id' : fields.many2one('hindu.state', 'Sub District', domain="[('hindu_state_id', '=', district_id)]", select=True, required=True),

'area_id' : fields.many2one('hindu.dist', 'Area', domain="[('hindu_state_id', '=', hindu_state_id)]", select=True, required=True),

}

hindu_data_super()

Avatar
Discard
Author

how to filter for many2many fields

I have given answer for many2many.

from openerp.osv import fields, osv # its cal.event class inherited

class calendar_event(osv.osv):
   
    _inherit = "calendar.event"
    _rec_name = 'number'
   
    _columns = {
            'number' : fields.char('Meeting ID',readonly=1),
            #'place' : fields.many2one('stock.location','Substation Location',),
           
            'place' : fields.many2one('asset.parentlocation','Substation Location',),
            #'location' : fields.selection(STATUS_SELECTION,'Location',  default='Board A'),
            'asset_catg_id' : fields.many2one('asset.catg', 'Asset Catg Selection',),
             'area_id' : fields.many2one('asset.name','Asset Name Selection', domain="[('asset_catg_id', '=', asset_catg_id)]", select=True, required=True),
            'assetmodelid_add' : fields.many2many('agile.portfolio1','agile_portfolio1_rel','super_id','agile_portfolio1_id','Asset Model Code',),
            'folio_num' : fields.many2many('asset.asset','asset_asset_rel','super_id','asset_asset_id','Folio Num',),
            #'folio_num' : fields.related('folio_num','folio_num',string='Folio Num',relation='asset.asset', type='many2one')   
            }
   
    _defaults = {
                'number' : lambda self,cr,uid,context={}:self.pool.get('ir.sequence').get(cr,uid,'calendar.event'),
                }

  
class asset_asset(osv.osv): #asset inherited
    _inherit = "asset.asset"
    #_name = "asset_asset"
    _rec_name= "folio_num"
    _columns = {
        'name': fields.char('Asset Name', size=64),
        'asset_catg_id' : fields.many2one('asset.catg', 'Asset Catg Selection',select=True, required=True),
               'area_id' : fields.many2one('asset.name', 'Asset Name Selection', domain="[('asset_catg_id', '=', asset_catg_id)]", select=True, required=True),
        'assetmodelid_add' : fields.many2one('agile.portfolio1','Asset Model Code',domain="[('area_id', '=', area_id)]",),
        'folio_num' : fields.char('Folio No', readonly=1),
        'asse_line':fields.one2many('asset.line','emp_id','Name Plate'),
        'asse_line2':fields.one2many('asset.part','emp_id1','Parts'),
               # 'assed_modelid':fields.many2one('agile.portfolio1','Asset Model ID',select=True, required=True),
        'quantity': fields.char('Quantity',size=64),
        'uom': fields.char('Uinit of Measure',size=64),
        'model_no' : fields.char('Model', size=64),
        'place': fields.many2one('asset.parentlocation', 'Location'),
        #'asset_id':fields.many2one('agile.portfolio','Asset ID'),
       
    }
class asset_parentlocation(osv.osv):
    _name="asset.parentlocation"
    _rec_name="location_name"
    _columns = {
        'location_name' : fields.char('Asset Location', required=True),
        'parent_location' : fields.many2one('asset.parentlocation','Parent Location'),}

    def name_get(self, cr, uid, ids, context=None):
        if context is None:
            context = {}
        if not ids:
            return []
        reads = self.read(cr, uid, ids, ['location_name','parent_location'], context=context)
        res = []
        for record in reads:
            name = record['location_name']
            if record['parent_location']:
                name = record['parent_location'][1]+' / '+name
            res.append((record['id'], name))
        return res



 i would like to domain filter in cal.event inherited class so i was tried but dint get it how to domain filter of place field in cal.event that will again filter to asset_catg and all
-- 
Best Regards,

Shridhar Ivani
Software programmer

Prasanna Technologies Pvt Ltd
Krishna Complex, M.G.Road,
Mangalore - 575003, Karnataka

(Off):  +91-824-2493009
(Fax):  +91-824-2493003
www.prasannatechnologies.com

Please reply me with solution thanks in advance
Best Answer

Hi,

First of all define you column as many2many and then you can make filter at xml level. For that you need to write down domain inside xml defination of that field as like below.

... ...

<field name="hindu_state_id" />

<field name="area_id" domain="[('hindu_state_id','=',hindu_state_id)]" />

... ...

I hope you will get your desire result.

Avatar
Discard
Related Posts Replies Views Activity
5
Sep 20
6854
1
Oct 19
4738
0
Feb 19
4150
2
Nov 18
5649
0
May 18
1828