You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. # Copyright 2014 ACSONE SA/NV (<http://acsone.eu>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. import base64
  4. from io import StringIO
  5. from lxml import etree
  6. import logging
  7. import os
  8. from odoo import api, fields, models
  9. from odoo.tools import convert, misc
  10. from odoo.tools.config import config
  11. _logger = logging.getLogger(__name__)
  12. class XmlImport(convert.xml_import):
  13. """Override base xml_import to be able to import record with an exported
  14. xml_id ('__export__.XXX-XXX')
  15. """
  16. def _test_xml_id(self, xml_id):
  17. if '.' in xml_id:
  18. module, _id = xml_id.split('.')
  19. if module == '__export__':
  20. return True
  21. super(XmlImport, self)._test_xml_id(xml_id)
  22. class ImportHelpWizard(models.TransientModel):
  23. _name = "import.help.wizard"
  24. source_file = fields.Binary('Source File')
  25. @api.multi
  26. def import_help(self):
  27. for this in self:
  28. xmlfile = StringIO(base64.decodestring(this.source_file))
  29. doc = etree.parse(xmlfile)
  30. relaxng = etree.RelaxNG(
  31. etree.parse(
  32. os.path.join(config['root_path'], 'import_xml.rng')))
  33. try:
  34. relaxng.assertTrue(doc)
  35. except Exception:
  36. _logger.info('The XML file does not fit the required schema !',
  37. exc_info=True)
  38. _logger.info(misc.ustr(relaxng.error_log.last_error))
  39. raise
  40. obj = XmlImport(self.env.cr, self._module, idref={}, mode='init',
  41. report=None, noupdate=False, xml_filename=None)
  42. obj.parse(doc.getroot(), mode='init')