예제 #1
0
    def onKeyPressedGridFactura(self, key):
        col = self.view.gridFactura.currentColumn()
        row = self.view.gridFactura.currentRow()
        if key == Qt.Key_F2 and col == 1:
            _ventana = UiBusqueda()
            _ventana.modelo = Articulo
            _ventana.cOrden = Articulo.nombre
            _ventana.campoBusqueda = _ventana.cOrden
            _ventana.campoRetorno = Articulo.idarticulo
            _ventana.campoRetornoDetalle = Articulo.nombre
            _ventana.campos = ['idarticulo', 'nombre', 'preciopub']
            _ventana.CargaDatos()
            _ventana.exec_()
            if _ventana.lRetval:
                self.view.gridFactura.ModificaItem(
                    valor=_ventana.ValorRetorno,
                    fila=self.view.gridFactura.currentRow(),
                    col=1)
                self.view.gridFactura.ModificaItem(
                    valor=_ventana.campoRetornoDetalle,
                    fila=self.view.gridFactura.currentRow(),
                    col=2)
                art = Articulo.get_by_id(_ventana.ValorRetorno)
                self.view.gridFactura.ModificaItem(
                    valor=art.preciopub,
                    fila=self.view.gridFactura.currentRow(),
                    col='Unitario')
            self.view.gridFactura.setFocus()
        if key in [Qt.Key_Return, Qt.Key_Enter, Qt.Key_Tab] and col == 1:
            if float(
                    self.view.gridFactura.ObtenerItem(fila=row,
                                                      col='Unitario')) == 0:
                codigo = self.view.gridFactura.ObtenerItem(fila=row, col=1)
                if codigo:
                    art = Articulo.get_by_id(codigo)
                    self.view.gridFactura.ModificaItem(
                        valor=art.preciopub,
                        fila=self.view.gridFactura.currentRow(),
                        col='Unitario')

        if key in [Qt.Key_Return, Qt.Key_Enter, Qt.Key_Tab]:
            if col < self.view.gridFactura.columnCount():
                self.view.gridFactura.setCurrentCell(row, col + 1)
            else:
                self.view.gridFactura.setCurrentCell(row + 1, 0)

        if key == Qt.Key_Down and row + 1 == self.view.gridFactura.rowCount():
            self.AgregaArt()

        self.SumaTodo()
예제 #2
0
    def Validacion(self):
        retorno = True
        if not self.view.validaCliente.text():
            Ventanas.showAlert(
                LeerIni('nombre_sistema'),
                "ERROR: No se ha especificado un cliente valido")
            retorno = False

        for x in range(self.view.gridFactura.rowCount()):
            iva = float(self.view.gridFactura.ObtenerItem(fila=x, col='IVA'))
            if str(iva) not in FEv1().TASA_IVA:
                Ventanas.showAlert(
                    LeerIni('nombre_sistema'),
                    "Error el item {} no tiene un IVA valido".format(x + 1))
                retorno = False
            codigo = self.view.gridFactura.ObtenerItem(fila=x, col='Codigo')
            try:
                articulo = Articulo.get_by_id(codigo)
            except Articulo.DoesNotExist:
                Ventanas.showAlert(
                    LeerIni('nombre_sistema'),
                    "Error el item {} tiene un articulo no valido".format(x +
                                                                          1))
                retorno = False

        return retorno
예제 #3
0
class ArticulosView(ABM):

    model = Articulo()
    camposAMostrar = [Articulo.idarticulo, Articulo.nombre, Articulo.preciopub]
    ordenBusqueda = Articulo.nombre
    campoClave = Articulo.idarticulo

    def __init__(self, *args, **kwargs):
        ABM.__init__(self, *args, **kwargs)

    @inicializar_y_capturar_excepciones
    def ArmaCarga(self, *args, **kwargs):
        self.layoutID = self.ArmaEntrada('idarticulo', texto='Codigo')
        self.ArmaEntrada('nombre', boxlayout=self.layoutID)
        self.layoutNombreTicket = self.ArmaEntrada('nombreticket', texto='Nombre Ticket')
        self.ArmaEntrada('codbarra', texto='Codigo de barra', boxlayout=self.layoutNombreTicket)
        self.layoutUnidad = self.ArmaEntrada(nombre='unidad', control=Unidades.ComboUnidad())
        self.ArmaEntrada('grupo', boxlayout=self.layoutUnidad, control=Grupos.ComboGrupo())
        self.lblNombreGrupo = Etiqueta()
        self.layoutUnidad.addWidget(self.lblNombreGrupo)
        self.controles['grupo'].widgetNombre = self.lblNombreGrupo
        self.layoutProvedor = self.ArmaEntrada('provppal', texto='Proveedor principal', control=Proveedores.Valida())
        self.lblNombreProveedor = Etiqueta()
        self.layoutProvedor.addWidget(self.lblNombreProveedor)
        self.controles['provppal'].widgetNombre = self.lblNombreProveedor
        self.ArmaEntrada('tipoiva', boxlayout=self.layoutProvedor, control=ComboIVA())
        self.lblNombreTipoiva = Etiqueta()
        self.layoutProvedor.addWidget(self.lblNombreTipoiva)
        self.controles['tipoiva'].widgetNombre = self.lblNombreTipoiva
        self.ArmaEntrada('modificaprecios', boxlayout=self.layoutProvedor, control=CheckBox(), texto="Modifica precios?")
        self.layoutCosto = self.ArmaEntrada('costo', texto='Costo', control=Spinner())
        self.ArmaEntrada('preciopub', boxlayout=self.layoutCosto, control=Spinner(), texto="Precio al publico")
        self.ArmaEntrada('concepto', boxlayout=self.layoutCosto, control=ComboConceptoFacturacion())

    @inicializar_y_capturar_excepciones
    def btnAceptarClicked(self, *args, **kwargs):
        # for x in self.controles:
        #     print("Control {} Valor {} tipo {}".format(x, self.controles[x].text(), type(self.controles[x].text())))
        if self.tipo == 'M':
            articulo = Articulo.get_by_id(self.controles[Articulo.idarticulo.column_name].text())
            articulo.idarticulo = int(self.controles['idarticulo'].text())
        else:
            articulo = Articulo()
        articulo.nombre = self.controles['nombre'].text()[:100]
        articulo.nombreticket = self.controles['nombreticket'].text()[:30]
        articulo.unidad = self.controles['unidad'].text() or 'UN'
        articulo.grupo = self.controles['grupo'].text() or 1
        articulo.costo = self.controles['costo'].value()
        articulo.provppal = int(str(self.controles['provppal'].text()) or 0)
        articulo.tipoiva = str(self.controles['tipoiva'].text()).zfill(2)
        articulo.modificaprecios = self.controles['modificaprecios'].text()
        articulo.preciopub = self.controles['preciopub'].value()
        articulo.concepto = self.controles['concepto'].text()
        articulo.codbarra = self.controles['codbarra'].text()
        articulo.save()
        ABM.btnAceptarClicked(self)
