94 lines
3.3 KiB
Python
94 lines
3.3 KiB
Python
import xmlrpc.client
|
|
|
|
import pandas
|
|
|
|
env = 'local'
|
|
data = {
|
|
'local': {
|
|
'url': 'http://localhost:8069',
|
|
'user': 'admin',
|
|
'password': 'ad134d04372f7029ff7be8cc8c8b6ca2fda6e98b', # cong ty
|
|
'database': 'cenhomes_odoo2' # database name
|
|
},
|
|
'server': {
|
|
'url': 'https://erp.cenhomes.vn',
|
|
|
|
'user': 'anhtv@cenland.vn',
|
|
'password': 'edcc6c1c2c913d98d0a2db96cfccfbb346b75beb',
|
|
'database': 'cenhomes_odoo' # database name
|
|
}
|
|
}
|
|
|
|
data_url = data[env]['url'] # odoo instance url
|
|
database = data[env]['database'] # database name
|
|
user = data[env]['user'] # username
|
|
password = data[env]['password']
|
|
|
|
print(data_url, user, password)
|
|
|
|
common_auth = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(data_url))
|
|
uid = common_auth.authenticate(database, user, password, {})
|
|
data_model = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(data_url))
|
|
|
|
group_hoc_vien = data_model.execute_kw(database, uid, password, 'res.groups', 'search',
|
|
[[['name', '=', 'Học viên du học kép']]])
|
|
group_manager = data_model.execute_kw(database, uid, password, 'res.groups', 'search',
|
|
[[['name', '=', 'Quản lý du học kép']]])
|
|
|
|
rows = []
|
|
data_b1 = pandas.read_csv(
|
|
'../data/Khóa học chuẩn bị hồ sơ ứng tuyển chương trình du học kép - Danh sách HV (TTĐT).csv',
|
|
skiprows=1, nrows=7)
|
|
|
|
data_a22 = pandas.read_csv(
|
|
'../data/Khóa học chuẩn bị hồ sơ ứng tuyển chương trình du học kép - Danh sách HV (TTĐT).csv',
|
|
skiprows=9)
|
|
data_k3_a22 = pandas.read_csv(
|
|
'../data/K3_DS HỌC VIÊN A2.2.csv',
|
|
skiprows=1)
|
|
|
|
data = pandas.concat([data_a22, data_b1, data_k3_a22])
|
|
|
|
|
|
x = []
|
|
|
|
|
|
def change_profile_info(r):
|
|
res = data_model.execute_kw(database, uid, password, 'res.users', 'write',
|
|
[[a], {"tz": 'Asia/Ho_Chi_Minh', 'email': r['Email'], 'login': r['Mã học viên']}])
|
|
print(res)
|
|
return res
|
|
|
|
|
|
def change_groups(r):
|
|
_user_info = data_model.execute_kw(database, uid, password, 'res.users', 'read', [[a], ['groups_id']])
|
|
_current_groups = _user_info[0]['groups_id']
|
|
res = True
|
|
if group_hoc_vien[0] not in _current_groups:
|
|
_current_groups.append(group_hoc_vien[0])
|
|
print(_current_groups)
|
|
|
|
res = data_model.execute_kw(database, uid, password, 'res.users', 'write',
|
|
[[a], {'groups_id': [(6, 0, _current_groups)]}])
|
|
print('c', res)
|
|
return res
|
|
|
|
|
|
if __name__ == '__main__':
|
|
for i, row in data.iterrows():
|
|
print(row['Mã học viên'])
|
|
try:
|
|
a = data_model.execute_kw(database, uid, password, 'res.users', 'create',
|
|
[{'name': row['Họ và đệm'] + ' ' + row['Tên'], 'login': row['Mã học viên']}])
|
|
b = data_model.execute_kw(database, uid, password, 'res.users', 'write', [[a], {"password": 'Duhockep@123'}])
|
|
print(b)
|
|
except Exception as e:
|
|
print(e)
|
|
a = data_model.execute_kw(database, uid, password, 'res.users', 'search',
|
|
[[['login', '=', row['Mã học viên']]]],
|
|
)[0]
|
|
profile = change_profile_info(row)
|
|
print(profile)
|
|
groups = change_groups(row)
|
|
print(groups)
|