Files
AttribWinbiz/custom_popup.py
2023-11-28 15:00:11 +01:00

289 lines
12 KiB
Python

from tkinter import *
from tkinter import font
from datetime import datetime
from tkinter import messagebox
class Check_addresses_popup(Toplevel):
x_row = 0
no_selection_possible = False
def __init__(self, parent, item_1=None, item_2=None, debitor=None, factureID=""):
super().__init__(parent)
if(item_1["complement"] is None):
item_1["complement"] = ""
self.geometry(f"700x450+{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']} / {factureID}. 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)
lbf_addr_2_new = LabelFrame(self, text="Livraison Attrib")
lbf_addr_2_new.grid(row=1, column=0, sticky='WE', padx=5, pady=5)
lbf_addr_2_old = LabelFrame(self, text="Livraison Winbiz")
lbf_addr_2_old.grid(row=1, 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=self.ifNotNull(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=self.ifNotNull(item_1['lastname']), str2=item_2.lastName)
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Prénom:", str1=self.ifNotNull(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(self.ifNotNull(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"{self.ifNotNull(item_1['street']).strip()} {self.ifNotNull(item_1['street_number']).strip()}", str2=item_2.street.strip())
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="Complément:", str1=f"{self.ifNotNull(item_1['complement']).strip()}", str2=item_2.street_cpl.strip())
self.add_compares_element(new_frame=lbf_new, old_frame=lbf_old, label="NPA/Localité:", str1=f"{self.ifNotNull(item_1['postal_code'])} {self.ifNotNull(item_1['city'])}", str2=f"{item_2.npa} {item_2.city}")
if int(debitor["code"]) < 100:
if item_1["selfish"]:
force_color = "green"
else:
force_color = None
self.add_compares_element(new_frame=lbf_addr_2_new, old_frame=lbf_addr_2_old, label="Adresse livraison:", str1=item_1["addr_2"],
str2=self.ifNotNull(item_2.addr_2),force_color_1=force_color)
str_address_1 += self.ifNotNull(item_1['insurance_policy_number']).replace('.', '')
str_address_1 += self.ifNotNull(item_1['lastname']).strip()
str_address_1 +=self.ifNotNull( item_1['firstname']).strip()
str_address_1 += datetime.strptime(item_1['birthdate'], "%Y-%m-%d").strftime("%d.%m.%Y")
str_address_1 += f"{self.ifNotNull(item_1['street']).strip()} {self.ifNotNull(item_1['street_number']).strip()}"
str_address_1 += f"{self.ifNotNull(item_1['complement']).strip()}"
str_address_1 += f"{self.ifNotNull(item_1['postal_code'])} {self.ifNotNull(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.street_cpl.strip()}"
str_address_2 += f"{item_2.npa} {item_2.city}"
self.listbox = Listbox(self, height=3, width=35)
self.listbox.grid(row=2,column=0, columnspan= 2, pady=15,padx=15, sticky='NSEW')
self.btn = Button(self, text="Valider", command=self.select)
self.btn.grid(row=3,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 ifNotNull(self, value, ret=""):
if value == None or value == "None":
return ret
return value.strip()
def add_compares_element(self,new_frame, old_frame,str1, str2, label, force_color_1=None):
label_font = font.Font(weight='bold', size=9)
value_color_1 = "black"
value_color_2 = "black"
con = ""
if str1 != str2:
value_color_1 = "red"
value_color_2 = "red"
con = "*"
if force_color_1 is not None:
value_color_1 = force_color_1
Label(new_frame, text=str(label), font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(new_frame, text=con + str(str1) + con, fg=value_color_1, anchor="w", justify=LEFT).grid(row=self.x_row, column=1, sticky="W")
Label(old_frame, text=str(label), font=label_font).grid(row=self.x_row, column=0, sticky="W")
Label(old_frame, text=con + str(str2) + con, fg=value_color_2, anchor="w", justify=LEFT).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 Check_debitor_popup(Toplevel):
x_row = 0
no_selection_possible = False
def __init__(self, parent, debitor=None, lists_available_names=None, factureID=None,fip=None,object=None):
super().__init__(parent)
self.object = object
self.debitor = debitor
self.inp_code = StringVar()
self.inp_code.set(debitor['code'])
self.geometry(f"900x275+{parent.winfo_x() + 25 }+{parent.winfo_y() +25 }")
self.resizable(True,True)
self.iconbitmap("./logo_clerc_03X_icon.ico")
self.title(f"Incohérence sur les débiteurs {fip} / {factureID}. Code débiteur: {debitor['code']}")
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
Label(self,text="Une incohérence a été trouvée entre le code débiteur saisi dans Attrib et le code débiteur saisi dans Attrib. \nIls ne correspondent pas.Le code débiteur présent dans le champs Code Saisi sera utiliser pour la facture winbiz \nMerci de vérifier et modifier le code débiteur puis cliquer sur Valider.", wraplength= 950, justify=LEFT).grid(row=0,column=0, columnspan=2, sticky="W")
lbf_new = LabelFrame(self, text="Données Attrib")
lbf_new.grid(row=1, column=0, sticky='WE', padx=5, pady=5)
label_font = font.Font(weight='bold', size=9)
Label(lbf_new, text="Code saisi", font=label_font).grid(row=0, column=0, sticky="W")
Entry(lbf_new, textvariable=self.inp_code, width= 10).grid(row=0, column=1, sticky="W", pady= 10)
Label(lbf_new, text="Débiteur sélectionné dans Attrib", font=label_font).grid(row=1, column=0, sticky="W")
text_name = Text(lbf_new, fg="red", height=3,width= 30)
text_name.grid(row=1, column=1, sticky="W")
if 'name' not in debitor:
debitor['name'] = ""
text_name.insert(END,debitor['name'])
text_name.configure(state='disabled')
lbf_old = LabelFrame(self, text="Noms possibles")
lbf_old.grid(row=1, column=1, sticky='NSEW', padx=5, pady=5)
self.listbox = Text(lbf_old, height=5, width=50)
self.listbox.grid(row=1,column=0, columnspan= 2, pady=15,padx=15, sticky='NSEW')
for info in lists_available_names :
self.listbox.insert(END, f"{info}\n")
self.listbox.configure(state='disabled')
self.no_selection_possible = True
menu_bar = Menu(self)
menu_param = Menu(menu_bar, tearoff=0)
menu_param.add_command(label="Ajouter à la liste", command=self.add)
menu_bar.add_cascade(label="Paramètre", menu=menu_param)
self.config(menu=menu_bar)
self.btn = Button(self, text="Valider", command=self.destroy)
self.btn.grid(row=2,column=0, columnspan= 2, pady=10,padx=10, sticky='NSEW')
def add(self):
self.destroy()
if self.object is not None:
self.object.add_items(code=self.inp_code.get(), name=self.debitor["name"])
self.object.save_debitors()
def destroy(self):
super().destroy()
def show(self):
self.deiconify()
self.wm_protocol("WM_DELETE_WINDOW", self.destroy)
self.wait_window(self)
print("nouveau code = "+ self.inp_code.get())
return self.inp_code.get()
class Input_popup(Toplevel):
x_row = 0
no_selection_possible = False
def __init__(self, parent, text="Veuillez saisir la nouvelle valeur.", default="" ,factureID=None, fip=None, object=None):
super().__init__(parent)
self.object = object
self.inp_value = StringVar()
if default is not None:
self.inp_value.set(default)
self.geometry(f"650x120+{parent.winfo_x() + 25}+{parent.winfo_y() + 25}")
self.resizable(True, True)
self.iconbitmap("./logo_clerc_03X_icon.ico")
self.title(f"Saisir une valeur {fip} / {factureID}.")
self.columnconfigure(0, weight=1)
self.columnconfigure(1, weight=1)
lbf_new = LabelFrame(self, text=text)
lbf_new.grid(row=0, column=0, sticky='WE', padx=5, pady=5)
label_font = font.Font(weight='bold', size=9)
Label(lbf_new, text="", font=label_font).grid(row=0, column=0, sticky="W")
input_entry = Entry(lbf_new, textvariable=self.inp_value, width=100)
input_entry.grid(row=0, column=1, sticky="W", pady=10)
input_entry.focus()
self.after(0,input_entry.focus)
self.btn = Button(self, text="Valider", command=self.destroy)
self.btn.grid(row=2, column=0, pady=10, padx=10, sticky='NSEW')
def add(self):
self.destroy()
if self.object is not None:
self.object.add_items(code=self.inp_code.get(), name=self.debitor["name"])
self.object.save_debitors()
def destroy(self):
if self.inp_value.get() is None or self.inp_value.get() == "":
messagebox.showerror(title="ERREUR", message="Veuillez saisir une valeur !")
self.focus()
else:
super().destroy()
def show(self):
self.deiconify()
self.wm_protocol("WM_DELETE_WINDOW", self.destroy)
self.wait_window(self)
print("nouvelle valeur = " + self.inp_value.get())
return self.inp_value.get()