forked from elmau/empresa-libre
Cancel sign xml
This commit is contained in:
parent
0389c0734f
commit
a54ad8d760
|
@ -231,9 +231,10 @@ class PACComercioDigital(object):
|
||||||
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
def cancel_xml(self, cfdi, xml, info, auth={}):
|
def cancel_xml(self, cfdi, xml, auth={}, info={'tipo': 'cfdi3.3'}):
|
||||||
if not auth:
|
if DEBUG or not auth:
|
||||||
auth = AUTH
|
auth = AUTH
|
||||||
|
|
||||||
url = self.URL['cancelxml']
|
url = self.URL['cancelxml']
|
||||||
headers = self._get_headers_cancel_xml(cfdi, info, auth)
|
headers = self._get_headers_cancel_xml(cfdi, info, auth)
|
||||||
result = self._post(url, xml, headers)
|
result = self._post(url, xml, headers)
|
||||||
|
|
|
@ -645,3 +645,30 @@ def make_xml(data, certificado):
|
||||||
xslt.close()
|
xslt.close()
|
||||||
|
|
||||||
return cfdi.add_sello(stamp, cert.cer_txt)
|
return cfdi.add_sello(stamp, cert.cer_txt)
|
||||||
|
|
||||||
|
|
||||||
|
def cancel_xml_sign(invoice, auth, certificado):
|
||||||
|
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||||
|
pac = PACS[auth['pac']]()
|
||||||
|
data = {
|
||||||
|
'rfc': certificado.rfc,
|
||||||
|
'fecha': now().isoformat()[:19],
|
||||||
|
'uuid': invoice.uuid,
|
||||||
|
}
|
||||||
|
template = TEMPLATE_CANCEL.format(**data)
|
||||||
|
tree = ET.fromstring(template.encode())
|
||||||
|
tree = cert.sign_xml(tree)
|
||||||
|
sign_xml = ET.tostring(tree).decode()
|
||||||
|
|
||||||
|
result = pac.cancel_xml(invoice.xml, sign_xml, auth)
|
||||||
|
if pac.error:
|
||||||
|
result = {'ok': False, 'msg': pac.error, 'row': {}}
|
||||||
|
return result
|
||||||
|
|
||||||
|
tree = ET.fromstring(result)
|
||||||
|
date_cancel = tree.xpath('string(//Acuse/@Fecha)')[:19]
|
||||||
|
|
||||||
|
msg = 'Factura cancelada correctamente'
|
||||||
|
result = {'ok': True, 'msg': '', 'row': {'estatus': 'Cancelada'},
|
||||||
|
'Fecha': date_cancel, 'Acuse': result}
|
||||||
|
return result
|
||||||
|
|
|
@ -3845,11 +3845,39 @@ class Facturas(BaseModel):
|
||||||
obj.fecha_cancelacion = util.now()
|
obj.fecha_cancelacion = util.now()
|
||||||
obj.save()
|
obj.save()
|
||||||
msg = 'Factura cancelada correctamente'
|
msg = 'Factura cancelada correctamente'
|
||||||
return {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'}}
|
return {'ok': True, 'msg': msg, 'row': {'estatus': obj.estatus}}
|
||||||
|
|
||||||
|
# ~ if CANCEL_SIGNATURE:
|
||||||
|
# ~ return cls._cancel_signature(cls, id)
|
||||||
|
# ~ return cls._cancel_xml(cls, id)
|
||||||
|
return cls._cancel_xml_sign(obj)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _cancel_xml_sign(cls, invoice):
|
||||||
|
if invoice.version != '3.3':
|
||||||
|
msg = 'Solo es posible cancelar CFDI 3.3'
|
||||||
|
return {'ok': False, 'msg': msg}
|
||||||
|
|
||||||
|
auth = Configuracion.get_({'fields': 'pac_auth'})
|
||||||
|
certificado = Certificado.get(Certificado.es_fiel==False)
|
||||||
|
result = utils.cancel_xml_sign(invoice, auth, certificado)
|
||||||
|
|
||||||
|
if result['ok']:
|
||||||
|
invoice.estatus = 'Cancelada'
|
||||||
|
invoice.error = ''
|
||||||
|
invoice.cancelada = True
|
||||||
|
invoice.fecha_cancelacion = result['Fecha']
|
||||||
|
invoice.acuse = result['Acuse'] or ''
|
||||||
|
cls._actualizar_saldo_cliente(cls, invoice, True)
|
||||||
|
cls._update_inventory(cls, invoice, True)
|
||||||
|
cls._uncancel_tickets(cls, invoice)
|
||||||
|
else:
|
||||||
|
invoice.error = result['msg']
|
||||||
|
invoice.save()
|
||||||
|
|
||||||
|
data = {'ok': result['ok'], 'msg': result['msg'], 'row': result['row']}
|
||||||
|
return data
|
||||||
|
|
||||||
if CANCEL_SIGNATURE:
|
|
||||||
return cls._cancel_signature(cls, id)
|
|
||||||
return cls._cancel_xml(cls, id)
|
|
||||||
|
|
||||||
def _cancel_xml(self, id):
|
def _cancel_xml(self, id):
|
||||||
msg = 'Factura cancelada correctamente'
|
msg = 'Factura cancelada correctamente'
|
||||||
|
|
|
@ -1366,6 +1366,7 @@ function send_cancel(id){
|
||||||
msg_ok(values.msg)
|
msg_ok(values.msg)
|
||||||
gi.updateItem(id, values.row)
|
gi.updateItem(id, values.row)
|
||||||
}else{
|
}else{
|
||||||
|
msg_error('No fue posible cancelar')
|
||||||
webix.alert({
|
webix.alert({
|
||||||
title: 'Error al Cancelar',
|
title: 'Error al Cancelar',
|
||||||
text: values.msg,
|
text: values.msg,
|
||||||
|
|
Loading…
Reference in New Issue