Odoo Mindscape. Understand Odoo faster. Explore modules, fields, dependencies and version differences in one place instead of digging through the source code.

Module: Romania - Mesaje SPV

Entity: l10n.ro.message.spv

Compute Method: _compute_derived_attachments

Inputs Method Outputs
attachment_obj = self.env["ir.attachment"].sudo()
for message in self:
            xml = anaf_pdf = embedded_pdf = attachment_obj.browse()
            if message.invoice_id and message.request_id:
                # The UBL import moves the source XML into the invoice's
                # ubl_cii_xml_file binary field, so include res_field
                # attachments in the search (they are filtered out by
                # default).
                attachments = attachment_obj.search(
                    [
                        ("res_model", "=", "account.move"),
                        ("res_id", "=", message.invoice_id.id),
                        "|",
                        ("res_field", "=", False),
                        ("res_field", "=", "ubl_cii_xml_file"),
                    ]
                )
                xml_name = f"{message.request_id}.xml"
                pdf_name = f"{message.request_id}.pdf"
                xml = attachments.filtered(lambda a, n=xml_name: a.name == n)[:1]
                anaf_pdf = attachments.filtered(lambda a, n=pdf_name: a.name == n)[:1]
                embedded_pdf = attachments.filtered(
                    lambda a, n=pdf_name: a.mimetype == "application/pdf"
                    and a.name != n
                    and "Generated by Odoo" not in a.name
                )[:1]
            message.attachment_xml_id = xml
            message.attachment_anaf_pdf_id = anaf_pdf
            message.attachment_embedded_pdf_id = embedded_pdf

Back to entity