예제 #4
0
    def ExportaExcel(self, mostrar=True):
        self.view.avance.setVisible(True)
        cArchivo = QFileDialog.getSaveFileName(caption="Guardar archivo",
                                               directory="",
                                               filter="*.XLSX")[0]
        if not cArchivo:
            return
        self.cArchivoGenerado = cArchivo
        workbook = xlsxwriter.Workbook(cArchivo)
        worksheet = workbook.add_worksheet()

        data = Cabfact().select().where(
            Cabfact.fecha.between(self.view.lineDesdeFecha.date().toPyDate(),
                                  self.view.lineHastaFecha.date().toPyDate()))
        fila, col = 0, 0
        worksheet.write(fila, 0, 'Fecha')
        worksheet.write(fila, 1, 'Tipo Comprobante')
        worksheet.write(fila, 2, 'Numero')
        worksheet.write(fila, 3, 'Cliente')
        worksheet.write(fila, 4, 'Reg IVA')
        worksheet.write(fila, 5, 'CUIT')
        worksheet.write(fila, 6, 'Neto 21')
        worksheet.write(fila, 7, 'Neto 10.5')
        worksheet.write(fila, 8, 'Operaciones Exentas')
        worksheet.write(fila, 9, 'IVA')
        worksheet.write(fila, 10, 'Percep. DGR')
        worksheet.write(fila, 11, 'CAE')
        worksheet.write(fila, 12, 'Venc CAE')
        worksheet.write(fila, 13, 'Producto')
        worksheet.write(fila, 14, 'Servicio')
        worksheet.write(fila, 15, 'Total')
        fila += 1
        totalData = len(data)
        cant = 0.0
        for d in data:
            QApplication.processEvents()
            cant += 1.
            self.view.avance.actualizar(cant / totalData * 100.)
            if str(self.view.controles['desdeptovta'].text()).zfill(4) <= d.numero[:4] <= \
                                str(self.view.controles['hastaptovta'].text()).zfill(4) \
                    and d.tipocomp.exporta:
                worksheet.write(fila, 0, d.fecha.strftime('%d/%m/%Y'))
                worksheet.write(fila, 1, d.tipocomp.nombre)
                worksheet.write(fila, 2, d.numero)
                worksheet.write(fila, 3, d.cliente.nombre)
                worksheet.write(fila, 4, d.cliente.tiporesp.nombre)
                worksheet.write(fila, 5, d.cliente.cuit)
                worksheet.write(
                    fila, 6,
                    d.netoa if d.tipocomp.lado == 'D' else d.netoa * -1)
                worksheet.write(
                    fila, 7,
                    d.netob if d.tipocomp.lado == 'D' else d.netob * -1)
                worksheet.write(
                    fila, 9, d.iva if d.tipocomp.lado == 'D' else d.iva * -1)
                worksheet.write(
                    fila, 10, d.percepciondgr
                    if d.tipocomp.lado == 'D' else d.percepciondgr * -1)
                worksheet.write(fila, 11, d.cae)
                worksheet.write(
                    fila, 12,
                    d.venccae.strftime('%d/%m/%Y') if d.venccae else '')
                deta = Detfact.select().where(Detfact.idcabfact == d.idcabfact)
                totserv = decimal.Decimal.from_float(0.)
                totprod = totserv
                op_exentas = 0
                for det in deta:
                    art = Articulo.get_by_id(det.idarticulo)
                    if art.concepto.strip():
                        if int(art.concepto.strip()) == FEv1.SERVICIOS:
                            totserv += det.precio * det.cantidad if d.tipocomp.lado == 'D' else \
                                det.precio * det.cantidad * -1
                        else:
                            totprod += det.precio * det.cantidad if d.tipocomp.lado == 'D' else \
                                det.precio * det.cantidad * -1
                    else:
                        totprod += det.precio * det.cantidad if d.tipocomp.lado == 'D' else \
                            det.precio * det.cantidad * -1
                    if det.montoiva == 0:
                        op_exentas += det.precio * det.cantidad
                worksheet.write(fila, 8, op_exentas)
                worksheet.write(fila, 13, totprod)
                worksheet.write(fila, 14, totserv)
                worksheet.write(fila, 15,
                                '=sum(G{}:J{})'.format(fila + 1, fila + 1))
                fila += 1
        worksheet.write(fila, 6, '=sum(G{}:G{})'.format(2, fila))
        worksheet.write(fila, 7, '=sum(H{}:H{})'.format(2, fila))
        worksheet.write(fila, 8, '=sum(I{}:I{})'.format(2, fila))
        worksheet.write(fila, 9, '=sum(J{}:J{})'.format(2, fila))
        worksheet.write(fila, 10, '=sum(K{}:K{})'.format(2, fila))
        worksheet.write(fila, 13, '=sum(N{}:N{})'.format(2, fila))
        worksheet.write(fila, 14, '=sum(O{}:O{})'.format(2, fila))
        worksheet.write(fila, 15, '=sum(P{}:P{})'.format(2, fila))
        workbook.close()
        self.view.avance.setVisible(False)
        if mostrar:
            AbrirArchivo(cArchivo)
예제 #5
0
    def GrabaFE(self, *args, **kwargs):
        self.view.layoutFactura.AssignNumero()
        cabfact = Cabfact()
        cabfact.tipocomp = self.tipo_cpte
        cabfact.cliente = self.cliente.idcliente
        cabfact.fecha = self.view.lineEditFecha.date().toPyDate()
        cabfact.numero = self.view.layoutFactura.numero
        cabfact.neto = sum([i for i in self.netos.values()])
        cabfact.netoa = self.netos[21]
        cabfact.netob = self.netos[10.5]
        cabfact.iva = self.view.lineEditTotalIVA.value()
        cabfact.total = self.view.lineEditTotal.value()
        if self.view.cboFormaPago.text() == 'Contado':
            cabfact.saldo = 0.00
        else:
            cabfact.saldo = self.view.lineEditTotal.value()
        cabfact.tipoiva = self.cliente.tiporesp.idtiporesp
        cabfact.cajero = 1  #por defecto cajero
        cabfact.formapago = 1 if self.view.cboFormaPago.text(
        ) == 'Contado' else 2
        cabfact.percepciondgr = self.view.lineEditTributos.value()
        cabfact.nombre = self.view.lblNombreCliente.text()
        cabfact.domicilio = self.view.lineEditDomicilio.text()
        cabfact.cae = self.view.lineditCAE.text()
        cabfact.venccae = self.view.fechaVencCAE.date().toPyDate()
        cabfact.concepto = self.concepto
        cabfact.desde = self.view.fechaDesde.date().toPyDate()
        cabfact.hasta = self.view.fechaHasta.date().toPyDate()
        cabfact.save()

        for x in range(self.view.gridFactura.rowCount()):
            codigo = self.view.gridFactura.ObtenerItem(fila=x, col='Codigo')
            cantidad = float(
                self.view.gridFactura.ObtenerItem(fila=x, col='Cant.'))
            importe = float(
                self.view.gridFactura.ObtenerItem(fila=x, col='SubTotal'))
            iva = float(self.view.gridFactura.ObtenerItem(fila=x, col='IVA'))
            detalle = self.view.gridFactura.ObtenerItem(fila=x, col='Detalle')
            try:
                articulo = Articulo.get_by_id(codigo)
                detfact = Detfact()
                detfact.idcabfact = cabfact.idcabfact
                detfact.idarticulo = codigo
                detfact.cantidad = cantidad
                detfact.unidad = articulo.unidad
                detfact.costo = articulo.costo

                if LeerIni(clave='cat_iva', key='WSFEv1') == 1:
                    if self.tipo_cpte in [6, 7, 8]:
                        detfact.precio = importe / cantidad
                    else:
                        detfact.precio = (importe +
                                          importe * iva / 100) / cantidad
                else:
                    detfact.precio = importe / cantidad
                try:
                    ti = Tipoiva.get(Tipoiva.iva == iva)
                    detfact.tipoiva = ti.codigo
                except Tipoiva.DoesNotExist:
                    detfact.tipoiva = articulo.tipoiva.codigo
                if self.tipo_cpte in [6, 7, 8]:
                    detfact.montoiva = importe * iva / 100
                else:
                    neto = round(importe / ((iva / 100) + 1), 3)
                    detfact.montoiva = neto * iva / 100
                if self.view.lineEditTributos.value() > 0:
                    detfact.montodgr = importe * float(
                        self.cliente.percepcion.porcentaje) / 100
                else:
                    detfact.montodgr = 0.00
                detfact.montomuni = 0.00
                detfact.descad = detalle
                detfact.detalle = detalle[:40]
                detfact.descuento = 0.00
                detfact.save()
            except peewee.DoesNotExist:
                pass
        # Agregar comprobantes asociados(si es una NC / ND):
        if str(self.view.cboComprobante.text()).find('credito'):
            cpbte = CpbteRel()
            cpbte.idcabfact = cabfact.idcabfact
            if self.tipo_cpte == 13:
                cpbte.idtipocpbte = 11
            else:
                if self.cliente.tiporesp.idtiporesp == 2:  # resp inscripto
                    cpbte.idtipocpbte = 1
                else:
                    cpbte.idtipocpbte = 6
            cpbte.numero = self.view.layoutCpbteRelacionado.numero
            cpbte.save()
        self.ImprimeFactura(idcabecera=cabfact.idcabfact)
예제 #6
0
    def SumaTodo(self):
        totalgral = 0.
        ivagral = 0.
        dgrgral = 0.
        subtotal = 0.
        self.netos = {0: 0, 10.5: 0, 21: 0}
        if not self.cliente:
            return
        try:
            impuesto = float(self.cliente.percepcion.porcentaje)
        except Impuesto.DoesNotExist:
            impuesto = decimal.Decimal.from_float(0.)
        for x in range(self.view.gridFactura.rowCount()):
            art = None
            if int(LeerIni(clave='cat_iva', key='WSFEv1')) == 6:
                self.view.gridFactura.ModificaItem(valor=21, fila=x, col='IVA')
            detalle = self.view.gridFactura.ObtenerItem(fila=x, col='Detalle')
            unitario = float(
                self.view.gridFactura.ObtenerItem(fila=x, col='Unitario'))
            if not detalle or unitario == 0:
                codigo = self.view.gridFactura.ObtenerItem(fila=x,
                                                           col='Codigo')
                try:
                    art = Articulo.get_by_id(codigo)
                except Articulo.DoesNotExist:
                    try:
                        art = Articulo.get(Articulo.codbarra == codigo)
                    except Articulo.DoesNotExist:
                        pass
                if art:
                    if not detalle:
                        self.view.gridFactura.ModificaItem(valor=art.nombre,
                                                           fila=x,
                                                           col='Detalle')
                    if unitario == 0:
                        self.view.gridFactura.ModificaItem(valor=art.preciopub,
                                                           fila=x,
                                                           col='Unitario')
            cantidad = self.view.gridFactura.ObtenerItem(fila=x, col='Cant.')
            #self.view.gridFactura.ModificaItem(valor=cantidad, fila=x, col='Cant.')
            unitario = float(
                self.view.gridFactura.ObtenerItem(fila=x, col='Unitario'))
            iva = float(self.view.gridFactura.ObtenerItem(fila=x, col='IVA'))
            total = float(cantidad) * float(unitario)
            if int(LeerIni(
                    clave='cat_iva',
                    key='WSFEv1')) == 1:  # si es Resp insc el contribuyente
                if self.tipo_cpte in [6, 7, 8]:
                    neto = round(total / ((iva / 100) + 1), 3)
                    try:
                        self.netos[iva] += neto
                    except KeyError:
                        pass
                    ivagral += (total - neto)
                    totalgral += neto
                else:
                    ivagral += total * iva / 100
                    totalgral += total
                    try:
                        self.netos[iva] += total
                    except KeyError:
                        pass
            else:
                try:
                    self.netos[iva] += total
                except KeyError:
                    pass
                totalgral += total

            # if int(LeerIni(clave='cat_iva',
            #                key='WSFEv1')) == 1:  # si es Resp insc el contribuyente
            #     ivagral += total * iva / 100
            # totalgral += total
            subtotal += total

            self.view.gridFactura.ModificaItem(valor=total,
                                               fila=x,
                                               col='SubTotal')

        if int(LeerIni(clave='cat_iva',
                       key='WSFEv1')) == 1:  # si es Resp insc el contribuyente
            dgrgral = totalgral * impuesto / 100

        if dgrgral > 0:
            row = self.view.gridAlicuotasTributos.currentRow()
            if self.view.gridAlicuotasTributos.rowCount() == 0:
                self.view.gridAlicuotasTributos.AgregaItem(items=[
                    self.cliente.percepcion.porcentaje, totalgral, dgrgral
                ])
            else:
                self.view.gridAlicuotasTributos.ModificaItem(
                    valor=totalgral, fila=row, col='Base Imponible')
                self.view.gridAlicuotasTributos.ModificaItem(valor=totalgral,
                                                             fila=row,
                                                             col='Importe')
        else:
            self.view.gridAlicuotasTributos.setRowCount(0)

        self.view.textSubTotal.setText(str(round(subtotal, self.decimales)))
        self.view.lineEditTributos.setText(str(round(dgrgral, self.decimales)))
        self.view.lineEditTotalIVA.setText(str(round(ivagral, self.decimales)))
        self.view.lineEditTotal.setText(
            str(round(totalgral + ivagral + dgrgral, 2)))
예제 #7
0
 def btnAceptarClicked(self, *args, **kwargs):
     # for x in self.controles:
     #     print("Control {} Valor {} tipo {}".format(x, self.controles[x].text(), type(self.controles[x].text())))
     if self.tipo == 'M':
         articulo = Articulo.get_by_id(self.controles[Articulo.idarticulo.column_name].text())
         articulo.idarticulo = int(self.controles['idarticulo'].text())
     else:
         articulo = Articulo()
     articulo.nombre = self.controles['nombre'].text()[:100]
     articulo.nombreticket = self.controles['nombreticket'].text()[:30]
     articulo.unidad = self.controles['unidad'].text() or 'UN'
     articulo.grupo = self.controles['grupo'].text() or 1
     articulo.costo = self.controles['costo'].value()
     articulo.provppal = int(str(self.controles['provppal'].text()) or 0)
     articulo.tipoiva = str(self.controles['tipoiva'].text()).zfill(2)
     articulo.modificaprecios = self.controles['modificaprecios'].text()
     articulo.preciopub = self.controles['preciopub'].value()
     articulo.concepto = self.controles['concepto'].text()
     articulo.codbarra = self.controles['codbarra'].text()
     articulo.save()
     ABM.btnAceptarClicked(self)
예제 #8
0
from modelos.Tipocomprobantes import TipoComprobante
from modelos.Tipodoc import Tipodoc
from modelos.Tipoiva import Tipoiva
from modelos.Tiporesp import Tiporesp
from modelos.Unidades import Unidad

