summaryrefslogtreecommitdiff
path: root/odoo/addons/base
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-08-08 11:52:13 +0200
committerChristophe Simonis <chs@odoo.com>2019-08-08 11:52:13 +0200
commitb792ba7d9a80e856e3c69c2852e6d44b78d0e13f (patch)
treea3ee5b7ef9f9317866deeb2b3e5964020c87b8fb /odoo/addons/base
parent22e0f88bce5bf162a6c67e915a3c27b101f74f2b (diff)
parent752b2553c6fad061ebf23e13585f7b7489b20840 (diff)
[MERGE] forward port branch saas-12.3 up to 752b2553c6f
Diffstat (limited to 'odoo/addons/base')
-rw-r--r--odoo/addons/base/models/ir_ui_view.py15
-rw-r--r--odoo/addons/base/rng/gantt_view.rng2
-rw-r--r--odoo/addons/base/tests/test_views.py109
-rw-r--r--odoo/addons/base/views/res_company_views.xml2
-rw-r--r--odoo/addons/base/views/res_partner_views.xml4
5 files changed, 128 insertions, 4 deletions
diff --git a/odoo/addons/base/models/ir_ui_view.py b/odoo/addons/base/models/ir_ui_view.py
index 5ee3d98b8aa..b3c1f9e8d07 100644
--- a/odoo/addons/base/models/ir_ui_view.py
+++ b/odoo/addons/base/models/ir_ui_view.py
@@ -674,9 +674,19 @@ actual arch.
if node.getparent() is None:
source = copy.deepcopy(spec[0])
else:
+ replaced_node_tag = None
for child in spec:
if child.get('position') == 'move':
child = extract(child)
+
+ if self._context.get('inherit_branding') and not replaced_node_tag and child.tag is not etree.Comment:
+ # To make a correct branding, we need to
+ # - know exactly which node has been replaced
+ # - store it before anything else has altered the Tree
+ # Do it exactly here :D
+ child.set('meta-oe-xpath-replacing', node.tag)
+ replaced_node_tag = node.tag # We just store the replaced node tag on the first child of the xpath replacing it
+
node.addprevious(child)
node.getparent().remove(node)
elif pos == 'attributes':
@@ -1299,6 +1309,11 @@ actual arch.
if child.get('data-oe-xpath'):
# injected by view inheritance, skip otherwise
# generated xpath is incorrect
+ # Also, if a node is known to have been replaced during applying xpath
+ # increment its index to compute an accurate xpath for susequent nodes
+ replaced_node_tag = child.attrib.pop('meta-oe-xpath-replacing', None)
+ if replaced_node_tag:
+ indexes[replaced_node_tag] += 1
self.distribute_branding(child)
else:
indexes[child.tag] += 1
diff --git a/odoo/addons/base/rng/gantt_view.rng b/odoo/addons/base/rng/gantt_view.rng
index 2180800c8de..5183fd65744 100644
--- a/odoo/addons/base/rng/gantt_view.rng
+++ b/odoo/addons/base/rng/gantt_view.rng
@@ -60,7 +60,7 @@
</rng:optional>
</rng:interleave>
- <rng:empty/>
+ <rng:empty/>
</rng:element>
</rng:define>
<rng:start>
diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py
index 6c371741855..e7f0d850ee2 100644
--- a/odoo/addons/base/tests/test_views.py
+++ b/odoo/addons/base/tests/test_views.py
@@ -674,6 +674,115 @@ class TestTemplating(ViewCase):
second.get('data-oe-id'),
"second should come from the extension view")
+ def test_branding_inherit_replace_node(self):
+ view1 = self.View.create({
+ 'name': "Base view",
+ 'type': 'qweb',
+ 'arch': """<hello>
+ <world></world>
+ <world><t t-esc="hello"/></world>
+ <world></world>
+ </hello>
+ """
+ })
+ self.View.create({
+ 'name': "Extension",
+ 'type': 'qweb',
+ 'inherit_id': view1.id,
+ 'arch': """<xpath expr="/hello/world[1]" position="replace">
+ <world>Is a ghetto</world>
+ <world>Wonder when I'll find paradise</world>
+ </xpath>
+ """
+ })
+
+ arch_string = view1.with_context(inherit_branding=True).read_combined(['arch'])['arch']
+
+ arch = etree.fromstring(arch_string)
+ self.View.distribute_branding(arch)
+
+ # First world - has been replaced by inheritance
+ [initial] = arch.xpath('/hello[1]/world[1]')
+ self.assertEqual(
+ '/xpath/world[1]',
+ initial.get('data-oe-xpath'),
+ 'Inherited nodes have correct xpath')
+
+ # Second world added by inheritance
+ [initial] = arch.xpath('/hello[1]/world[2]')
+ self.assertEqual(
+ '/xpath/world[2]',
+ initial.get('data-oe-xpath'),
+ 'Inherited nodes have correct xpath')
+
+ # Third world - is not editable
+ [initial] = arch.xpath('/hello[1]/world[3]')
+ self.assertFalse(
+ initial.get('data-oe-xpath'),
+ 'node containing t-esc is not branded')
+
+ # The most important assert
+ # Fourth world - should have a correct oe-xpath, which is 3rd in main view
+ [initial] = arch.xpath('/hello[1]/world[4]')
+ self.assertEqual(
+ '/hello[1]/world[3]',
+ initial.get('data-oe-xpath'),
+ "The node's xpath position should be correct")
+
+ def test_branding_inherit_replace_node2(self):
+ view1 = self.View.create({
+ 'name': "Base view",
+ 'type': 'qweb',
+ 'arch': """<hello>
+ <world></world>
+ <world><t t-esc="hello"/></world>
+ <world></world>
+ </hello>
+ """
+ })
+ self.View.create({
+ 'name': "Extension",
+ 'type': 'qweb',
+ 'inherit_id': view1.id,
+ 'arch': """<xpath expr="/hello/world[1]" position="replace">
+ <war>Is a ghetto</war>
+ <world>Wonder when I'll find paradise</world>
+ </xpath>
+ """
+ })
+
+ arch_string = view1.with_context(inherit_branding=True).read_combined(['arch'])['arch']
+
+ arch = etree.fromstring(arch_string)
+ self.View.distribute_branding(arch)
+
+ [initial] = arch.xpath('/hello[1]/war[1]')
+ self.assertEqual(
+ '/xpath/war',
+ initial.get('data-oe-xpath'),
+ 'Inherited nodes have correct xpath')
+
+ # First world: from inheritance
+ [initial] = arch.xpath('/hello[1]/world[1]')
+ self.assertEqual(
+ '/xpath/world',
+ initial.get('data-oe-xpath'),
+ 'Inherited nodes have correct xpath')
+
+ # Second world - is not editable
+ [initial] = arch.xpath('/hello[1]/world[2]')
+ self.assertFalse(
+ initial.get('data-oe-xpath'),
+ 'node containing t-esc is not branded')
+
+ # The most important assert
+ # Third world - should have a correct oe-xpath, which is 3rd in main view
+ [initial] = arch.xpath('/hello[1]/world[3]')
+ self.assertEqual(
+ '/hello[1]/world[3]',
+ initial.get('data-oe-xpath'),
+ "The node's xpath position should be correct")
+
def test_branding_primary_inherit(self):
view1 = self.View.create({
'name': "Base view",
diff --git a/odoo/addons/base/views/res_company_views.xml b/odoo/addons/base/views/res_company_views.xml
index c835527c8c2..6eb7a57838f 100644
--- a/odoo/addons/base/views/res_company_views.xml
+++ b/odoo/addons/base/views/res_company_views.xml
@@ -30,7 +30,7 @@
</div>
</group>
<group>
- <field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
+ <field name="website" widget="url" placeholder="e.g. https://www.odoo.com"/>
<field name="phone"/>
<field name="email"/>
<field name="vat"/>
diff --git a/odoo/addons/base/views/res_partner_views.xml b/odoo/addons/base/views/res_partner_views.xml
index 4b1828c8c22..f8c9ba3d7af 100644
--- a/odoo/addons/base/views/res_partner_views.xml
+++ b/odoo/addons/base/views/res_partner_views.xml
@@ -117,7 +117,7 @@
<field name="zip" placeholder="ZIP" class="o_address_zip"/>
<field name="country_id" placeholder="Country" class="o_address_country" options='{"no_open": True, "no_create": True}'/>
</div>
- <field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
+ <field name="website" widget="url" placeholder="e.g. https://www.odoo.com"/>
</group>
<group>
</group>
@@ -263,7 +263,7 @@
<field name="mobile" widget="phone"/>
<field name="user_ids" invisible="1"/>
<field name="email" widget="email" context="{'gravatar_image': True}" attrs="{'required': [('user_ids','!=', [])]}"/>
- <field name="website" widget="url" placeholder="e.g. www.odoo.com"/>
+ <field name="website" widget="url" placeholder="e.g. https://www.odoo.com"/>
<field name="title" options='{"no_open": True}'
attrs="{'invisible': [('is_company', '=', True)]}"/>
<field name="lang"/>