def Transporte(self):
        if not self.IndTraslado and not self.Aduana and not self.es_exportacion:
            return False
        Transporte = collections.OrderedDict()
        if self.Patente:
            Transporte['Patente'] = self.Patente[:8]
        if self.TipoDespacho in [2, 3]:
            if self.TipoDespacho == 2:
                Transporte['RUTTrans'] = self.RUTTrans
            elif self.TipoDespacho == 3:
                if not hasattr(self, '_rut_trans'):
                    raise UserError("Debe especificar el RUT del transportista\
, en su ficha de receptor")
                Transporte['RUTTrans'] = self.RUTTrans
            if self.RUTChofer:
                Transporte['Chofer'] = collections.OrderedDict()
                Transporte['Chofer']['RUTChofer'] = self.RUTChofer
                Transporte['Chofer']['NombreChofer'] = self.NombreChofer[:30]
        if self.IndTraslado:
            Transporte['DirDest'] = self.DirDest
            if self.CmnaDest:
                Transporte['CmnaDest'] = self.CmnaDest[:20]
            Transporte['CiudadDest'] = self.CiudadDest
        if self.Aduana or self.es_exportacion:
            Transporte['Aduana'] = self.Aduana or ''
        return Transporte
    def Referencia(self):
        if not hasattr(self, '_referencias') or not self._referencias:
            return False
        lin_ref = 1
        ref_lines = []
        for ref in self._referencias:
            ref_line = collections.OrderedDict()
            ref_line['NroLinRef'] = ref.NroLinRef or lin_ref
            if not self.es_boleta():
                if ref.TpoDocRef:
                    ref_line['TpoDocRef'] = ref.TpoDocRef
                    ref_line['FolioRef'] = ref.FolioRef
                ref_line['FchRef'] = ref.FchRef or datetime.strftime(
                    datetime.now(), '%Y-%m-%d')
            if ref.CodRef:
                ref_line['CodRef'] = ref.CodRef
                if ref.CodRef == 2:
                    dice = re.compile(r'DICE:(.*)DEBE DECIR:')
                    if len(dice.findall(ref.RazonRef.upper())) == 0:
                        raise UserError('Modificación de texto debe \
llevar estrictamente las palabras Dice: y debe decir:')
            if ref.RazonRef:
                ref_line['RazonRef'] = ref.RazonRef
            if self.es_boleta():
                if self.CodVndor:
                    ref_line['CodVndor'] = self.CodVndor
                if self.CodCaja:
                    ref_line['CodCaja'] = self.CodCaja
            ref_lines.append({'Referencia': ref_line})
            lin_ref += 1
        return ref_lines
    def Detalle(self):
        if not hasattr(self, '_lineas_detalle'):
            return []
        line_number = 1
        invoice_lines = []
        for line in self._lineas_detalle:
            lines = collections.OrderedDict()
            lines['NroLinDet'] = line_number
            if line.CdgItem:
                cdg_items = []
                for cdg in line.CdgItem:
                    if cdg.get('VlrCodigo') == 'NO_PRODUCT':
                        no_product = True
                    else:
                        cdg_line = collections.OrderedDict()
                        cdg_line['TpoCodigo'] = cdg.get('TpoCodigo', 'INT1')
                        cdg_line['VlrCodigo'] = cdg.get('VlrCodigo', False)
                        cdg_items.append({'CdgItem': cdg_line})
                lines['cdg_items'] = cdg_items
            for t in line.Impuesto:
                taxInclude = t.price_include
            if line.IndExe:
                lines['IndExe'] = 1
            #if line.product_id.type == 'events':
            #   lines['ItemEspectaculo'] =
