Remove empty pages from notebook

issue3295
review40421002
This commit is contained in:
Nicolas Évrard
2017-06-09 16:07:03 +02:00
parent b637c503e7
commit ddf4e0fe3c
7 changed files with 47 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Remove empty pages from notebook
* Allow to store Dict as JSON on the database
Version 4.4.0 - 2017-05-01
+5
View File
@@ -410,6 +410,11 @@ class ModelView(Model):
if colspan is not None:
element.attrib['colspan'] = colspan
# Remove empty pages
if type == 'form':
for page in tree.xpath('//page[not(descendant::*)]'):
page.getparent().remove(page)
if type == 'tree':
ViewTreeWidth = pool.get('ir.ui.view_tree_width')
viewtreewidth_ids = ViewTreeWidth.search([
+1
View File
@@ -139,6 +139,7 @@ def register():
ModelViewChangedValuesTarget,
ModelViewButton,
ModelViewRPC,
ModelViewEmptyPage,
MPTT,
ImportDataBoolean,
ImportDataInteger,
+6
View File
@@ -10,6 +10,7 @@ __all__ = [
'ModelViewChangedValuesTarget',
'ModelViewButton',
'ModelViewRPC',
'ModelViewEmptyPage',
]
@@ -106,3 +107,8 @@ class ModelViewRPC(ModelView):
@classmethod
def get_function_reference(cls):
pass
class ModelViewEmptyPage(ModelView):
'ModelView Empty Page'
__name__ = 'test.modelview.empty_page'
+19
View File
@@ -0,0 +1,19 @@
<?xml version="1.0"?>
<tryton>
<record model="ir.ui.view" id="test_modelview_empty_page_view_form">
<field name="model">test.modelview.empty_page</field>
<field name="type">form</field>
<field name="data">
<!--[CDATA[
<form>
<notebook>
<page id="empty"></page>
<page id="non-empty">
<label id="foo"/>
</page>
</notebook>
</form>
]-->
</field>
</record>
</tryton>
+14
View File
@@ -3,6 +3,7 @@
import unittest
from mock import patch
from lxml import etree
from trytond.tests.test_tryton import activate_module, with_transaction
from trytond.pool import Pool
@@ -297,6 +298,19 @@ class ModelView(unittest.TestCase):
self.assertIn(rpc_name, TestModel.__rpc__)
check_rpc(TestModel.__rpc__[rpc_name], rpc_attrs)
@with_transaction()
def test_remove_empty_page(self):
"Testing the removal of empty pages"
pool = Pool()
EmptyPage = pool.get('test.modelview.empty_page')
arch = EmptyPage.fields_view_get(view_type='form')['arch']
parser = etree.XMLParser()
tree = etree.fromstring(arch, parser=parser)
pages = tree.xpath('//page')
self.assertEqual(len(pages), 1)
self.assertEqual(pages[0].attrib['id'], 'non-empty')
def suite():
func = unittest.TestLoader().loadTestsFromTestCase
+1
View File
@@ -7,3 +7,4 @@ xml:
sequence.xml
workflow.xml
wizard.xml
modelview.xml