Disrupt Odoo flow

I am developing an electronic invoicing system with a third party invoice certifier. When there is an error in the invoice and it is not certified, the certifier returns a json with information about the error.

I made a new module that places the errors in the corresponding invoice, but here comes my problem.

I want to launch an alert with “UserError” that tells me that the invoice has not been certified, but when I use “raise UserError”, all the transactions of the transaction that triggered the alert are reverted, therefore the errors are not placed in the invoice view.

On the other hand, if I don’t use a “raise UserError”, the errors are placed, but the invoice within Odoo continues its flow and is published, which is not right for my business logic.

This are the error view

But the invoice is published now and this is wrong

I would like to stop the Odoo flow and prevent the invoice from posting and errors from being set on the invoice.

    def certificar_documento(self, url, headers, tree):
        certificar_xml = ET.tostring(tree.getroot(), encoding="UTF-8", method="xml")
        respuesta = requests.post(url, headers=headers, data=certificar_xml)
        respuesta_json = respuesta.json()

        return certificar_xml, respuesta_json

    def establecer_error(self, json):
        errores = self.env["errores.fel"]
        for error in json["descripcion_errores"]:
            errores.create(
                {
                    "mensaje_error": error.get("mensaje_error"),
                    "fecha_hora_error": datetime.now(),
                    "account_move_factuas_ids": self.id,
                }
            )

    def facturacion_electronica(self):
        url = "https://certificador.feel.com.gt/fel/procesounificado/transaccion/v2/xml"

        headers = {
            "UsuarioFirma": f"{self.company_id.usuario}",
            "LlaveFirma": f"{self.company_id.llave_firma}",
            "UsuarioApi": f"{self.company_id.usuario}",
            "LlaveApi": f"{self.company_id.llave_api}",
            "Content-Type": "application/xml",
        }

        for factura in self:
            if (
                factura.tipo_factura == "none"
                and factura.move_type != "out_refund"
                and factura.move_type != "in_invoice"
                and not factura.debit_origin_id
            ):
                raise UserError("Debe ingresar el tipo de documento que va a emitir")

            elif factura.debit_origin_id:
                tree = NDEB.generar_nota_debito(self, factura)

            elif factura.move_type == "out_refund":
                tree = NCRE.generar_nota_credito(self, factura)

            elif factura.tipo_factura == "fact" or factura.tipo_factura == "fact_cambiaria":
                tree = FACT.generar_factura(self, factura)

            elif factura.factura_especial:
                tree = FESP.generar_especial(self, factura)

            else:
                continue

            certificar_xml, respuesta_json = self.certificar_documento(url, headers, tree)
            if respuesta_json["resultado"] == False:
                # mensajes_error = "n".join(error["mensaje_error"] for error in respuesta_json["descripcion_errores"])
                # raise ValidationError(f"La factura no se certificón{mensajes_error}")
                self.establecer_error(respuesta_json)
                return
            else:
                factura.numero_autorizacion = respuesta_json["uuid"]
                factura.serie = respuesta_json["serie"]
                factura.numero_dte = respuesta_json["numero"]
                factura.xml_generado = certificar_xml
                factura.fecha_emision = datetime.now()
                fecha_hora_certificado = respuesta_json["fecha"].split("T")
                hora_certificado = fecha_hora_certificado[1].split("-")
                fecha_hora_str = f"{fecha_hora_certificado[0]} {hora_certificado[0]}"
                fecha_hora_time = datetime.strptime(fecha_hora_str, "%Y-%m-%d %H:%M:%S")
                fecha_hora_modificada = fecha_hora_time + timedelta(hours=6)
                factura.fecha_certificacion = fecha_hora_modificada
                factura.xml_certificado = respuesta_json["xml_certificado"]
                factura.certificada = True

                var_numero_autorizacion = respuesta_json["uuid"]
                var_serie = respuesta_json["serie"]
                var_numero_dte = respuesta_json["numero"]
                var_fecha = date.today()

                link_factura = (
                    f"https://report.feel.com.gt/ingfacereport/ingfacereport_documento?uuid={var_numero_autorizacion}"
                )

                mensaje = f"""
                    <strong style='display:block;'>Datos FEL de la factura</strong>
                    <ul>
                        <li>
                            Número de autorización: {var_numero_autorizacion}
                        </li>
                        <li>
                            Serie: {var_serie}
                        </li>
                        <li>
                            Número DTE: {var_numero_dte}
                        </li>
                        <li>
                            Fecha: {var_fecha}
                        </li>
                    </ul>
                    <a href='{link_factura}' target='_blank'>Ver factura<a/>
                """

                factura.message_post(
                    body=mensaje,
                    body_is_html=True,
                    author_id=self.env.ref("base.partner_root").id,
                    subject="Factura certificada correctamente",
                    message_type="comment",
                    subtype_xmlid="mail.mt_comment",
                )

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật