如何在odoo中获取以下情况的域过滤器?

时间:2015-11-25 12:55:10

标签: python openerp

以下代码适用于配置模块(自有模块)中的inspection.py文件。

class asset1_inspection(osv.Model):
    _name = "asset1.inspection"
    _rec_name="inspection_name"

    MAINTENANCE_SELECTION=[
        ('0','Daily'),
        ('1','Weekly'),
        ('2','Fortnight'),
        ('3','Bi-Monthly'),
        ('4','Quarterly'),
        ('5','Half-Yearly'),
        ('6','Yearly'),
        ('7','Bi-Yearly'),

    ]
    MAINTENANCE_TYPE=[
        ('0', 'Corrective'),
        ('1', 'Preventive'),
        ('2', 'Predictive'),

    ]
    SHOUTDOWN_SELECTION=[
        ('0','Yes'),
        ('1','No'),

    ]
    _columns = {
        '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)]", select=True, required=True),
        'inspection_name':fields.char('Inspection Type',),
        'freq_sel':fields.selection(MAINTENANCE_SELECTION,'Frequency'),

        'shut_down':fields.selection(SHOUTDOWN_SELECTION,'Shut Down'),
        'main_type':fields.selection(MAINTENANCE_TYPE,'Maintenance Type',),
        'insp_id1' : fields.one2many('inspec1.grid','insp_id','BoM',),
        'msr_insp' : fields.one2many('results.measure','insp_msr','Inspection Measure',),
        'msr_insp1' : fields.one2many('results.attr','insp_msr1','Inspection Attr',),

        #'asset_type': fields.many2one('asset.cat','Asset Categ'),
        #'asset_part_id': fields.many2one('ainspcat_name','Asset Cat',)

    }

asset1_inspection()

下一个代码是calendar.event.py继承的模块。

class calendar_event(osv.osv):

    _inherit = "calendar.event"
    _rec_name = 'number'
    STATE_SELECTION = [
        ('1', 'Corrective'),
        ('2', 'Preventive'),
        ('3', 'Predictive'),
        ]

    _columns = {
            'number' : fields.char('Calendar Inspection ID',readonly=1),
            'tags' : fields.selection(STATE_SELECTION, 'Tags',),
            'user_id': fields.many2one('res.users','res_users_rel','Assigned', track_visibility='onchange',),

            'company_id11': fields.many2one('res.company', 'Company', required=True),


            'asset_catg_id' : fields.many2one('asset.catg','Asset Catg Selection',),


            'assetmodelid_add' : fields.many2one('agile.portfolio1','Asset Model Code',),
            'folio_num1' : fields.many2one('asset.asset','Folio Num',),


            'inspection_name' : fields.many2many('asset1.inspection','asset1_inspection_rel','super_id','asset1_inspection_id','Inspection Type'),

            }

以下代码是资产继承模块中的asset.py。

class asset_asset(osv.osv):
    _inherit = "asset.asset"
    #_name = "asset_asset"
    _rec_name= "folio_num"
    #_rec_name = "assetmodelid_add"
    CRITICALITY_SELECTION = [
        ('0', 'General'),
        ('1', 'Important'),
        ('2', 'Very important'),
        ('3', 'Critical')
    ]
    _columns = {
        'name': fields.char('Asset Name', size=64),
        'company_id1': fields.many2one('res.company', 'Substation', required=True),
        #'place1': fields.many2one('asset.parentlocation', 'Location'),
        '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)]",),
        'user_id': fields.many2one('res.users', 'Assigned to', track_visibility='onchange'),
        'criticality': fields.selection(CRITICALITY_SELECTION, 'Criticality'),
            'active': fields.boolean('Active'),
        'folio_num' : fields.char('Folio No',),
        '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),

        #'asset_id':fields.many2one('agile.portfolio','Asset ID'),

    }

以下代码位于反馈模块(自有模块)中的feedback.py

class feedback_form(osv.Model):
    _name = 'feedback.form'

    _columns = {
        'company_id111': fields.many2one('res.company', 'Substation', required=True),

        'folionum' : fields.many2one('calendar.event','Maintenance ID',),
        'folio_number' : fields.many2one('asset.asset','Folio number',),


        'frequency' : fields.char('Frequency'),
        'shutdown' : fields.char('Shut Down'),


        'insp_rslt' : fields.one2many('feedback.tree','insp_rsltts','Inspection Result',),

    }

    def get_detail_emp(self, cr, uid, ids, folionum, context=None):
        val = {}
            res = []
            if folionum:
                    for mom in self.pool.get('calendar.event').browse(cr,uid,folionum,context=context):
                        val = {
                                    'inspec_type' : mom.inspection_name,

                                 }
                        res.append(val)

            return {'value': val} 


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


feedback_form()

class feedback_tree(osv.Model):
    _name = 'feedback.tree'

    _columns = {

        'inspec_type' : fields.many2one('asset1.inspection','Inspection Type',),
        'valuess' : fields.char('Values/Results'),
        'insp_rsltts': fields.many2one('feedback.form','Result Id'),
        'insp_msr1' : fields.many2one('results.measure','Result',),
    }


    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)]}}

feedback_tree()

我的要求是 我将使用 asset_model_id inspection.py 模块中创建检查。 然后我将使用作品集编号,资产模型代码创建Asset(使用asset.py)。 我将在 calendar.event和'number'(auto_increment)安排任务并保存。 最后一个案例是反馈模块我会选择'folionum'('number'(auto_increment))'folio_number'。在网格视图或树视图中选择作品集编号后,我应该只获得那些检查名称。 在我的情况下,它没有获得**'inspec_type':fields.many2one('asset1.inspection','Inspection Type'),这不起作用,因为它在其他类。怎么摆脱这个?**

0 个答案:

没有答案