如何添加到字段中的字段?

时间:2015-06-25 11:57:17

标签: python odoo

folio_num字段中,我希望得到两个值,即'assetmodelid_add' + 'place'。在我的情况下,我已经完成了更改方法的功能,但他们我得到的索引不是字符串值。这是我在这里发布的完整代码,它有asset.asset和agile.poertfilio1 .py文件。请仔细检查并告诉我正确的代码。我认为不需要添加.xml文件。

        from openerp.osv import fields, osv


    class asset_asset(osv.osv):
        _inherit = "asset.asset"
        #_name = "asset_asset"
        _rec_name= "folio_num"
        _columns = {
            'name': fields.char('Asset Name', size=64),
            'place': 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)]",),
            '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'),

        }


        '''def get_asset_parts1(self, cr, uid, ids, assetmodelid_add,model_no, context=None):
            val = {}

            res = []

            if model_no:
                val['model_no'] = model_name


            return {'value': val}'''

        def onchange_first_last(self, cr, uid, ids, place, assetmodelid_add, context=None):
                v = {}
                asset_val=''
                place_val=''
                place_obj=self.pool.get('asset.parentlocation')
            asset_obj=self.pool.get('agile.portfolio1')

            if assetmodelid_add:
                    asset_val = asset_obj.browse(cr, uid, assetmodelid_add, context=None).name
            if place:
                    place_val = place_obj.browse(cr, uid, place, context=None).name

                v['folio_num'] = asset_val + place_val
                return {'value': v}

        def get_asset_parts(self, cr, uid, ids, assetmodelid_add,context=None):
            val = {}
            #
            res = []
            res2 = []
            res3 = []


            if assetmodelid_add:
                for asset in self.pool.get('agile.portfolio1').browse(cr,uid,assetmodelid_add,context=context):
                    for ass in asset.asspart_id1:
                        val = {
                            'pname_id' : ass.asspart_name,
                            'vsurname' : ass.assvalue_code,

                            }

                        res.append(val)
                    for ass in asset.strat_id1:
                        val = {
                            'part_name' : ass.start_name,
                            'part_code' : ass.strat_code,
                            'part_quty' : ass.strat_quty,
                            'part_uom' : ass.strat_uom,
                            }
                        res2.append(val)

                val['model_no'] = asset.model_name  


                val.update({'asse_line':res, 'asse_line2':res2,'model_no':asset.model_name })


            return {'value': val}



    asset_asset()

    class asset_attach(osv.osv):
        _inherit = "asset.asset"
        _columns = {
            #'rp_resume1' : fields.Binary(string='Resume'),
            #'rp_resume1_name' : fields.Char(string='File name')
            #'rp_more1_docs' : fields.many2many('ir.attachment', 'room_partner_attachment_rel', 'room_partner_id', 'attachment_id', 'More Documents'),
            'attachments': fields.many2many('ir.attachment', 'partner_id',string="Attachments"),

            #'nameee':fields.many2one('ir.attachment','Attachments'),
        }
    asset_attach()

    class asset_model_id(osv.osv):
        _inherit = "asset.asset"
        _columns = {

            'assetcat_id' : fields.char('Asset Catg',)
        }
    asset_model_id()

    class pname_line(osv.osv):
        _name='pname.line'
        _columns = {

            'name':fields.char('Name'),
        }

    pname_line()



    class asset_line(osv.osv):
        _name="asset.line"
        APPOINTMENT_SELECTION=[
            ('0','Regular'),
            ('1','Aditional'),
            ('2','Deputation'),

        ]
        _columns = {
            'pname_id':fields.char('Pname'),
            'vsurname':fields.char('Value'),

            'emp_id': fields.many2one('asset.asset', 'vendor_id'),
        }

    asset_line()

    class pname_part(osv.osv):
        _name='pname.part'
        _rec_name = 'namee'
        _columns = {

            'namee':fields.char('Name'),
        }

    pname_line()

    class asset_part(osv.osv):
        _name="asset.part"
        #_rec_name = 'part_name'
        APPOINTMENT_SELECTION=[
            ('0','Regular'),
            ('1','Aditional'),
            ('2','Deputation'),

        ]
        _columns = {
            'part_name':fields.char('Name'),
            'part_code':fields.char('Code'),
            'part_quty':fields.char('Quantity'),
            'part_uom':fields.char('UoM'),
            'emp_id1': fields.many2one('asset.asset', 'vendor_id'),
        }

    asset_part()


    class asset_parentlocation(osv.osv):
        _name="asset.parentlocation"
        _rec_name="parent_location"
        _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


agile.portfolio1 .py file here

class asset_catg(osv.Model): 
    _name="asset.catg" 
    _rec_name='name1'
    _description="Define Asset Catgs" 
    _columns={ 'name1':fields.char('Asset Catg Names',size=64,required=True),}
asset_catg()

class asset_name(osv.Model): 
    _name="asset.name" 
    _rec_name='name'
    _description="Define asset name" 
    _columns={ 'name':fields.char('Asset Name',size=64,required=True),
        'material_code' : fields.char('Material Code',),
        #'area_type': fields.selection(area_type_lov,'Area Type',required=True), 
        'asset_catg_id':fields.many2one('asset.catg','Asset Catg Name',size=64,required=True),
}

