def save_category(self): nombre = (self.nombrecat.get()) name_find = Inventario().find_category_by_name(nombre) if (name_find == None): if len(nombre) != 0: insert = Inventario().add_category(nombre) tkinter.messagebox.showinfo( "Terranova gestión de productos", "La categoría " + nombre + " añadida correctamente!") #refresh page self.add_frame_product() else: tkinter.messagebox.showinfo("Terranova gestión de productos", "No dejes campos en blanco!") else: tkinter.messagebox.showinfo( "Terranova gestión de productos", "La categoría " + nombre + " ya existe") self.reset()
def add_producto(self): name = (self.nombre.get()) categoria = (self.categoria.get()) precio = (self.precio.get()) cantidad = (self.cantidad.get()) name_find = Inventario().find_product_by_name(name) if (name_find == None): if (self.comboCategoria.get() != "Selecciona categoria" and len(self.nombre.get()) != 0): insert = Inventario().add_product(name, categoria, precio, cantidad) tkinter.messagebox.showinfo( "Terranova gestión de productos", "El producto " + name + " añadido correctamente!") self.reset() else: tkinter.messagebox.showinfo( "Terranova gestión de productos", "Selecciona una categoria o no dejes campos en blanco!") else: tkinter.messagebox.showinfo("Terranova gestión de productos", "El producto " + name + " ya existe") self.reset()
def modificar_producto(self): name = (self.nombre.get()) categoria = (self.categoria.get()) precio = (self.precio.get()) cantidad = (self.cantidad.get()) if name == self.current: if ( name != "Seleciona producto" and precio != "" and cantidad != "" ): insert = Inventario().update_product(name, categoria, precio, cantidad) tkinter.messagebox.showinfo("Terranova gestión de productos", "El Producto " + name + " modificado correctamente!") from interfaces.principal import Principal frame = Principal(self.master) self.frame.destroy() else: tkinter.messagebox.showinfo("Terranova gestión de productos", "Los campos no pueden estar vacios") else: tkinter.messagebox.showinfo("Terranova gestión de productos", "El producto " + name + " no es del que esta modificando datos!")
def __init__(self, master): self.master = master self.master.title("Terranova | Añadir Usuario") width_value = self.master.winfo_screenwidth() height_value = self.master.winfo_screenheight() self.master.geometry("%dx%d+0+0" % (width_value, height_value)) self.frame = Frame(self.master) self.frame.pack() ################# VAR FORM ############################################# all_products = Inventario().find_all() list_products = [product['nombre'] for product in all_products] self.nombre = StringVar() self.categoria = StringVar() self.precio = DoubleVar() self.cantidad = DoubleVar() self.LabelTitle = Label(self.frame, text = "Modificar Producto", font = ('arial', 50, 'bold'), bd=20) self.LabelTitle.grid(row = 0, column = 0, columnspan = 2, pady = 20) self.FormFrame1 = Frame(self.frame, width=1010, height=300, bd = 20, relief='ridge') self.FormFrame1.grid(row=1, column=0) self.FormFrame2 = Frame(self.frame, width=1000, height=100, bd = 20, relief='ridge') self.FormFrame2.grid(row=2, column=0) ######################## TEXT LOGIN #################################### self.LblRole = Label(self.FormFrame1, text = "Producto", font = ('arial', 20, 'bold'), bd=5) self.LblRole.grid(row = 0, column = 0) self.comboProduct = ttk.Combobox(self.FormFrame1, font = ('arial', 20, 'bold'), textvariable=self.nombre, state = "readonly") self.comboProduct['values'] = list_products self.comboProduct.set("Seleciona producto") self.comboProduct.grid(row = 0, column = 1) self.btnGetData = ttk.Button(self.FormFrame1, text="Ver datos", command = self.fill_data) self.btnGetData.grid(row = 0, column = 2) ######################### BOTONES ###################################### self.btnCrear = Button(self.FormFrame2, text = "Modificar", width = 17, font =('arial', 20, 'bold'), command = self.modificar_producto) self.btnCrear.grid(row = 0, column = 0) self.btnReset = Button(self.FormFrame2, text = "Reset", width = 17, font =('arial', 20, 'bold'), command = self.reset) self.btnReset.grid(row = 0, column = 1) self.btnAtras = Button(self.FormFrame2, text = "Atras", width = 17, font =('arial', 20, 'bold'), command = self.back_system) self.btnAtras.grid(row = 0, column = 2)
def eliminar_categoria_frame(self): self.categoria = StringVar() self.LabelTitle = Label(self.frame, text="Eliminar Categoria", font=('arial', 50, 'bold'), bd=20) self.LabelTitle.grid(row=0, column=0, columnspan=2, pady=20) self.LoginFrame1 = Frame(self.frame, width=1010, height=300, bd=20, relief='ridge') self.LoginFrame1.grid(row=1, column=0) self.LoginFrame2 = Frame(self.frame, width=1000, height=100, bd=20, relief='ridge') self.LoginFrame2.grid(row=2, column=0) ######################## Delete User ################################### self.LblRole = Label(self.LoginFrame1, text="Categoría", font=('arial', 20, 'bold'), bd=5) self.LblRole.grid(row=0, column=0) self.comboRole = ttk.Combobox(self.LoginFrame1, font=('arial', 20, 'bold'), textvariable=self.categoria, state="readonly") my_list = Inventario().find_category() self.comboRole['values'] = [category['nombre'] for category in my_list] self.comboRole.grid(row=0, column=1) ######################### BOTONES ###################################### self.btnCrear = Button(self.LoginFrame2, text="Eliminar", width=17, font=('arial', 20, 'bold'), command=self.eliminar_categoria) self.btnCrear.grid(row=0, column=0) self.btnAtras = Button(self.LoginFrame2, text="Atras", width=17, font=('arial', 20, 'bold'), command=self.back_system) self.btnAtras.grid(row=0, column=1)
def eliminar_categoria(self): category = (self.categoria.get()) self.eliminar_categoria = tkinter.messagebox.askyesno( "Terranova sistema de gestión", "De verdad quieres eliminar la categoria" + category) if self.eliminar_categoria > 0: Inventario().delete_category(category) tkinter.messagebox.showinfo( "Terranova eliminación de categorias", "La categoria " + category + " eliminado correctamente!") from interfaces.principal import Principal frame = Principal(self.master) self.frame.destroy() else: pass
def eliminar_categoria(self): nombre = (self.nombre.get()) self.eliminar_categoria = tkinter.messagebox.askyesno( "Terranova sistema de gestión", "De verdad quieres eliminar el producto " + nombre) if self.eliminar_categoria > 0: Inventario().delete_product(nombre) tkinter.messagebox.showinfo( "Terranova eliminación de productos", "El producto " + nombre + " eliminado correctamente!") from interfaces.principal import Principal frame = Principal(self.master) self.frame.destroy() else: pass
def fill_data(self): if self.comboProduct.get() != "Seleciona producto": self.categoria.set("") self.precio.set("") self.cantidad.set("") self.current = self.comboProduct.get() product_data = Inventario().find_product_by_name(self.comboProduct.get()) self.LblRole = Label(self.FormFrame1, text = "categoría", font = ('arial', 20, 'bold'), bd=5) self.LblRole.grid(row = 3, column = 0) self.comboCategoria = ttk.Combobox(self.FormFrame1, font = ('arial', 20, 'bold'), textvariable=self.categoria, state = "readonly") all_categories = Inventario().find_category() list_categories = [category['nombre'] for category in all_categories] self.comboCategoria['values']= list_categories self.comboCategoria.set(product_data.get("categoria")) self.comboCategoria.grid(row = 3, column = 1) self.LblApellido = Label(self.FormFrame1, text = "precio", font = ('arial', 20, 'bold'), bd=5) self.LblApellido.grid(row = 2, column = 0) self.TxtApellido = Entry(self.FormFrame1, font = ('arial', 20, 'bold'), bd=5, textvariable=self.precio) self.TxtApellido.insert(END, product_data.get("precio")) self.TxtApellido.grid(row = 2, column = 1) self.LblCargo = Label(self.FormFrame1, text = "Cantidad", font = ('arial', 20, 'bold'), bd=5) self.LblCargo.grid(row = 4, column = 0) self.TxtCargo = Entry(self.FormFrame1, text = "Cargo", font = ('arial', 20, 'bold'), bd=5, textvariable=self.cantidad) self.TxtCargo.insert(END, product_data.get("cantidad")) self.TxtCargo.grid(row = 4, column = 1)
def add_frame_product(self): ################# VAR FORM ############################################# self.nombre = StringVar() self.categoria = StringVar() self.precio = DoubleVar() self.cantidad = DoubleVar() self.LabelTitle = Label(self.frame, text="Añadir Producto", font=('arial', 50, 'bold'), bd=20) self.LabelTitle.grid(row=0, column=0, columnspan=2, pady=20) self.AddFrame1 = Frame(self.frame, width=1010, height=300, bd=20, relief='ridge') self.AddFrame1.grid(row=1, column=0) self.AddFrame2 = Frame(self.frame, width=1000, height=100, bd=20, relief='ridge') self.AddFrame2.grid(row=3, column=0) ######################## TEXT LOGIN #################################### self.LblNombre = Label(self.AddFrame1, text="Nombre", font=('arial', 20, 'bold'), bd=5) self.LblNombre.grid(row=0, column=0) self.TxtNombre = Entry(self.AddFrame1, font=('arial', 20, 'bold'), bd=5, textvariable=self.nombre) self.TxtNombre.grid(row=0, column=1) self.LblCategoria = Label(self.AddFrame1, text="Categoria", font=('arial', 20, 'bold'), bd=5) self.LblCategoria.grid(row=3, column=0) self.comboCategoria = ttk.Combobox(self.AddFrame1, font=('arial', 20, 'bold'), textvariable=self.categoria, state="readonly") all_categories = Inventario().find_category() list_categories = [category['nombre'] for category in all_categories] self.comboCategoria['values'] = list_categories self.comboCategoria.set("Selecciona categoria") self.comboCategoria.grid(row=3, column=1) self.btnCrear = Button(self.AddFrame1, text="Crear categoría", width=17, font=('arial', 20, 'bold'), command=self.add_category) self.btnCrear.grid(row=3, column=2) self.LblPrecio = Label(self.AddFrame1, text="Precio", font=('arial', 20, 'bold'), bd=5) self.LblPrecio.grid(row=4, column=0) self.TxtPrecio = Entry(self.AddFrame1, font=('arial', 20, 'bold'), bd=5, textvariable=self.precio) self.TxtPrecio.grid(row=4, column=1) self.LblCantidad = Label(self.AddFrame1, text="Cantidad", font=('arial', 20, 'bold'), bd=5) self.LblCantidad.grid(row=5, column=0) self.TxtCantidad = Entry(self.AddFrame1, font=('arial', 20, 'bold'), bd=5, textvariable=self.cantidad) self.TxtCantidad.grid(row=5, column=1, padx=65) ######################### BOTONES ###################################### self.btnCrear = Button(self.AddFrame2, text="Añadir", width=17, font=('arial', 20, 'bold'), command=self.add_producto) self.btnCrear.grid(row=0, column=0) self.btnReset = Button(self.AddFrame2, text="Reset", width=17, font=('arial', 20, 'bold'), command=self.reset) self.btnReset.grid(row=0, column=1) self.btnAtras = Button(self.AddFrame2, text="Atras", width=17, font=('arial', 20, 'bold'), command=self.back_system) self.btnAtras.grid(row=0, column=2)
class TestSum(unittest.TestCase): def test_add_product(): testprod = myinventario.add_product("cocacola", "Bebida", "Refresco", 10, 1) self.assertIs("cocacola", testprod) def test_add_product_alredy_db(): testprod = myinventario.add_product("cocacola", "Bebida", "Refresco", 10, 1) assert testprod == "producto Cocacola ya esta registrado!", "ya en bd" if __name__ == "__main__": # you want to initialize the class database = MongoDB() collection = database.createCollection("test") myinventario = Inventario() unittest.main() ''' if __name__ == '__main__': # you want to initialize the class database = MongoDB() collection = database.createCollection("productos") myinventario = Inventario() print("------ añadir producto ------") articulo1 = myinventario.add_product("cocacola", "Bebida", "Refresco", 10, 1) print("------ buscar producto ------") buscar = myinventario.find_product_by_name("Cocacola")
def fill_table(self): all_products = Inventario().find_all() for product in all_products: self.listBox.insert("", "end", values=(product['categoria'], product['nombre'], product['precio']))