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.

57 lines
2.0 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # licence AGPL version 3 or later
  5. # see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
  6. # Copyright (C) 2014 Akretion (http://www.akretion.com).
  7. # @author David BEAL <david.beal@akretion.com>
  8. #
  9. ##############################################################################
  10. from openerp.osv import orm
  11. from lxml import etree
  12. import os
  13. """ procedural code is executed even if the module is not installed
  14. """
  15. module_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
  16. DUMMY_MODEL = 'module.%s.installed' % module_name.replace('_', '.')
  17. class DummyModel(orm.Model):
  18. """ Allow to check if module is installed or not
  19. in fields_view_get method to avoid code execution if not
  20. Only executed if the module is installed
  21. """
  22. _name = DUMMY_MODEL
  23. fields_view_get_orginal = orm.BaseModel.fields_view_get
  24. def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None,
  25. toolbar=False, submenu=False):
  26. res = fields_view_get_orginal(
  27. self, cr, uid, view_id=view_id, view_type=view_type, context=context,
  28. toolbar=toolbar, submenu=submenu)
  29. if view_type == 'tree':
  30. compatible_tree = False
  31. # Tree views with res['field_parent'] different from False
  32. # looks like 'Products by Category'.
  33. # We don't modify these views
  34. # to avoid to break them (js error)
  35. if res.get('field_parent', True) is False:
  36. compatible_tree = True
  37. if compatible_tree and DUMMY_MODEL in self.pool.models.keys():
  38. doc = etree.XML(res['arch'])
  39. if doc.xpath("//tree") and len(doc.xpath("//field[@name='id']")) == 0:
  40. node = doc.xpath("//tree")[0]
  41. node.append(etree.Element("field", name="id", string="Id"))
  42. res['arch'] = etree.tostring(node)
  43. return res
  44. orm.BaseModel.fields_view_get = fields_view_get