refactor code

This commit is contained in:
Ambulance Clerc
2024-11-09 17:26:52 +01:00
parent 94ca5534e5
commit 756eeab00c
4 changed files with 397 additions and 197 deletions

222
cl_attriblink.py Normal file
View File

@@ -0,0 +1,222 @@
class cl_AttribLink():
def __init__(self):
self.invoice_ID = None
self.FIP = None
self.comments = None
self.km = None
self.invoice_date = None
self.debtor_code = None
self.debtor_name = None
self.debtor_lastname = None
self.debtor_firstname = None
self.debtor_addr_complement = None
self.debtor_street = None
self.debtor_street_number = None
self.debtor_postal_code = None
self.debtor_city = None
self.debtor_country = None
self.debtor_gender = None
self.patient_AVS = None
self.patient_category = None
self.patient_birthdate = None
self.patient_lastname = None
self.patient_firstname = None
self.patient_addr_complement = None
self.patient_addr_2 = None
self.patient_street = None
self.patient_street_number = None
self.patient_postal_code = None
self.patient_city = None
self.patient_country = None
self.patient_gender = None
self.patient_insurance_name = None
self.intervention_type = None
self.intervention_base = None
self.intervention_team = None
self.intervention_start_time = None
self.intervention_end_time = None
#Intervention DEST
self.intervention_dest_name = None
self.intervention_dest_street = None
self.intervention_dest_street_number = None
self.intervention_dest_postal_code = None
self.intervention_dest_city = None
#Intervention Site
self.intervention_site_name = None
self.intervention_site_street = None
self.intervention_site_street_number = None
self.intervention_site_postal_code = None
self.intervention_site_city = None
self.src_key_invoice = {
"id": ["id"],
"total_price": ["total_price"],
"date": ["date"],
"comments": ["comments"],
}
self.src_key_debtor = {
"code": ["code"],
"name": ["name"],
"lastname": ["lastname"],
"firstname": ["firstname"],
"addr_complement": ["complement"],
"street": ["street"],
"addr_2": ["addr_2"],
"street_number": ["street_number"],
"postal_code": ["postal_code"],
"city": ["city"],
"country_name": ["country","country_name"],
"gender_name": ["gender","gender_name"],
}
self.src_key_patient = {
"fip": ["fip_number"],
"category_name": ["category", "category_name"],
"birthdate": ["birthdate"],
"AVS": ["insurance_policy_number"],
"lastname": ["lastname"],
"firstname": ["firstname"],
"addr_complement": ["complement"],
"street": ["street"],
"addr_2": ["addr_2"],
"street_number": ["street_number"],
"postal_code": ["postal_code"],
"city": ["city"],
"country_name": ["country","country_name"],
"gender_name": ["gender","gender_name"],
"insurance_name": ["insurance","insurance_name"],
}
self.src_key_article = {
"price": ["price"],
"code": ["code"],
"line_1": ["line_1"],
"line_2": ["line_2"],
"quantity": ["quantity"],
"unit_price": ["unit_price"],
"unit": ["unit", "unit_name"],
"price": ["price"],
}
self.src_key_intervention = {
"date": ["date"],
"type": ["type"],
"kilometers": ["kilometers"],
"start_time": ["start_time"],
"end_time": ["end_time"],
"base_name": ["base", "base_name"],
"team_name": ["team", "team_name"],
"destination_name": ["destination", "destination_name"],
"destination_street": ["destination", "destination_street"],
"destination_street_number": ["destination_street_number"],
"destination_city": ["destination_city"],
"destination_postal_code": ["destination_postal_code"],
"site_name": ["site", "site_name"],
"site_street": ["site", "site_street"],
"site_street_number": ["site_street_number"],
"site_city": ["site_city"],
"site_postal_code": ["site_postal_code"],
}
def parse_data(self, data):
self.invoice_ID = self.get_value_from_attrib(data=data, obj="data", key="id")
self.comments = self.get_value_from_attrib(data=data, obj="data", key="comments")
self.invoice_date = self.get_value_from_attrib(data=data, obj="data", key="date")
self.debtor_code = self.get_value_from_attrib(data=data, obj="debtor", key="code")
self.debtor_name = self.get_value_from_attrib(data=data, obj="debtor", key="name")
self.debtor_lastname = self.get_value_from_attrib(data=data,obj="debtor",key="lastname")
self.debtor_firstname = self.get_value_from_attrib(data=data,obj="debtor",key="firstname")
self.debtor_addr_complement = self.get_value_from_attrib(data=data,obj="debtor",key="addr_complement")
self.debtor_street = self.get_value_from_attrib(data=data,obj="debtor",key="street")
self.debtor_street_number = self.get_value_from_attrib(data=data,obj="debtor",key="street_number")
self.debtor_postal_code = self.get_value_from_attrib(data=data,obj="debtor",key="postal_code")
self.debtor_city = self.get_value_from_attrib(data=data,obj="debtor",key="city")
self.debtor_gender = self.get_value_from_attrib(data=data,obj="debtor",key="gender_name")
self.debtor_country = self.get_value_from_attrib(data=data,obj="debtor",key="country_name")
self.FIP = self.get_value_from_attrib(data=data, obj="patient", key="fip")
self.patient_category = self.get_value_from_attrib(data=data, obj="patient", key="category_name")
self.patient_birthdate = self.get_value_from_attrib(data=data, obj="patient", key="birthdate")
self.patient_lastname = self.get_value_from_attrib(data=data, obj="patient", key="lastname")
self.patient_addr_2 = self.get_value_from_attrib(data=data, obj="patient", key="addr_2")
self.patient_firstname = self.get_value_from_attrib(data=data, obj="patient", key="firstname")
self.patient_addr_complement = self.get_value_from_attrib(data=data, obj="patient", key="addr_complement")
self.patient_street = self.get_value_from_attrib(data=data,obj="patient",key="street")
self.patient_street_number = self.get_value_from_attrib(data=data,obj="patient",key="street_number")
self.patient_postal_code = self.get_value_from_attrib(data=data,obj="patient",key="postal_code")
self.patient_city = self.get_value_from_attrib(data=data,obj="patient",key="city")
self.patient_gender = self.get_value_from_attrib(data=data,obj="patient",key="gender_name")
self.patient_country = self.get_value_from_attrib(data=data,obj="patient",key="country_name")
self.patient_insurance_name = self.get_value_from_attrib(data=data,obj="patient",key="insurance_name")
self.km = self.get_value_from_attrib(data=data, obj="intervention", key="kilometers")
self.intervention_start_time = self.get_value_from_attrib(data=data, obj="intervention", key="start_time")
self.intervention_end_time = self.get_value_from_attrib(data=data, obj="intervention", key="end_time")
self.intervention_base = self.get_value_from_attrib(data=data, obj="intervention", key="base_name")
self.intervention_team = self.get_value_from_attrib(data=data, obj="intervention", key="team_name")
self.intervention_type = self.get_value_from_attrib(data=data, obj="intervention", key="type")
self.intervention_dest_name = self.get_value_from_attrib(data=data, obj="intervention", key="destination_name")
self.intervention_dest_street = self.get_value_from_attrib(data=data, obj="intervention", key="destination_street")
self.intervention_dest_street_number = self.get_value_from_attrib(data=data, obj="intervention", key="destination_street_number")
self.intervention_dest_postal_code = self.get_value_from_attrib(data=data, obj="intervention", key="destination_postal_code")
self.intervention_dest_city = self.get_value_from_attrib(data=data, obj="intervention", key="destination_city")
self.intervention_site_name = self.get_value_from_attrib(data=data, obj="intervention", key="site_name")
self.intervention_site_street = self.get_value_from_attrib(data=data, obj="intervention", key="site_street")
self.intervention_site_street_number = self.get_value_from_attrib(data=data, obj="intervention", key="site_street_number")
self.intervention_site_postal_code = self.get_value_from_attrib(data=data, obj="intervention", key="site_postal_code")
self.intervention_site_city = self.get_value_from_attrib(data=data, obj="intervention", key="site_city")
def on_error_not_found(self, obj, key):
print(f"ERROR AttribLink => obi[{obj}] and key [{key}] not found.")
def get_value_from_attrib(self,data,obj, key):
print(f"get value from {obj}=>{key}")
ret = False
t_obj = None
if obj == "data":
t_obj = data.data
key_src = self.src_key_invoice
elif obj == "debtor":
t_obj = data.Debtor
key_src = self.src_key_debtor
elif obj == "patient":
t_obj = data.Patient
key_src = self.src_key_patient
elif obj == "article":
t_obj = data
key_src = self.src_key_article
elif obj == "invoice":
t_obj = data
key_src = self.src_key_invoice
if obj == "intervention":
t_obj = data.Intervention
key_src = self.src_key_intervention
for t_key in key_src[key]:
if t_key in t_obj:
ret = t_obj[t_key]
if ret == False:
self.on_error_not_found(obj, key)
return None
else:
return ret

