@@ -212,6 +212,9 @@ def _perform_cancel_operation(self, cancellation: XElement, operation: str):
212212 self ._validate_cancel_response (root )
213213
214214 ack = root .find (".//apps:Acuse" , self .namespaces )
215+ acuse_bytes = None
216+ if ack is not None and ack .text :
217+ acuse_bytes = unescape (ack .text ).encode ()
215218
216219 if operation == "accept_reject" :
217220 acceptances = root .find (".//apps:aceptacion" , self .namespaces )
@@ -229,12 +232,28 @@ def _perform_cancel_operation(self, cancellation: XElement, operation: str):
229232
230233 return AcceptRejectAcknowledgment (
231234 folios = folios ,
232- acuse = unescape ( ack . text ). encode () if ack is not None else None ,
235+ acuse = acuse_bytes ,
233236 )
234237
238+ estatus_uuid_elem = root .find (".//apps:EstatusUUID" , self .namespaces )
239+ if estatus_uuid_elem is not None :
240+ code = estatus_uuid_elem .text
241+ else :
242+ cod_estatus_elem = root .find (".//apps:CodEstatus" , self .namespaces )
243+ code = cod_estatus_elem .text if cod_estatus_elem is not None else None
244+
245+ if code is None and acuse_bytes :
246+ try :
247+ acuse_root = etree .fromstring (acuse_bytes )
248+ estatus_in_acuse = acuse_root .find (".//*[local-name()='EstatusUUID']" )
249+ if estatus_in_acuse is not None and estatus_in_acuse .text :
250+ code = estatus_in_acuse .text
251+ except Exception :
252+ pass
253+
235254 return CancelationAcknowledgment (
236- code = root . find ( ".//apps:EstatusUUID" , self . namespaces ). text ,
237- acuse = unescape ( ack . text ). encode () ,
255+ code = code ,
256+ acuse = acuse_bytes ,
238257 )
239258
240259 def issue (self , cfdi : CFDI , accept : Accept = Accept .XML ) -> Document :
0 commit comments