asset_name()

class asset_config_super(osv.Model): 

    _name = "asset.config.super" 

    _description = "Assigning to substation"
    _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),
    }

asset_config_super()

#Asset Creation 

class agile_portfolio1(osv.Model):
    _name = "agile.portfolio1"
    _rec_name = 'asset_id_add'
    _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)]",),  
        'material_code' : fields.char('Material Code'),
        'strat_id1' : fields.one2many('portfolio1.grid','strat_id','BoM',),
        'asspart_id1' :fields.one2many('asset1.grid','asspart_id','Specification',),
        'asset_id_add' : fields.char('Asset Model Code',),
        'make_name' : fields.char('Make',),
        'model_name': fields.char('Model',),

        #'asset_categ': fields.many2one('asset.cat','Asset Catg',select=True,required=True,ondelete="restrict"),
    }
    def get_meet_dets(self, cr, uid, ids, area_id, context=None):
        val = {}
        if area_id:
            for det in self.pool.get('asset.name').browse(cr,uid,area_id,context=context):
                    val = {
                        'material_code' : det.material_code,
                        }
        return {'value': val}

    def onchange_first_last(self, cr, uid, ids, make_name, model_name, context=None):
        v = {}
        #'area_ref':fields.related('area_ref','area_id',readonly=True,type='char',relation='agile.portfolio1',string='Area'),
        if make_name and model_name:
            v['asset_id_add'] = make_name + model_name
        return {'value': v}


agile_portfolio1()

class portfolio1_grid(osv.Model):
    _name = 'portfolio1.grid'
    _columns = { 
                'start_name' : fields.char('Part'),
                'strat_code' : fields.char('Code'),
                'strat_quty' : fields.char('Quantity '),
                'strat_uom' : fields.char('UoM'),
                'strat_id': fields.many2one('agile.portfolio1','Strat Id'),
            }

portfolio1_grid()

class asset1_grid(osv.Model):
    _name = 'asset1.grid'
    _columns = { 
                'asspart_name' : fields.char('Part'),
                'assvalue_code' : fields.char('Value'),

                'asspart_id': fields.many2one('agile.portfolio1','Specifications'),
            }

asset1_grid()
#Inspection Class


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

    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,'Shout Down'),
        'main_type':fields.selection(MAINTENANCE_TYPE,'Maintenance Type',),
        'insp_id1' : fields.one2many('inspec1.grid','insp_id','BoM',),
        'ainsp_id1' : fields.one2many('assetinspec1.grid','ainsp_id','Asset Maintenance',),
        #'asset_type': fields.many2one('asset.cat','Asset Categ'),
        #'asset_part_id': fields.many2one('ainspcat_name','Asset Cat',)

    }

asset1_inspection()

class inspec1_grid(osv.Model):
    _name = 'inspec1.grid'
    _columns = { 
                'insp_name' : fields.char('Part'),
                'insp_code' : fields.char('Code'),
                'insp_quty' : fields.char('Quantity '),
                'insp_uom' : fields.char('UoM'),
                'insp_id': fields.many2one('asset1.inspection','Insp Id'),
            }

inspec1_grid()

class assetinspec1_grid(osv.Model):
    _name = 'assetinspec1.grid'
    _columns = { 
                'ainsp_name' : fields.many2one('assetcat1.grid','Asset Name',),
                'ainsp_id': fields.many2one('asset1.inspection','aInsp Id'),
            }

assetinspec1_grid()


class asset1_cat(osv.Model):
    _name = "asset1.cat"
    #_rec_name="asset_catname"

    _columns = {
        'asset_catname':fields.char('Asset Type',),
        'assetcat_id':fields.one2many('assetcat1.grid','ainspcat_id','Asset Name',)

    }

asset1_cat()

class assetcat1_grid(osv.Model):
    _name = 'assetcat1.grid'
    #_rec_name='ainspcat_name'
    _columns = { 
                'ainspcat_name' : fields.char('Asset Names'),
                'ainspcat_id': fields.many2one('asset1.cat','AssetCat ID'),
            }


assetcat1_grid()

2 个答案:

答案 0 :(得分:0)

听到很多2个字段总是返回id而不是值,因为我们需要浏览从该字段到该特定对象的记录并使用该现有字段名称

你应该遵循这样的事情。

        //$searchString = '[{
        //                  "status" : "SENT",
        //                  "page" : 0,
        //                  "page_size" : 0,
        //                  "total_count_required" : true
        //                 }]';

我希望这对你有用:)

答案 1 :(得分:0)

尝试以下,

def onchange_first_last(self, cr, uid, ids, place, assetmodelid_add, context=None):
    v = {}
    asset_val=''
    place_val=''
    place_obj=self.pool.get('asset.parentlocation')
    asset_obj=self.pool.get('agile.portfolio1')

    if assetmodelid_add:
        asset_val = asset_obj.browse(cr, uid, assetmodelid_add, context=None).asset_id_add
    if place:
        place_val = place_obj.browse(cr, uid, place, context=None).name

    v['folio_num'] = asset_val + place_val
    return {'value': v}