人力资源模块hr_employee中的Openerp相关字段包括Department,Division ... etc和Location

时间:2016-01-27 16:28:34

标签: python openerp openerp-7

我的OpenERP hr模块中有以下四个类

res_company ---> hr_department - > hr_division - > hr_section

    class company_new_registration(osv.osv):
        _name = "hr.company.n.registration"
        _description = "Company"
        _columns = {
            'name': fields.char('Company Name', size=128, required=True),
            'depts': fields.one2many('hr.dept.n.registration', 'company_id', 'Dept'),

        }
    company_new_registration()

    class dept_new_registration(osv.osv):
        _name = "hr.dept.n.registration"
        _description = "depts"
        _columns = {
            'name': fields.char('Dept Name', size=128, required=True),
            'company_id': fields.many2one('res.company', 'Company Name', required=True),
            'divisions': fields.one2many('hr.division.n.registration', 'dept_id', 'Division'),
            'resres':fields.one2many('res.users','alias_id')

        }

    dept_new_registration()

    class division_new_registration(osv.osv):
        _name = "hr.division.n.registration"
        _description = "Divisions"
        _columns = {
            'name': fields.char('Division Name', size=128, ),
            'dept_id': fields.many2one('hr.dept.n.registration', 'Dept. Name', select=True, required=True),
            'sections': fields.one2many('hr.section.n.registration', 'division_id', 'Section'),

        }

    division_new_registration()

    class section_new_registration(osv.osv):
        _name = "hr.section.n.registration"
        _description = "sections"
        _columns = {
            'name': fields.char('Name', size=128), 
            'section_name': fields.char('Section Name', size=128, required=True),
            'division_id': fields.many2one('hr.division.n.registration', 'Division Name', select=True, required=True),
        }

    section_new_registration()

one2many 关系中的所有四个类以及所有上述类都有名称字段和另一个字段分别具有关系。

我的模块中还有另一个名为 hr_location 的类,它需要保留以上四个类的引用才能创建组织结构。

我的问题是:

  1. 我需要创建一个字段,在 hr_location 表格中显示“公司名称/部门名称/部门名称/部门名称”部门或部门或等等

  2. 我需要创建四个相关字段,当我从上方选择位置时,在 hr_employee 表中存储 company_id,department_id,division_id和section_id (之前的位置)问题)领域。

1 个答案:

答案 0 :(得分:1)

首先,您需要在section_new_registration中创建一个计算字段,该字段在您需要的“公司名称/部门名称/部门名称/部门名称”中连接整个层次结构的名称。

或者您可以覆盖create而不是计算字段:

def create(self, cr, uid, values, context=None):
     company = self.pool.get('res.company').browse(cr, uid, values['company_id'], context=context)
     dept = self.pool.get('hr.dept.n.registration').browse(cr, uid, values['department_id'], context=context)
     division = self.pool.get('hr.division.n.registration').browse(cr, uid, values['division_id'], context=context)

     values['name'] = company.name + '/' + dept.name + '/' + division.name + '/'+ values['section_name']
     return super(hr_location, self).create(cr, uid, values, context=context)

其次,您需要在 hr_location 中创建一个

字段
'section_id': fields.many2one('hr.section.n.registration')

完成你的观点(1)

第三,对于您的观点(2),您需要创建五个字段,如下所示:

'location_id': fields.many2one('hr.location')
'section_id': fields.related('location_id', 'section_id', type='many2one', relation='hr.section.n.registration', store=True)
'division_id': fields.related('location_id', 'section_id', 'division_id', type='many2one', relation='hr.division.n.registration', store=True)
'department_id': fields.related('location_id', 'section_id', 'division_id', 'dept_id', type='many2one', relation='hr.dept.n.registration', store=True)
'company_id': fields.related('location_id', 'section_id', 'division_id', 'dept_id', 'company_id', type='many2one', relation='res.company', store=True)