{"record":{"id":"4b03616dd08332d1","repo":"odoo/odoo","slug":"cannot-decode-origin-file-try-by-importing-it-aga","errorCode":null,"errorMessage":"Cannot decode origin file, try by importing it again","messagePattern":"Cannot decode origin file, try by importing it again","errorType":"exception","errorClass":"UserError","httpStatus":null,"severity":"error","filePath":"addons/account_edi_ubl_cii/models/account_move.py","lineNumber":140,"sourceCode":"        else:\n            self._group_lines_by_tax()\n\n    def _ungroup_lines(self):\n        \"\"\"\n        Ungroup lines using the original file, used to import the move\n        \"\"\"\n        self.ensure_one()\n        error_message = self.env._(\"Cannot find the origin file, try by importing it again\")\n        if not self.ubl_cii_xml_id:\n            raise UserError(error_message)\n\n        files_data = self._to_files_data(self.ubl_cii_xml_id)\n        files_data.extend(self._unwrap_attachments(files_data))\n        file_data_group = self._group_files_data_into_groups_of_mixed_types(files_data)[0]\n\n        decoder = file_data_group[0].get('decoder_info', {}).get('decoder')\n        if decoder is None:\n            raise UserError(self.env._(\"Cannot decode origin file, try by importing it again\"))\n\n        self.invoice_line_ids = [Command.clear()]\n        if decoder(self, file_data_group[0]) is None:\n            self._message_log(body=self.env._(\"Ungrouped lines from %s\", file_data_group[0]['attachment'].name))\n        else:\n            raise UserError(error_message)\n\n    def _group_lines_by_tax(self):\n        \"\"\"\n        Group lines by tax, based on the invoice lines\n        \"\"\"\n        self.ensure_one()\n        if not self.is_invoice(include_receipts=True):\n            raise UserError(self.env._(\"You can only group lines of an invoice\"))\n\n        line_vals = self._get_line_vals_group_by_tax(self.partner_id)\n        self.invoice_line_ids = [Command.clear()]\n        self.invoice_line_ids = line_vals","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/odoo/odoo/blob/1e661df964b1b264c9cef3ab28430d4785be3fda/addons/account_edi_ubl_cii/models/account_move.py#L122-L158","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the attachment referenced by ubl_cii_xml_id is the original valid XML (UBL/CII); re-import the correct file if not.","For PDF e-invoices, ensure the PDF actually embeds the XML (Factur-X/ZUGFeRD) and is not a plain visual PDF.","Fix mimetype/extension so file recognition works, then retry ungroup.","If decoding genuinely fails, fall back to editing the grouped line manually."],"exampleFix":"# before\nmove._ungroup_lines()  # decoder is None\n\n# after: verify a decoder exists before mutating lines\nfiles_data = move._to_files_data(move.ubl_cii_xml_id)\nfiles_data.extend(move._unwrap_attachments(files_data))\ngroup = move._group_files_data_into_groups_of_mixed_types(files_data)[0]\nif group[0].get('decoder_info', {}).get('decoder') is None:\n    raise UserError('Origin file is not a decodable UBL/CII document; re-import it.')\nmove._ungroup_lines()","handlingStrategy":"validation","validationCode":"files_data = move._to_files_data(move.ubl_cii_xml_id)\nfiles_data.extend(move._unwrap_attachments(files_data))\ngroup = move._group_files_data_into_groups_of_mixed_types(files_data)[0]\nassert group[0].get('decoder_info', {}).get('decoder') is not None, 'undecodable origin file'","typeGuard":"def has_decoder(move) -> bool:\n    fd = move._to_files_data(move.ubl_cii_xml_id)\n    fd.extend(move._unwrap_attachments(fd))\n    g = move._group_files_data_into_groups_of_mixed_types(fd)[0]\n    return g[0].get('decoder_info', {}).get('decoder') is not None","tryCatchPattern":null,"preventionTips":["Do not replace the origin attachment with non-XML files after import","Ensure PDF e-invoices embed the XML (Factur-X/ZUGFeRD) with a correct mimetype"],"tags":["odoo","edi","ubl","decoder","attachment"],"backgroundTag":null,"analyzedSha":"1e661df964b1b264c9cef3ab28430d4785be3fda","analyzedAt":"2026-08-15T05:22:16.142Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}