Changement popup check adresse

This commit is contained in:
Ambulance Clerc
2022-06-08 23:57:16 +02:00
parent ff789f409c
commit 934ed40937
2 changed files with 125 additions and 120 deletions

123
custom_popup.py Normal file
View File

@@ -0,0 +1,123 @@
from tkinter import *
from tkinter import font
from datetime import datetime
class Check_addresses_popup(Toplevel):
x_row = 0
no_selection_possible = False
def __init__(self, parent, item_1=None, item_2=None, debitor=None):
super().__init__(parent)
self.geometry(f"700x300+{parent.winfo_x() + 25 }+{parent.winfo_y() +25 }")
self.resizable(True,True)
self.iconbitmap("./logo_clerc_03X_icon.ico")
self.title(f"Choix de l'adresse à conserver {item_1['fip_number']}. Code débiteur: {debitor['code']}")
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
lbf_new = LabelFrame(self, text="Données Attrib")
lbf_new.grid(row=0, column=0, sticky='WE', padx=5, pady=5)
lbf_old = LabelFrame(self, text="Données Winbiz")
lbf_old.grid(row=0, column=1, sticky='NSEW', padx=5, pady=5)
str_address_1 = ""
fonts = []
self.x_row = 0
self.add_compares_element(new_frame=lbf_new,old_frame=lbf_old,label="N° AVS de l'adresse:",str1=item_1['insurance_policy_number'].replace('.',''), str2=item_2.AVS)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Nom:", str1=item_1['lastname'], str2=item_2.lastName)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Prénom:", str1=item_1['firstname'], str2=item_2.firstName)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Date de naissance:", str1=datetime.strptime(item_1['birthdate'], "%Y-%m-%d").strftime("%d.%m.%Y"), str2=item_2.birth)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Adresse:", str1=f"{item_1['street']} {item_1['street_number']}", str2=item_2.street)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="NPA/Localité:", str1=f"{item_1['postal_code']} {item_1['city']}", str2=f"{item_2.npa} {item_2.city}")
str_address_1 += item_1['insurance_policy_number'].replace('.', '')
str_address_1 += item_1['lastname'].strip()
str_address_1 += item_1['firstname'].strip()
str_address_1 += datetime.strptime(item_1['birthdate'], "%Y-%m-%d").strftime("%d.%m.%Y")
str_address_1 += f"{item_1['street']} {item_1['street_number']}"
str_address_1 += f"{item_1['postal_code']} {item_1['city']}"
str_address_2 = ""
str_address_2 += item_2.AVS
str_address_2 += item_2.lastName
str_address_2 += item_2.firstName
str_address_2 += item_2.birth
str_address_2 += f"{item_2.street.strip()}"
str_address_2 += f"{item_2.npa} {item_2.city}"
self.listbox = Listbox(self, height=3, width=35)
self.listbox.grid(row=1,column=0, columnspan= 2, pady=15,padx=15, sticky='NSEW')
self.btn = Button(self, text="Valider", command=self.select)
self.btn.grid(row=2,columnspan=2 , pady=10,padx=10, sticky='NSEW')
for (idd, info) in ((0, "Winbiz"), (1, "Attrib")) :
self.listbox.insert(END, info)
if int(debitor["code"]) >= 100:
self.listbox.delete(0,END)
self.listbox.delete(0, END)
self.listbox.insert(END, f"Aucun changement possible, code débiteur {debitor['code']}")
self.listbox.configure(state='disabled')
self.no_selection_possible = True
if int(debitor["code"]) == 1:
if str_address_1 == str_address_2:
self.listbox.selection_set(0)
print("adresse identique")
else:
self.listbox.selection_set(1)
print(f"adresse différente [{str_address_1}] ({str_address_2})")
def add_compares_element(self,new_frame, old_frame,str1, str2, label):
label_font = font.Font(weight='bold', size=9)
value_color = "black"
con = ""
if str1 != str2:
value_color = "red"
con = "*"
Label(new_frame, text=label, font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(new_frame, text=con + str1 + con, fg=value_color).grid(row=self.x_row, column=1, sticky="W")
Label(old_frame, text=label, font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(old_frame, text=con + str2 + con, fg=value_color).grid(row=self.x_row, column=1, sticky="W")
self.x_row += 1
self.selection = None
def destroy(self):
if self.selection is None:
self.selection = True
super().destroy()
def select(self):
selection = self.listbox.curselection()
if selection:
self.selection = self.listbox.get(selection[0])
self.selection = True if self.selection == "Attrib" else False
self.destroy()
if self.no_selection_possible:
self.destroy()
def show(self):
self.deiconify()
self.wm_protocol("WM_DELETE_WINDOW", self.destroy)
self.wait_window(self)
return self.selection

122
main.py
View File

@@ -24,6 +24,7 @@ from auto_update import *
from class_debitors import *
from version import *
from custom_popup import *
src_dir = os.getenv('APPDATA') + "\Attrib2Biz\src"
@@ -46,125 +47,6 @@ if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
class SuggestionPopup(Toplevel):
x_row = 0
no_selection_possible = False
def __init__(self, parent, item_1=None, item_2=None, debitor=None):
super().__init__(parent)
self.geometry(f"700x300+{parent.winfo_x() + 25 }+{parent.winfo_y() +25 }")
self.resizable(True,True)
self.iconbitmap("./logo_clerc_03X_icon.ico")
self.title(f"Choix de l'adresse à conserver {item_1['fip_number']}. Code débiteur: {debitor['code']}")
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
lbf_new = LabelFrame(self, text="Données Attrib")
lbf_new.grid(row=0, column=0, sticky='WE', padx=5, pady=5)
lbf_old = LabelFrame(self, text="Données Winbiz")
lbf_old.grid(row=0, column=1, sticky='NSEW', padx=5, pady=5)
str_address_1 = ""
fonts = []
self.x_row = 0
self.add_compares_element(new_frame=lbf_new,old_frame=lbf_old,label="N° AVS de l'adresse:",str1=item_1['insurance_policy_number'].replace('.',''), str2=item_2.AVS)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Nom:", str1=item_1['lastname'], str2=item_2.lastName)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Prénom:", str1=item_1['firstname'], str2=item_2.firstName)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Date de naissance:", str1=datetime.strptime(item_1['birthdate'], "%Y-%m-%d").strftime("%d.%m.%Y"), str2=item_2.birth)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Adresse:", str1=f"{item_1['street']} {item_1['street_number']}", str2=item_2.street)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="NPA/Localité:", str1=f"{item_1['postal_code']} {item_1['city']}", str2=f"{item_2.npa} {item_2.city}")
str_address_1 += item_1['insurance_policy_number'].replace('.', '')
str_address_1 += item_1['lastname'].strip()
str_address_1 += item_1['firstname'].strip()
str_address_1 += datetime.strptime(item_1['birthdate'], "%Y-%m-%d").strftime("%d.%m.%Y")
str_address_1 += f"{item_1['street']} {item_1['street_number']}"
str_address_1 += f"{item_1['postal_code']} {item_1['city']}"
str_address_2 = ""
str_address_2 += item_2.AVS
str_address_2 += item_2.lastName
str_address_2 += item_2.firstName
str_address_2 += item_2.birth
str_address_2 += f"{item_2.street.strip()}"
str_address_2 += f"{item_2.npa} {item_2.city}"
self.listbox = Listbox(self, height=3, width=35)
self.listbox.grid(row=1,column=0, columnspan= 2, pady=15,padx=15, sticky='NSEW')
self.btn = Button(self, text="Valider", command=self.select)
self.btn.grid(row=2,columnspan=2 , pady=10,padx=10, sticky='NSEW')
for (idd, info) in ((0, "Winbiz"), (1, "Attrib")) :
self.listbox.insert(END, info)
if int(debitor["code"]) >= 100:
self.listbox.delete(0,END)
self.listbox.delete(0, END)
self.listbox.insert(END, f"Aucun changement possible, code débiteur {debitor['code']}")
self.listbox.configure(state='disabled')
self.no_selection_possible = True
if int(debitor["code"]) == 1:
if str_address_1 == str_address_2:
self.listbox.selection_set(0)
print("adresse identique")
else:
self.listbox.selection_set(1)
print(f"adresse différente [{str_address_1}] ({str_address_2})")
def add_compares_element(self,new_frame, old_frame,str1, str2, label):
label_font = font.Font(weight='bold', size=9)
value_color = "black"
con = ""
if str1 != str2:
value_color = "red"
con = "*"
Label(new_frame, text=label, font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(new_frame, text=con + str1 + con, fg=value_color).grid(row=self.x_row, column=1, sticky="W")
Label(old_frame, text=label, font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(old_frame, text=con + str2 + con, fg=value_color).grid(row=self.x_row, column=1, sticky="W")
self.x_row += 1
self.selection = None
def destroy(self):
if self.selection is None:
self.selection = True
super().destroy()
def select(self):
selection = self.listbox.curselection()
if selection:
self.selection = self.listbox.get(selection[0])
self.selection = True if self.selection == "Attrib" else False
self.destroy()
if self.no_selection_possible:
self.destroy()
def show(self):
self.deiconify()
self.wm_protocol("WM_DELETE_WINDOW", self.destroy)
self.wait_window(self)
return self.selection
class TextHandler(logging.Handler):
"""This class allows you to log to a Tkinter Text or ScrolledText widget"""
@@ -519,7 +401,7 @@ class ClercAttrib2Biz():
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:
popup = SuggestionPopup(self.fenetre, item_1=data.Patient, item_2=addresses_exist, debitor=data.Debtor)
popup = Check_addresses_popup(self.fenetre, item_1=data.Patient, item_2=addresses_exist, debitor=data.Debtor)
b_address_update = popup.show()
print(f"Result Popup: {b_address_update}")
else: