Merge branch 'develop'
Mejora: Permitir importar CFDI 3.2
This commit is contained in:
commit
dc8aeaebba
|
@ -1,3 +1,8 @@
|
|||
v 1.23.0 [30-oct-2018]
|
||||
----------------------
|
||||
- Mejora: Permitir importar CFDI 3.2
|
||||
|
||||
|
||||
v 1.22.0 [25-oct-2018]
|
||||
----------------------
|
||||
- Mejora: Permitir cambiar descripción al facturar en lote
|
||||
|
|
|
@ -6,6 +6,10 @@ siempre actualizado.** Solo se da soporte sobre la ultima versión de **Empresa
|
|||
Libre**.
|
||||
|
||||
|
||||
### 1.23.0 [25-oct-2018]
|
||||
- Mejora: Permitir importar CFDI 3.2
|
||||
|
||||
|
||||
### 1.22.0 [25-oct-2018]
|
||||
- Mejora: Permitir cambiar descripción al facturar en lote
|
||||
|
||||
|
|
|
@ -4617,6 +4617,89 @@ class Facturas(BaseModel):
|
|||
|
||||
return result
|
||||
|
||||
def _validate_import_32(self, data, sxml):
|
||||
currencies = {
|
||||
'Peso Mexicano': 'MXN',
|
||||
}
|
||||
regimenes = {
|
||||
'REGIMEN GENERAL DE LEY PERSONAS MORALES': '601',
|
||||
}
|
||||
# ~ print(data)
|
||||
invoice = data['invoice']
|
||||
receptor = data['receptor']
|
||||
name = receptor.get('nombre', '')
|
||||
tipo_persona = 1
|
||||
if receptor['rfc'] == 'XEXX010101000':
|
||||
tipo_persona = 4
|
||||
elif receptor['rfc'] == RFC_PUBLICO:
|
||||
tipo_persona = 3
|
||||
elif len(receptor['rfc']) == 12:
|
||||
tipo_persona = 2
|
||||
new = {
|
||||
'tipo_persona': tipo_persona,
|
||||
'rfc': receptor['rfc'],
|
||||
'slug': util.to_slug(name),
|
||||
'nombre': name,
|
||||
'es_cliente': True,
|
||||
}
|
||||
cliente, _ = Socios.get_or_create(**new)
|
||||
|
||||
tipo_cambio = float(invoice.get('TipoCambio', '1.0'))
|
||||
total = float(invoice['Total'])
|
||||
invoice = {
|
||||
'cliente': cliente,
|
||||
'version': invoice['version'],
|
||||
'serie': invoice.get('serie', ''),
|
||||
'folio': int(invoice.get('folio', '0')),
|
||||
'fecha': invoice['fecha'],
|
||||
'fecha_timbrado': invoice['FechaTimbrado'],
|
||||
'forma_pago': invoice['formaDePago'],
|
||||
'condiciones_pago': invoice.get('CondicionesDePago', ''),
|
||||
'subtotal': float(invoice['SubTotal']),
|
||||
'descuento': float(invoice.get('Descuento', '0.0')),
|
||||
'moneda': currencies[invoice['Moneda']],
|
||||
'tipo_cambio': tipo_cambio,
|
||||
'total': total,
|
||||
'saldo': total,
|
||||
'total_mn': round(float(total * tipo_cambio), DECIMALES),
|
||||
'tipo_comprobante': invoice['TipoDeComprobante'],
|
||||
'metodo_pago': invoice['metodoDePago'],
|
||||
'lugar_expedicion': invoice['LugarExpedicion'],
|
||||
# ~ 'uso_cfdi': invoice['UsoCFDI'],
|
||||
'total_retenciones': float(invoice.get('TotalImpuestosRetenidos', '0.0')),
|
||||
'total_trasladados': float(invoice.get('TotalImpuestosTrasladados', '0.0')),
|
||||
'xml': sxml,
|
||||
'uuid': invoice['uuid'],
|
||||
'estatus': 'Importada',
|
||||
'regimen_fiscal': regimenes[invoice['regimen_fiscal']],
|
||||
'pagada': False,
|
||||
'tipo_relacion': invoice.get('TipoRelacion', '')
|
||||
}
|
||||
# ~ donativo = BooleanField(default=False)
|
||||
|
||||
conceptos = []
|
||||
for concepto in data['conceptos']:
|
||||
valor_unitario = float(concepto['ValorUnitario'])
|
||||
descuento = float(concepto.get('Descuento', '0.0'))
|
||||
c = {
|
||||
'cantidad': float(concepto['Cantidad']),
|
||||
'valor_unitario': valor_unitario,
|
||||
'descuento': descuento,
|
||||
'precio_final': round(valor_unitario - descuento, DECIMALES),
|
||||
'importe': float(concepto['Importe']),
|
||||
'descripcion': concepto['Descripcion'],
|
||||
'unidad': concepto.get('Unidad', ''),
|
||||
'clave': concepto.get('NoIdentificacion', ''),
|
||||
'clave_sat': '01010101',
|
||||
}
|
||||
conceptos.append(c)
|
||||
|
||||
new = {
|
||||
'invoice': invoice,
|
||||
'conceptos': conceptos,
|
||||
}
|
||||
return True, new
|
||||
|
||||
def _validate_import(self, data, sxml):
|
||||
try:
|
||||
emisor = Emisor.select()[0]
|
||||
|
@ -4632,10 +4715,6 @@ class Facturas(BaseModel):
|
|||
return False, {}
|
||||
|
||||
invoice = data['invoice']
|
||||
if invoice['version'] != '3.3':
|
||||
msg = 'CFDI no es 3.3'
|
||||
log.error(msg)
|
||||
return False, {}
|
||||
|
||||
w = (Facturas.uuid==invoice['uuid'])
|
||||
if Facturas.select().where(w).exists():
|
||||
|
@ -4643,6 +4722,14 @@ class Facturas(BaseModel):
|
|||
log.error(msg)
|
||||
return False, {}
|
||||
|
||||
if invoice['version'] != '3.3':
|
||||
if invoice['version'] != '3.2':
|
||||
msg = 'CFDI no soportado'
|
||||
log.error(msg)
|
||||
return False, {}
|
||||
|
||||
return self._validate_import_32(self, data, sxml)
|
||||
|
||||
receptor = data['receptor']
|
||||
name = receptor.get('nombre', '')
|
||||
tipo_persona = 1
|
||||
|
|
|
@ -47,7 +47,7 @@ except ImportError:
|
|||
|
||||
|
||||
DEBUG = DEBUG
|
||||
VERSION = '1.22.0'
|
||||
VERSION = '1.23.0'
|
||||
EMAIL_SUPPORT = ('soporte@empresalibre.net',)
|
||||
TITLE_APP = '{} v{}'.format(TITLE_APP, VERSION)
|
||||
|
||||
|
|
Loading…
Reference in New Issue