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.

75 lines
2.6 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 LasLabs Inc.
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from openerp import api
  5. from lxml import etree
  6. from openerp.addons.base.res.res_config import \
  7. res_config_settings
  8. class ResConfigSettings(res_config_settings):
  9. @api.model
  10. def fields_view_get(self, view_id=None, view_type='form',
  11. context=None, toolbar=False, submenu=False):
  12. ret_val = super(ResConfigSettings, self).fields_view_get(
  13. view_id=view_id,
  14. view_type=view_type,
  15. context=context,
  16. toolbar=toolbar,
  17. submenu=submenu,
  18. )
  19. doc = etree.XML(ret_val['arch'])
  20. # Remove Individual Elements
  21. xpath_specific_queries = [
  22. # Sale
  23. "//div[field[@name='module_sale_contract']] \
  24. /preceding-sibling::label[1]",
  25. # Inventory
  26. "//div[div[field[@name='module_delivery_dhl']]] \
  27. /preceding-sibling::label[1]",
  28. "//div[div[field[@name='module_stock_barcode']]] \
  29. /preceding-sibling::label[1]",
  30. # Invoicing
  31. "//a[@href='https://www.odoo.com/page/accounting-features']",
  32. "//div[@name='bank_statement_import_options'] \
  33. /preceding-sibling::label[1]",
  34. "//div[@name='bank_payments']/preceding-sibling::label[1]",
  35. # Project
  36. "//div[div[field[@name='module_project_forecast']]] \
  37. /preceding-sibling::label[1]",
  38. "//div[field[@name='module_project_timesheet_synchro']] \
  39. /preceding-sibling::label[1]",
  40. # WebsiteAdmin
  41. "//div[div[field[@name='module_website_form_editor']]] \
  42. /preceding-sibling::label[1]",
  43. ]
  44. for query in xpath_specific_queries:
  45. items = doc.xpath("%s" % query)
  46. for item in items:
  47. item.getparent().remove(item)
  48. # Bulk Remove Fields and Labels
  49. upgrade_fields = doc.xpath("//field[@widget='upgrade_boolean']")
  50. for field in upgrade_fields:
  51. for label in doc.xpath("//label[@for='%s']" % field.get('name')):
  52. label.getparent().remove(label)
  53. field.getparent().remove(field)
  54. # Clean Up Empty Divs
  55. complete = False
  56. while not complete:
  57. divs = doc.xpath("//div[not(*)]")
  58. if not divs:
  59. complete = True
  60. else:
  61. for div in divs:
  62. div.getparent().remove(div)
  63. ret_val['arch'] = etree.tostring(doc)
  64. return ret_val