如何获得many2one过滤值?

时间:2015-07-22 11:26:16

标签: python odoo

我有以下代码 calender.event 继承的类。在那里,我将通过数字序列创建事件。我还有其他字段,如'inspection_name'

    from openerp.osv import fields, osv
from openerp import api
import logging

class feedback_form(osv.Model):
    _name = 'feedback.form'
    _rec_name = 'inspec_type'
    _columns={
        'folionum' : fields.many2one('calendar.event','Maintainace ID',),
        'folio_number' : fields.many2one('asset.asset','Folio number',),
        'inspec_type' : fields.many2one('asset1.inspection','Inspection Type',domain="[('inspec_type' , '=' , folio_number)]"),

        'frequency' : fields.char('Frequency'),
        'shutdown' : fields.char('Shout Down'),
        'insp_msr1' : fields.many2one('results.measure','Result',domain="[('inspec_type', '=', inspec_type)]"),
    }

    def onchange_folio(self, cr, uid, ids, folionum, context=None):
        dids = []
        for record in self.pool.get('calendar.event').browse(cr, uid, folionum, context=context):
            dids = [x.id for x in record.folio_num]
        return {'domain':{'folio_number':[('id','in',dids)]}}

    '''def onchange_insp(self, cr, uid, ids, folio_number, context=None):
        dids = []
        for record in self.pool.get('calendar.event').browse(cr, uid, folio_number, context=context):
            dids = [x.id for x in record.inspection_name]
        return {'domain':{'inspec_type':[('id','in',dids)]}}'''

    def onchange_measure(self, cr, uid, ids, inspec_type, context=None):
        dids = []
        for record in self.pool.get('asset1.inspection').browse(cr, uid, inspec_type, context=context):
            dids = [x.id for x in record.msr_insp]
        return {'domain':{'insp_msr1':[('id','in',dids)]}}

calendar.event

来自openerp.osv导入字段,osv 来自openerp import api

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',),
        #'inspection_name' : fields.many2one('asset1.inspection','Inspection Type', ),
        'inspection_name' : fields.many2many('asset1.inspection','asset1_inspection_rel','super_id','asset1_inspection_id','Inspection Type'),
        #'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'),
            }

1 个答案:

答案 0 :(得分:0)

第一

我想这是你做过的非常简单的拼写错误,声明:

mesure_fil = self.pool.get('calender.event')

应该是:

mesure_fil = self.pool.get('calendar.event')

您的型号名称上有拼写错误。

第二

你需要在这里输入你的on_chnage方法,以使其正常工作:

def onchange_folio(self, cr, uid, ids, folionum, context=None):
    dids = []
    for record in self.pool.get('calendar.event').browse(cr, uid, folionum, context=context):
            dids = [x.id for x in record.inspection_name]
    return {'domain':{'inspec_type':[('id','in',dids)]}}

并在您的表单视图中,请确保您的代码像这样调用

<field name="folionum" options="{'no_create': True, 'no_open': True}" on_change="onchange_folio(folionum)"/>

这将正常工作。

贝斯茨