Replace save for update in invoice
This commit is contained in:
parent
229be3b415
commit
4aad1a94eb
|
@ -5123,8 +5123,7 @@ class Facturas(BaseModel):
|
|||
values['forma_pago'] = ''
|
||||
|
||||
with database_proxy.atomic() as txn:
|
||||
print('VALUES\n\n', values)
|
||||
print(type(values['tipo_cambio']))
|
||||
# ~ print('VALUES\n\n', values)
|
||||
obj = Facturas.create(**values)
|
||||
totals = cls._calculate_totals(cls, obj, productos, tipo_comprobante)
|
||||
cls._guardar_relacionados(cls, obj, relacionados)
|
||||
|
@ -5527,25 +5526,46 @@ class Facturas(BaseModel):
|
|||
|
||||
rfc = Emisor.select()[0].rfc
|
||||
obj = Facturas.get(Facturas.id == id)
|
||||
obj.xml = cls._make_xml(cls, obj)
|
||||
obj.estatus = 'Generada'
|
||||
obj.save()
|
||||
# ~ obj.xml = cls._make_xml(cls, obj)
|
||||
xml = cls._make_xml(cls, obj)
|
||||
# ~ obj.estatus = 'Generada'
|
||||
# ~ obj.save()
|
||||
q = (Facturas
|
||||
.update(xml=xml, estatus='Generada')
|
||||
.where(Facturas.id == id)
|
||||
)
|
||||
q.execute()
|
||||
|
||||
enviar_correo = util.get_bool(Configuracion.get_('correo_directo'))
|
||||
auth = Configuracion.get_({'fields': 'pac_auth'})
|
||||
|
||||
anticipo = False
|
||||
msg = 'Factura timbrada correctamente'
|
||||
result = utils.xml_stamp(obj.xml, auth)
|
||||
# ~ result = utils.xml_stamp(obj.xml, auth)
|
||||
result = utils.xml_stamp(xml, auth)
|
||||
|
||||
if result['ok']:
|
||||
obj.xml = result['xml']
|
||||
obj.uuid = result['uuid']
|
||||
obj.fecha_timbrado = result['date']
|
||||
obj.estatus = 'Timbrada'
|
||||
obj.error = ''
|
||||
obj.save()
|
||||
row = {'uuid': obj.uuid, 'estatus': 'Timbrada'}
|
||||
cfdi_uuid = result['uuid']
|
||||
values = dict(
|
||||
xml = result['xml'],
|
||||
uuid = cfdi_uuid,
|
||||
fecha_timbrado = result['date'],
|
||||
estatus = 'Timbrada',
|
||||
error = '',
|
||||
)
|
||||
q = (Facturas
|
||||
.update(**values)
|
||||
.where(Facturas.id == id)
|
||||
)
|
||||
q.execute()
|
||||
|
||||
# ~ obj.xml = result['xml']
|
||||
# ~ obj.uuid = result['uuid']
|
||||
# ~ obj.fecha_timbrado = result['date']
|
||||
# ~ obj.estatus = 'Timbrada'
|
||||
# ~ obj.error = ''
|
||||
# ~ obj.save()
|
||||
row = {'uuid': cfdi_uuid, 'estatus': 'Timbrada'}
|
||||
if enviar_correo:
|
||||
cls._send(cls, id, rfc)
|
||||
if obj.tipo_comprobante == 'I' and obj.tipo_relacion == '07':
|
||||
|
@ -5857,6 +5877,7 @@ class Facturas(BaseModel):
|
|||
WareHouseProduct.warehouse==warehouse,
|
||||
WareHouseProduct.product==p.producto,
|
||||
)
|
||||
|
||||
obj = WareHouseProduct.get(*fields)
|
||||
obj.exists -= cant
|
||||
obj.save()
|
||||
|
@ -9772,10 +9793,14 @@ class InventoryEntries(BaseModel):
|
|||
|
||||
WareHouseProduct.update_exists(values)
|
||||
|
||||
product.existencia += cant
|
||||
product.save()
|
||||
new_cant = product.existencia + cant
|
||||
q = (Productos
|
||||
.update(existencia=Productos.existencia + cant)
|
||||
.where(Productos.id==product.id)
|
||||
)
|
||||
q.execute()
|
||||
|
||||
result = {'ok': True, 'row': {'existencia': product.existencia}}
|
||||
result = {'ok': True, 'row': {'existencia': new_cant}}
|
||||
return result
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue