示例#1
0
class cargarFact:
    def __init__(self, parent):
        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = NuevaFact(self.main_frame)
        self.model = ObjectListModel(Factura)

        self.frame.Bind(wx.EVT_BUTTON, self.crearF, self.frame.btnCargrNueFac)

    def show(self):
        self.frame.Show()

    def crearF(self, event):
        fields = {}
        fields["cuenta_id"] = self.cuentaId
        fields["periodo"] = self.frame.txtPeriodoNueFac.GetValue()
        fields["monto"] = self.frame.txtMontoNueFac.GetValue()
        fields["primerVencimiento"] = self.parseDate(self.frame.datepicker1vencNueFac.GetValue())
        fields["segundoVencimiento"] = self.parseDate(self.frame.datepicker2vencNueFac.GetValue())
        fields["primerMonto"] = self.frame.txt1increNueFac.GetValue()
        fields["segundoMonto"] = self.frame.txt2increNueFac.GetValue()
        self.model.createObject(fields)
        self.frame.Destroy()
        event.Skip()

    def cargarDatos(self, cuentaId):
        self.cuentaId = cuentaId
        self.frame.lblNumCuentaNueFac.SetLabel(str(cuentaId))

    def parseDate(self, dt):
        day = dt.GetDay()
        month = dt.GetMonth()
        year = dt.GetYear()
        return datetime.datetime(year, month, day)
示例#2
0
class VincularCuentasController:
    def __init__(self, parent, cuentaId, clienteId):
        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = VincularCuentas(self.main_frame)
        self.model = ObjectListModel(Cuenta)

        self.cuentaId = cuentaId
        self.cliente = clienteId

        self.frame.Bind(wx.EVT_BUTTON, self.vincularCuenta, self.frame.btnAgreNueCue)

    def vincularCuenta(self, event):
        fields = {}
        fields["tipocuenta_id"] = self.cuentaId
        fields["cliente_id"] = self.cliente
        fields["numeroRef"] = self.frame.txtNumRefNueCue.GetValue()

        self.model.createObject(fields)
        self.frame.Destroy()
        event.Skip()

    def show(self):
        self.frame.ShowModal()
示例#3
0
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = VerFacturas(self.main_frame)
        self.model = ObjectListModel(Factura)

        self.frame.comboBoxFiltroEmpreFac.Enable(False)
        self.setupListColumns()
        self.pasarTipoCuenta("")
        self.pasarEmpresaCuenta("")
        self.cargarFacturas()

        pub.subscribe(self.pasarEmpresaCuenta, "tipo_cuentas.changed")
        pub.subscribe(self.pasarEmpresaCuenta, "tipo_cuentas.added")
        pub.subscribe(self.pasarEmpresaCuenta2, "tipo_cuentas.deleted")
        pub.subscribe(self.pasarTipoCuenta2, "tipo_cuentas.deleted")
        pub.subscribe(self.pasarTipoCuenta, "tipo_cuentas.added")
        pub.subscribe(self.pasarTipoCuenta, "tipo_cuenta.changed")
        pub.subscribe(self.facturaChanged, "factura.changed")
        pub.subscribe(self.facturaAdded, "facturas.added")
        pub.subscribe(self.facturaDeleted, "facturas.deleted")

        self.frame.comboBoxFiltroFac.Bind(wx.EVT_COMBOBOX, self.onCombo)
示例#4
0
    def __init__(self, parent):
        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = NuevaFact(self.main_frame)
        self.model = ObjectListModel(Factura)

        self.frame.Bind(wx.EVT_BUTTON, self.crearF, self.frame.btnCargrNueFac)
示例#5
0
    def __init__(self, parent, cuentaId, clienteId):
        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = VincularCuentas(self.main_frame)
        self.model = ObjectListModel(Cuenta)

        self.cuentaId = cuentaId
        self.cliente = clienteId

        self.frame.Bind(wx.EVT_BUTTON, self.vincularCuenta, self.frame.btnAgreNueCue)
