class SeccionesCategoriasGUI(BaseGUI): def __init__(self, manager, managers=[]): BaseGUI.__init__(self, manager, managers) self.FILENAME = 'model/seccion/secciones.ui' self.managerSecciones = managers[0].manager self.managerCuentas = managers[1].manager self.SeccionesGUI = managers[0] self.CategoriasGUI = managers[1] self._start_operations() def _start_operations(self): self.loadUI(self.FILENAME) self.setWindowTitle(u"Categorías") self.loadShortcuts() self.fullScreen = False centerOnScreen(self) self.SeccionesGUI.DialogAddClass.postSaveMethod = self.recargarListaSecciones #self._makeTableSecciones() self._makeTreeCuentas() #self._makeTablaCuentasEnSecciones() #self.cargarTablaSecciones() self.cargarTreeCuentas() #=============================================================================== # Metodos reimplementados : SECCIONES #=============================================================================== def _makeTableSecciones(self): if not self.ATRIBUTOSLISTA: columnasTablas = [ p.capitalize() for p in self.SeccionesGUI._obtener_atributos_names() ] else: self.ATRIBUTOSLISTA_CLASSNAMES = [ self.SeccionesGUI.manager.obtenerNombreAtributo(p.values()[0]) for p in self.ATRIBUTOSLISTA ] columnasTablas = [p.keys()[0] for p in self.ATRIBUTOSLISTA] self.SeccionesGUI.MyTabla = MyTableWidget(self.twDatosSeccion, columnasTablas) def _makeTablaCuentasEnSecciones(self): self.MyTablaCuentasSecciones = MyTableWidget( self.twDatosSeccionCategoria, ["Cuenta"]) def cargarTablaSecciones(self, listadeobj=None): ''' carga la lista de objetos en la tabla @param listadeobj:if none carga todos, sino lo de la lista ''' if listadeobj == None: listadeobj = self.managerSecciones.getall() listadefilas = [ self.SeccionesGUI._obtenerValoresAtributos(obj) for obj in listadeobj ] self.SeccionesGUI.MyTabla.addItems(listadefilas) self.lbCantidadItemsSeccion.setText( str(len(listadefilas)) + ' items(s) seleccionado(s)') def recargarListaSecciones(self): valor = '' campo = '' if self.ATRI_COMBO_BUSQUEDA: campo = [p[campo] for p in self.ATRI_COMBO_BUSQUEDA if campo in p][0] else: if campo != '': campo = self._obtaincolumnforname(campo) resultado = self.SeccionesGUI.search(campo, valor) self.cargarTablaSecciones(resultado) def cargarTablaCuentasEnUnaSeccion(self): cuentas = self.SeccionesGUI.obtenerCuentasDeLaSeccionSeleccionada() if cuentas: self.MyTablaCuentasSecciones.addItems([[cuenta.nombre] for cuenta in cuentas]) @QtCore.pyqtSlot() def on_btAgregarSeccion_clicked(self): if len(self.managerCuentas.getall()) > 1: self.SeccionesGUI.on_btAgregar_clicked(self.recargarListaSecciones) else: QtGui.QMessageBox.warning( self, "Agregar Seccion", u"Deben existir mas de <1> cuenta(s) para poder crear una sección." ) @QtCore.pyqtSlot() def on_btEditarSeccion_clicked(self): self.SeccionesGUI.on_btEditar_clicked(self.recargarListaSecciones) @QtCore.pyqtSlot() def on_btEliminarSeccion_clicked(self): self.SeccionesGUI.on_btEliminar_clicked() self.recargarListaSecciones() self.MyTablaCuentasSecciones.fullClear() def on_twDatosSeccion_itemSelectionChanged(self): self.SeccionesGUI.on_twDatosSeccion_itemSelectionChanged( self.cargarTablaCuentasEnUnaSeccion) #=============================================================================== # Metodos reimplementados : CUENTAS #=============================================================================== def _makeTreeCuentas(self): self.treeCuentas = TreeView(self.treeCuentas, self.connect, self.on_treeCuentas_selectedItem, QtGui.QIcon(':/newPrefix/Book.png'), QtGui.QIcon(':/newPrefix/kwikdisk.png')) def cargarTreeCuentas(self, listadeobj=None): ''' carga la lista de objetos en la tabla @param listadeobj:if none carga todos, sino lo de la lista ''' if listadeobj == None: listadeobj = self.managerCuentas.getall() listadefilas = [ self.CategoriasGUI._getAttributesValues(obj) for obj in listadeobj ] cuentas_ingresos, cuentas_egresos, items = [], [], [] for fila in listadefilas: if fila[2] == u'Ingreso': cuentas_ingresos.append(fila[1]) else: cuentas_egresos.append(fila[1]) cuentas_ingresos.sort() cuentas_egresos.sort() map(lambda item: items.append([u'CUENTAS DE INGRESOS', item]), cuentas_ingresos) map(lambda item: items.append([u'CUENTAS DE EGRESOS', item]), cuentas_egresos) self.treeCuentas.addItems(items) self.treeCuentas.widget.expandAll() self.lbCantidadItemsCategoria.setText( str(len(items)) + ' items(s) seleccionado(s)') def recargarListaCuentas(self): valor = '' campo = '' resultado = self.CategoriasGUI.search(campo, valor) self.cargarTreeCuentas(resultado) @QtCore.pyqtSlot() def on_btAgregarCategoria_clicked(self): self.CategoriasGUI.on_btAgregar_clicked(self.cargarTreeCuentas) @QtCore.pyqtSlot() def on_btEditarCategoria_clicked(self): try: cuenta = self.CategoriasGUI.manager.get(self.hijo)[0] self.CategoriasGUI.on_btEditar_clicked(self.cargarTreeCuentas, cuenta) except: pass @QtCore.pyqtSlot() def on_btEliminarCategoria_clicked(self): try: cuenta = self.CategoriasGUI.manager.get(self.hijo)[0] self.CategoriasGUI.on_btEliminar_clicked(self.cargarTreeCuentas, cuenta) except: pass @QtCore.pyqtSlot(int) def on_cbFiltro_currentIndexChanged(self, index): filtro = unicode( self.cbFiltro.itemText(self.cbFiltro.currentIndex()).toUtf8(), 'utf-8') cuentas = None if filtro == "Todos": cuentas = self.managerCuentas.getall() elif filtro == "Ingreso": cuentas = self.managerCuentas.cuentasDeIngreso() elif filtro == "Egreso": cuentas = self.managerCuentas.cuentasDeEgreso() self.cargarTreeCuentas(cuentas) def on_treeCuentas_selectedItem(self, indice, b): if indice.parent().row() != -1: self.padre = unicode(indice.parent().data().toString().toUtf8(), 'utf-8') self.hijo = unicode(indice.data().toString().toUtf8(), 'utf-8')
class SeccionesCategoriasGUI(BaseGUI): def __init__(self,manager, managers = []): BaseGUI.__init__(self, manager, managers) self.FILENAME = 'seccion/secciones.ui' self.managerSecciones = managers[0].manager self.managerCuentas = managers[1].manager self.SeccionesGUI = managers[0] self.CategoriasGUI = managers[1] self._start_operations() def _start_operations(self): self.loadUI(self.FILENAME) self.setWindowTitle(u"Categorías") self.loadShortcuts() self.fullScreen = False centerOnScreen(self) self.SeccionesGUI.DialogAddClass.postSaveMethod = self.recargarListaSecciones #self._makeTableSecciones() self._makeTreeCuentas() #self._makeTablaCuentasEnSecciones() #self.cargarTablaSecciones() self.cargarTreeCuentas() #=============================================================================== # Metodos reimplementados : SECCIONES #=============================================================================== def _makeTableSecciones(self): if not self.ATRIBUTOSLISTA : columnasTablas = [p.capitalize() for p in self.SeccionesGUI._obtener_atributos_names()] else: self.ATRIBUTOSLISTA_CLASSNAMES = [ self.SeccionesGUI.manager.obtenerNombreAtributo( p.values()[0] ) for p in self.ATRIBUTOSLISTA] columnasTablas = [p.keys()[0] for p in self.ATRIBUTOSLISTA] self.SeccionesGUI.MyTabla = MyTableWidget(self.twDatosSeccion,columnasTablas) def _makeTablaCuentasEnSecciones(self): self.MyTablaCuentasSecciones = MyTableWidget(self.twDatosSeccionCategoria,["Cuenta"]) def cargarTablaSecciones(self,listadeobj = None): ''' carga la lista de objetos en la tabla @param listadeobj:if none carga todos, sino lo de la lista ''' if listadeobj == None: listadeobj = self.managerSecciones.getall() listadefilas = [self.SeccionesGUI._obtenerValoresAtributos(obj) for obj in listadeobj] self.SeccionesGUI.MyTabla.addItems(listadefilas) self.lbCantidadItemsSeccion.setText( str(len(listadefilas)) + ' items(s) seleccionado(s)') def recargarListaSecciones(self): valor = '' campo = '' if self.ATRI_COMBO_BUSQUEDA : campo = [p[campo] for p in self.ATRI_COMBO_BUSQUEDA if campo in p ][0] else: if campo != '' : campo = self._obtaincolumnforname(campo) resultado = self.SeccionesGUI.search(campo,valor) self.cargarTablaSecciones(resultado) def cargarTablaCuentasEnUnaSeccion(self): cuentas = self.SeccionesGUI.obtenerCuentasDeLaSeccionSeleccionada() if cuentas : self.MyTablaCuentasSecciones.addItems( [[cuenta.nombre] for cuenta in cuentas] ) @QtCore.pyqtSlot() def on_btAgregarSeccion_clicked(self): if len(self.managerCuentas.getall()) > 1 : self.SeccionesGUI.on_btAgregar_clicked( self.recargarListaSecciones ) else: QtGui.QMessageBox.warning(self, "Agregar Seccion",u"Deben existir mas de <1> cuenta(s) para poder crear una sección.") @QtCore.pyqtSlot() def on_btEditarSeccion_clicked(self): self.SeccionesGUI.on_btEditar_clicked( self.recargarListaSecciones ) @QtCore.pyqtSlot() def on_btEliminarSeccion_clicked(self): self.SeccionesGUI.on_btEliminar_clicked() self.recargarListaSecciones() self.MyTablaCuentasSecciones.fullClear() def on_twDatosSeccion_itemSelectionChanged(self): self.SeccionesGUI.on_twDatosSeccion_itemSelectionChanged( self.cargarTablaCuentasEnUnaSeccion ) #=============================================================================== # Metodos reimplementados : CUENTAS #=============================================================================== def _makeTreeCuentas(self): self.treeCuentas = TreeView( self.treeCuentas, self.connect, self.on_treeCuentas_selectedItem, QtGui.QIcon(':/newPrefix/Book.png'), QtGui.QIcon(':/newPrefix/kwikdisk.png')) def cargarTreeCuentas(self,listadeobj = None): ''' carga la lista de objetos en la tabla @param listadeobj:if none carga todos, sino lo de la lista ''' if listadeobj == None: listadeobj = self.managerCuentas.getall() listadefilas = [self.CategoriasGUI._getAttributesValues(obj) for obj in listadeobj] cuentas_ingresos, cuentas_egresos, items = [], [], [] for fila in listadefilas : if fila[2] == u'Ingreso' : cuentas_ingresos.append( fila[1] ) else: cuentas_egresos.append( fila[1] ) cuentas_ingresos.sort() cuentas_egresos.sort() map(lambda item: items.append( [u'CUENTAS DE INGRESOS',item] ), cuentas_ingresos) map(lambda item: items.append( [u'CUENTAS DE EGRESOS',item] ), cuentas_egresos) self.treeCuentas.addItems(items) self.treeCuentas.widget.expandAll() self.lbCantidadItemsCategoria.setText( str(len(items)) + ' items(s) seleccionado(s)') def recargarListaCuentas(self): valor = '' campo = '' resultado = self.CategoriasGUI.search(campo,valor) self.cargarTreeCuentas(resultado) @QtCore.pyqtSlot() def on_btAgregarCategoria_clicked(self): self.CategoriasGUI.on_btAgregar_clicked( self.cargarTreeCuentas ) @QtCore.pyqtSlot() def on_btEditarCategoria_clicked(self): try: cuenta = self.CategoriasGUI.manager.get( self.hijo )[0] self.CategoriasGUI.on_btEditar_clicked( self.cargarTreeCuentas, cuenta) except: pass @QtCore.pyqtSlot() def on_btEliminarCategoria_clicked(self): try: cuenta = self.CategoriasGUI.manager.get( self.hijo )[0] self.CategoriasGUI.on_btEliminar_clicked( self.cargarTreeCuentas , cuenta) except: pass @QtCore.pyqtSlot(int) def on_cbFiltro_currentIndexChanged(self , index): filtro = unicode(self.cbFiltro.itemText(self.cbFiltro.currentIndex()).toUtf8(),'utf-8') cuentas = None if filtro == "Todos" : cuentas = self.managerCuentas.getall() elif filtro == "Ingreso" : cuentas = self.managerCuentas.cuentasDeIngreso() elif filtro == "Egreso" : cuentas = self.managerCuentas.cuentasDeEgreso() self.cargarTreeCuentas( cuentas ) def on_treeCuentas_selectedItem(self,indice,b): if indice.parent().row() != -1: self.padre = unicode(indice.parent().data().toString().toUtf8(),'utf-8') self.hijo = unicode(indice.data().toString().toUtf8(),'utf-8')
class AddPedidos(BaseAdd): def __init__(self, manager, itemToEdit=False, managers=[], parent=None): BaseAdd.__init__(self, manager, itemToEdit, managers, parent) self.loadUI('model/pedidos/uis/add.ui') self.linkToAttribute(self.deFecha, Pedidos.fecha) self.linkToAttribute(self.cbClientes, Pedidos.cliente) self.singleTitle = 'pedido' self._start_operations() self.loadReferenceCombo(self.cbClientes, Pedidos.cliente, sortAttr='nombres') self.objs = {} self.productosEnLista = [] self.loadWidgets() # si es modo edit if itemToEdit: # se obtienen y cargan los productos # correspondientes al pedido en cuestion productos = self.manager.obtenerProductosPedido(itemToEdit) # parse los objs para regenerar el formato de la lista de diccionarios for obj in productos: self.productosEnLista.append({ 'cantidad': obj.cantidad, 'tela': obj.tela, 'talle': obj.talle, 'producto': obj.producto, 'subtotal': obj.precio }) self.reloadTableProductos() def loadWidgets(self): self.deFecha.setDate(date.today()) # carga el combo de productos y los productos actuales en la ram self.objs['productos'] = sortListOfListObjs( self.managers.productos.getall(), campo='producto') self.cbProductos.clear() [ self.cbProductos.addItem(obj.producto) for obj in self.objs['productos'] ] # carga el combo de telas y los productos actuales en la ram self.objs['telas'] = sortListOfListObjs( self.managers.materiasprimas.get(u'tela'), campo='nombre') #self.managers.materiasprimas.getall(), campo='nombre') self.cbTela.clear() [self.cbTela.addItem(obj.nombre) for obj in self.objs['telas']] # carga el combo de colores y los productos actuales en la ram #tela = self.cbTela.currentText #self.objs['colores'] = sortListOfListObjs(self.managers.materiasprimas.get(tela), campo='color') #self.cbColor.clear() #[self.cbColor.addItem(obj.color) for obj in self.objs['colores']] def reloadTableProductos(self): cols = [ u'Cantidad', u'Producto', u'tela', u'talle', u'Costo', u'Subtotal' ] self.otwProductos = MyTableWidget(self.twProductos, cols, ['C', 'L', 'L', 'L', 'C', 'C']) self.otwProductos.fullClear() for prod in self.productosEnLista: item = [ prod['cantidad'], prod['producto'].producto, prod['tela'].nombre, prod['talle'], "$ %8.2f" % prod['producto'].costo, "$ %8.2f" % prod['subtotal'], ] self.otwProductos.appendItem(item) self.obtenerTotal() def obtenerTotal(self): total = 0 for prod in self.productosEnLista: total += prod['subtotal'] self.lbTotal.setText("$ %8.2f" % total) return total #MODULOS FALTANTES: ''' CALCULAR DISPONIBILIDAD DE MATERIA PRIMA, SEGUN LA CANTIDAD QUE LLEVA CADA PRODUCTO EN EL PEDIDO Y LA CANTIDAD DE PRODUCTOS PEDIDOS ''' '''def calcularTiempo(self): buscar el tiempo que tarda un empleado en producir una unidad de cada producto seleccionado y en base a eso calcular el tiempo for prod in self.productosEnLista: tiempo = self.manager.empleados.get(tiempo) pass''' '''ef calcularDescuento(self): buscar en el historial de pedidos del cliente seleccionado: cantidad de pedidos que hizo hasta el momento y si el monto de estos supera los $X, ofrecer un descuento del X%''' #REIMPLEMENTED def save(self, listData): data = { 'fecha': datetime.strptime(listData[0], "%d/%m/%Y"), 'cliente': listData[1], 'estado': u'en_curso', 'costo': self.obtenerTotal(), } # guarda el pedido en la bd try: pedido = self.manager.add(data) if not pedido: return False # se generan los objetos PedidoProducto # por cada item de la tabla productos for item in self.productosEnLista: data = { 'pedido': pedido, 'producto': item['producto'], 'cantidad': item['cantidad'], 'talle': item['talle'], 'tela': item['tela'], 'precio': item['producto'].costo, } obj = self.manager.store.add(Pedidoproducto(**data)) self.manager.store.flush() self.manager.store.commit() return True except Exception as e: print e return False ############################################################################### @QtCore.pyqtSlot() def on_btAgregarProducto_clicked(self): if self.cbProductos.currentIndex() < 0: return producto = self.objs['productos'][self.cbProductos.currentIndex()] tela = self.objs['telas'][self.cbTela.currentIndex()] # valida que el producto no se encuentre en la lista if producto in [p['producto'] for p in self.productosEnLista]: return item = { 'cantidad': self.sbCantidad.value(), 'talle': self.sbTalle.value(), 'color': self.cbColor.currentText(), 'tela': tela, 'producto': producto, 'subtotal': self.sbCantidad.value() * producto.costo } self.productosEnLista.append(item) self.reloadTableProductos() @QtCore.pyqtSlot() def on_btQuitarProducto_clicked(self): idx = self.otwProductos.widget.currentRow() if idx >= 0: del self.productosEnLista[idx] self.reloadTableProductos() @QtCore.pyqtSlot() def on_btSave_clicked(self): if len(self.productosEnLista) == 0: QtGui.QMessageBox.warning( self, self.windowTitle(), "No se puede crear un pedido sin productos. Por favor agregue al menos uno." ) return BaseAdd.on_btSave_clicked(self)