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.

61 lines
2.3 KiB

11 years ago
11 years ago
  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. # TRY TO SWITCH to _register_hook() in the model to avoid
  15. # execution when not installed in V 8.0 version
  16. module_name = os.path.basename(os.path.dirname(os.path.abspath(__file__)))
  17. DUMMY_MODEL = 'module.%s.installed' % module_name.replace('_', '.')
  18. class DummyModel(orm.Model):
  19. """ Allow to check if module is installed or not
  20. in fields_view_get method to avoid code execution if not
  21. Only executed if the module is installed
  22. """
  23. _name = DUMMY_MODEL
  24. fields_view_get_orginal = orm.BaseModel.fields_view_get
  25. def fields_view_get(self, cr, uid, view_id=None, view_type='form',
  26. context=None, toolbar=False, submenu=False):
  27. res = fields_view_get_orginal(
  28. self, cr, uid, view_id=view_id, view_type=view_type, context=context,
  29. toolbar=toolbar, submenu=submenu)
  30. if view_type == 'tree':
  31. compatible_tree = res.get('field_parent', True) is False
  32. # Tree views with res['field_parent'] different from False
  33. # looks like 'Products by Category'.
  34. # We don't modify these views
  35. # to avoid to break them (js error)
  36. if '_transient_max_count' in self.pool[res['model']].__dict__.keys():
  37. # model with '_transient_max_count' key are transient model
  38. # transient models haven't 'id' column in mostly case
  39. compatible_tree = False
  40. if compatible_tree and DUMMY_MODEL in self.pool.models.keys():
  41. doc = etree.XML(res['arch'])
  42. if (doc.xpath("//tree") and
  43. len(doc.xpath("//field[@name='id']"))) == 0:
  44. node = doc.xpath("//tree")[0]
  45. node.append(etree.Element("field", name="id", string="Id"))
  46. res['arch'] = etree.tostring(node)
  47. return res
  48. orm.BaseModel.fields_view_get = fields_view_get