odoo 加用户

 

加用户

    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 @ 2023-10-24 16:15  CrossPython  阅读(51)  评论(0)    收藏  举报