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.

112 lines
3.8 KiB

  1. # Copyright 2016 Therp BV <http://therp.nl>
  2. # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
  3. from lxml import etree
  4. from odoo.tests.common import TransactionCase
  5. class TestBaseViewInheritanceExtension(TransactionCase):
  6. def test_base_view_inheritance_extension(self):
  7. view_id = self.env.ref('base.view_partner_simple_form').id
  8. fields_view_get = self.env['res.partner'].fields_view_get(
  9. view_id=view_id
  10. )
  11. view = etree.fromstring(fields_view_get['arch'])
  12. # verify normal attributes work
  13. self.assertEqual(view.xpath('//form')[0].get('string'), 'Partner form')
  14. # verify our extra context key worked
  15. self.assertTrue(
  16. 'default_name' in
  17. view.xpath('//field[@name="parent_id"]')[0].get('context')
  18. )
  19. self.assertTrue(
  20. "context.get('company_id', context.get('company'))" in
  21. view.xpath('//field[@name="parent_id"]')[0].get('context')
  22. )
  23. # verify we moved the child_ids field
  24. self.assertEqual(
  25. view.xpath('//field[@name="mobile"]')[0].getparent(),
  26. view.xpath('//page[@name="phone_book"]')[0]
  27. )
  28. def test_list_add(self):
  29. view_model = self.env['ir.ui.view']
  30. inherit_id = self.env.ref('base.view_partner_form').id
  31. source = etree.fromstring(
  32. """\
  33. <form>
  34. <button name="test" states="draft,open"/>
  35. </form>
  36. """
  37. )
  38. # extend with single value
  39. specs = etree.fromstring(
  40. """\
  41. <button name="test" position="attributes">
  42. <attribute
  43. name="states"
  44. operation="list_add"
  45. >valid</attribute>
  46. </button>
  47. """
  48. )
  49. modified_source = \
  50. view_model.inheritance_handler_attributes_list_add(
  51. source, specs, inherit_id
  52. )
  53. button_node = modified_source.xpath('//button[@name="test"]')[0]
  54. self.assertEqual(
  55. button_node.attrib['states'],
  56. 'draft,open,valid'
  57. )
  58. # extend with list of values
  59. specs = etree.fromstring(
  60. """\
  61. <button name="test" position="attributes">
  62. <attribute
  63. name="states"
  64. operation="list_add"
  65. >payable,paid</attribute>
  66. </button>
  67. """
  68. )
  69. modified_source = \
  70. view_model.inheritance_handler_attributes_list_add(
  71. source, specs, inherit_id
  72. )
  73. button_node = modified_source.xpath('//button[@name="test"]')[0]
  74. self.assertEqual(
  75. button_node.attrib['states'],
  76. 'draft,open,valid,payable,paid'
  77. )
  78. def test_list_remove(self):
  79. view_model = self.env['ir.ui.view']
  80. inherit_id = self.env.ref('base.view_partner_form').id
  81. source = etree.fromstring(
  82. """\
  83. <form>
  84. <button name="test" states="draft,open,valid,payable,paid"/>
  85. </form>
  86. """
  87. )
  88. # remove list of values
  89. specs = etree.fromstring(
  90. """\
  91. <button name="test" position="attributes">
  92. <attribute
  93. name="states"
  94. operation="list_remove"
  95. >open,payable</attribute>
  96. </button>
  97. """
  98. )
  99. modified_source = \
  100. view_model.inheritance_handler_attributes_list_remove(
  101. source, specs, inherit_id
  102. )
  103. button_node = modified_source.xpath('//button[@name="test"]')[0]
  104. self.assertEqual(
  105. button_node.attrib['states'],
  106. 'draft,valid,paid'
  107. )