示例#6
0
    def __init__(self, parent, cuentas, cliente):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = AdmCuentas(self.main_frame)
        self.model = ObjectListModel(Cuenta)
        self.modelTipo = ObjectListModel(TipoCuenta)

        self.setupListColumns()
        self.loadAllCuentas()
        self.cargarDatos(cuentas, cliente)
        self.setTitle(cliente)

        pub.subscribe(self.cuentaAgregada, "cuentas.added")

        pub.subscribe(self.cuentaChanged, "tipo_cuenta.changed")
        pub.subscribe(self.cuentaAdded, "tipo_cuentas.added")
        pub.subscribe(self.cuentaDeleted, "tipo_cuentas.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnVincular, self.frame.btnVincCue)
        self.frame.Bind(wx.EVT_BUTTON, self.OnCargFact, self.frame.btnAgregFac)
示例#7
0
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = ObjectListFrameTipoCuenta(self.main_frame, size=(700, 500))
        self.model = ObjectListModel(TipoCuenta)

        self.setupListColumns()
        self.setupSearchBy()
        self.loadAllTipoCuenta()
        self.setTitle()
        self.bindEvents()

        pub.subscribe(self.tipoCuentaChanged, "tipo_cuenta.changed")
        pub.subscribe(self.tipoCuentaAdded, "tipo_cuentas.added")
        pub.subscribe(self.tipoCuentaDeleted, "tipo_cuentas.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnModify, self.frame.btn_modify)
        self.frame.Bind(wx.EVT_BUTTON, self.OnNew, self.frame.btn_add)
        self.frame.Bind(wx.EVT_BUTTON, self.OnDelete, self.frame.btn_delete)
        self.frame.Bind(wx.EVT_BUTTON, self.OnMayor, self.frame.btn_mayor)
示例#8
0
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = ObjectListFrameClient(self.main_frame)
        self.model = ObjectListModel(Client)

        self.setupListColumns()
        self.setupSearchBy()
        self.loadAllClients()
        self.setTitle()
        # self.bindEvents()

        pub.subscribe(self.clientChanged, "client.changed")
        pub.subscribe(self.clientAdded, "clients.added")
        pub.subscribe(self.clientDeleted, "clients.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnModify, self.frame.btn_modify)
        self.frame.Bind(wx.EVT_BUTTON, self.OnNew, self.frame.btn_add)
        self.frame.Bind(wx.EVT_BUTTON, self.OnDelete, self.frame.btn_delete)
        self.frame.Bind(wx.EVT_BUTTON, self.OnAdmCuent, self.frame.btn_admCuent)
        self.frame.Bind(wx.EVT_BUTTON, self.OnVerFactura, self.frame.btn_verFact)
示例#9
0
class FacturaController:
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = VerFacturas(self.main_frame)
        self.model = ObjectListModel(Factura)

        self.frame.comboBoxFiltroEmpreFac.Enable(False)
        self.setupListColumns()
        self.pasarTipoCuenta("")
        self.pasarEmpresaCuenta("")
        self.cargarFacturas()

        pub.subscribe(self.pasarEmpresaCuenta, "tipo_cuentas.changed")
        pub.subscribe(self.pasarEmpresaCuenta, "tipo_cuentas.added")
        pub.subscribe(self.pasarEmpresaCuenta2, "tipo_cuentas.deleted")
        pub.subscribe(self.pasarTipoCuenta2, "tipo_cuentas.deleted")
        pub.subscribe(self.pasarTipoCuenta, "tipo_cuentas.added")
        pub.subscribe(self.pasarTipoCuenta, "tipo_cuenta.changed")
        pub.subscribe(self.facturaChanged, "factura.changed")
        pub.subscribe(self.facturaAdded, "facturas.added")
        pub.subscribe(self.facturaDeleted, "facturas.deleted")

        self.frame.comboBoxFiltroFac.Bind(wx.EVT_COMBOBOX, self.onCombo)

    def cargarFacturas(self):
        # facturas =	self.model.getObjects()

        for i in self.model.getObjects():

            tipocuenta = i.getFieldValue("cuenta").tipocuenta
            self.frame.insertRow(
                (
                    i.getId(),
                    (
                        "",
                        tipocuenta.tipo,
                        tipocuenta.empresa,
                        i.model.periodo,
                        str(i.model.monto),
                        str(i.model.fechaPago),
                    ),
                )
            )

    def cargarFactFiltrado(self, filtro):
        tipo = ObjectListModel(TipoCuenta).getFilteredData(**{"tipo": filtro})
        tipol = []
        for i in tipo:
            tipol.append(i.model)
        cuenta = ObjectListModel(Cuenta).getFilteredData(**{"tipocuenta__in": tipol})

        facturas = self.model.getFilteredData(**{"cuenta__in": cuenta})
        for i in facturas:

            self.frame.insertRow(
                (i.getId(), ("", filtro, i.model.empresa, i.model.periodo, str(i.model.monto), i.model.fechaPago))
            )

    def onCombo(self, event):
        filtrado = self.frame.comboBoxFiltroFac.GetValue()
        self.frame.list_objects.Clear()
        if filtrado == "":
            self.cargarFacturas()
            self.frame.comboBoxFiltroEmpreFac.Enable(False)
        else:
            self.frame.comboBoxFiltroEmpreFac.Enable(True)
            self.cargarFactFiltrado(filtrado)

        event.Skip()

    def show(self):

        self.frame.ShowModal()

    def facturaChanged():
        pass

    def facturaAdded(self, object):
        self.frame.insertRow(
            (
                object.getId(),
                (
                    "",
                    object.model.tipo,
                    object.model.empresa,
                    object.model.periodo,
                    object.model.monto,
                    object.model.fechaPago,
                ),
            )
        )

    def facturaDeleted():
        pass

    def setupListColumns(self):

        self.frame.setColumns(
            (("Titular", 120), ("Tipo", 120), ("Empresa", 120), ("Periodo", 120), ("Monto", 120), ("Fecha pago", 120))
        )

    def facturasPorCliente(self, facturas):

        for fact in facturas:
            self.frame.insertRow(
                (
                    fact.getId(),
                    (
                        fact.model.titular,
                        fact.model.tipo,
                        fact.model.empresa,
                        fact.model.periodo,
                        fact.model.monto,
                        fact.model.fechaPago,
                    ),
                )
            )

    def pasarEmpresaCuenta(self, object):
        arreglo = []

        for i in ObjectListModel(TipoCuenta).getObjects():
            arreglo.append(i.getFieldValue("empresa"))

        self.frame.setFiltrarBotonesEmpresa(arreglo)

    def pasarEmpresaCuenta2(self, object_id):
        arreglo = []

        for i in ObjectListModel(TipoCuenta).getObjects():
            arreglo.append(i.getFieldValue("empresa"))

        self.frame.setFiltrarBotonesEmpresa(arreglo)

    def pasarTipoCuenta(self, object):
        arreglo = []

        for i in ObjectListModel(TipoCuenta).getObjects():
            arreglo.append(i.getFieldValue("tipo"))

        self.frame.setFiltrarBotonesTipo(arreglo)

    def pasarTipoCuenta2(self, object_id):
        arreglo = []

        for i in ObjectListModel(TipoCuenta).getObjects():
            arreglo.append(i.getFieldValue("tipo"))

        self.frame.setFiltrarBotonesTipo(arreglo)

    def setFacturas(self, arreglo):
        self.frame.setDatos(arreglo)
示例#10
0
class cuentasController:
    def __init__(self, parent, cuentas, cliente):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = AdmCuentas(self.main_frame)
        self.model = ObjectListModel(Cuenta)
        self.modelTipo = ObjectListModel(TipoCuenta)

        self.setupListColumns()
        self.loadAllCuentas()
        self.cargarDatos(cuentas, cliente)
        self.setTitle(cliente)

        pub.subscribe(self.cuentaAgregada, "cuentas.added")

        pub.subscribe(self.cuentaChanged, "tipo_cuenta.changed")
        pub.subscribe(self.cuentaAdded, "tipo_cuentas.added")
        pub.subscribe(self.cuentaDeleted, "tipo_cuentas.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnVincular, self.frame.btnVincCue)
        self.frame.Bind(wx.EVT_BUTTON, self.OnCargFact, self.frame.btnAgregFac)

    def OnCargFact(self, event):
        cuentaId = self.getFocusedCuentaId("listCueVinc")

        if cuentaId != -1:

            try:
                self.cargarFact.show()
            except:
                self.cargarFact = cargarFact(self.frame)
                self.cargarFact.show()

            self.cargarFact.cargarDatos(cuentaId)

        event.Skip()

    def OnVincular(self, event):
        cuentaId = self.getFocusedCuentaId("listCueCarg")
        if cuentaId != -1:

            try:
                self.vincular.show()
            except:
                self.vincular = VincularCuentasController(self.main_frame, cuentaId, self.clienteId)
                self.vincular.show()
        event.Skip()

    def getFocusedCuentaId(self, list):
        lista = getattr(self.frame, list)
        selected_item_idx = lista.GetFocusedItem()

        if selected_item_idx != -1:

            item = lista.GetItem(selected_item_idx)
            cid = int(item.GetData())

        else:

            cid = -1

            info_dlg = wx.MessageDialog(
                self.frame,
                "Debe seleccionar una cuenta primero",
                caption="Error",
                style=wx.OK | wx.CENTRE | wx.ICON_ERROR,
            )

            info_dlg.ShowModal()
            info_dlg.Destroy()

        return cid

    def cargarDatos(self, cuentas, cliente):
        self.clienteId = cliente
        for cuent in cuentas:
            self.frame.insertRow("listCueVinc", (cuent.getId(), (str(cuent.model.tipocuenta),)))

    def cuentaChanged(self, object):
        item_idx = self.frame.listCueCarg.FindItemData(-1, object.getId())

        tipo = object.getFieldValue("tipo")
        empresa = object.getFieldValue("empresa")

        self.frame.setRow("listCueCarg", item_idx, (tipo + " - " + empresa,))

        item_idx = self.frame.listCueVinc.FindItemData(-1, object.getId())

        if item_idx != -1:
            self.frame.setRow("listCueVinc", item_idx, (tipo + " - " + empresa,))

    def cuentaAgregada(self, object):
        self.frame.insertRow(
            "listCueVinc", (object.getId(), (object.model.tipocuenta.tipo + " - " + object.model.tipocuenta.empresa,))
        )

    def cuentaAdded(self, object):
        self.frame.insertRow("listCueCarg", (object.getId(), (object.model.tipo + " - " + object.model.empresa,)))

    def cuentaDeleted(self, object_id):
        item_idx = self.frame.listCueCarg.FindItemData(-1, object_id)
        self.frame.deleteRow("listCueCarg", item_idx)
        item_idx = self.frame.listCueVinc.FindItemData(-1, object_id)
        self.frame.deleteRow("listCueVinc", item_idx)

    def show(self):
        self.frame.ShowModal()

    def setupListColumns(self):

        self.frame.setColumns("listCueCarg", (("Seleccione", 425),))
        self.frame.setColumns("listCueVinc", (("Cuentas", 400),))

    def setTitle(self, cliente):
        client_model = ObjectListModel(Client).getObjectById(cliente).model
        self.frame.SetTitle(u"Administrar cuentas de " + client_model.name)

    def loadAllCuentas(self):
        for cuent in self.modelTipo.getObjects():
            self.frame.insertRow("listCueCarg", (cuent.getId(), (cuent.model.tipo + " - " + cuent.model.empresa,)))
示例#11
0
class ClientsController:
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = ObjectListFrameClient(self.main_frame)
        self.model = ObjectListModel(Client)

        self.setupListColumns()
        self.setupSearchBy()
        self.loadAllClients()
        self.setTitle()
        # self.bindEvents()

        pub.subscribe(self.clientChanged, "client.changed")
        pub.subscribe(self.clientAdded, "clients.added")
        pub.subscribe(self.clientDeleted, "clients.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnModify, self.frame.btn_modify)
        self.frame.Bind(wx.EVT_BUTTON, self.OnNew, self.frame.btn_add)
        self.frame.Bind(wx.EVT_BUTTON, self.OnDelete, self.frame.btn_delete)
        self.frame.Bind(wx.EVT_BUTTON, self.OnAdmCuent, self.frame.btn_admCuent)
        self.frame.Bind(wx.EVT_BUTTON, self.OnVerFactura, self.frame.btn_verFact)

    def setupListColumns(self):

        self.frame.setColumns((("ID", 100), ("Nombre", 200), ("DNI/CUIL", 150)))

        self.frame.setResizableColumn(2)

    def setupSearchBy(self):

        self.frame.setSearchBy(["Nombre", "ID"])

    def setTitle(self):

        self.frame.SetTitle("Lista de Clientes")

    def loadAllClients(self):

        for client in self.model.getObjects():
            self.frame.insertRow((client.getId(), (str(client.model.pk), client.model.name, client.model.dni_cuil)))

    def bindEvents(self):

        # Bind event to DClick on ListItem
        self.frame.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnListItemActivated)

    def show(self):

        self.frame.Show()

    def setModel(self, client_dialog, model):

        controls = client_dialog.getControls()
        field_names = model.getFieldNames()

        for field in controls:
            if field in field_names:

                value = model.getFieldValue(field)
                client_dialog.getControl(field).SetValue(str(value))

                # Setting name in dialog title
        client_dialog.SetTitle("Cliente: %s" % model.getFieldValue("name"))

        client_dialog.setUnmodified()

    def saveModel(self, client_dialog, model=None):

        controls = client_dialog.getControls()
        field_names = self.model.getFieldNames()

        fields_to_save = {}

        for field in controls:
            if field in field_names:

                value = client_dialog.getControl(field).GetValue()
                # model.setFieldValue(field, value)
                fields_to_save[field] = value

        if model is not None:
            model.setFieldsValues(fields_to_save)
        else:
            self.model.createObject(fields_to_save)

    def clientChanged(self, object):

        # print "el cliente %d cambio" % object_id
        item_idx = self.frame.list_objects.FindItemData(-1, object.getId())

        pk = object.getFieldValue("pk")
        name = object.getFieldValue("name")
        dni_cuil = object.getFieldValue("dni_cuil")

        self.frame.setRow(item_idx, (str(pk), name, dni_cuil))

    def clientAdded(self, object):

        self.frame.insertRow((object.getId(), (str(object.model.pk), object.model.name, object.model.dni_cuil)))

    def clientDeleted(self, object_id):

        item_idx = self.frame.list_objects.FindItemData(-1, object_id)
        self.frame.deleteRow(item_idx)

    def showClientDialog(self, client_model=None):

        # Show the Client Frame
        client_dialog = ClientDialog(self.frame)

        if client_model is not None:

            # Existent Client
            self.setModel(client_dialog, client_model)

            # Save Model Data
            if client_dialog.ShowModal() == wx.ID_OK:
                self.saveModel(client_dialog, client_model)

        else:

            # Create New Client
            client_dialog.SetTitle("Nuevo Cliente")
            if client_dialog.ShowModal() == wx.ID_OK:
                self.saveModel(client_dialog)

        client_dialog.Destroy()

    def getFocusedClientId(self):

        selected_item_idx = self.frame.list_objects.GetFocusedItem()

        if selected_item_idx != -1:

            item = self.frame.list_objects.GetItem(selected_item_idx)
            cid = int(item.GetData())

        else:

            cid = -1

            info_dlg = wx.MessageDialog(
                self.frame,
                "Debe seleccionar un cliente primero",
                caption="Error",
                style=wx.OK | wx.CENTRE | wx.ICON_ERROR,
            )

            info_dlg.ShowModal()
            info_dlg.Destroy()

        return cid

    def OnListItemActivated(self, event):

        client_id = int(event.GetData())
        client_model = self.model.getObjectById(client_id)

        self.showClientDialog(client_model)

        event.Skip()

    def OnAdmCuent(self, event):

        client_id = self.getFocusedClientId()

        if client_id != -1:

            cuentas = ObjectListModel(Cuenta).getFilteredData(**{"cliente_id": client_id})

            try:
                self.cuentasController.Show()
            except:
                self.cuentasController = cuentasController(self.frame, cuentas, client_id)
                self.cuentasController.show()

        event.Skip()

    def OnVerFactura(self, event):

        client_id = self.getFocusedClientId()

        if client_id != -1:

            cuentas = ObjectListModel(Cuenta).getFilteredData(**{"cliente_id": client_id})

            arreglo = []
            for i in cuentas:
                arreglo.append(i.getId())

            facturas = ObjectListModel(Factura).getFilteredData(**{"cuenta__in": arreglo})
            cliente = self.model.getObjectById(client_id)
            arregloCliente = []
            arregloCliente.append(cliente.getFieldValue("name"))
            arregloCliente.append(cliente.getFieldValue("dni_cuil"))
            try:
                self.facturas_controller.show()
            except:
                self.facturas_controller = FacturaController(self.frame)
                self.facturas_controller.show()
            self.facturas_controller.facturasPorCliente(facturas)

            self.facturas_controller.setFacturas(arregloCliente)
        event.Skip()

    def OnModify(self, event):

        client_id = self.getFocusedClientId()

        if client_id != -1:
            client_model = self.model.getObjectById(client_id)
            self.showClientDialog(client_model)

    def OnNew(self, event):

        self.showClientDialog()
        event.Skip()

    def OnDelete(self, event):

        client_id = self.getFocusedClientId()

        if client_id != -1:

            client_model = self.model.getObjectById(client_id)

            confirm_dlg = wx.MessageDialog(
                self.frame,
                "Esta seguro que desea eliiminar el cliente %s?" % client_model.getFieldValue("name"),
                caption="Confirmar",
                style=wx.OK | wx.CANCEL | wx.CENTRE | wx.ICON_QUESTION,
            )

            if confirm_dlg.ShowModal() == wx.ID_OK:
                self.model.deleteObjectById(client_model.getId())
示例#12
0
class NuevoTipoCuentaController:
    def __init__(self, parent):

        self.main_controller = parent
        self.main_frame = parent.getFrame()

        self.frame = ObjectListFrameTipoCuenta(self.main_frame, size=(700, 500))
        self.model = ObjectListModel(TipoCuenta)

        self.setupListColumns()
        self.setupSearchBy()
        self.loadAllTipoCuenta()
        self.setTitle()
        self.bindEvents()

        pub.subscribe(self.tipoCuentaChanged, "tipo_cuenta.changed")
        pub.subscribe(self.tipoCuentaAdded, "tipo_cuentas.added")
        pub.subscribe(self.tipoCuentaDeleted, "tipo_cuentas.deleted")

        self.frame.Bind(wx.EVT_BUTTON, self.OnModify, self.frame.btn_modify)
        self.frame.Bind(wx.EVT_BUTTON, self.OnNew, self.frame.btn_add)
        self.frame.Bind(wx.EVT_BUTTON, self.OnDelete, self.frame.btn_delete)
        self.frame.Bind(wx.EVT_BUTTON, self.OnMayor, self.frame.btn_mayor)

    def setupListColumns(self):

        self.frame.setColumns((("Tipo", 100), ("Empresa", 200)))

        self.frame.setResizableColumn(2)

    def setupSearchBy(self):

        self.frame.setSearchBy(["Tipo", "Empresa"])

    def setTitle(self):

        self.frame.SetTitle("Lista de cuentas")

    def loadAllTipoCuenta(self):

        for tipoCuenta in self.model.getObjects():
            self.frame.insertRow((tipoCuenta.getId(), (tipoCuenta.model.tipo, tipoCuenta.model.empresa)))

    def bindEvents(self):

        # Bind event to DClick on ListItem
        self.frame.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.OnListItemActivated)

    def show(self):

        self.frame.Show()

    def setModel(self, tipoCuenta_dialog, model):

        controls = tipoCuenta_dialog.getControls()
        field_names = model.getFieldNames()

        for field in controls:
            if field in field_names:

                value = model.getFieldValue(field)
                tipoCuenta_dialog.getControl(field).SetValue(unicode(value))

                # Setting name in dialog title
        tipoCuenta_dialog.SetTitle("Cuenta: %s" % model.getFieldValue("tipo"))

        tipoCuenta_dialog.setUnmodified()

    def saveModel(self, tipoCuenta_dialog, model=None):

        controls = tipoCuenta_dialog.getControls()
        field_names = self.model.getFieldNames()

        fields_to_save = {}

        for field in controls:
            if field in field_names:

                value = tipoCuenta_dialog.getControl(field).GetValue()
                # model.setFieldValue(field, value)
                fields_to_save[field] = value

        if model is not None:
            model.setFieldsValues(fields_to_save)
        else:
            self.model.createObject(fields_to_save)

    def tipoCuentaChanged(self, object):

        # print "el cliente %d cambio" % object_id
        item_idx = self.frame.list_objects.FindItemData(-1, object.getId())

        tipo = object.getFieldValue("tipo")
        empresa = object.getFieldValue("empresa")

        self.frame.setRow(item_idx, (tipo, empresa))

    def tipoCuentaAdded(self, object):

        self.frame.insertRow((object.getId(), (object.model.tipo, object.model.empresa)))

    def tipoCuentaDeleted(self, object_id):

        item_idx = self.frame.list_objects.FindItemData(-1, object_id)
        self.frame.deleteRow(item_idx)

    def showTipoCuentaDialog(self, tipoCuenta_model=None):

        # Show the Client Frame
        tipoCuenta_dialog = agregarNuevoTipoCuenta(self.frame)

        if tipoCuenta_model is not None:

            # Existent Client
            self.setModel(tipoCuenta_dialog, tipoCuenta_model)

            # Save Model Data
            if tipoCuenta_dialog.ShowModal() == wx.ID_OK:
                self.saveModel(tipoCuenta_dialog, tipoCuenta_model)

        else:

            # Create New Client
            tipoCuenta_dialog.SetTitle("Nueva Cuenta")
            if tipoCuenta_dialog.ShowModal() == wx.ID_OK:
                self.saveModel(tipoCuenta_dialog)

        tipoCuenta_dialog.Destroy()

    def getFocusedTipoCuentaId(self):

        selected_item_idx = self.frame.list_objects.GetFocusedItem()

        if selected_item_idx != -1:

            item = self.frame.list_objects.GetItem(selected_item_idx)
            cid = int(item.GetData())

        else:

            cid = -1

            info_dlg = wx.MessageDialog(
                self.frame,
                "Debe seleccionar una cuenta primero",
                caption="Error",
                style=wx.OK | wx.CENTRE | wx.ICON_ERROR,
            )

            info_dlg.ShowModal()
            info_dlg.Destroy()

        return cid

    def OnListItemActivated(self, event):

        tipoCuentaId = int(event.GetData())
        tipoCuenta_model = self.model.getObjectById(tipoCuentaId)

        self.showTipoCuentaDialog(tipoCuenta_model)

        event.Skip()

    def OnMayor(self, event):
        tipoCuentaId = self.getFocusedTipoCuentaId()

        if tipoCuentaId != -1:
            tipocuenta = self.model.getObjectById(tipoCuentaId)
            listaCuentas = ObjectListModel(Cuenta).getFilteredData(**{"tipocuenta_id": tipoCuentaId})
            self.mayor = CuentaMayor(self.frame)
            self.mayor.setColumns((("DEBE", 295), ("HABER", 295)))
            self.mayor.setResizableColumn(2)
            self.mayor.setTitle(
                "Mayor cuenta " + unicode(tipocuenta.model.tipo) + " - " + unicode(tipocuenta.model.empresa)
            )
            # self.armarMayor(listaCuentas,tipocuenta)
            self.mayor.Layout()
            self.mayor.Show()

    def armarMayor(self, obj, tipocuenta):
        facturas = ObjectListModel(Factura).getFilteredData(**{"cuenta_id": obj.getId()})
        pagos = ObjectListModel(PagosPorCliente).getFilteredData(**{"factura__in": facturas})
        cobros = ObjectListModel(Factura).getFilteredData(**{"factura__in": facturas})
        for obj in facturas:
            self.mayor.insertRow((obj.getId(), (cobros)))

    def OnModify(self, event):

        tipoCuentaId = self.getFocusedTipoCuentaId()

        if tipoCuentaId != -1:
            tipoCuenta_model = self.model.getObjectById(tipoCuentaId)
            self.showTipoCuentaDialog(tipoCuenta_model)

    def OnNew(self, event):

        self.showTipoCuentaDialog()
        event.Skip()

    def OnDelete(self, event):
        tipoCuentaId = self.getFocusedTipoCuentaId()

        if tipoCuentaId != -1:

            tipoCuenta_model = self.model.getObjectById(tipoCuentaId)

            confirm_dlg = wx.MessageDialog(
                self.frame,
                "Esta seguro que desea eliminar la cuenta %s?" % tipoCuenta_model.getFieldValue("tipo"),
                caption="Confirmar",
                style=wx.OK | wx.CANCEL | wx.CENTRE | wx.ICON_QUESTION,
            )

            if confirm_dlg.ShowModal() == wx.ID_OK:
                self.model.deleteObjectById(tipoCuenta_model.getId())