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.

53 lines
1.7 KiB

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