From cc8110e9a143b84a21f37da7a0aae999fa576221 Mon Sep 17 00:00:00 2001 From: Nicolas JEUDY Date: Tue, 5 Nov 2019 11:42:54 +0100 Subject: [PATCH] [MIG] Migration to V12.0 - initial release --- .../module_prototyper_api_version_data.xml | 5 ++ module_prototyper/models/module_prototyper.py | 39 ++++---------- .../templates/12.0/__init__.py.template | 7 +++ .../templates/12.0/__manifest__.py.template | 54 +++++++++++++++++++ .../12.0/data/model_name.xml.template | 6 +++ .../12.0/demo/model_name.xml.template | 6 +++ .../templates/12.0/header.template | 4 ++ .../12.0/models/__init__.py.template | 9 ++++ .../12.0/models/model_name.py.template | 35 ++++++++++++ .../security/ir.model.access.csv.template | 4 ++ .../12.0/security/model_name.xml.template | 8 +++ .../12.0/views/model_menus.xml.template | 27 ++++++++++ .../12.0/views/model_views.xml.template | 15 ++++++ module_prototyper/tests/test_prototype.py | 4 +- .../tests/test_prototype_module_export.py | 4 +- .../views/module_prototyper_view.xml | 6 --- .../wizard/module_prototyper_module_export.py | 14 ++--- 17 files changed, 200 insertions(+), 47 deletions(-) create mode 100644 module_prototyper/templates/12.0/__init__.py.template create mode 100644 module_prototyper/templates/12.0/__manifest__.py.template create mode 100644 module_prototyper/templates/12.0/data/model_name.xml.template create mode 100644 module_prototyper/templates/12.0/demo/model_name.xml.template create mode 100644 module_prototyper/templates/12.0/header.template create mode 100644 module_prototyper/templates/12.0/models/__init__.py.template create mode 100644 module_prototyper/templates/12.0/models/model_name.py.template create mode 100644 module_prototyper/templates/12.0/security/ir.model.access.csv.template create mode 100644 module_prototyper/templates/12.0/security/model_name.xml.template create mode 100644 module_prototyper/templates/12.0/views/model_menus.xml.template create mode 100644 module_prototyper/templates/12.0/views/model_views.xml.template diff --git a/module_prototyper/data/module_prototyper_api_version_data.xml b/module_prototyper/data/module_prototyper_api_version_data.xml index d9fc0f300..5b720816c 100644 --- a/module_prototyper/data/module_prototyper_api_version_data.xml +++ b/module_prototyper/data/module_prototyper_api_version_data.xml @@ -13,4 +13,9 @@ __manifest__ + + 12.0 + __manifest__ + + diff --git a/module_prototyper/models/module_prototyper.py b/module_prototyper/models/module_prototyper.py index 6e278f956..ede489b80 100644 --- a/module_prototyper/models/module_prototyper.py +++ b/module_prototyper/models/module_prototyper.py @@ -242,28 +242,6 @@ class ModulePrototyper(models.Model): "want to export in this module." ), ) - activity_ids = fields.Many2many( - "workflow.activity", - "prototype_wf_activity_rel", - "module_prototyper_id", - "activity_id", - "Activities", - help=( - "Enter the list of workflow activities that you have created " - "and want to export in this module" - ), - ) - transition_ids = fields.Many2many( - "workflow.transition", - "prototype_wf_transition_rel", - "module_prototyper_id", - "transition_id", - "Transitions", - help=( - "Enter the list of workflow transitions that you have created " - "and want to export in this module" - ), - ) _env = None _api_version = None @@ -398,7 +376,7 @@ class ModulePrototyper(models.Model): relations = {} field_descriptions = self._field_descriptions or {} - for field in field_descriptions.itervalues(): + for field in list(field_descriptions.values()): model = field.get("model_id") relations.setdefault(model, []).append(field) # dependencies.add(model.id) @@ -408,8 +386,8 @@ class ModulePrototyper(models.Model): # 'dependencies': [(6, 0, [id_ for id_ in dependencies])] # }) - files.append(self.generate_models_init_details(relations.keys())) - for model, custom_fields in relations.iteritems(): + files.append(self.generate_models_init_details(list(relations.keys()))) + for model, custom_fields in list(relations.items()): files.append(self.generate_model_details(model, custom_fields)) return files @@ -433,9 +411,10 @@ class ModulePrototyper(models.Model): relations.setdefault(view.model, []).append(view) views_details = [] - for model, views in relations.iteritems(): + _logger.debug(relations) + for model, views in list(relations.items()): filepath = "views/%s_view.xml" % ( - self.friendly_name(self.unprefix(model)), + self.friendly_name(self.unprefix(model)) if model else 'website_templates', ) views_details.append( self.generate_file_details( @@ -458,7 +437,7 @@ class ModulePrototyper(models.Model): relations.setdefault(model, []).append(menu) menus_details = [] - for model_name, menus in relations.iteritems(): + for model_name, menus in list(relations.items()): model_name = self.unprefix(model_name) filepath = "views/%s_menus.xml" % (self.friendly_name(model_name),) menus_details.append( @@ -506,7 +485,7 @@ class ModulePrototyper(models.Model): ("data", data, self._data_files), ("demo", demo, self._demo_files), ]: - for model_name, records in model_data.iteritems(): + for model_name, records in list(model_data.items()): fname = self.friendly_name(self.unprefix(model_name)) filename = "%s/%s.xml" % (prefix, fname) self._data_files.append(filename) @@ -564,7 +543,7 @@ class ModulePrototyper(models.Model): continue if isinstance(attrs, dict): - for key, val in attrs.iteritems(): + for key, val in list(attrs.items()): if isinstance(val, (list, tuple)): attrs[key] = cls.fixup_domain(val) elem.attrib["attrs"] = repr(attrs) diff --git a/module_prototyper/templates/12.0/__init__.py.template b/module_prototyper/templates/12.0/__init__.py.template new file mode 100644 index 000000000..384a9cd45 --- /dev/null +++ b/module_prototyper/templates/12.0/__init__.py.template @@ -0,0 +1,7 @@ +{% extends "header.template" %} +{% block body %} +{% if models %} + +from . import models +{% endif %} +{% endblock %} diff --git a/module_prototyper/templates/12.0/__manifest__.py.template b/module_prototyper/templates/12.0/__manifest__.py.template new file mode 100644 index 000000000..f534f11ca --- /dev/null +++ b/module_prototyper/templates/12.0/__manifest__.py.template @@ -0,0 +1,54 @@ +{% extends "header.template" %} +{% block body %} + +{ + 'name': '{{ prototype.human_name }}', + 'version': '{{ prototype.version }}', + 'author': '{{ prototype.author }}', + 'maintainer': '{{ prototype.maintainer }}', + 'website': '{{ prototype.website }}', + 'license': '{{ prototype.licence }}', + + # Categories can be used to filter modules in modules listing + # Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml # noqa + # for the full list + 'category': '{{ prototype.with_context({}).category_id.name }}',{# In english please! #} + 'summary': '{{ prototype.summary }}', + 'description': """ +{{ prototype.description }} +""", + + # any module necessary for this one to work correctly + 'depends': [ + {% for dependency in prototype.dependency_ids %} + '{{ dependency.name }}', + {% endfor %} + ], + 'external_dependencies': { + 'python': [], + }, + + # always loaded + 'data': [ + {% for data_file in data_files %} + '{{ data_file }}', + {% endfor %} + ], + # only loaded in demonstration mode + 'demo': [ + {% for demo_file in prototype.demo_ids %} + '{{ demo_file.name }}', + {% endfor %} + ], + + 'js': [], + 'css': [], + 'qweb': [], + + 'installable': True, + # Install this module automatically if all dependency have been previously + # and independently installed. Used for synergetic or glue modules. + 'auto_install': {{ prototype.auto_install }}, + 'application': {{ prototype.application }}, +} +{% endblock %} diff --git a/module_prototyper/templates/12.0/data/model_name.xml.template b/module_prototyper/templates/12.0/data/model_name.xml.template new file mode 100644 index 000000000..9e8646b49 --- /dev/null +++ b/module_prototyper/templates/12.0/data/model_name.xml.template @@ -0,0 +1,6 @@ + + + + {{ data }} + + diff --git a/module_prototyper/templates/12.0/demo/model_name.xml.template b/module_prototyper/templates/12.0/demo/model_name.xml.template new file mode 100644 index 000000000..f45e348d1 --- /dev/null +++ b/module_prototyper/templates/12.0/demo/model_name.xml.template @@ -0,0 +1,6 @@ + + + + {{ demo }} + + diff --git a/module_prototyper/templates/12.0/header.template b/module_prototyper/templates/12.0/header.template new file mode 100644 index 000000000..57f90c678 --- /dev/null +++ b/module_prototyper/templates/12.0/header.template @@ -0,0 +1,4 @@ +# Copyright {{ export_year }} {% if author %}{{ author }}{% endif %} ({% if website %}({{ website }}).{% endif %}) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{% block body %} +{% endblock %} diff --git a/module_prototyper/templates/12.0/models/__init__.py.template b/module_prototyper/templates/12.0/models/__init__.py.template new file mode 100644 index 000000000..8e1a1083d --- /dev/null +++ b/module_prototyper/templates/12.0/models/__init__.py.template @@ -0,0 +1,9 @@ +{% extends "header.template" %} +{% block body %} +{% for model in models %} +{% if loop.first %} + +{% endif %} +from . import {{ model }} +{% endfor %} +{% endblock %} diff --git a/module_prototyper/templates/12.0/models/model_name.py.template b/module_prototyper/templates/12.0/models/model_name.py.template new file mode 100644 index 000000000..b1790803e --- /dev/null +++ b/module_prototyper/templates/12.0/models/model_name.py.template @@ -0,0 +1,35 @@ +{% extends "header.template" %} +{% block body %} + +from odoo import models, fields +from odoo.tools.translate import _ + + +class {{ unprefix(name) }}(models.Model): + {% if model.state == 'base' %} + _name = "{{ model.model }}" + {% else %} + _inherit = "{{ model.model }}" + {% endif %} + {% if description %} + _description = "{{ description }}" + {% endif %} + + {% for field in fields %} + {% for line in wrap(field.notes, replace_whitespace=False) %} + # {{line}} + {% endfor %} + {{ unprefix(field.name) }} = fields.{{ field.ttype|capitalize }}( + string=_("{{ field.field_description }}"), + required={{ field.required }}, + translate={{ field.translate }}, + readonly={{ field.readonly }} + {% if field.size %} + size={{ field.size }}, + {% endif %} + {% if field.helper %} + help=_("{{ field.helper }}"), + {% endif %} + ) + {% endfor %} +{% endblock %} diff --git a/module_prototyper/templates/12.0/security/ir.model.access.csv.template b/module_prototyper/templates/12.0/security/ir.model.access.csv.template new file mode 100644 index 000000000..0d2111f9d --- /dev/null +++ b/module_prototyper/templates/12.0/security/ir.model.access.csv.template @@ -0,0 +1,4 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +{% for rule in access_rules %} +{{ rule.id }},{{ rule.name }},{{ rule.model_id.id }},{{ rule.group_id.id }},{{ rule.perm_write }},{{ rule.perm_write }},{{ rule.perm_create }},{{ rule.perm_unlink }} +{% endfor %} diff --git a/module_prototyper/templates/12.0/security/model_name.xml.template b/module_prototyper/templates/12.0/security/model_name.xml.template new file mode 100644 index 000000000..eb8ededa9 --- /dev/null +++ b/module_prototyper/templates/12.0/security/model_name.xml.template @@ -0,0 +1,8 @@ + + + + {{ groups }} + + {{ rules }} + + diff --git a/module_prototyper/templates/12.0/views/model_menus.xml.template b/module_prototyper/templates/12.0/views/model_menus.xml.template new file mode 100644 index 000000000..b6119cf06 --- /dev/null +++ b/module_prototyper/templates/12.0/views/model_menus.xml.template @@ -0,0 +1,27 @@ + + + {% for menu in menus %} + + {{ unprefix(menu.action.name) }} + {{ menu.action.type }} + {{ unprefix(menu.action.res_model) }} + {{ menu.action.view_type }} + {{ menu.action.view_mode }} + {% if menu.action.help %} + {{ menu.action.help }} + + {% endif %} + + + + {% if not loop.last %} + + {% endif %} + {% endfor %} + diff --git a/module_prototyper/templates/12.0/views/model_views.xml.template b/module_prototyper/templates/12.0/views/model_views.xml.template new file mode 100644 index 000000000..fd769ff68 --- /dev/null +++ b/module_prototyper/templates/12.0/views/model_views.xml.template @@ -0,0 +1,15 @@ + + + + {% for view in views %} + + {{ unprefix(view.name) }}.view + {{ unprefix(view.model) }} + {{ view.type }} + + + {{ fixup_arch(view.arch) }} + + + {% endfor %} + diff --git a/module_prototyper/tests/test_prototype.py b/module_prototyper/tests/test_prototype.py index eced2ab23..fe8575096 100644 --- a/module_prototyper/tests/test_prototype.py +++ b/module_prototyper/tests/test_prototype.py @@ -66,8 +66,8 @@ class TestModulePrototyper(common.TransactionCase): # namedtuples in tuple for file_details in details: self.assertIsInstance(file_details, tuple) - self.assertIsInstance(file_details.filename, basestring) - self.assertIsInstance(file_details.filecontent, basestring) + self.assertIsInstance(file_details.filename, str) + self.assertIsInstance(file_details.filecontent, str) name, contents = file_details if name.endswith(".py"): diff --git a/module_prototyper/tests/test_prototype_module_export.py b/module_prototyper/tests/test_prototype_module_export.py index 025e74adf..4fc1896df 100644 --- a/module_prototyper/tests/test_prototype_module_export.py +++ b/module_prototyper/tests/test_prototype_module_export.py @@ -20,7 +20,7 @@ ############################################################################## from odoo.tests import common import zipfile -import StringIO +import io class TestPrototypeModuleExport(common.TransactionCase): @@ -70,4 +70,4 @@ class TestPrototypeModuleExport(common.TransactionCase): self.assertIsInstance(ret, tuple) self.assertIsInstance(ret.zip_file, zipfile.ZipFile) - self.assertIsInstance(ret.stringIO, StringIO.StringIO) + self.assertIsInstance(ret.stringIO, io.StringIO) diff --git a/module_prototyper/views/module_prototyper_view.xml b/module_prototyper/views/module_prototyper_view.xml index 421127e27..a46cc3919 100644 --- a/module_prototyper/views/module_prototyper_view.xml +++ b/module_prototyper/views/module_prototyper_view.xml @@ -88,12 +88,6 @@