#            if self.es_boleta():
#                lines['RUTMandante']
            lines['NmbItem'] = line.NmbItem
            lines['DscItem'] = line.DscItem  #descripción más extenza
            if line.CdgItem:
                lines['NmbItem'] = line.NmbItem
            #lines['InfoTicket']
            if line.QtyItem > 0:
                lines['QtyItem'] = line.QtyItem
                lines['UnmdItem'] = line.uom_id[:4]
            elif line.QtyItem < 0:
                raise UserError("NO puede ser menor que 0")
            if line.PrcItem:
                lines['PrcItem'] = line.PrcItem
            if line.CodImpAdic:
                lines['CodImpAdic'] = line.CodImpAdic
            else:
                for imp in line.Impuesto:
                    if imp.es_adicional:
                        lines['CodImpAdic'] = imp.CodImp
            if line.DescuentoMonto > 0:
                if line.DescuentoPct:
                    lines['DescuentoPct'] = line.DescuentoPct
                lines['DescuentoMonto'] = line.DescuentoMonto
            if not line.MntBruto:
                lines['MontoItem'] = line.MontoItem
            line_number += 1
            invoice_lines.extend([{'Detalle': lines}])
            if line.IndExe and not self.es_boleta(False):
                self.MntBruto = False
        return invoice_lines
Exemple #4
0
 def __init__(self, vals={}):
     self.firma_electronica = vals
     if vals.get('rut_firmante') and not self.rut_firmante:
         self.rut_firmante = vals['rut_firmante']
     if not self.firma_electronica:
         return
     if not self.rut_firmante:
         raise UserError(
             "La firma no tiene rut de firmante, debe acompañar el rut del firmante en {'rut_firmante':12312, 'string_firma':.....}"
         )
 def Cesionario(self):
     if not hasattr(self, '_cesionario'):
         return []
     Receptor = collections.OrderedDict()
     if not self._cesionario or not self._cesionario.RUT:
         raise UserError("Debe Ingresar RUT Cesionario")
     Receptor['RUT'] = self._cesionario.RUT
     Receptor['RazonSocial'] = self._cesionario.RazonSocial
     Receptor['Direccion'] = self._cesionario.Direccion
     Receptor['eMail'] = self._cesionario.eMail
     return Receptor
    def Totales(self):
        Totales = collections.OrderedDict()
        imps = []
        if not self.MntTotal or self.no_product:
            imps.append({'MntTotal': 0})
            # Totales['MntTotal'] = 0
            # return Totales
            return imps
        if not self.es_exportacion and self.IndMntNeto:  # (not self.es_boleta() or self.IndMntNeto)
            #Totales['MntNeto'] = self.MntNeto
            imps.append({'MntNeto': self.MntNeto})

        if self.es_boleta() and self.MntNeto:
            imps.append({'MntNeto': self.MntNeto})

        if self.TpoMoneda:
            # Totales['TpoMoneda'] = self.TpoMoneda
            imps.append({'TpoMoneda': self.TpoMoneda})
        if self.MntExe:
            # Totales['MntExe'] = self.MntExe
            imps.append({'MntExe': self.MntExe})
        if not self.es_exportacion and (not self.es_boleta()
                                        or self.IndMntNeto):
            if self.MntIVA:
                Totales['TasaIVA'] = self.TasaIVA
                Totales['IVA'] = self.MntIVA

                imps.append({'TasaIVA': self.TasaIVA})
                imps.append({'IVA': self.MntIVA})

            for i in self.impuestos:
                if i.tax_id.es_adicional:
                    ctx = collections.OrderedDict()
                    # Totales['ImptoReten'] = collections.OrderedDict()
                    ctx['TipoImp'] = i.tax_id.CodImp
                    ctx['TasaImp'] = 1 if i.tax_id.especifico else round(
                        i.tax_id.TasaImp, 2)
                    decimal.getcontext().rounding = decimal.ROUND_HALF_UP
                    ctx['MontoImp'] = int(
                        decimal.Decimal(i.MontoImp).to_integral_value())
                    imps.append({'ImptoReten': ctx})

        elif self.es_exportacion and self.MntIVA:
            raise UserError("Todos los productos deben ser Exentos")

        if self.MntIVA and self.es_boleta():

            imps.append({'IVA': self.MntIVA})

        imps.append({'MntTotal': self.MntTotal})

        return imps
 def IdDTE(self):
     if not hasattr(self, '_folio'):
         return False
     IdDoc = collections.OrderedDict()
     IdDoc['TipoDTE'] = self.TipoDTE
     IdDoc['RUTEmisor'] = self.Emisor.RUTEmisor
     if not self.RUTReceptor:
         raise UserError("Debe Ingresar RUT Receptor")
     IdDoc['RUTReceptor'] = self.RUTReceptor
     IdDoc['Folio'] = self.Folio
     IdDoc['FchEmis'] = self.FchEmis
     IdDoc['MntTotal'] = self.MntTotal
     return IdDoc