View File

@@ -1 +1 @@
20241101-2031
20241109-1726

368
main.py
View File

@@ -29,6 +29,8 @@ from class_debitors import *
from version import *
from custom_popup import *
from cl_attriblink import cl_AttribLink
src_dir = os.getenv('APPDATA') + "\Attrib2Biz\src"
dest_dir = os.getenv('APPDATA') + "\Attrib2Biz\output"
@@ -313,7 +315,7 @@ class ClercAttrib2Biz():
def start_parsing(self):
dir = src_dir
self.count_facture = 0
x = 0
x = 0
self.export_filename = f"bizexdoc_export_Attrib_v{datetime.now().year}{datetime.now().month}{datetime.now().day}{datetime.now().hour}{datetime.now().minute}.csv"
@@ -356,27 +358,27 @@ class ClercAttrib2Biz():
return value.strip()
def trim_all_data(self, data):
if data.Patient["lastname"] is not None:
data.Patient["lastname"] = data.Patient["lastname"].strip()
if data.Patient["firstname"] is not None:
data.Patient["firstname"] = data.Patient["firstname"].strip()
if data.Patient["street"] is not None:
data.Patient["street"] = data.Patient["street"].strip()
if data.Debtor["lastname"] is not None:
data.Debtor["lastname"] = data.Debtor["lastname"].strip()
if data.Debtor["firstname"] is not None:
data.Debtor["firstname"] = data.Debtor["firstname"].strip()
if data.Debtor["street"] is not None:
data.Debtor["street"] = data.Debtor["street"].strip()
if data.data["comments"] is not None:
data.data["comments"] = data.data["comments"].strip().replace("\n",'')
if data.Debtor["code"] is not None:
data.Debtor["code"] = data.Debtor["code"].strip()
data.Debtor["code"] = re.sub(r'[^0-9]', '', data.Debtor["code"])
if self.attrib_link.patient_lastname is not None:
self.attrib_link.patient_lastname = self.attrib_link.patient_lastname.strip()
if self.attrib_link.patient_firstname is not None:
self.attrib_link.patient_firstname = self.attrib_link.patient_firstname.strip()
if self.attrib_link.patient_street is not None:
self.attrib_link.patient_street = self.attrib_link.patient_street.strip()
if self.attrib_link.debtor_lastname is not None:
self.attrib_link.debtor_lastname = self.attrib_link.debtor_lastname.strip()
if self.attrib_link.debtor_firstname is not None:
self.attrib_link.debtor_firstname = self.attrib_link.debtor_firstname.strip()
if self.attrib_link.debtor_street is not None:
self.attrib_link.debtor_street = self.attrib_link.debtor_street.strip()
if self.attrib_link.comments is not None:
self.attrib_link.comments = self.attrib_link.comments.strip().replace("\n",'')
if self.attrib_link.debtor_code is not None:
self.attrib_link.debtor_code = self.attrib_link.debtor_code.strip()
self.attrib_link.debtor_code = re.sub(r'[^0-9]', '', self.attrib_link.debtor_code)
if "name" in data.Debtor.keys() and data.Debtor["name"] is not None:
data.Debtor["name"] = data.Debtor["name"].replace("(facturation)","")
data.Debtor["name"] = data.Debtor["name"].strip()
if "name" in data.Debtor.keys() and self.attrib_link.debtor_name is not None:
self.attrib_link.debtor_name = self.attrib_link.debtor_name.replace("(facturation)","")
self.attrib_link.debtor_name = self.attrib_link.debtor_name.strip()
def check_required_field_by_code(self, code, data):
@@ -389,7 +391,7 @@ class ClercAttrib2Biz():
if data.Patient[field] is None or data.Debtor[field] is None:
messagebox.showerror(
title="Erreur Critique",
message=f"Les informations de la facture [{data.data['id']}] comportent trop d'erreurs. Arrêt du processus.",
message=f"Les informations de la facture [{self.attrib_link.invoice_ID}] comportent trop d'erreurs. Arrêt du processus.",
)
return False
@@ -429,6 +431,7 @@ class ClercAttrib2Biz():
def parseFile(self, data, filename):
self.attrib_link = cl_AttribLink()
self.progress_bar["value"] = 0
self.index_counter += 1
lines = []
@@ -455,123 +458,98 @@ class ClercAttrib2Biz():
self.trim_all_data(data)
self.attrib_link.parse_data(data)
print(f"Code débiteur => {data.data['id']}: {data.Debtor['code']}")
if data.Debtor["code"] is None or '.' in data.Debtor["code"]:
print(f"Code débiteur => {self.attrib_link.invoice_ID}: {self.attrib_link.debtor_code}")
if self.attrib_link.debtor_code is None or '.' in self.attrib_link.debtor_code:
print("ERROR code débiteur #1")
messagebox.showerror(title="Erreur code débiteur", message=f"Le code débiteur de la facture {data.data['id']} est faux: [{data.Debtor['code']}], merci de le corriger ")
inp_popup = Input_popup(self.fenetre, default=data.Debtor["code"], factureID=data.data['id'], fip=data.Patient['fip_number'])
data.Debtor["code"] = str(inp_popup.show())
if data.Debtor["code"] is None or '.' in data.Debtor["code"]:
messagebox.showerror(title="Erreur code débiteur", message=f"Le code débiteur de la facture {self.attrib_link.invoice_ID} est faux: [{self.attrib_link.debtor_code}], merci de le corriger ")
inp_popup = Input_popup(self.fenetre, default=self.attrib_link.debtor_code, factureID=self.attrib_link.invoice_ID, fip=self.attrib_link.FIP)
self.attrib_link.debtor_code = str(inp_popup.show())
if self.attrib_link.debtor_code is None or '.' in self.attrib_link.debtor_code:
messagebox.showerror(title="Erreur Critique",
message=f"Les informations de la factures [{data.data['id']}] comportes trop d'erreur arrêt du processus ")
message=f"Les informations de la factures [{self.attrib_link.invoice_ID}] comportes trop d'erreur arrêt du processus ")
return False
if int(data.Debtor["code"]) == 1:
if not self.check_required_field_by_code(data.Debtor["code"], data):
if int(self.attrib_link.debtor_code) == 1:
if not self.check_required_field_by_code(self.attrib_link.debtor_code, data):
messagebox.showerror(title="Erreur Critique",
message=f"Les informations de la factures [{data.data['id']}] comportes trop d'erreur arrêt du processus ")
message=f"Les informations de la factures [{self.attrib_link.invoice_ID}] comportes trop d'erreur arrêt du processus ")
return False
if data.Debtor["code"] != "1" and data.Debtor["code"] != None and int(data.Debtor["code"]) < 100:
if data.Patient["fip_number"] not in self.a_listings["to_check"]:
self.a_listings["to_check"].append(data.Patient["fip_number"])
#self.logger.warning(f"Vérifier facture N°: {data.data['id']} / {data.Patient['fip_number']} {data.Debtor['code']} {data.Debtor['lastname']} {data.Debtor['firstname']}")
if self.attrib_link.debtor_code != "1" and self.attrib_link.debtor_code != None and int(self.attrib_link.debtor_code) < 100:
if self.attrib_link.FIP not in self.a_listings["to_check"]:
self.a_listings["to_check"].append(self.attrib_link.FIP)
#self.logger.warning(f"Vérifier facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP} {self.attrib_link.debtor_code} {self.attrib_link.debtor_lastname} {self.attrib_link.debtor_firstname}")
for elem in data.Debtor:
pass
''' TODO activer ce code quand les débiteur auront un bon numéro
try:
if int(data.Debtor["code"]) > 100:
print("code débiteur > 100 => no update data")
b_update_debitor = False
except:
messagebox.showerror(title="Erreur de code débiteur", message=f"il y a une erreur dans le code débiteur, il faut le vérifier. \n(n'est pas un chiffre) {data.Patient['fip_number']}")
exit()
'''
'''
if data.Debtor["type_name"] == "Établissement":
self.a_listings["to_check"].append(data.Patient["fip_number"])
print(data.Patient["complement"])
self.logger.warn(f"Débiteur établissement facture N°: {data.data['id']} / {data.Patient['fip_number']} {data.Debtor['name']}")
'''
if int(data.Debtor["code"]) == 1:
if int(self.attrib_link.debtor_code) == 1:
b_check_debitor = False
if data.Debtor["lastname"] == None:
if self.attrib_link.debtor_lastname == None:
b_check_debitor = True
data.Debtor["lastname"] = ""
self.attrib_link.debtor_lastname = ""
messagebox.showerror(title="Erreur",
message=f"Le débiteur n'a pas de nom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
if data.Debtor["firstname"] == None:
message=f"Le débiteur n'a pas de nom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}")
if self.attrib_link.debtor_firstname == None:
b_check_debitor = True
data.Debtor["firstname"] = ""
self.attrib_link.debtor_firstname = ""
messagebox.showerror(title="Erreur",
message=f"Le débiteur n'a pas de prénom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
message=f"Le débiteur n'a pas de prénom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}")
if b_check_debitor:
debitor_popup = Check_debitor_popup(self.fenetre, data.Debtor,
self.o_debs.get_names_by_code(data.Debtor['code']),
data.data['id'],
data.Patient['fip_number'], object=self.o_debs)
data.Debtor["code"] = debitor_popup.show()
if data.Patient["lastname"] + data.Patient["firstname"] != data.Debtor["lastname"] + data.Debtor["firstname"]:
self.a_listings["to_check"].append(data.Patient["fip_number"])
print(data.Patient["complement"])
self.logger.warning(f"Débiteur différents: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
self.o_debs.get_names_by_code(self.attrib_link.debtor_code),
self.attrib_link.invoice_ID,
self.attrib_link.FIP, object=self.o_debs)
self.attrib_link.debtor_code = debitor_popup.show()
if self.attrib_link.patient_lastname + self.attrib_link.patient_firstname != self.attrib_link.debtor_lastname + self.attrib_link.debtor_firstname:
self.a_listings["to_check"].append(self.attrib_link.FIP)
print(self.attrib_link.patient_addr_complement)
self.logger.warning(f"Débiteur différents: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}")
if int(data.Debtor["code"]) >= 100:
if int(self.attrib_link.debtor_code) >= 100:
if "name" not in data.Debtor.keys():
data.Debtor["name"] = "Invalide"
self.attrib_link.debtor_name = "Invalide"
self.logger.warning(
f"Débiteur > 100 sans nom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
f"Débiteur > 100 sans nom, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}")
messagebox.showerror(title="Erreur",
message=f"Débiteur > 100 sans nom de débiteur ou d'établissement, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
self.a_listings["to_check"].append(data.Patient["fip_number"])
message=f"Débiteur > 100 sans nom de débiteur ou d'établissement, vérifier la facture ATTRIB et vérifier le code débiteur: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}")
self.a_listings["to_check"].append(self.attrib_link.FIP)
if not self.o_debs.is_in_debitor_name(code=data.Debtor["code"],search_name=data.Debtor["name"]):
#messagebox.showerror(title="Erreur code débiteur erroné", message=f"Information débiteur incohérente: facture N°: {data.data['id']} / {data.Patient['fip_number']}.\nCode débiteur: {data.Debtor['code']}\nNom du débiteur: {data.Debtor['name']}. \nAurait dû être: {self.o_debs.get_names_by_code(data.Debtor['code'])}")
debitor_popup = Check_debitor_popup(self.fenetre,data.Debtor,self.o_debs.get_names_by_code(data.Debtor['code']),data.data['id'],data.Patient['fip_number'], object=self.o_debs)
data.Debtor["code"] = debitor_popup.show()
if not self.o_debs.is_in_debitor_name(code=self.attrib_link.debtor_code,search_name=self.attrib_link.debtor_name):
#messagebox.showerror(title="Erreur code débiteur erroné", message=f"Information débiteur incohérente: facture N°: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP}.\nCode débiteur: {self.attrib_link.debtor_code}\nNom du débiteur: {data.Debtor['name']}. \nAurait dû être: {self.o_debs.get_names_by_code(self.attrib_link.debtor_code)}")
debitor_popup = Check_debitor_popup(self.fenetre,data.Debtor,self.o_debs.get_names_by_code(self.attrib_link.debtor_code),self.attrib_link.invoice_ID,self.attrib_link.FIP, object=self.o_debs)
self.attrib_link.debtor_code = debitor_popup.show()
if data.Debtor["code"] is None or '.' in data.Debtor["code"]:
if self.attrib_link.debtor_code is None or '.' in self.attrib_link.debtor_code:
messagebox.showerror(title="Erreur Critique",
message=f"Les informations de la factures [{data.data['id']}] comportes trop d'erreur arrêt du processus ")
message=f"Les informations de la factures [{self.attrib_link.invoice_ID}] comportes trop d'erreur arrêt du processus ")
return False
'''
Désactivé, plus utile
if data.Patient["complement"] != None :
self.a_listings["to_check"].append(data.Patient["fip_number"])
print(data.Patient["complement"])
self.logger.warning(f"Complément patient: facture N°: {data.data['id']} / {data.Patient['fip_number']}")
'''
if data.Patient['insurance_policy_number'] == None:
data.Patient['insurance_policy_number'] = f"{uuid.uuid4()}"[:15]
if self.attrib_link.patient_AVS == None:
self.attrib_link.patient_AVS = f"{uuid.uuid4()}"[:15]
if self.check_addresses.get():
addresses_exist = self.addresses.get_item_by_AVS(data.Patient['insurance_policy_number'].replace(".", ""))
if addresses_exist is not None and not self.compare_old_and_new_adresses(new=data.Patient, old=addresses_exist, code=data.Debtor['code']):
addresses_exist = self.addresses.get_item_by_AVS(self.attrib_link.patient_AVS.replace(".", ""))
if addresses_exist is not None and not self.compare_old_and_new_adresses(new=data.Patient, old=addresses_exist, code=self.attrib_link.debtor_code):
popup = Check_addresses_popup(self.fenetre, item_1=data.Patient, item_2=addresses_exist, debitor=data.Debtor, factureID=data.data['id'])
popup = Check_addresses_popup(self.fenetre, item_1=data.Patient, item_2=addresses_exist, debitor=data.Debtor, factureID=self.attrib_link.invoice_ID)
b_address_update = popup.show()
mode_selected = "Attrib" if b_address_update else "Winbiz"
self.logger.warning(
f"Adresse connue données {mode_selected} conservées: {data.data['id']} / {data.Patient['fip_number']} {data.Debtor['code']} {data.Debtor['lastname']} {data.Debtor['firstname']}")
f"Adresse connue données {mode_selected} conservées: {self.attrib_link.invoice_ID} / {self.attrib_link.FIP} {self.attrib_link.debtor_code} {self.attrib_link.debtor_lastname} {self.attrib_link.debtor_firstname}")
print(f"Result Popup: {b_address_update}")
else:
b_address_update = True
#self.draw_test(item_1=data.Patient, item_2=addresses_exist)
#messagebox.showerror(title="AVS Trouvé", message=f"Le code AVS de l'adresse {data.Patient['insurance_policy_number']} est déjà existant: [{data.Debtor['code']}], merci de le corriger ")
#messagebox.showerror(title="AVS Trouvé", message=f"Le code AVS de l'adresse {self.attrib_link.patient_AVS} est déjà existant: [{self.attrib_link.debtor_code}], merci de le corriger ")
b_HRF = False
sHRF = ""
@@ -579,35 +557,35 @@ class ClercAttrib2Biz():
facture_total = 0
for article in data.Articles:
if 'price' in article:
facture_total += float(article['price'])
facture_total += float(self.attrib_link.get_value_from_attrib(data=article,obj="article",key="price"))
if "code" in article.keys():
if article["code"] == "HRF":
if self.attrib_link.get_value_from_attrib(data=article,obj="article",key="code") == "HRF":
b_HRF = True
sHRF = article["line_1"].replace("h", ":")
print(f"pass HRF => {data.Patient['fip_number']} = {b_HRF}")
#self.logger.warning(f"HRF: {data.data['id']}")
sHRF = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_1").replace("h", ":")
print(f"pass HRF => {self.attrib_link.FIP} = {b_HRF}")
#self.logger.warning(f"HRF: {self.attrib_link.invoice_ID}")
print(f"Lecture de la facture #{cur_invoice_index} {ele['id']} montant total = {ele['total_price']} <> {facture_total}")
if float(ele['total_price']) != facture_total:
print(f"Lecture de la facture #{cur_invoice_index} {self.attrib_link.get_value_from_attrib(data=ele,obj="invoice",key="id")} montant total = {self.attrib_link.get_value_from_attrib(data=ele,obj="invoice",key="total_price")} <> {facture_total}")
if float(self.attrib_link.get_value_from_attrib(data=ele,obj="invoice",key="total_price")) != facture_total:
print(f"ERROR NOT SAME PRICE")
total_facture_total += facture_total
total_facture_amount += float(ele['total_price'])
total_facture_amount += float(self.attrib_link.get_value_from_attrib(data=ele,obj="invoice",key="total_price"))
for article in data.Articles:
self.bs_counter += 1
csv_col = cls_Col(True)
print(article)
if "code" in article.keys() and article["code"] == "HRF":
if "code" in article.keys() and self.attrib_link.get_value_from_attrib(data=article,obj="article",key="code") == "HRF":
break
##Donnée globales
csv_col.data[0] = data.data["id"] # N° document
csv_col.data[0] = self.attrib_link.invoice_ID # N° document
csv_col.data[1] = 20 # Type of document 20 = facture débiteur
csv_col.data[2] = datetime.strptime(data.data["date"], "%Y-%m-%d").strftime("%d.%m.%Y") # Date du document
csv_col.data[4] = data.Patient["fip_number"] # Référence
csv_col.data[2] = datetime.strptime(self.attrib_link.invoice_date, "%Y-%m-%d").strftime("%d.%m.%Y") # Date du document
csv_col.data[4] = self.attrib_link.FIP # Référence
csv_col.data[10] = "<AUTO>" # Compte collectif du tiers = <AUTO>
csv_col.data[139] = "COND-30" # Conditions de payement à 30, COND-30 selon config dans winbiz
@@ -615,45 +593,45 @@ class ClercAttrib2Biz():
if "without_transportation" in data.Intervention.keys() and data.Intervention["without_transportation"] == True:
csv_col.data[15] = "Sans transport"
print(f"->NO DEST** {data.data['id']}")
elif data.Intervention["destination_name"] == None and data.Intervention["destination_street"] == None and data.Intervention["destination_city"] == None:
print(f"->NO DEST** {self.attrib_link.invoice_ID}")
elif self.attrib_link.intervention_dest_name == None and self.attrib_link.intervention_dest_street == None and self.attrib_link.intervention_dest_city == None:
csv_col.data[15] = "Sans destination"
print(f"->NO DEST sans destination transmis à autruit** {data.data['id']}")
print(f"->NO DEST sans destination transmis à autruit** {self.attrib_link.invoice_ID}")
else:
con = ""
concat_str = ""
if data.Intervention["destination_name"] is not None:
concat_str += con + data.Intervention["destination_name"]
if self.attrib_link.intervention_dest_name is not None:
concat_str += con + self.attrib_link.intervention_dest_name
con = ", "
if data.Intervention["destination_street"] is not None:
concat_str += con + data.Intervention["destination_street"] + " " + self.ifNotNull(data.Intervention["destination_street_number"])
if self.attrib_link.intervention_dest_street is not None:
concat_str += con + self.attrib_link.intervention_dest_street + " " + self.ifNotNull(self.attrib_link.intervention_dest_street_number)
con = ", "
concat_str += con + data.Intervention["destination_postal_code"] + " " + data.Intervention["destination_city"]
concat_str += con + self.attrib_link.intervention_dest_postal_code + " " + self.attrib_link.intervention_dest_city
csv_col.data[15] = concat_str # Adresse DEST
con = ""
concat_str = ""
if data.Intervention["site_name"] is not None:
concat_str += con + data.Intervention["site_name"]
if self.attrib_link.intervention_site_name is not None:
concat_str += con + self.attrib_link.intervention_site_name
con = ", "
if data.Intervention["site_street"] is not None:
concat_str += con + self.ifNotNull(data.Intervention["site_street"]) + " " + self.ifNotNull(data.Intervention["site_street_number"])
if self.attrib_link.intervention_site_street is not None:
concat_str += con + self.ifNotNull(self.attrib_link.intervention_site_street) + " " + self.ifNotNull(self.attrib_link.intervention_site_street_number)
con = ", "
concat_str += con + self.ifNotNull(data.Intervention["site_postal_code"]) + " " + self.ifNotNull(data.Intervention["site_city"])
concat_str += con + self.ifNotNull(self.attrib_link.intervention_site_postal_code) + " " + self.ifNotNull(self.attrib_link.intervention_site_city)
csv_col.data[18] = concat_str # Adresse PEC
print(f'debug FIP:{data.Patient["fip_number"]} id:{data.data["id"]} code: {data.Debtor["code"]}')
if int(data.Debtor["code"]) < 100:
csv_col.data[19] = data.Patient['insurance_policy_number'].replace(".","")
csv_col.data[22] = data.Patient["lastname"]
csv_col.data[23] = data.Patient["firstname"]
csv_col.data[24] = data.Patient["complement"]
csv_col.data[25] = self.ifNotNull(data.Patient["street"]) + " " + self.ifNotNull(data.Patient["street_number"])
csv_col.data[26] = data.Patient["postal_code"]
csv_col.data[27] = data.Patient["city"]
if data.Patient["country_name"] != "Suisse":
csv_col.data[29] = data.Patient["country_name"]
print(f'debug FIP:{self.attrib_link.FIP} id:{self.attrib_link.invoice_ID} code: {self.attrib_link.debtor_code}')
if int(self.attrib_link.debtor_code) < 100:
csv_col.data[19] = self.attrib_link.patient_AVS.replace(".","")
csv_col.data[22] = self.attrib_link.patient_lastname
csv_col.data[23] = self.attrib_link.patient_firstname
csv_col.data[24] = self.attrib_link.patient_addr_complement
csv_col.data[25] = self.ifNotNull(self.attrib_link.patient_street) + " " + self.ifNotNull(self.attrib_link.patient_street_number)
csv_col.data[26] = self.attrib_link.patient_postal_code
csv_col.data[27] = self.attrib_link.patient_city
if self.attrib_link.patient_country != "Suisse":
csv_col.data[29] = self.attrib_link.patient_country
csv_col.data[41] = "Monsieur" if data.Patient["gender_name "] == "Masculin" else "Madame"
csv_col.data[41] = "Monsieur" if self.attrib_link.patient_gender == "Masculin" else "Madame"
csv_col.data[44] = csv_col.data[41]
#csv_col.data[46] = 0 # Maj adresse
@@ -664,70 +642,70 @@ class ClercAttrib2Biz():
csv_col.data[46] = 1 # Maj adresse, ajoute, mais ne met pas à jour l'adresse si elle existe
print("NON mise à jour de l'adresse")
if int(data.Debtor["code"]) > 1:
csv_col.data[42] = data.Patient["addr_2"].replace("\n", "#chr(13)##chr(10)#") #Adresse de livraison
if int(self.attrib_link.debtor_code) > 1:
csv_col.data[42] = self.attrib_link.patient_addr_2.replace("\n", "#chr(13)##chr(10)#") #Adresse de livraison
else:
csv_col.data[19] = data.Debtor["code"] # Code adresse à récupérer dans recherche d'adresse automatisée
csv_col.data[22] = data.Debtor["lastname"]
csv_col.data[23] = data.Debtor["firstname"]
csv_col.data[24] = data.Debtor["complement"]
csv_col.data[25] = self.ifNotNull(data.Debtor["street"]) + " " + self.ifNotNull(data.Debtor["street_number"])
csv_col.data[26] = data.Debtor["postal_code"]
csv_col.data[27] = data.Debtor["city"]
if data.Debtor["country_name"] != "Suisse":
csv_col.data[29] = data.Debtor["country_name"]
csv_col.data[19] = self.attrib_link.debtor_code # Code adresse à récupérer dans recherche d'adresse automatisée
csv_col.data[22] = self.attrib_link.debtor_lastname
csv_col.data[23] = self.attrib_link.debtor_firstname
csv_col.data[24] = self.attrib_link.debtor_addr_complement
csv_col.data[25] = self.ifNotNull(self.attrib_link.debtor_street) + " " + self.ifNotNull(self.attrib_link.debtor_street_number)
csv_col.data[26] = self.attrib_link.debtor_postal_code
csv_col.data[27] = self.attrib_link.debtor_city
if self.attrib_link.debtor_country != "Suisse":
csv_col.data[29] = self.attrib_link.debtor_country
csv_col.data[46] =1 # Maj adresse, ajoute, mais ne met pas à jour l'adresse si elle existe
if "name" in data.Debtor.keys():
csv_col.data[21] = self.ifNotNull(data.Debtor["name"])
csv_col.data[21] = self.ifNotNull(self.attrib_link.debtor_name)
else:
csv_col.data[21] = ''
if data.Patient["birthdate"] is not None:
csv_col.data[40] = datetime.strptime(data.Patient["birthdate"], "%Y-%m-%d").strftime("%d.%m.%Y")
if self.attrib_link.patient_birthdate is not None:
csv_col.data[40] = datetime.strptime(self.attrib_link.patient_birthdate, "%Y-%m-%d").strftime("%d.%m.%Y")
else:
csv_col.data[40] = ""
messagebox.showerror(title="Erreur date de naissance", message=f"La date de naissance de la facture {data.data['id']} ({data.Patient['lastname']}) est faux: [{data.Patient['birthdate']}], merci de le corriger ")
messagebox.showerror(title="Erreur date de naissance", message=f"La date de naissance de la facture {self.attrib_link.invoice_ID} ({self.attrib_link.patient_lastname}) est faux: [{self.attrib_link.patient_birthdate}], merci de le corriger ")
csv_col.data[48] = 0
## Données prestations
if "code" in article.keys():
csv_col.data[49] = article["code"] # Code de prestations
csv_col.data[50] = article["line_1"]
if article["line_2"] != None:
csv_col.data[50] = article["line_1"] + "#chr(13)##chr(10)#" + article["line_2"] # Descriptions prestations
csv_col.data[52] = article["quantity"] # Quantité
csv_col.data[53] = article["unit_price"] # prix unitaire
csv_col.data[54] = self.ifNotNull(article["unit"]) # unité
csv_col.data[56] = article["price"] # prix total
csv_col.data[49] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="code") # Code de prestations
csv_col.data[50] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_1")
if self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_2") != None:
csv_col.data[50] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_1") + "#chr(13)##chr(10)#" + self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_2") # Descriptions prestations
csv_col.data[52] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="quantity") # Quantité
csv_col.data[53] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="unit_price") # prix unitaire
csv_col.data[54] = self.ifNotNull(self.attrib_link.get_value_from_attrib(data=article,obj="article",key="unit")) # unité
csv_col.data[56] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="price") # prix total
else:
csv_col.data[49] = "0"
csv_col.data[50] = article["line_1"]
if article["line_2"] != None:
csv_col.data[50] = article["line_1"] + " / " + article["line_2"] # Descriptions prestations
csv_col.data[50] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_1")
if self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_2") != None:
csv_col.data[50] = self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_1") + " / " + self.attrib_link.get_value_from_attrib(data=article,obj="article",key="line_2") # Descriptions prestations
csv_col.data[52] = 0
csv_col.data[53] = 0
csv_col.data[56] = 0 # prix total
compte_number = None
if data.Intervention["base_name"] == "Uvrier":
if self.attrib_link.intervention_base == "Uvrier":
compte_number = 3018
else:
if data.Intervention["type"] == "P1":
compte_number = 3001 if data.Intervention["team_name"] == "Planification" else 3011
if data.Intervention["type"] == "P2":
compte_number = 3002 if data.Intervention["team_name"] == "Planification" else 3012
if data.Intervention["type"] == "P3":
compte_number = 3003 if data.Intervention["team_name"] == "Planification" else 3013
if data.Intervention["type"] == "S1":
compte_number = 3004 if data.Intervention["team_name"] == "Planification" else 3014
if data.Intervention["type"] == "S2":
compte_number = 3005 if data.Intervention["team_name"] == "Planification" else 3015
if data.Intervention["type"] == "S3":
compte_number = 3005 if data.Intervention["team_name"] == "Planification" else 3015
if self.attrib_link.intervention_type == "P1":
compte_number = 3001 if self.attrib_link.intervention_team == "Planification" else 3011
if self.attrib_link.intervention_type == "P2":
compte_number = 3002 if self.attrib_link.intervention_team == "Planification" else 3012
if self.attrib_link.intervention_type == "P3":
compte_number = 3003 if self.attrib_link.intervention_team == "Planification" else 3013
if self.attrib_link.intervention_type == "S1":
compte_number = 3004 if self.attrib_link.intervention_team == "Planification" else 3014
if self.attrib_link.intervention_type == "S2":
compte_number = 3005 if self.attrib_link.intervention_team == "Planification" else 3015
if self.attrib_link.intervention_type == "S3":
compte_number = 3005 if self.attrib_link.intervention_team == "Planification" else 3015
csv_col.data[59] = compte_number
csv_col.data[60] = 0
@@ -740,43 +718,43 @@ class ClercAttrib2Biz():
csv_col.data[73] = 0
#Objet facture
csv_col.data[108] = self.ifNotNull(data.Patient["lastname"]) + " " + self.ifNotNull(data.Patient["firstname"])
csv_col.data[115] = data.Patient["complement"]
csv_col.data[109] = datetime.strptime(data.Patient["birthdate"], "%Y-%m-%d").strftime("%d.%m.%Y") if data.Patient["birthdate"] is not None else ""
if data.Patient["insurance_policy_number"] is not None and '-' not in data.Patient["insurance_policy_number"]:
csv_col.data[109] += ", " + data.Patient["insurance_policy_number"]
csv_col.data[108] = self.ifNotNull(self.attrib_link.patient_lastname) + " " + self.ifNotNull(self.attrib_link.patient_firstname)
csv_col.data[115] = self.attrib_link.patient_addr_complement
csv_col.data[109] = datetime.strptime(self.attrib_link.patient_birthdate, "%Y-%m-%d").strftime("%d.%m.%Y") if self.attrib_link.patient_birthdate is not None else ""
if self.attrib_link.patient_AVS is not None and '-' not in self.attrib_link.patient_AVS:
csv_col.data[109] += ", " + self.attrib_link.patient_AVS
csv_col.data[110] = data.Patient["insurance_name"]
date_PEC = datetime.strptime(data.Intervention["start_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
csv_col.data[110] = self.attrib_link.patient_insurance_name
date_PEC = datetime.strptime(self.attrib_link.intervention_start_time, "%Y-%m-%dT%H:%M:%S%z").strftime(
"%d.%m.%Y")
csv_col.data[51] = date_PEC # Date de ligne articles
csv_col.data[111] =date_PEC # Date PEC
csv_col.data[111] += " - " + datetime.strptime(data.Intervention["start_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
csv_col.data[111] += " - " + datetime.strptime(self.attrib_link.intervention_start_time, "%Y-%m-%dT%H:%M:%S%z").strftime(
"%H:%M") # Heure START PEC
if b_HRF:
csv_col.data[111] += "-" + sHRF
else:
csv_col.data[111] += "-" + datetime.strptime(data.Intervention["end_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
csv_col.data[111] += "-" + datetime.strptime(self.attrib_link.intervention_end_time, "%Y-%m-%dT%H:%M:%S%z").strftime(
"%H:%M") # Heure END PEC
csv_col.data[112] = self.ifNotNull(data.Patient["street"]) + " " + self.ifNotNull(data.Patient["street_number"])
csv_col.data[113] = self.ifNotNull(data.Patient["postal_code"]) + " " + self.ifNotNull(data.Patient["city"])
if data.Patient["country_name"] != "Suisse":
csv_col.data[113] += ", " + data.Patient["country_name"]
csv_col.data[112] = self.ifNotNull(self.attrib_link.patient_street) + " " + self.ifNotNull(self.attrib_link.patient_street_number)
csv_col.data[113] = self.ifNotNull(self.attrib_link.patient_postal_code) + " " + self.ifNotNull(self.attrib_link.patient_city)
if self.attrib_link.patient_country != "Suisse":
csv_col.data[113] += ", " + self.attrib_link.patient_country
csv_col.data[107] = data.Patient["fip_number"]
csv_col.data[107] += " - " + data.data["comments"] if data.data["comments"] is not None else ""
csv_col.data[116] = self.ifNotNull(data.Patient["category_name"]) + " - " + self.ifNotNull(data.Intervention["type"])
csv_col.data[118] = data.Intervention["kilometers"]
csv_col.data[135] = data.Intervention["base_name"]
if data.Debtor["code"] == "100" or data.Debtor["code"] == "101" or data.Debtor["code"] == "158":
csv_col.data[107] = self.attrib_link.FIP
csv_col.data[107] += " - " + self.attrib_link.comments if self.attrib_link.comments is not None else ""
csv_col.data[116] = self.ifNotNull(self.attrib_link.patient_category) + " - " + self.ifNotNull(self.attrib_link.intervention_type)
csv_col.data[118] = self.attrib_link.km
csv_col.data[135] = self.attrib_link.intervention_base
if self.attrib_link.debtor_code == "100" or self.attrib_link.debtor_code == "101" or self.attrib_link.debtor_code == "158":
csv_col.data[136] = "EBILL" #code présentation de facture
else:
csv_col.data[136] = 3 #code présentation de facture
csv_col.data[146] = 3 #Code méthode de payement définit à 3
csv_col.data[168] = 1 if data.Intervention["team_name"] == "Planification" else 2
csv_col.data[169] = data.Patient['insurance_policy_number']
csv_col.data[168] = 1 if self.attrib_link.intervention_team == "Planification" else 2
csv_col.data[169] = self.attrib_link.patient_AVS
lines.append(csv_col.data)
csv_col = None

View File

@@ -1,2 +1,2 @@
VERSION = "20241101-2031"
VERSION = "20241109-1726"