Suppression des fichiers README et script d'importation des tiers
This commit is contained in:
Vendored
-14
@@ -1,14 +0,0 @@
|
|||||||
Import Third parties into Chill from the canvas
|
|
||||||
===============================================
|
|
||||||
|
|
||||||
This folder contains a single Python script that reads a csv file with Third party and print to the console some SQL to execute on the database.
|
|
||||||
|
|
||||||
The csv file should be simply exported from the sheet "Tiers" from the xls canvas.
|
|
||||||
|
|
||||||
Then, you can run the python script with adapting the following:
|
|
||||||
|
|
||||||
- name of the csv file to open
|
|
||||||
- change the mapping of third party categories, civilities and third party kinds according to your Chill database
|
|
||||||
|
|
||||||
|
|
||||||
So far, the addresses are not treated.
|
|
||||||
-118
@@ -1,118 +0,0 @@
|
|||||||
import csv
|
|
||||||
|
|
||||||
print_to_screen = "INSERT INTO chill_3party.third_party (id, civility_id, name, firstname, name_company, acronym, kind, parent_id, profession, email, telephone, comment, contact_data_anonymous, active, created_at) VALUES"
|
|
||||||
|
|
||||||
|
|
||||||
def get_parent_id(arg):
|
|
||||||
return int(arg) + 1000 if arg else "NULL"
|
|
||||||
|
|
||||||
|
|
||||||
def get_third_party_civility(arg):
|
|
||||||
if arg == "Madame":
|
|
||||||
return 1
|
|
||||||
elif arg == "Monsieur":
|
|
||||||
return 2
|
|
||||||
elif arg == "Docteur":
|
|
||||||
return 3
|
|
||||||
else:
|
|
||||||
return "NULL"
|
|
||||||
|
|
||||||
|
|
||||||
def get_third_party_kind(arg):
|
|
||||||
if arg == "Tiers institutionnel":
|
|
||||||
return "company"
|
|
||||||
elif arg == "Personne de contact":
|
|
||||||
return "child"
|
|
||||||
elif arg == "Personne morale":
|
|
||||||
return "contact"
|
|
||||||
else:
|
|
||||||
return "company"
|
|
||||||
|
|
||||||
|
|
||||||
def make_bool_with_default_false(arg):
|
|
||||||
if arg == "oui":
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def make_telephone(arg):
|
|
||||||
if arg:
|
|
||||||
return f"'+32{arg}'"
|
|
||||||
else:
|
|
||||||
return "NULL"
|
|
||||||
|
|
||||||
|
|
||||||
with open("HalleDeHan_tiers.csv", newline="") as csv_file:
|
|
||||||
csv_reader = csv.reader(csv_file)
|
|
||||||
|
|
||||||
for skip in range(7):
|
|
||||||
next(csv_file)
|
|
||||||
|
|
||||||
for row in csv_reader:
|
|
||||||
third_party_id = int(row[0]) + 1000
|
|
||||||
civility = get_third_party_civility(row[1])
|
|
||||||
name = row[2]
|
|
||||||
firstname = row[3]
|
|
||||||
name_company = row[4]
|
|
||||||
acronym = row[5]
|
|
||||||
kind = get_third_party_kind(row[6])
|
|
||||||
parent_id = get_parent_id(row[7])
|
|
||||||
# row[8] is the name of the parent in the csv
|
|
||||||
profession = row[9]
|
|
||||||
# category = row[10] # category -> see below
|
|
||||||
email = row[11]
|
|
||||||
telephone = make_telephone(row[12])
|
|
||||||
# street = row[13] # TODO address
|
|
||||||
# extra = row[14]
|
|
||||||
# streetnumber = row[15]
|
|
||||||
# postcode = row[16]
|
|
||||||
# country = row[17]
|
|
||||||
# validfrom = row[18]
|
|
||||||
comment = row[19]
|
|
||||||
contact_data_anonymous = make_bool_with_default_false(row[20])
|
|
||||||
print_to_screen += f"({third_party_id}, {civility}, '{name}', '{firstname}', '{name_company}', '{acronym}', '{kind}', {parent_id}, '{profession}', '{email}', {telephone}, '{comment}', {contact_data_anonymous}, True, NOW()),"
|
|
||||||
|
|
||||||
print_to_screen = print_to_screen[:-1]
|
|
||||||
|
|
||||||
print(print_to_screen)
|
|
||||||
|
|
||||||
## categories
|
|
||||||
|
|
||||||
print_to_screen_cat = (
|
|
||||||
"INSERT INTO chill_3party.thirdparty_category (thirdparty_id, category_id) VALUES"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def get_third_party_category(arg):
|
|
||||||
if arg == "Stage vente":
|
|
||||||
return 2
|
|
||||||
elif arg == "Stage reassort":
|
|
||||||
return 8
|
|
||||||
elif arg == "Stage social / educ":
|
|
||||||
return 9
|
|
||||||
elif arg == "Stage logistique":
|
|
||||||
return 10
|
|
||||||
elif arg == "Stage bureautique":
|
|
||||||
return 11
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
with open("HalleDeHan_tiers.csv", newline="") as csv_file:
|
|
||||||
csv_reader = csv.reader(csv_file)
|
|
||||||
|
|
||||||
for skip in range(7):
|
|
||||||
next(csv_file)
|
|
||||||
|
|
||||||
for row in csv_reader:
|
|
||||||
third_party_id = int(row[0]) + 1000
|
|
||||||
category_id = get_third_party_category(row[10])
|
|
||||||
if category_id:
|
|
||||||
print_to_screen_cat += f"({third_party_id}, {category_id}),"
|
|
||||||
|
|
||||||
print_to_screen_cat = print_to_screen_cat[:-1]
|
|
||||||
|
|
||||||
print(print_to_screen_cat)
|
|
||||||
|
|
||||||
# TODO addresses
|
|
||||||
Reference in New Issue
Block a user