Cancel old with Finkok
This commit is contained in:
parent
a7945dba58
commit
0a04ec6c26
|
@ -249,7 +249,14 @@ class PACComercioDigital(object):
|
||||||
self._error(result.headers['errmsg'])
|
self._error(result.headers['errmsg'])
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return result.text
|
tree = ET.fromstring(result.text)
|
||||||
|
date_cancel = tree.xpath('string(//Acuse/@Fecha)')[:19]
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'acuse': result.text,
|
||||||
|
'date': date_cancel,
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|
||||||
def status(self, data, auth={}):
|
def status(self, data, auth={}):
|
||||||
if not auth:
|
if not auth:
|
||||||
|
|
|
@ -196,7 +196,7 @@ class PACFinkok(object):
|
||||||
return rfc_emisor, cfdi_uuid
|
return rfc_emisor, cfdi_uuid
|
||||||
|
|
||||||
def cancel(self, cfdi, info, auth={}):
|
def cancel(self, cfdi, info, auth={}):
|
||||||
if not auth:
|
if DEBUG or not auth:
|
||||||
auth = AUTH
|
auth = AUTH
|
||||||
|
|
||||||
rfc_emisor, cfdi_uuid = self._get_data_cancel(cfdi)
|
rfc_emisor, cfdi_uuid = self._get_data_cancel(cfdi)
|
||||||
|
@ -255,6 +255,12 @@ class PACFinkok(object):
|
||||||
|
|
||||||
folio = result['Folios']['Folio'][0]
|
folio = result['Folios']['Folio'][0]
|
||||||
status = folio['EstatusUUID']
|
status = folio['EstatusUUID']
|
||||||
|
|
||||||
|
if status == '708':
|
||||||
|
self._error = 'Error 708 del SAT, intenta más tarde.'
|
||||||
|
log.error(self.error)
|
||||||
|
return ''
|
||||||
|
|
||||||
if status != '201':
|
if status != '201':
|
||||||
log.debug(f'Cancel status: {status} -')
|
log.debug(f'Cancel status: {status} -')
|
||||||
|
|
||||||
|
|
|
@ -657,13 +657,32 @@ def get_pac_by_rfc(cfdi):
|
||||||
return RFCS[rfc_pac]
|
return RFCS[rfc_pac]
|
||||||
|
|
||||||
|
|
||||||
|
def _cancel_finkok(invoice, auth, certificado):
|
||||||
|
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||||
|
pac = PACS[auth['pac']]()
|
||||||
|
info = {'cer': cert.cer_pem, 'key': cert.key_pem}
|
||||||
|
|
||||||
|
result = pac.cancel(invoice.xml, info, auth)
|
||||||
|
if pac.error:
|
||||||
|
data = {'ok': False, 'msg': pac.error, 'row': {}}
|
||||||
|
return data
|
||||||
|
|
||||||
|
msg = 'Factura cancelada correctamente'
|
||||||
|
data = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
||||||
|
'date': result['date'], 'acuse': result['acuse']}
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
def cancel_xml_sign(invoice, auth, certificado):
|
def cancel_xml_sign(invoice, auth, certificado):
|
||||||
|
if auth['pac'] == 'finkok':
|
||||||
|
return _cancel_finkok(invoice, auth, certificado)
|
||||||
|
|
||||||
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
cert = SATCertificate(certificado.cer, certificado.key_enc.encode())
|
||||||
pac = PACS[auth['pac']]()
|
pac = PACS[auth['pac']]()
|
||||||
data = {
|
data = {
|
||||||
'rfc': certificado.rfc,
|
'rfc': certificado.rfc,
|
||||||
'fecha': now().isoformat()[:19],
|
'fecha': now().isoformat()[:19],
|
||||||
'uuid': invoice.uuid,
|
'uuid': str(invoice.uuid).upper(),
|
||||||
}
|
}
|
||||||
template = TEMPLATE_CANCEL.format(**data)
|
template = TEMPLATE_CANCEL.format(**data)
|
||||||
tree = ET.fromstring(template.encode())
|
tree = ET.fromstring(template.encode())
|
||||||
|
@ -672,13 +691,10 @@ def cancel_xml_sign(invoice, auth, certificado):
|
||||||
|
|
||||||
result = pac.cancel_xml(sign_xml, auth, invoice.xml)
|
result = pac.cancel_xml(sign_xml, auth, invoice.xml)
|
||||||
if pac.error:
|
if pac.error:
|
||||||
result = {'ok': False, 'msg': pac.error, 'row': {}}
|
data = {'ok': False, 'msg': pac.error, 'row': {}}
|
||||||
return result
|
return data
|
||||||
|
|
||||||
tree = ET.fromstring(result)
|
|
||||||
date_cancel = tree.xpath('string(//Acuse/@Fecha)')[:19]
|
|
||||||
|
|
||||||
msg = 'Factura cancelada correctamente'
|
msg = 'Factura cancelada correctamente'
|
||||||
result = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
data = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
||||||
'Fecha': date_cancel, 'Acuse': result}
|
'date': result['date'], 'acuse': result['acuse']}
|
||||||
return result
|
return data
|
||||||
|
|
|
@ -392,7 +392,7 @@ class Configuracion(BaseModel):
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _get_partners(self):
|
def _get_partners(self, args={}):
|
||||||
fields = (
|
fields = (
|
||||||
'chk_config_change_balance_partner',
|
'chk_config_change_balance_partner',
|
||||||
)
|
)
|
||||||
|
@ -3879,8 +3879,8 @@ class Facturas(BaseModel):
|
||||||
invoice.estatus = 'Cancelada'
|
invoice.estatus = 'Cancelada'
|
||||||
invoice.error = ''
|
invoice.error = ''
|
||||||
invoice.cancelada = True
|
invoice.cancelada = True
|
||||||
invoice.fecha_cancelacion = result['Fecha']
|
invoice.fecha_cancelacion = result['date']
|
||||||
invoice.acuse = result['Acuse'] or ''
|
invoice.acuse = result['acuse'] or ''
|
||||||
cls._actualizar_saldo_cliente(cls, invoice, True)
|
cls._actualizar_saldo_cliente(cls, invoice, True)
|
||||||
cls._update_inventory(cls, invoice, True)
|
cls._update_inventory(cls, invoice, True)
|
||||||
cls._uncancel_tickets(cls, invoice)
|
cls._uncancel_tickets(cls, invoice)
|
||||||
|
|
Loading…
Reference in New Issue