Exemple #8
0
    def caratula_libro(self):
        if self.Libro.TipoOperacion == 'BOLETA' and\
                self.Libro.TipoLibro != 'ESPECIAL':
            raise UserError(
                "Boletas debe ser solamente Tipo Operación ESPECIAL")
        if self.Libro.TipoLibro in ['ESPECIAL'] or\
                self.Libro.TipoOperacion in ['BOLETA']:
            FolioNotificacion = '<FolioNotificacion>{0}</FolioNotificacion>'\
                .format(self.Libro.FolioNotificacion)
        else:
            FolioNotificacion = ''
        if self.Libro.TipoOperacion in ['BOLETA', 'GUIA']:
            TipoOperacion = ''
        else:
            TipoOperacion = '<TipoOperacion>' + self.Libro.TipoOperacion\
                + '</TipoOperacion>'
        CodigoRectificacion = ''
        if self.Libro.TipoLibro == 'RECTIFICA':
            CodigoRectificacion = '\n<CodAutRec>' +\
                self.Libro.CodigoRectificacion + '</CodAutRec>'
        xml = '''<EnvioLibro ID="{10}">
<Caratula>
<RutEmisorLibro>{0}</RutEmisorLibro>

<RutEnvia>{1}</RutEnvia>
<PeriodoTributario>{2}</PeriodoTributario>
<FchResol>{3}</FchResol>
<NroResol>{4}</NroResol>{5}
<TipoLibro>{6}</TipoLibro>
<TipoEnvio>{7}</TipoEnvio>
{8}{11}
</Caratula>
{9}
</EnvioLibro>
'''.format(self.Emisor.RUTEmisor,
           self.firma_electronica.rut_firmante\
            if self.firma_electronica else '66666666-6',
           self.Libro.PeriodoTributario,
           self.Emisor.FchResol,
           self.Emisor.NroResol,
           TipoOperacion,
           self.Libro.TipoLibro,
           self.Libro.TipoEnvio,
           FolioNotificacion,
           self.Libro.sii_xml_request,
           self.doc_id,
           CodigoRectificacion,
           )
        return xml
 def Documento(self, docs):
     _documentos = []
     for vals in docs:
         TipoDTE = vals.get('TipoDTE', False)
         if TipoDTE in [39, 41]:
             self.es_boleta = True
         elif not TipoDTE:
             raise UserError('No especifica tipo de documento')
         caf_file = vals.get('caf_file', [])
         for docData in vals["documentos"]:
             docu = Doc(docData, resumen=False)
             docu._dte_emsior = self.Emisor
             docu._firma = self.firma
             docu.verify = self.verify
             docu.test = self.test
             if caf_file:
                 docu.caf_file = caf_file
             docu.TipoDTE = TipoDTE
             _documentos.append(docu)
     self._documentos = sorted(_documentos, key=lambda t: t.NroDTE)
    def Transporte(self):
        if not self.IndTraslado:
            return False
        Transporte = collections.OrderedDict()
        if self.Patente:
            Transporte['Patente'] = self.Patente[:8]
        if self.IndTraslado in [2, 3]:
            if self.IndTraslado == 2:
                Transporte['RUTTrans'] = self.RUTTrans
            else:
                if not self.carrier_id:
                    raise UserError("Debe especificar el RUT del transportista\
, en su ficha de receptor")
                Transporte['RUTTrans'] = self.RUTTrans
            if self.RUTChofer:
                Transporte['Chofer'] = collections.OrderedDict()
                Transporte['Chofer']['RUTChofer'] = self.RUTChofer
                Transporte['Chofer']['NombreChofer'] = self.NombreChofer[:30]
        Transporte['DirDest'] = self.DirDest
        Transporte['CmnaDest'] = self.CmnaDest
        Transporte['CiudadDest'] = self.CiudadDest
        ''' @TODO SUb Area Aduana '''
        return Transporte
 def Aduana(self):
     if not hasattr(self, '_aduana'):
         return False
     Aduana = collections.OrderedDict()
     aduana = self._aduana
     if self.IndServicio in [3, 4, 5]:
         aduana.CodModVenta = 1
     if aduana.CodModVenta:
         Aduana['CodModVenta'] = aduana.CodModVenta
     elif not self.es_nc_exportacion:
         raise UserError("Debe Ingresar Modalidad de Venta")
     if aduana.CodClauVenta and not aduana.CodModVenta:
         raise UserError("Debe Ingresar un Término de Pago")
     if aduana.CodClauVenta:
         Aduana['CodClauVenta'] = aduana.CodClauVenta
     if aduana.TotClauVenta and aduana.CodClauVenta != 32:
         Aduana['TotClauVenta'] = aduana.TotClauVenta
     if aduana.CodViaTransp:
         Aduana['CodViaTransp'] = aduana.CodViaTransp
     if aduana.NombreTransp:
         Aduana['NombreTransp'] = aduana.NombreTransp
     if aduana.RUTCiaTransp:
         Aduana['RUTCiaTransp'] = aduana.RUTCiaTransp
     if aduana.NomCiaTransp:
         Aduana['NomCiaTransp'] = aduana.NomCiaTransp
     #Aduana['IdAdicTransp'] = self.indicador_adicional
     if aduana.CodPtoEmbarque:
         Aduana['CodPtoEmbarque'] = aduana.CodPtoEmbarque
     #Aduana['IdAdicPtoEmb'] = expo.ind_puerto_embarque
     if aduana.CodPtoDesemb:
         Aduana['CodPtoDesemb'] = aduana.CodPtoDesemb
     #Aduana['IdAdicPtoDesemb'] = expo.ind_puerto_desembarque
     if aduana.Tara:
         Aduana['Tara'] = aduana.Tara
     if aduana.CodUnidMedTara:
         Aduana['CodUnidMedTara'] = aduana.CodUnidMedTara
     if aduana.PesoBruto:
         Aduana['PesoBruto'] = aduana.PesoBruto
     if aduana.CodUnidPesoBruto:
         Aduana['CodUnidPesoBruto'] = aduana.CodUnidPesoBruto
     if aduana.PesoNeto:
         Aduana['PesoNeto'] = aduana.PesoNeto
     if aduana.CodUnidPesoNeto:
         Aduana['CodUnidPesoNeto'] = aduana.CodUnidPesoNeto
     if aduana.TotItems:
         Aduana['TotItems'] = aduana.TotItems
     if aduana.TotBultos:
         bultos = []
         for b in aduana.Bultos:
             bulto = collections.OrderedDict()
             bulto['CodTpoBultos'] = b.CodTpoBultos
             bulto['CantBultos'] = b.CantBultos
             if b.Marcas:
                 bulto['Marcas'] = b.Marcas
             if b.IdContainer:
                 bulto['IdContainer'] = b.IdContainer
                 bulto['Sello'] = b.Sello
                 bulto['EmisorSello'] = b.EmisorSello
             bultos.append(bulto)
         Aduana['TotBultos'] = aduana.TotBultos
         Aduana['TipoBultos'] = bultos
     #Aduana['Marcas'] =
     #Solo si es contenedor
     #Aduana['IdContainer'] =
     #Aduana['Sello'] =
     #Aduana['EmisorSello'] =
     if aduana.MntFlete:
         Aduana['MntFlete'] = aduana.MntFlete
     if aduana.MntSeguro:
         Aduana['MntSeguro'] = aduana.MntSeguro
     if aduana.CodPaisRecep:
         Aduana['CodPaisRecep'] = aduana.CodPaisRecep
     if aduana.CodPaisDestin:
         Aduana['CodPaisDestin'] = aduana.CodPaisDestin
     return Aduana