odoo/odoo · error · UserError

Cannot decode origin file, try by importing it again

Error message

Cannot decode origin file, try by importing it again

What it means

UserError raised in _ungroup_lines when the origin attachment exists (ubl_cii_xml_id is set) but no decoder could be resolved for it: after unwrapping attachments and grouping files by type, fileData_group[0]['decoder_info']['decoder'] is None. That happens when the attached file's type/format is not recognized by any UBL/CII decoder.

Source

Thrown at addons/account_edi_ubl_cii/models/account_move.py:140

        else:
            self._group_lines_by_tax()

    def _ungroup_lines(self):
        """
        Ungroup lines using the original file, used to import the move
        """
        self.ensure_one()
        error_message = self.env._("Cannot find the origin file, try by importing it again")
        if not self.ubl_cii_xml_id:
            raise UserError(error_message)

        files_data = self._to_files_data(self.ubl_cii_xml_id)
        files_data.extend(self._unwrap_attachments(files_data))
        file_data_group = self._group_files_data_into_groups_of_mixed_types(files_data)[0]

        decoder = file_data_group[0].get('decoder_info', {}).get('decoder')
        if decoder is None:
            raise UserError(self.env._("Cannot decode origin file, try by importing it again"))

        self.invoice_line_ids = [Command.clear()]
        if decoder(self, file_data_group[0]) is None:
            self._message_log(body=self.env._("Ungrouped lines from %s", file_data_group[0]['attachment'].name))
        else:
            raise UserError(error_message)

    def _group_lines_by_tax(self):
        """
        Group lines by tax, based on the invoice lines
        """
        self.ensure_one()
        if not self.is_invoice(include_receipts=True):
            raise UserError(self.env._("You can only group lines of an invoice"))

        line_vals = self._get_line_vals_group_by_tax(self.partner_id)
        self.invoice_line_ids = [Command.clear()]
        self.invoice_line_ids = line_vals

View on GitHub (pinned to 1e661df964)

Solutions

  1. Verify the attachment referenced by ubl_cii_xml_id is the original valid XML (UBL/CII); re-import the correct file if not.
  2. For PDF e-invoices, ensure the PDF actually embeds the XML (Factur-X/ZUGFeRD) and is not a plain visual PDF.
  3. Fix mimetype/extension so file recognition works, then retry ungroup.
  4. If decoding genuinely fails, fall back to editing the grouped line manually.

Example fix

# before
move._ungroup_lines()  # decoder is None

# after: verify a decoder exists before mutating lines
files_data = move._to_files_data(move.ubl_cii_xml_id)
files_data.extend(move._unwrap_attachments(files_data))
group = move._group_files_data_into_groups_of_mixed_types(files_data)[0]
if group[0].get('decoder_info', {}).get('decoder') is None:
    raise UserError('Origin file is not a decodable UBL/CII document; re-import it.')
move._ungroup_lines()
Defensive patterns

Strategy: validation

Validate before calling

files_data = move._to_files_data(move.ubl_cii_xml_id)
files_data.extend(move._unwrap_attachments(files_data))
group = move._group_files_data_into_groups_of_mixed_types(files_data)[0]
assert group[0].get('decoder_info', {}).get('decoder') is not None, 'undecodable origin file'

Type guard

def has_decoder(move) -> bool:
    fd = move._to_files_data(move.ubl_cii_xml_id)
    fd.extend(move._unwrap_attachments(fd))
    g = move._group_files_data_into_groups_of_mixed_types(fd)[0]
    return g[0].get('decoder_info', {}).get('decoder') is not None

Prevention

When it happens

Trigger: The move's ubl_cii_xml_id points to a file that is not a decodable UBL/CII document — e.g. a PDF without embedded XML, an attachment wrapper whose inner file is another format, or a manually attached XML of an unsupported dialect. _group_files_data_into_groups_of_mixed_types finds files but decoder registration yields None.

Common situations: Users replacing/adding attachments on an imported invoice so the origin file is no longer the actual XML; hybrid PDFs (Factur-X/ZUGFeRD) where XML extraction fails; third-party files with wrong extensions/mimetypes.

Related errors


AI-assisted analysis of odoo/odoo@1e661df964 (2026-08-15). Data as JSON: /api/errors/4b03616dd08332d1. Report an issue: GitHub.