odoo 加用户

 

加用户

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def trigger(self):
    sql = '''select b.USERNAME,b.LOGINID,a.email,b.PASSWORD,a.orgcode_show,a.dianhua from CP_yuangongdy a
            left join AU_USERINFO b on a.xingming=b.USERNAME
            where a.shiyong!='离职' and USERNAME is not null;'''
    df = pd.read_sql(sql, con=jl_conn)
    for _, row in df.iterrows():
        self.insert(row)
 
def insert(self, info):
    dept = self.env['hr.department'].search([('name', '=', info['orgcode_show'])], limit=1)
    if not dept:
        a = self.env['hr.department'].create({'name': info['orgcode_show']})
        deptid = a.id
    else:
        deptid = dept.id
    b = self.env['hr.employee'].create(
        {'name': info['USERNAME'], 'department_id': deptid, 'mobile_phone': info['dianhua'], 'work_email': info['email']})
    c = self.env['res.partner'].search([('name', '=', info['USERNAME'])], limit=1)
    c.write({'mobile': info['dianhua'], 'email': info['email']})
    d = self.env['res.users'].create(
        {'partner_id': c.id, 'login': info['LOGINID'], 'password': info['PASSWORD'], 'notification_type': 'inbox'})
    b.write({'user_id': d.id})
    self._cr.commit()

  

posted @   CrossPython  阅读(42)  评论(0)    收藏  举报
点击右上角即可分享
微信分享提示