如何在odoo中添加以下案例中的相关字段?

时间:2016-06-21 07:04:05

标签: python xml openerp

在我的下一个模块中,我有两个类。当我从 feeder_data 类中选择 date_of1 字段时。所选日期应该在树视图中自动填充 data_value < / strong>在 time_read 。现在有两个字段使用 def get_feeder_catg 功能进行自动填充。所以我希望将相同的日期 date_of1 添加到填充记录的 time_read

class feeder_data(osv.Model):

    _name = "feeder.data"
    _rec_name= "company_id1"

    _columns = {
        'company_id1': fields.many2one('res.company', 'Substation', required=True),
        'date_of1':fields.datetime('Date',),
        'group_name':fields.many2one('feeder.catg','Please Select Group'),


        'combine2':fields.one2many('data.value','combine','Details'),

           }
      def get_feeder_catg(self, cr, uid, ids, group_name,context=None):
        val = {}
        res = []
        res2 = []
        res3 = []
        if group_name:
            for asset in self.pool.get('feeder.catg').browse(cr,uid,group_name,context=context):
                for ass in asset.combine_table:
                    val = {
                        'Hours' : ass.feeder.folio_num,
                        'company_id1': ass.company_id1.name,
                        #'time_read':date.today().strftime('%Y-%m-%d')

                        }

                    res.append(val)

            val.update({'combine2':res,})
        return {'value': val}

class data_value(osv.Model):
    _name = "data.value"
    _rec_name = "mega_wat"
    _columns={
        'company_id1':fields.char('Comapny'),
        'Hours':fields.char('Folio'),
        'time_read':fields.datetime('Time'),
        'current':fields.float('Current',),
        'mega_wat':fields.float('Mega Watts'),
        #'Max':fields.char('Maximum'),
        'combine':fields.many2one('feeder.data','details'),
    }

1 个答案:

答案 0 :(得分:2)

class feeder_data(osv.Model):
    _name="feeder.data"
    _columns = {
        'date_of1':fields.datetime('Date',),
    }

class data_value(osv.Model):
    _name = "data.value"
    _rec_name = "mega_wat"
    _columns = {
        'time_read':fields.datetime('Time'),
        # just add this to your code
        'time_read_new':field.related('combine', 'date_of1',
            type="datetime", string="Your Field Name" )
    }