diff --git a/CHANGELOG b/CHANGELOG index 17eb8837ba..7308862641 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Add depends attribute to data tag * Add tree_invisible attribute to button in tree view * Drop support of Python 2.6 * Deprecate on_change, on_change_with, selection_change_with and autocomplete diff --git a/doc/topics/modules/index.rst b/doc/topics/modules/index.rst index fe1a7e4443..bd6de6474d 100644 --- a/doc/topics/modules/index.rst +++ b/doc/topics/modules/index.rst @@ -110,9 +110,12 @@ Here is the list of the tags: * ``tryton``: The main tag of the xml * ``data``: Define a set of data inside the file. It can have the - attributes ``noupdate`` to prevent the framework to update the records, - ``skiptest`` to prevent import of data when running tests and ``grouped`` - to create records at the end with a grouped call. + attributes: + * ``noupdate`` to prevent the framework to update the records, + * ``skiptest`` to prevent import of data when running tests, + * ``depends`` to import data only if all modules in the comma separated + module list value are installed, + * ``grouped`` to create records at the end with a grouped call. * ``record``: Create a record of the model defined by the attribute ``model`` in the database. The ``id`` attribute can be used to refer to diff --git a/trytond/convert.py b/trytond/convert.py index 4a56439787..378da55719 100644 --- a/trytond/convert.py +++ b/trytond/convert.py @@ -408,6 +408,10 @@ class TrytondXmlHandler(sax.handler.ContentHandler): self.grouped_write = defaultdict(list) self.grouped_model_data = [] self.skip_data = False + Module = pool.get('ir.module.module') + self.installed_modules = [m.name for m in Module.search([ + ('state', 'in', ['installed', 'to upgrade']), + ])] # Tag handlders are used to delegate the processing self.taghandlerlist = { @@ -459,6 +463,11 @@ class TrytondXmlHandler(sax.handler.ContentHandler): self.skip_data = True else: self.skip_data = False + depends = attributes.get('depends', '').split(',') + depends = [m.strip() for m in depends if m] + if depends: + if not all((m in self.installed_modules for m in depends)): + self.skip_data = True elif name == "tryton": pass diff --git a/trytond/tryton.rnc b/trytond/tryton.rnc index 5eef7ca1ca..3c46d63ec5 100644 --- a/trytond/tryton.rnc +++ b/trytond/tryton.rnc @@ -7,6 +7,7 @@ attlist.data &= [ a:defaultValue = "0" ] attribute noupdate { "0" | "1" }? attlist.data &= [ a:defaultValue = "0" ] attribute grouped { "0" | "1" }? +attlist.data &= attribute depends { text } record = element record { attlist.record, field* } attlist.record &= attribute model { text } attlist.record &= attribute id { text }