if 'drop' in sys.argv:
    CpbteRel().drop_table()
    CtaCte().drop_table()
    Detfact().drop_table()
    Cabfact().drop_table()
    CabFactProv().drop_table()
    DetFactProv().drop_table()
    EmailCliente().drop_table()
    Cliente().drop_table()
    Articulo().drop_table()
    Proveedor().drop_table()
    Unidad().drop_table()
    Grupo().drop_table()
    Impuesto().drop_table()
    Formapago().drop_table()
    Tiporesp().drop_table()
    Tipodoc().drop_table()
    Localidad().drop_table()
    Tipoiva().drop_table()
    Cajero().drop_table()
    TipoComprobante().drop_table()
    CentroCosto().drop_table()

Grupo().create_table()
grupo = [
예제 #9
0
    def onClickBtnImportar(self, *args, **kwargs):
        if not os.path.isfile(self.view.textArchivo.text()) or \
            not os.path.isfile(self.view.textArchivo_det.text()):
            Ventanas.showAlert("Sistema",
                               "Archivos no validos o no encontrados")
            return

        if self.view.checkBorra.isChecked():
            self.BorraComprobantes()

        archivo = open(self.view.textArchivo.text(), "r")
        total = total_lineas_archivo(self.view.textArchivo.text())
        avance = 1
        for linea in archivo:
            avance += 1
            QApplication.processEvents()
            self.view.avance.actualizar(avance / total * 100)
            fecha_cbte = datetime.strptime(linea[0:8], "%Y%m%d").date()
            if self.view.textDesdeFecha.toPyDate(
            ) <= fecha_cbte <= self.view.textHastaFecha.toPyDate():
                tipo_doc = linea[56:58]
                nro_doc = linea[59:78][-11:]
                nombre = linea[78:108]
                pto_vta = linea[11:16]
                nro_comp = linea[17:36]
                tipo_comp = linea[8:11]
                cliente = self.VerificaCliente(tipo_doc, nro_doc, nombre)
                cabecera = self.VerificaFactura(tipo_comp, pto_vta, nro_comp)
                cabecera.tipocomp = tipo_comp
                cabecera.cliente = cliente.idcliente
                cabecera.fecha = fecha_cbte
                cabecera.numero = '{}{}'.format(pto_vta[-4:], nro_comp[-8:])
                if tipo_comp in ['011', '012', '013']:  #comprobantes sin iva
                    cabecera.neto = float(linea[109:123]) / 100
                    cabecera.iva = 0
                    cabecera.netoa = 0
                    cabecera.netob = 0
                    cabecera.descuento = 0
                    cabecera.recargo = 0
                    cabecera.total = cabecera.neto
                    cabecera.saldo = 0

                cabecera.tipoiva = cliente.tiporesp.idtiporesp
                cabecera.formapago = 1
                cabecera.cuotapago = 0
                cabecera.percepciondgr = float(linea[184:198]) / 100
                cabecera.nombre = nombre
                cabecera.domicilio = ""
                cabecera.obs = ""
                cabecera.save()
        archivo.close()

        archivo = open(self.view.textArchivo_det.text(), "r")
        total = total_lineas_archivo(self.view.textArchivo_det.text())
        avance = 1
        for linea in archivo:
            avance += 1
            QApplication.processEvents()
            self.view.avance.actualizar(avance / total * 100)
            try:
                cabecera = Cabfact.get(
                    Cabfact.tipocomp == linea[0:3],
                    Cabfact.numero == '{}{}'.format(linea[4:8], linea[20:28]))
                try:
                    detalle = Detfact.get(
                        Detfact.idcabfact == cabecera.idcabfact,
                        Detfact.idarticulo == 1)
                except DoesNotExist:
                    detalle = Detfact()
                articulo = Articulo.get_by_id(1)
                detalle.idcabfact = cabecera.idcabfact
                detalle.idarticulo = articulo.idarticulo
                detalle.cantidad = 1
                detalle.unidad = 'UN'
                detalle.costo = 0
                detalle.precio = cabecera.neto
                detalle.tipoiva = articulo.tipoiva.codigo
                detalle.montoiva = cabecera.total / (
                    articulo.tipoiva.iva / 100 +
                    1) * articulo.tipoiva.iva / 100
                detalle.montodgr = cabecera.percepciondgr
                detalle.montomuni = 0
                detalle.detalle = articulo.nombre
                detalle.descuento = 0
                detalle.save()
            except DoesNotExist:
                pass