Guardar datos para carta porte
This commit is contained in:
parent
7b2467f99a
commit
481594839d
|
@ -20,6 +20,7 @@ import datetime
|
|||
from xml.etree import ElementTree as ET
|
||||
from xml.dom.minidom import parseString
|
||||
|
||||
from dateutil import parser
|
||||
from logbook import Logger
|
||||
|
||||
|
||||
|
@ -120,6 +121,7 @@ class CFDI(object):
|
|||
self._pagos = False
|
||||
self._is_nomina = False
|
||||
self._leyendas = False
|
||||
self._carta_porte = False
|
||||
self._divisas = ''
|
||||
self.error = ''
|
||||
|
||||
|
@ -171,6 +173,7 @@ class CFDI(object):
|
|||
self._ine = True
|
||||
self._pagos = bool(datos['complementos'].get('pagos', False))
|
||||
self._leyendas = bool(datos['complementos'].get('leyendas', False))
|
||||
self._carta_porte = bool(datos['complementos'].get('cartaporte', False))
|
||||
|
||||
self._divisas = datos['comprobante'].pop('divisas', '')
|
||||
|
||||
|
@ -236,9 +239,16 @@ class CFDI(object):
|
|||
attributes[name] = SAT['leyendas']['xmlns']
|
||||
schema_leyendas = SAT['leyendas']['schema']
|
||||
|
||||
schema_carta_porte = ''
|
||||
if self._carta_porte:
|
||||
name = 'xmlns:{}'.format(SAT['cartaporte']['prefix'])
|
||||
attributes[name] = SAT['cartaporte']['xmlns']
|
||||
schema_carta_porte = SAT['cartaporte']['schema']
|
||||
|
||||
attributes['xsi:schemaLocation'] = self._sat_cfdi['schema'] + \
|
||||
schema_locales + schema_donativo + schema_ine + schema_edu + \
|
||||
schema_divisas + schema_nomina + schema_pagos + schema_leyendas
|
||||
schema_divisas + schema_nomina + schema_pagos + schema_leyendas + \
|
||||
schema_carta_porte
|
||||
attributes.update(datos)
|
||||
|
||||
if not 'Version' in attributes:
|
||||
|
@ -461,6 +471,32 @@ class CFDI(object):
|
|||
self._complemento = ET.SubElement(
|
||||
self._cfdi, '{}:Complemento'.format(self._pre))
|
||||
|
||||
if self._carta_porte:
|
||||
datos = datos['cartaporte']
|
||||
print('\nDatos', datos)
|
||||
ubicaciones = datos.pop('ubicaciones')
|
||||
mercancias = datos.pop('mercancias', ())
|
||||
tiposfigura = datos.pop('tiposfigura', ())
|
||||
|
||||
atributos = {'Version': SAT['cartaporte']['version']}
|
||||
atributos.update(datos)
|
||||
|
||||
prefix = SAT['cartaporte']['prefix']
|
||||
node_carta = ET.SubElement(self._complemento, f'{prefix}:CartaPorte', atributos)
|
||||
|
||||
node = ET.SubElement(node_carta, f'{prefix}:Ubicaciones')
|
||||
for ubicacion in ubicaciones:
|
||||
dt = parser.parse(ubicacion['FechaHoraSalidaLlegada'])
|
||||
ubicacion['FechaHoraSalidaLlegada'] = dt.isoformat()[:19]
|
||||
ET.SubElement(node, f'{prefix}:Ubicacion', ubicacion)
|
||||
|
||||
attr = mercancias
|
||||
mercancias = attr.pop('mercancias')
|
||||
node = ET.SubElement(node_carta, f'{prefix}:Mercancias', attr)
|
||||
for mercancia in mercancias:
|
||||
ET.SubElement(node, f'{prefix}:Mercancia', mercancia)
|
||||
|
||||
|
||||
if self._divisas:
|
||||
atributos = {
|
||||
'version': SAT['divisas']['version'],
|
||||
|
|
|
@ -43,6 +43,7 @@ from controllers import utils
|
|||
from settings import (
|
||||
DEBUG,
|
||||
CANCEL_VERSION,
|
||||
CARTA_PORTE,
|
||||
DEFAULT_GLOBAL,
|
||||
DB_COMPANIES,
|
||||
EXT,
|
||||
|
@ -5317,6 +5318,17 @@ class Facturas(BaseModel):
|
|||
FacturasComplementos.create(**data)
|
||||
return
|
||||
|
||||
def _save_cartaporte(self, invoice, valores):
|
||||
if not valores:
|
||||
return
|
||||
data = {
|
||||
'factura': invoice,
|
||||
'nombre': 'cartaporte',
|
||||
'valores': valores,
|
||||
}
|
||||
FacturasComplementos.create(**data)
|
||||
return
|
||||
|
||||
def _get_serie(self, user, default_serie):
|
||||
if user.sucursal is None:
|
||||
return default_serie
|
||||
|
@ -5328,6 +5340,7 @@ class Facturas(BaseModel):
|
|||
productos = util.loads(values.pop('productos'))
|
||||
relacionados = util.loads(values.pop('relacionados'))
|
||||
ine = values.pop('ine', {})
|
||||
cartaporte = values.pop('cartaporte', {})
|
||||
tipo_comprobante = values['tipo_comprobante']
|
||||
folio_custom = values.pop('folio_custom', '')
|
||||
divisas = values.pop('divisas', '')
|
||||
|
@ -5354,9 +5367,14 @@ class Facturas(BaseModel):
|
|||
values['lugar_expedicion'] = emisor.cp_expedicion or emisor.codigo_postal
|
||||
values['anticipo'] = util.get_bool(values['anticipo'])
|
||||
values['donativo'] = util.get_bool(values['donativo'])
|
||||
|
||||
if tipo_comprobante == 'T':
|
||||
values['metodo_pago'] = ''
|
||||
values['forma_pago'] = ''
|
||||
values['moneda'] = CARTA_PORTE['MONEDA']
|
||||
self_client = Socios.get(Socios.rfc==emisor.rfc)
|
||||
if values['cliente'] != self_client.id:
|
||||
values['cliente'] = self_client
|
||||
|
||||
with database_proxy.atomic() as txn:
|
||||
# ~ print('VALUES\n\n', values)
|
||||
|
@ -5365,6 +5383,7 @@ class Facturas(BaseModel):
|
|||
cls, obj, productos, tipo_comprobante, user)
|
||||
cls._guardar_relacionados(cls, obj, relacionados)
|
||||
cls._guardar_ine(cls, obj, ine)
|
||||
cls._save_cartaporte(cls, obj, cartaporte)
|
||||
cls._save_leyendas_fiscales(cls, obj, leyendas_fiscales)
|
||||
obj.subtotal = totals['subtotal']
|
||||
obj.descuento = totals['descuento']
|
||||
|
@ -5463,9 +5482,10 @@ class Facturas(BaseModel):
|
|||
comprobante['Descuento'] = FORMAT.format(invoice.descuento)
|
||||
|
||||
if invoice.tipo_comprobante == 'T':
|
||||
comprobante['SubTotal'] = '0.00'
|
||||
comprobante['Total'] = '0.00'
|
||||
comprobante['SubTotal'] = '0'
|
||||
comprobante['Total'] = '0'
|
||||
del comprobante['FormaPago']
|
||||
del comprobante['TipoCambio']
|
||||
|
||||
if invoice.tipo_relacion:
|
||||
relacionados = {
|
||||
|
|
|
@ -209,6 +209,10 @@ EXT = {
|
|||
}
|
||||
MXN = 'MXN'
|
||||
|
||||
CARTA_PORTE = {
|
||||
'MONEDA': 'XXX',
|
||||
}
|
||||
|
||||
PATHS = {
|
||||
'STATIC': path_static,
|
||||
'CSS': path_css,
|
||||
|
|
|
@ -699,10 +699,38 @@ function guardar_y_timbrar(values){
|
|||
|
||||
var usar_cartaporte = $$('chk_cfdi_usar_cartaporte').getValue()
|
||||
if(usar_cartaporte){
|
||||
var total_distance = 0.00
|
||||
var total_weight = 0.00
|
||||
var cartaporte = {
|
||||
TranspInternac: $$('lst_carta_TranspInternac').getValue()
|
||||
TranspInternac: $$('lst_carta_TranspInternac').getValue(),
|
||||
TotalDistRec: total_distance,
|
||||
}
|
||||
var ubicaciones = $$('grid_carta_ubicaciones').data.getRange()
|
||||
ubicaciones.forEach(function(row, index){
|
||||
delete row['id']
|
||||
delete row['delete']
|
||||
if(row['DistanciaRecorrida']){
|
||||
total_distance += parseFloat(row['DistanciaRecorrida'])
|
||||
}
|
||||
})
|
||||
cartaporte['TotalDistRec'] = String(total_distance)
|
||||
cartaporte['ubicaciones'] = ubicaciones
|
||||
|
||||
var mercancias = $$('grid_carta_mercancias').data.getRange()
|
||||
mercancias.forEach(function(row, index){
|
||||
delete row['id']
|
||||
row['Cantidad'] = String(row['Cantidad'])
|
||||
if(row['PesoEnKg']){
|
||||
total_weight += parseFloat(row['PesoEnKg'])
|
||||
}
|
||||
})
|
||||
var mercancias = {
|
||||
'PesoBrutoTotal': String(total_weight),
|
||||
'UnidadPeso': $$('lst_carta_UnidadPeso').getValue(),
|
||||
'NumTotalMercancias': String(mercancias.length),
|
||||
mercancias: mercancias,
|
||||
}
|
||||
cartaporte['mercancias'] = mercancias
|
||||
|
||||
data['cartaporte'] = cartaporte
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue