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'])
|
||||
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={}):
|
||||
if not auth:
|
||||
|
|
|
@ -196,7 +196,7 @@ class PACFinkok(object):
|
|||
return rfc_emisor, cfdi_uuid
|
||||
|
||||
def cancel(self, cfdi, info, auth={}):
|
||||
if not auth:
|
||||
if DEBUG or not auth:
|
||||
auth = AUTH
|
||||
|
||||
rfc_emisor, cfdi_uuid = self._get_data_cancel(cfdi)
|
||||
|
@ -255,6 +255,12 @@ class PACFinkok(object):
|
|||
|
||||
folio = result['Folios']['Folio'][0]
|
||||
status = folio['EstatusUUID']
|
||||
|
||||
if status == '708':
|
||||
self._error = 'Error 708 del SAT, intenta más tarde.'
|
||||
log.error(self.error)
|
||||
return ''
|
||||
|
||||
if status != '201':
|
||||
log.debug(f'Cancel status: {status} -')
|
||||
|
||||
|
|
|
@ -657,13 +657,32 @@ def get_pac_by_rfc(cfdi):
|
|||
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):
|
||||
if auth['pac'] == 'finkok':
|
||||
return _cancel_finkok(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,
|
||||
'uuid': str(invoice.uuid).upper(),
|
||||
}
|
||||
template = TEMPLATE_CANCEL.format(**data)
|
||||
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)
|
||||
if pac.error:
|
||||
result = {'ok': False, 'msg': pac.error, 'row': {}}
|
||||
return result
|
||||
|
||||
tree = ET.fromstring(result)
|
||||
date_cancel = tree.xpath('string(//Acuse/@Fecha)')[:19]
|
||||
data = {'ok': False, 'msg': pac.error, 'row': {}}
|
||||
return data
|
||||
|
||||
msg = 'Factura cancelada correctamente'
|
||||
result = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
||||
'Fecha': date_cancel, 'Acuse': result}
|
||||
return result
|
||||
data = {'ok': True, 'msg': msg, 'row': {'estatus': 'Cancelada'},
|
||||
'date': result['date'], 'acuse': result['acuse']}
|
||||
return data
|
||||
|
|
|
@ -392,7 +392,7 @@ class Configuracion(BaseModel):
|
|||
return True
|
||||
return False
|
||||
|
||||
def _get_partners(self):
|
||||
def _get_partners(self, args={}):
|
||||
fields = (
|
||||
'chk_config_change_balance_partner',
|
||||
)
|
||||
|
@ -3879,8 +3879,8 @@ class Facturas(BaseModel):
|
|||
invoice.estatus = 'Cancelada'
|
||||
invoice.error = ''
|
||||
invoice.cancelada = True
|
||||
invoice.fecha_cancelacion = result['Fecha']
|
||||
invoice.acuse = result['Acuse'] or ''
|
||||
invoice.fecha_cancelacion = result['date']
|
||||
invoice.acuse = result['acuse'] or ''
|
||||
cls._actualizar_saldo_cliente(cls, invoice, True)
|
||||
cls._update_inventory(cls, invoice, True)
|
||||
cls._uncancel_tickets(cls, invoice)
|
||||
|
|
Loading…
Reference in New Issue