Browse Source

[IMP] prototype: added helper fields and placeholders on new fields.

[IMP] prototype: no more bug when no icon, commented no implemented page in the view.

[IMP] prototype: better management of special cases.

[IMP] prototype: prototype.py removed print statement and shadowing of "fields".

[IMP] prototype -> module_prototyper

[IMP] module_prototyper: gathered menuitems that is helpfull to create a prototype under the menu 'Module Prototypes'

[IMP] module_prototyper: more comment and docstrings.

[IMP] module_prototyper: translations.

[FIX] module_prototyper: pep8

[IMP] update module_prototyper:

* pump up the version of the module to 0.3
* replace ir.ui.model by ir.ui.view in generated xml views
* improve pep8 compatibility of generation of models

[IMP] update module_prototyper: update of README with versions.
pull/107/head
Jordi Riera 10 years ago
committed by Maxime Chambreuil
parent
commit
02cc47bbb1
  1. 4
      module_prototyper/README.rst
  2. 59
      module_prototyper/README.rst~HEAD
  3. 2
      module_prototyper/__openerp__.py
  4. 14
      module_prototyper/__openerp__.py~HEAD
  5. 10
      module_prototyper/i18n/fr.po
  6. 338
      module_prototyper/i18n/fr.po~HEAD
  7. 5
      module_prototyper/models/__init__.py~HEAD
  8. 23
      module_prototyper/models/ir_model_fields.py~HEAD
  9. 556
      module_prototyper/models/module_prototyper.py~HEAD
  10. 3
      module_prototyper/templates/8.0/__init__.py.template
  11. 3
      module_prototyper/templates/8.0/__init__.py.template~HEAD
  12. 39
      module_prototyper/templates/8.0/__openerp__.py.template
  13. 44
      module_prototyper/templates/8.0/__openerp__.py.template~HEAD
  14. 13
      module_prototyper/templates/8.0/data/model_name.xml.template
  15. 17
      module_prototyper/templates/8.0/data/model_name.xml.template~HEAD
  16. 32
      module_prototyper/templates/8.0/header.template
  17. 26
      module_prototyper/templates/8.0/header.template~HEAD
  18. 7
      module_prototyper/templates/8.0/models/__init__.py.template
  19. 9
      module_prototyper/templates/8.0/models/__init__.py.template~HEAD
  20. 66
      module_prototyper/templates/8.0/models/model_name.py.template
  21. 68
      module_prototyper/templates/8.0/models/model_name.py.template~HEAD
  22. 41
      module_prototyper/templates/8.0/views/model_menus.xml.template
  23. 29
      module_prototyper/templates/8.0/views/model_menus.xml.template~HEAD
  24. 26
      module_prototyper/templates/8.0/views/model_views.xml.template
  25. 17
      module_prototyper/templates/8.0/views/model_views.xml.template~HEAD
  26. 4
      module_prototyper/tests/__init__.py~HEAD
  27. 36
      module_prototyper/tests/test_prototype.py~HEAD
  28. 9
      module_prototyper/tests/test_prototype_module_export.py~HEAD
  29. 51
      module_prototyper/views/ir_model_fields_view.xml~HEAD
  30. 3
      module_prototyper/views/module_prototyper_view.xml
  31. 145
      module_prototyper/views/module_prototyper_view.xml~HEAD
  32. 3
      module_prototyper/wizard/module_prototyper_module_export.py
  33. 73
      module_prototyper/wizard/module_prototyper_module_export.py~HEAD
  34. 2
      prototype/demo/prototype.prototype.csv
  35. 272
      prototype/i18n/fr.po
  36. 268
      prototype/i18n/prototype.pot
  37. 339
      prototype/models/prototype.py
  38. 2
      prototype/security/ir.model.access.csv
  39. BIN
      prototype/static/description/icon.png
  40. 8
      prototype/templates/8.0/data/model_name.xml.template
  41. 8
      prototype/templates/8.0/demo/model_name.xml.template
  42. 22
      prototype/templates/8.0/header.template
  43. 6
      prototype/templates/8.0/models/__init__.py.template
  44. 21
      prototype/templates/8.0/models/model_name.py.template
  45. 4
      prototype/templates/8.0/security/ir.model.access.csv.template
  46. 10
      prototype/templates/8.0/security/model_name.xml.template
  47. 24
      prototype/templates/8.0/views/model_menus.xml.template
  48. 23
      prototype/templates/8.0/views/model_views.xml.template
  49. 28
      prototype/tests/__init__.py
  50. 30
      prototype/views/ir_model_fields_view.xml
  51. 103
      prototype/views/prototype_view.xml
  52. 22
      prototype/wizard/__init__.py
  53. 43
      prototype/wizard/prototype_module_export_view.xml

4
module_prototyper/README.rst

@ -42,8 +42,8 @@ You will get a zip file containing your module ready to be installed and complia
conventions of the OCA. You can then provide the module to a developer who have to implement conventions of the OCA. You can then provide the module to a developer who have to implement
things like default values or onchange methods. things like default values or onchange methods.
Roadmap
=======
Known issues / Roadmap
======================
* `#104`_ - Include controllers.py and templates.xml from scaffold. * `#104`_ - Include controllers.py and templates.xml from scaffold.
* Attach images to the prototype and export them to be used in the 'images' module manifest. * Attach images to the prototype and export them to be used in the 'images' module manifest.

59
prototype/README.rst → module_prototyper/README.rst~HEAD

@ -42,8 +42,8 @@ You will get a zip file containing your module ready to be installed and complia
conventions of the OCA. You can then provide the module to a developer who have to implement conventions of the OCA. You can then provide the module to a developer who have to implement
things like default values or onchange methods. things like default values or onchange methods.
Known issues / Roadmap
======================
Roadmap
=======
* `#104`_ - Include controllers.py and templates.xml from scaffold. * `#104`_ - Include controllers.py and templates.xml from scaffold.
* Attach images to the prototype and export them to be used in the 'images' module manifest. * Attach images to the prototype and export them to be used in the 'images' module manifest.
@ -52,7 +52,13 @@ Known issues / Roadmap
.. _#104: https://github.com/OCA/server-tools/issues/104 .. _#104: https://github.com/OCA/server-tools/issues/104
Please report any idea or issue to https://github.com/OCA/server-tools/issues.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20module_prototyper%0Aversion:%200.3%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits Credits
======= =======
@ -63,7 +69,9 @@ Contributors
* David Arnold <blaggacao@users.noreply.github.com> * David Arnold <blaggacao@users.noreply.github.com>
* Jordi Riera <jordi.riera@savoirfairelinux.com> * Jordi Riera <jordi.riera@savoirfairelinux.com>
* Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com> * Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com>
* El hadji Dem <elhadji.dem@savoirfairelinux.com>
* Savoir-faire Linux <support@savoirfairelinux.com> * Savoir-faire Linux <support@savoirfairelinux.com>
* Vincent Vinet <vincent.vinet@savoirfairelinux.com>
Maintainer Maintainer
---------- ----------
@ -77,3 +85,48 @@ This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
To contribute to this module, please visit http://odoo-community.org. To contribute to this module, please visit http://odoo-community.org.
Versions
========
v0.1
----
All the features are not implemented but the minimal is done.
With this version you can:
The set up of openerp.py is covered, description, maintainer, website, name, technical name...
Views and menus can be set through odoo and gathered in prototype. The files will be automatically generated and add to the data section of the openerp.py. Be aware some advanced feature as domain or context might still missing.
Dependencies can be set throught the Dependency page
Custom fields can be added. A file by model will be generated with all the fields of the model. The init.py files are updated accordingly. Be aware that some features are not implemented yet, as the domain, the context.
This version should be enought for:
set up the client module
create a new field in a view.
Features that you might expect in next version:
better generation of fields (many2many fields, domain, context)
Generation of data and demo data files.
Security files (rules, ir.model.access.csv)
openerp's description editing README.rst and index.html
module screenshots
v0.2
----
Renamed from prototype to module_prototyper as discussed in #108
menu in Settings that gather element used to create a prototype (menu views, views, fields)
v0.3
----
Replace ir.ui.model by ir.ui.view in generated xml views
Improve pep8 compatibility of generation of models
Known bugs
----------
icon file extension might be wrong. The extension is hard coded for now. It is planned add Document as dependency to handle it.

2
module_prototyper/__openerp__.py

@ -28,7 +28,7 @@
'website': 'http://www.savoirfairelinux.com', 'website': 'http://www.savoirfairelinux.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'Others', 'category': 'Others',
'summary': 'Prototype your module.',
'summary': 'Prototype your module',
'depends': [ 'depends': [
'admin_technical_features', 'admin_technical_features',
], ],

14
prototype/__openerp__.py → module_prototyper/__openerp__.py~HEAD

@ -21,26 +21,26 @@
############################################################################## ##############################################################################
{ {
'name': 'Prototype',
'version': '0.1',
'author': 'Savoir-faire Linux',
'name': 'Module Prototyper',
'version': '0.3',
'author': 'Savoir-faire Linux, Odoo Community Association (OCA)',
'maintainer': 'Savoir-faire Linux', 'maintainer': 'Savoir-faire Linux',
'website': 'http://www.savoirfairelinux.com', 'website': 'http://www.savoirfairelinux.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
'category': 'Others', 'category': 'Others',
'summary': 'Prototype your module',
'summary': 'Prototype your module.',
'depends': [ 'depends': [
'base',
'admin_technical_features', 'admin_technical_features',
], ],
'external_dependencies': { 'external_dependencies': {
'python': [], 'python': [],
}, },
'data': [ 'data': [
'wizard/prototype_module_export_view.xml',
'views/prototype_view.xml',
'wizard/module_prototyper_module_export_view.xml',
'views/module_prototyper_view.xml',
'views/ir_model_fields_view.xml', 'views/ir_model_fields_view.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',
], ],
'installable': True, 'installable': True,
'application': True,
} }

10
module_prototyper/i18n/fr.po

@ -153,7 +153,7 @@ msgstr "Groupes"
#. module: module_prototyper #. module: module_prototyper
#: field:ir.model.fields,helper:0 #: field:ir.model.fields,helper:0
msgid "Helper" msgid "Helper"
msgstr "Texte d'aide"
msgstr "Texte d'aider"
#. module: module_prototyper #. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard #: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
@ -189,8 +189,8 @@ msgstr "Mis à jour le"
#. module: module_prototyper #. module: module_prototyper
#: field:module_prototyper,licence:0 #: field:module_prototyper,licence:0
msgid "License"
msgstr "Licence"
msgid "Licence"
msgstr ""
#. module: module_prototyper #. module: module_prototyper
#: field:module_prototyper,maintainer:0 #: field:module_prototyper,maintainer:0
@ -230,8 +230,8 @@ msgstr ""
#. module: module_prototyper #. module: module_prototyper
#: field:ir.model.fields,notes:0 #: field:ir.model.fields,notes:0
msgid "Notes to developers"
msgstr "Notes aux développeurs"
msgid "Notes to developers."
msgstr "Notes aux développeurs."
#. module: module_prototyper #. module: module_prototyper
#: view:ir.model.fields:module_prototyper.view_ir_model_fields_form #: view:ir.model.fields:module_prototyper.view_ir_model_fields_form

338
module_prototyper/i18n/fr.po~HEAD

@ -0,0 +1,338 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * module_prototyper
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-01-02 17:07+0000\n"
"PO-Revision-Date: 2015-01-02 12:18-0500\n"
"Last-Translator: Jordi Riera <jordi.riera@savoirfairelinux.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 1.5.4\n"
#. module: module_prototyper
#: selection:module_prototyper.module.export,api_version:0
msgid "8.0"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper.module.export,api_version:0
msgid "API version"
msgstr "Version de l'API"
#. module: module_prototyper
#: field:module_prototyper,right_ids:0
msgid "Access Rights"
msgstr "Liste des contrôles d'accès"
#. module: module_prototyper
#: field:module_prototyper,application:0
msgid "Application"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper,author:0
msgid "Author"
msgstr "Auteur"
#. module: module_prototyper
#: field:module_prototyper,auto_install:0
msgid "Auto Install"
msgstr "Installation automatique"
#. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Cancel"
msgstr "Annuler"
#. module: module_prototyper
#: field:module_prototyper,category_id:0
msgid "Category"
msgstr "Catégorie"
#. module: module_prototyper
#: help:module_prototyper,application:0
msgid "Check if the module is an Odoo application."
msgstr "Cocher si le module est une application Odoo."
#. module: module_prototyper
#: help:module_prototyper,auto_install:0
msgid "Check if the module should be install by default."
msgstr "Cocher si le module devrait être installé par défaut."
#. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Close"
msgstr "Fermer"
#. module: module_prototyper
#: field:module_prototyper,create_uid:0
#: field:module_prototyper.module.export,create_uid:0
msgid "Created by"
msgstr "Créé par"
#. module: module_prototyper
#: field:module_prototyper,create_date:0
#: field:module_prototyper.module.export,create_date:0
msgid "Created on"
msgstr "Créé le"
#. module: module_prototyper
#: field:module_prototyper,data_ids:0
msgid "Data filters"
msgstr "Filtres pour les données"
#. module: module_prototyper
#: field:module_prototyper,demo_ids:0
msgid "Demo filters"
msgstr "Filtres pour les données de démo"
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
#: field:module_prototyper,dependency_ids:0
msgid "Dependencies"
msgstr "Dépendances"
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
#: field:module_prototyper,description:0
msgid "Description"
msgstr "Descriptions"
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Export"
msgstr "Exporter"
#. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Export Complete"
msgstr "Export terminé"
#. module: module_prototyper
#: model:ir.actions.act_window,name:module_prototyper.button_module_export_action
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Export Module"
msgstr "Exporter le module"
#. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Export Settings"
msgstr "Configuration de l'export"
#. module: module_prototyper
#: model:ir.model,name:module_prototyper.model_ir_model_fields
#: model:ir.ui.menu,name:module_prototyper.ir_model_model_fields
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
#: field:module_prototyper,field_ids:0
msgid "Fields"
msgstr "Champs"
#. module: module_prototyper
#: field:module_prototyper.module.export,data:0
msgid "File"
msgstr "Fichier"
#. module: module_prototyper
#: field:module_prototyper.module.export,name:0
msgid "File Name"
msgstr "Nom du fichier"
#. module: module_prototyper
#: field:module_prototyper,group_ids:0
msgid "Groups"
msgstr "Groupes"
#. module: module_prototyper
#: field:ir.model.fields,helper:0
msgid "Helper"
msgstr "Texte d'aide"
#. module: module_prototyper
#: view:module_prototyper.module.export:module_prototyper.view_module_export_wizard
msgid "Here is the exported module:"
msgstr "Voici le module exporté :"
#. module: module_prototyper
#: field:module_prototyper,id:0 field:module_prototyper.module.export,id:0
msgid "ID"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper,icon_image:0
msgid "Icon"
msgstr "Icône"
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
msgid "Interface"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper,write_uid:0
#: field:module_prototyper.module.export,write_uid:0
msgid "Last Updated by"
msgstr "Mis à jour par"
#. module: module_prototyper
#: field:module_prototyper,write_date:0
#: field:module_prototyper.module.export,write_date:0
msgid "Last Updated on"
msgstr "Mis à jour le"
#. module: module_prototyper
#: field:module_prototyper,licence:0
msgid "License"
msgstr "Licence"
#. module: module_prototyper
#: field:module_prototyper,maintainer:0
msgid "Maintainer"
msgstr "Mainteneur"
#. module: module_prototyper
#: model:ir.ui.menu,name:module_prototyper.menu_grant_menu_access
#: field:module_prototyper,menu_ids:0
msgid "Menu Items"
msgstr "Éléments du menu"
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_form_view
msgid "Module"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper,human_name:0
msgid "Module Name"
msgstr "Nom du module"
#. module: module_prototyper
#: model:ir.model,name:module_prototyper.model_module_prototyper
msgid "Module Prototyper"
msgstr ""
#. module: module_prototyper
#: model:ir.ui.menu,name:module_prototyper.menu_module_prototyper
msgid "Module Prototypers"
msgstr ""
#. module: module_prototyper
#: view:ir.model:module_prototyper.view_ir_model_form
msgid "Notes"
msgstr ""
#. module: module_prototyper
#: field:ir.model.fields,notes:0
msgid "Notes to developers"
msgstr "Notes aux développeurs"
#. module: module_prototyper
#: view:ir.model.fields:module_prototyper.view_ir_model_fields_form
msgid ""
"Notes to help developers to understand the work or advanced features that "
"should be added, ie: onchange, etc."
msgstr ""
"Notes pour aider les développeurs à comprendre le travail effectué ou les "
"ajouts à faire. Exemple: onchanges, etc."
#. module: module_prototyper
#: view:module_prototyper:module_prototyper.module_prototyper_base_tree_view
msgid "Prototype"
msgstr ""
#. module: module_prototyper
#: model:ir.actions.act_window,name:module_prototyper.open_module_prototyper_list
#: model:ir.ui.menu,name:module_prototyper.menu_open_module_prototyper
msgid "Prototypes"
msgstr ""
#. module: module_prototyper
#: field:module_prototyper,rule_ids:0
msgid "Record Rules"
msgstr "Règles sur les enregistrements"
#. module: module_prototyper
#: field:module_prototyper.module.export,state:0
msgid "State"
msgstr "État"
#. module: module_prototyper
#: field:module_prototyper,summary:0
msgid "Summary"
msgstr "Résumé"
#. module: module_prototyper
#: field:module_prototyper,name:0
msgid "Technical Name"
msgstr "Nom technique"
#. module: module_prototyper
#: view:ir.model.fields:module_prototyper.view_ir_model_fields_form
msgid "Text that will be set as the helper of the field..."
msgstr "Texte qui sera placé en tant que texte d'aide du champs."
#. module: module_prototyper
#: help:module_prototyper,human_name:0
msgid ""
"The Module Name will be used as the displayed name of the exported module."
msgstr "Le nom du module sera affiché en tant que nom du module exporté."
#. module: module_prototyper
#: help:module_prototyper,icon_image:0
msgid ""
"The icon set up here will be used as the icon for the exported module also"
msgstr "L'icône sera utilisé comme icône du module exporté."
#. module: module_prototyper
#: help:module_prototyper,data_ids:0
msgid "The records matching the filters will be added as data."
msgstr ""
"Les enregistrements correspondant aux critères des filtres seront exportées "
"dans le module comme données."
#. module: module_prototyper
#: help:module_prototyper,demo_ids:0
msgid "The records matching the filters will be added as demo data."
msgstr ""
"Les enregistrements correspondant aux critères des filtres seront exportées "
"dans le module comme données de démo."
#. module: module_prototyper
#: help:module_prototyper,name:0
msgid ""
"The technical name will be used to define the name of the exported module, "
"the name of the model."
msgstr "Le nom technique sera utilisé comme nom du module exporté."
#. module: module_prototyper
#: field:module_prototyper,version:0
msgid "Version"
msgstr ""
#. module: module_prototyper
#: model:ir.ui.menu,name:module_prototyper.menu_action_ui_view
#: field:module_prototyper,view_ids:0
msgid "Views"
msgstr "Vues"
#. module: module_prototyper
#: field:module_prototyper,website:0
msgid "Website"
msgstr "Site web"
#. module: module_prototyper
#: selection:module_prototyper.module.export,state:0
msgid "choose"
msgstr "choisir"
#. module: module_prototyper
#: selection:module_prototyper.module.export,state:0
msgid "get"
msgstr "récupérer"

5
prototype/__init__.py → module_prototyper/models/__init__.py~HEAD

@ -20,6 +20,7 @@
# #
############################################################################## ##############################################################################
from . import ( from . import (
models,
wizard
module_prototyper,
ir_model_fields,
default_description
) )

23
prototype/models/ir_model_fields.py → module_prototyper/models/ir_model_fields.py~HEAD

@ -19,10 +19,31 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
from openerp import fields, models from openerp import fields, models
from openerp.tools.translate import _
class ir_model_fields(models.Model): class ir_model_fields(models.Model):
"""Addition of text fields to fields."""
_inherit = "ir.model.fields" _inherit = "ir.model.fields"
notes = fields.Text('Notes')
notes = fields.Text('Notes to developers.')
helper = fields.Text('Helper')
# TODO: Make column1 and 2 required if a model has a m2m to itself
column1 = fields.Char(
'Column1',
help=_("name of the column referring to 'these' records in the "
"relation table"),
)
column2 = fields.Char(
'Column2',
help=_("name of the column referring to 'those' records in the "
"relation table"),
)
limit = fields.Integer('Read limit', help=_("Read limit"))
client_context = fields.Char(
'Context',
help=_("Context to use on the client side when handling the field "
"(python dictionary)"),
)

556
module_prototyper/models/module_prototyper.py~HEAD

@ -0,0 +1,556 @@
# -*- encoding: utf-8 -*-
# #############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2010 - 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import base64
import logging
import lxml.etree
import os
import re
import textwrap
from collections import namedtuple
from datetime import date
from jinja2 import Environment, FileSystemLoader
from openerp import models, api, fields
from openerp.tools.safe_eval import safe_eval
from .default_description import get_default_description
from . import licenses
_logger = logging.getLogger(__name__)
class ModulePrototyper(models.Model):
"""Module Prototyper gathers different information from all over the
database to build a prototype of module.
We are calling it a prototype as it will most likely need to be reviewed
by a developer to fix glitch that would sneak it during the generation of
files but also to add not supported features.
"""
_name = "module_prototyper"
_description = "Module Prototyper"
license = fields.Selection(
[
(licenses.GPL3, 'GPL Version 3'),
(licenses.GPL3_L, 'GPL-3 or later version'),
(licenses.LGPL3, 'LGPL-3'),
(licenses.LGPL3_L, 'LGPL-3 or later version'),
(licenses.AGPL3, 'Affero GPL-3'),
(licenses.OSI, 'Other OSI Approved Licence'),
('Other proprietary', 'Other Proprietary')
],
string='License',
default=licenses.AGPL3,
)
name = fields.Char(
'Technical Name', required=True,
help=('The technical name will be used to define the name of '
'the exported module, the name of the model.')
)
category_id = fields.Many2one('ir.module.category', 'Category')
human_name = fields.Char(
'Module Name', required=True,
help=('The Module Name will be used as the displayed name of the '
'exported module.')
)
summary = fields.Char('Summary', required=True,
help=('Enter a summary of your module'))
description = fields.Text(
'Description',
required=True,
help=('Enter the description of your module, what it does, how to '
'install, configure and use it, the roadmap or known issues. '
'The description will be exported in README.rst'),
default=get_default_description
)
author = fields.Char('Author', required=True, help=('Enter your name'))
maintainer = fields.Char(
'Maintainer',
help=('Enter the name of the person or organization who will '
'maintain this module')
)
website = fields.Char('Website', help=('Enter the URL of your website'))
icon_image = fields.Binary(
'Icon',
help=('The icon set up here will be used as the icon '
'for the exported module also')
)
version = fields.Char(
'Version',
size=3,
default='0.1',
help=('Enter the version of your module with 2 digits')
)
auto_install = fields.Boolean(
'Auto Install',
default=False,
help='Check if the module should be install by default.'
)
application = fields.Boolean(
'Application',
default=False,
help='Check if the module is an Odoo application.'
)
# Relations
dependency_ids = fields.Many2many(
'ir.module.module', 'module_prototyper_module_rel',
'module_prototyper_id', 'module_id',
'Dependencies',
help=('Enter the list of required modules that need to be installed '
'for your module to work properly')
)
data_ids = fields.Many2many(
'ir.filters',
'prototype_data_rel',
'module_prototyper_id', 'filter_id',
'Data filters',
help="The records matching the filters will be added as data."
)
demo_ids = fields.Many2many(
'ir.filters',
'prototype_demo_rel',
'module_prototyper_id', 'filter_id',
'Demo filters',
help="The records matching the filters will be added as demo data."
)
field_ids = fields.Many2many(
'ir.model.fields', 'prototype_fields_rel',
'module_prototyper_id', 'field_id', 'Fields',
help=('Enter the list of fields that you have created or modified '
'and want to export in this module. New models will be '
'exported as long as you choose one of his fields.')
)
menu_ids = fields.Many2many(
'ir.ui.menu', 'prototype_menu_rel',
'module_prototyper_id', 'menu_id', 'Menu Items',
help=('Enter the list of menu items that you have created and want '
'to export in this module. Related windows actions will be '
'exported as well.')
)
view_ids = fields.Many2many(
'ir.ui.view', 'prototype_view_rel',
'module_prototyper_id', 'view_id', 'Views',
help=('Enter the list of views that you have created and want to '
'export in this module.')
)
group_ids = fields.Many2many(
'res.groups', 'prototype_groups_rel',
'module_prototyper_id', 'group_id', 'Groups',
help=('Enter the list of groups that you have created and want to '
'export in this module.')
)
right_ids = fields.Many2many(
'ir.model.access', 'prototype_rights_rel',
'module_prototyper_id', 'right_id',
'Access Rights',
help=('Enter the list of access rights that you have created and '
'want to export in this module.')
)
rule_ids = fields.Many2many(
'ir.rule', 'prototype_rule_rel',
'module_prototyper_id', 'rule_id', 'Record Rules',
help=('Enter the list of record rules that you have created and '
'want to export in this module.')
)
report_ids = fields.Many2many(
'ir.actions.report.xml', 'prototype_report_rel',
'module_prototyper_id', 'report_id', 'Reports',
help=('Enter the list of reports that you have created and '
'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
_data_files = ()
_demo_files = ()
_field_descriptions = None
File_details = namedtuple('file_details', ['filename', 'filecontent'])
template_path = '{}/../templates/'.format(os.path.dirname(__file__))
@api.model
def set_jinja_env(self, api_version):
"""Set the Jinja2 environment.
The environment will helps the system to find the templates to render.
:param api_version: string, odoo api
:return: jinja2.Environment instance.
"""
if self._env is None:
self._env = Environment(
lstrip_blocks=True,
trim_blocks=True,
loader=FileSystemLoader(
os.path.join(self.template_path, api_version)
)
)
return self._env
def set_field_descriptions(self):
"""Mock the list of fields into dictionary.
It allows us to add or change attributes of the fields.
:return: None
"""
for field in self.field_ids:
field_description = {}
# This will mock a field record.
# the mock will allow us to add data or modify the data
# of the field (like for the name) with keeping all the
# attributes of the record.
field_description.update({
attr_name: getattr(field, attr_name)
for attr_name in dir(field)
if not attr_name[0] == '_'
})
field_description['name'] = self.unprefix(field.name)
self._field_descriptions[field] = field_description
@api.model
def generate_files(self):
""" Generates the files from the details of the prototype.
:return: tuple
"""
assert self._env is not None, \
'Run set_env(api_version) before to generate files.'
# Avoid sharing these across instances
self._data_files = []
self._demo_files = []
self._field_descriptions = {}
self.set_field_descriptions()
file_details = []
file_details.extend(self.generate_models_details())
file_details.extend(self.generate_views_details())
file_details.extend(self.generate_menus_details())
file_details.append(self.generate_module_init_file_details())
file_details.extend(self.generate_data_files())
# must be the last as the other generations might add information
# to put in the __openerp__: additional dependencies, views files, etc.
file_details.append(self.generate_module_openerp_file_details())
if self.icon_image:
file_details.append(self.save_icon())
return file_details
@api.model
def save_icon(self):
"""Save the icon of the prototype as a image.
The image is used afterwards as the icon of the exported module.
:return: FileDetails instance
"""
# TODO: The image is not always a jpg.
# 2 ways to do it:
# * find a way to detect image type from the data
# * add document as a dependency.
# The second options seems to be better, as Document is a base module.
return self.File_details(
os.path.join('static', 'description', 'icon.jpg'),
base64.b64decode(self.icon_image)
)
@api.model
def generate_module_openerp_file_details(self):
"""Wrapper to generate the __openerp__.py file of the module."""
return self.generate_file_details(
'__openerp__.py',
'__openerp__.py.template',
prototype=self,
data_files=self._data_files,
demo_fiels=self._demo_files,
)
@api.model
def generate_module_init_file_details(self):
"""Wrapper to generate the __init__.py file of the module."""
return self.generate_file_details(
'__init__.py',
'__init__.py.template',
# no import models if no work of fields in
# the prototype
models=bool(self.field_ids)
)
@api.model
def generate_models_details(self):
"""
Finds the models from the list of fields and generates
the __init__ file and each models files (one by class).
"""
files = []
# TODO: doesn't work as need to find the module to import
# and it is not necessary the name of the model the fields
# belongs to.
# ie. field.cell_phone is defined in a model inheriting from
# res.partner.
# How do we find the module the field was defined in?
# dependencies = set([dep.id for dep in self.dependencies])
relations = {}
field_descriptions = self._field_descriptions or {}
for field in field_descriptions.itervalues():
model = field.get('model_id')
relations.setdefault(model, []).append(field)
# dependencies.add(model.id)
# blind update of dependencies.
# self.write({
# '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_model_details(model, custom_fields))
return files
@api.model
def generate_models_init_details(self, ir_models):
"""Wrapper to generate the __init__.py file in models folder."""
return self.generate_file_details(
'models/__init__.py',
'models/__init__.py.template',
models=[
self.friendly_name(ir_model.model)
for ir_model in ir_models
]
)
@api.model
def generate_views_details(self):
"""Wrapper to generate the views files."""
relations = {}
for view in self.view_ids:
relations.setdefault(view.model, []).append(view)
views_details = []
for model, views in relations.iteritems():
filepath = 'views/{}_view.xml'.format(
self.friendly_name(self.unprefix(model))
)
views_details.append(
self.generate_file_details(
filepath,
'views/model_views.xml.template',
views=views
)
)
self._data_files.append(filepath)
return views_details
@api.model
def generate_menus_details(self):
"""Wrapper to generate the menus files."""
relations = {}
for menu in self.menu_ids:
if menu.action and menu.action.res_model:
model = self.unprefix(menu.action.res_model)
else:
model = 'ir_ui'
relations.setdefault(model, []).append(menu)
menus_details = []
for model_name, menus in relations.iteritems():
model_name = self.unprefix(model_name)
filepath = 'views/{}_menus.xml'.format(
self.friendly_name(model_name)
)
menus_details.append(
self.generate_file_details(
filepath,
'views/model_menus.xml.template',
menus=menus,
)
)
self._data_files.append(filepath)
return menus_details
@api.model
def generate_model_details(self, model, field_descriptions):
"""Wrapper to generate the python file for the model.
:param model: ir.model record.
:param field_descriptions: list of ir.model.fields records.
:return: FileDetails instance.
"""
python_friendly_name = self.friendly_name(self.unprefix(model.model))
return self.generate_file_details(
'models/{}.py'.format(python_friendly_name),
'models/model_name.py.template',
name=python_friendly_name,
model=model,
fields=field_descriptions,
)
@api.model
def generate_data_files(self):
""" Generate data and demo files """
data, demo = {}, {}
filters = [
(data, ir_filter)
for ir_filter in self.data_ids
] + [
(demo, ir_filter)
for ir_filter in self.demo_ids
]
for target, ir_filter in filters:
model = ir_filter.model_id
model_obj = self.env[model]
target.setdefault(model, model_obj.browse([]))
target[model] |= model_obj.search(safe_eval(ir_filter.domain))
res = []
for prefix, model_data, file_list in [
('data', data, self._data_files),
('demo', demo, self._demo_files)]:
for model_name, records in model_data.iteritems():
fname = self.friendly_name(self.unprefix(model_name))
filename = '{0}/{1}.xml'.format(prefix, fname)
self._data_files.append(filename)
res.append(self.generate_file_details(
filename,
'data/model_name.xml.template',
model=model_name,
records=records,
))
return res
@classmethod
def unprefix(cls, name):
if not name:
return name
return re.sub('^x_', '', name)
@classmethod
def is_prefixed(cls, name):
return bool(re.match('^x_', name))
@classmethod
def friendly_name(cls, name):
return name.replace('.', '_')
@classmethod
def fixup_domain(cls, domain):
""" Fix a domain according to unprefixing of fields """
res = []
for elem in domain:
if len(elem) == 3:
elem = list(elem)
elem[0] = cls.unprefix(elem[0])
res.append(elem)
return res
@classmethod
def fixup_arch(cls, archstr):
doc = lxml.etree.fromstring(archstr)
for elem in doc.xpath("//*[@name]"):
elem.attrib["name"] = cls.unprefix(elem.attrib["name"])
for elem in doc.xpath("//*[@attrs]"):
try:
attrs = safe_eval(elem.attrib["attrs"])
except Exception:
_logger.error("Unable to eval attribute: %s, skipping",
elem.attrib["attrs"])
continue
if isinstance(attrs, dict):
for key, val in attrs.iteritems():
if isinstance(val, (list, tuple)):
attrs[key] = cls.fixup_domain(val)
elem.attrib["attrs"] = repr(attrs)
for elem in doc.xpath("//field"):
# Make fields self-closed by removing useless whitespace
if elem.text and not elem.text.strip():
elem.text = None
return lxml.etree.tostring(doc)
@api.model
def generate_file_details(self, filename, template, **kwargs):
""" generate file details from jinja2 template.
:param filename: name of the file the content is related to
:param template: path to the file to render the content
:param kwargs: arguments of the template
:return: File_details instance
"""
template = self._env.get_template(template)
# keywords used in several templates.
kwargs.update(
{
'export_year': date.today().year,
'author': self.author,
'website': self.website,
'license_text': licenses.get_license_text(self.license),
'cr': self._cr,
# Utility functions
'fixup_arch': self.fixup_arch,
'is_prefixed': self.is_prefixed,
'unprefix': self.unprefix,
'wrap': wrap,
}
)
return self.File_details(filename, template.render(kwargs))
# Utility functions for rendering templates
def wrap(text, **kwargs):
""" Wrap some text for inclusion in a template, returning lines
keyword arguments available, from textwrap.TextWrapper:
width=70
initial_indent=''
subsequent_indent=''
expand_tabs=True
replace_whitespace=True
fix_sentence_endings=False
break_long_words=True
drop_whitespace=True
break_on_hyphens=True
"""
if not text:
return []
wrapper = textwrap.TextWrapper(**kwargs)
# We join the lines and split them again to offer a stable api for
# the jinja2 templates, regardless of replace_whitspace=True|False
text = "\n".join(wrapper.wrap(text))
return text.splitlines()

3
module_prototyper/templates/8.0/__init__.py.template

@ -1,7 +1,6 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
{% if models %}
{% if models -%}
from . import models from . import models
{% endif %} {% endif %}
{% endblock %} {% endblock %}

3
prototype/templates/8.0/__init__.py.template → module_prototyper/templates/8.0/__init__.py.template~HEAD

@ -1,6 +1,7 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
{% if models -%}
{% if models %}
from . import models from . import models
{% endif %} {% endif %}
{% endblock %} {% endblock %}

39
module_prototyper/templates/8.0/__openerp__.py.template

@ -1,19 +1,17 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
{ {
'name': '{{ prototype.human_name }}',
'name': '{{ prototype.name }}',
'version': '{{ prototype.version }}', 'version': '{{ prototype.version }}',
'author': '{{ prototype.author }}', 'author': '{{ prototype.author }}',
'maintainer': '{{ prototype.maintainer }}', 'maintainer': '{{ prototype.maintainer }}',
'website': '{{ prototype.website }}', 'website': '{{ prototype.website }}',
'license': '{{ prototype.license }}',
'license': '{{ prototype.licence }}',
# Categories can be used to filter modules in modules listing # 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
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml
# for the full list # for the full list
{# Use with_context({}) to get english category #}
'category': '{{ prototype.with_context({}).category_id.name }}',
'category': '{{ prototype.category_id.name }}',
'summary': '{{ prototype.summary }}', 'summary': '{{ prototype.summary }}',
'description': """ 'description': """
{{ prototype.description }} {{ prototype.description }}
@ -25,36 +23,33 @@
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': [ 'depends': [
{% for dependency in prototype.dependency_ids %}
{% for dependency in prototype.dependency_ids -%}
'{{ dependency.name }}', '{{ dependency.name }}',
{% endfor %}
],
{% endfor -%}],
'external_dependencies': { 'external_dependencies': {
'python': [], 'python': [],
}, },
# always loaded # always loaded
'data': [ 'data': [
{% for data_file in data_files %}
{% for data_file in data_files -%}
'{{ data_file }}', '{{ data_file }}',
{% endfor %}
],
{% endfor -%}],
# only loaded in demonstration mode # only loaded in demonstration mode
'demo': [ 'demo': [
{% for demo_file in demo_files %}
'{{ demo_file }}',
{% endfor %}
],
{% for demo_file in prototype.demo_ids -%}
'{{ demo_file.name }}',
{% endfor -%}],
# used for Javascript Web CLient Testing with QUnit / PhantomJS # used for Javascript Web CLient Testing with QUnit / PhantomJS
# https://www.odoo.com/documentation/8.0/reference/javascript.html#testing-in-odoo-web-client # noqa
# https://www.odoo.com/documentation/8.0/reference/javascript.html#testing-in-odoo-web-client
'js': [], 'js': [],
'css': [], 'css': [],
'qweb': [], 'qweb': [],
'installable': True, 'installable': True,
# Install this module automatically if all dependency have been previously
# and independently installed. Used for synergetic or glue modules.
# Install this module automatically if all dependency have been previously and independently installed.
# Used for synergetic or glue modules.
'auto_install': {{ prototype.auto_install }}, 'auto_install': {{ prototype.auto_install }},
'application': {{ prototype.application }}, 'application': {{ prototype.application }},
} }

44
prototype/templates/8.0/__openerp__.py.template → module_prototyper/templates/8.0/__openerp__.py.template~HEAD

@ -1,56 +1,60 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
{ {
'name': '{{ prototype.name }}',
'name': '{{ prototype.human_name }}',
'version': '{{ prototype.version }}', 'version': '{{ prototype.version }}',
'author': '{{ prototype.author }}', 'author': '{{ prototype.author }}',
'maintainer': '{{ prototype.maintainer }}', 'maintainer': '{{ prototype.maintainer }}',
'website': '{{ prototype.website }}', 'website': '{{ prototype.website }}',
'license': '{{ prototype.licence }}',
'license': '{{ prototype.license }}',
# Categories can be used to filter modules in modules listing # 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
# Check https://github.com/odoo/odoo/blob/master/openerp/addons/base/module/module_data.xml # noqa
# for the full list # for the full list
'category': '{{ prototype.category_id.name }}',
{# Use with_context({}) to get english category #}
'category': '{{ prototype.with_context({}).category_id.name }}',
'summary': '{{ prototype.summary }}', 'summary': '{{ prototype.summary }}',
'description': """ 'description': """
{{ prototype.description }} {{ prototype.description }}
* Module exported by the prototype module for version 8.0.
* If you have any questions, please contact Savoir-faire Linux \
* Module exported by the Module Prototyper module for version 8.0.
* If you have any questions, please contact Savoir-faire Linux
(support@savoirfairelinux.com) (support@savoirfairelinux.com)
""", """,
# any module necessary for this one to work correctly # any module necessary for this one to work correctly
'depends': [ 'depends': [
{% for dependency in prototype.dependency_ids -%}
{% for dependency in prototype.dependency_ids %}
'{{ dependency.name }}', '{{ dependency.name }}',
{% endfor -%}],
{% endfor %}
],
'external_dependencies': { 'external_dependencies': {
'python': [], 'python': [],
}, },
# always loaded # always loaded
'data': [ 'data': [
{% for data_file in data_files -%}
{% for data_file in data_files %}
'{{ data_file }}', '{{ data_file }}',
{% endfor -%}],
{% endfor %}
],
# only loaded in demonstration mode # only loaded in demonstration mode
'demo': [ 'demo': [
{% for demo_file in prototype.demo_ids -%}
'{{ demo_file.name }}',
{% endfor -%}],
{% for demo_file in demo_files %}
'{{ demo_file }}',
{% endfor %}
],
# used for Javascript Web CLient Testing with QUnit / PhantomJS # used for Javascript Web CLient Testing with QUnit / PhantomJS
# https://www.odoo.com/documentation/8.0/reference/javascript.html#testing-in-odoo-web-client
# https://www.odoo.com/documentation/8.0/reference/javascript.html#testing-in-odoo-web-client # noqa
'js': [], 'js': [],
'css': [], 'css': [],
'qweb': [], 'qweb': [],
'installable': True, 'installable': True,
# Install this module automatically if all dependency have been previously and independently installed.
# Used for synergetic or glue modules.
# Install this module automatically if all dependency have been previously
# and independently installed. Used for synergetic or glue modules.
'auto_install': {{ prototype.auto_install }}, 'auto_install': {{ prototype.auto_install }},
'application': {{ prototype.application }}, 'application': {{ prototype.application }},
} }

13
module_prototyper/templates/8.0/data/model_name.xml.template

@ -1,17 +1,8 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<openerp> <openerp>
<data> <data>
{% for record in records %}
<!--
<record id="{{ model }}_{{ loop.index }}" model="{{ model }}">
{% for key, val in record.read()[0].items() %}
<field name="{{ key }}">{{ val }}</field>
{% endfor %}
</record>
-->
{% if not loop.last %}
{% endif %}
{% endfor %}
{{ data }}
</data> </data>
</openerp> </openerp>

17
module_prototyper/templates/8.0/data/model_name.xml.template~HEAD

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<openerp>
<data>
{% for record in records %}
<!--
<record id="{{ model }}_{{ loop.index }}" model="{{ model }}">
{% for key, val in record.read()[0].items() %}
<field name="{{ key }}">{{ val }}</field>
{% endfor %}
</record>
-->
{% if not loop.last %}
{% endif %}
{% endfor %}
</data>
</openerp>

32
module_prototyper/templates/8.0/header.template

@ -2,25 +2,21 @@
############################################################################## ##############################################################################
# #
# Odoo, Open Source Management Solution # Odoo, Open Source Management Solution
{% if author %}
# This module copyright (C) {{ export_year }} {{ author }}
{% else %}
# This module copyright (C) {{ export_year }}
{% endif %}
{% if website %}
# ({{ website }}).
{% endif %}
{% if license_text %}
# This module copyright (C) {{ export_year }} {% if author %}{{ author }}{% endif %}
# {% if website %}({{ website }}).{% endif %}
# #
{% for line in license_text %}
{% if line.strip() %}
# {{ line }}
{% else %}
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# #
{% endif %}
{% endfor %}
{% endif %}
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
{% block body %}
{% endblock %}
{% block body %}{% endblock %}

26
module_prototyper/templates/8.0/header.template~HEAD

@ -0,0 +1,26 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Odoo, Open Source Management Solution
{% if author %}
# This module copyright (C) {{ export_year }} {{ author }}
{% else %}
# This module copyright (C) {{ export_year }}
{% endif %}
{% if website %}
# ({{ website }}).
{% endif %}
{% if license_text %}
#
{% for line in license_text %}
{% if line.strip() %}
# {{ line }}
{% else %}
#
{% endif %}
{% endfor %}
{% endif %}
#
##############################################################################
{% block body %}
{% endblock %}

7
module_prototyper/templates/8.0/models/__init__.py.template

@ -1,9 +1,6 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
{% for model in models %}
{% if loop.first %}
{% endif %}
from . import {{ unprefix(model) }}
{% for model in models -%}
from . import {{ model }}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

9
module_prototyper/templates/8.0/models/__init__.py.template~HEAD

@ -0,0 +1,9 @@
{% extends "header.template" %}
{% block body %}
{% for model in models %}
{% if loop.first %}
{% endif %}
from . import {{ unprefix(model) }}
{% endfor %}
{% endblock %}

66
module_prototyper/templates/8.0/models/model_name.py.template

@ -1,68 +1,22 @@
{% extends "header.template" %} {% extends "header.template" %}
{% block body %} {% block body %}
from openerp import models, fields from openerp import models, fields
from openerp.tools.translate import _ from openerp.tools.translate import _
class {{ unprefix(name) }}(models.Model):
{% if model.state == 'base' and not is_prefixed(model.model) %}
_inherit = "{{ unprefix(model.model) }}"
{% else %}
_name = "{{ unprefix(model.model) }}"
{% endif %}
{% if description %}
_description = "{{ description }}"
{% endif %}
class {{ name }}(models.Model):
_inherit = "{{ inherit }}"
{% if description -%}_description = "{{ description }}"{% endif %}
{% for field in fields %}
{% for line in wrap(field.notes, replace_whitespace=False) %}
{% if line %}
# {{line}}
{% else %}
#
{% endif %}
{% endfor %}
{{ unprefix(field.name) }} = fields.{{ field.ttype|capitalize }}(
{% for field in fields -%}
{% if field.notes -%}# {{ field.notes }}{% endif %}
{{ field.name }} = fields.{{ field.ttype|capitalize }}(
string=_("{{ field.field_description }}"), string=_("{{ field.field_description }}"),
{% if field.selection %}
selection={{ field.selection }},
{% endif %}
{% if field.relation %}
comodel_name="{{ unprefix(field.relation) }}",
{% endif %}
{% if field.ttype == 'one2many' %}
inverse_name="{{ unprefix(field.relation_field) }}",
{% endif %}
{% if field.column1 %}
column1="{{ field.column1 }}",
{% endif %}
{% if field.column2 %}
column1="{{ field.column2 }}",
{% endif %}
required={{ field.required }}, required={{ field.required }},
translate={{ field.translate }}, translate={{ field.translate }},
readonly={{ field.readonly }}, readonly={{ field.readonly }},
{% if field.size %}
size={{ field.size }},
{% endif %}
{% if field.ttype in ('many2one', 'many2many', 'one2many') %}
{% if field.domain %}
domain={{ field.domain }},
{% endif %}
{% if field.client_context %}
context={{ field.client_context }},
{% endif %}
{% endif %}
{% if field.limit %}
limit={{ field.limit }},
{% endif %}
{% if field.ttype == 'many2one' and field.on_delete %}
on_delete="{{ field.on_delete }}",
{% endif %}
{% if field.helper %}
help=_("{{ field.helper }}"),
{% endif %}
)
{% endfor %}
{% if field.size -%}size={{ field.size }},{% endif %}
{% if field.helper -%}help=_("{{ field.helper }}"),{% endif %}
){% endfor %}
{% endblock %} {% endblock %}

68
module_prototyper/templates/8.0/models/model_name.py.template~HEAD

@ -0,0 +1,68 @@
{% extends "header.template" %}
{% block body %}
from openerp import models, fields
from openerp.tools.translate import _
class {{ unprefix(name) }}(models.Model):
{% if model.state == 'base' and not is_prefixed(model.model) %}
_inherit = "{{ unprefix(model.model) }}"
{% else %}
_name = "{{ unprefix(model.model) }}"
{% endif %}
{% if description %}
_description = "{{ description }}"
{% endif %}
{% for field in fields %}
{% for line in wrap(field.notes, replace_whitespace=False) %}
{% if line %}
# {{line}}
{% else %}
#
{% endif %}
{% endfor %}
{{ unprefix(field.name) }} = fields.{{ field.ttype|capitalize }}(
string=_("{{ field.field_description }}"),
{% if field.selection %}
selection={{ field.selection }},
{% endif %}
{% if field.relation %}
comodel_name="{{ unprefix(field.relation) }}",
{% endif %}
{% if field.ttype == 'one2many' %}
inverse_name="{{ unprefix(field.relation_field) }}",
{% endif %}
{% if field.column1 %}
column1="{{ field.column1 }}",
{% endif %}
{% if field.column2 %}
column1="{{ field.column2 }}",
{% endif %}
required={{ field.required }},
translate={{ field.translate }},
readonly={{ field.readonly }},
{% if field.size %}
size={{ field.size }},
{% endif %}
{% if field.ttype in ('many2one', 'many2many', 'one2many') %}
{% if field.domain %}
domain={{ field.domain }},
{% endif %}
{% if field.client_context %}
context={{ field.client_context }},
{% endif %}
{% endif %}
{% if field.limit %}
limit={{ field.limit }},
{% endif %}
{% if field.ttype == 'many2one' and field.on_delete %}
on_delete="{{ field.on_delete }}",
{% endif %}
{% if field.helper %}
help=_("{{ field.helper }}"),
{% endif %}
)
{% endfor %}
{% endblock %}

41
module_prototyper/templates/8.0/views/model_menus.xml.template

@ -1,29 +1,24 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<openerp> <openerp>
<data> <data>
{% for menu in menus %}
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}">
<field name="name">{{ unprefix(menu.action.name) }}</field>
<field name="type">{{ menu.action.type }}</field>
<field name="res_model">{{ unprefix(menu.action.res_model) }}</field>
<field name="view_type">{{ menu.action.view_type }}</field>
<field name="view_mode">{{ menu.action.view_mode }}</field>
{% if menu.action.help %}
<field name="help" type="html">{{ menu.action.help }}
</field>
{% endif %}
</record>
{% for menu in menus -%}
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}">
<field name="name">{{ menu.action.name }}</field>
<field name="type">{{ menu.action.type }}</field>
<field name="res_model">{{ menu.action.res_model }}</field>
<field name="view_type">{{ menu.action.view_type }}</field>
<field name="view_mode">{{ menu.action.view_mode }}</field>
{% if menu.action.help %}<field name="help" type="html">{{ menu.action.help }}
</field>{% endif %}
</record>
<menuitem action="action_{{ unprefix(menu.action.name) }}_{{ menu.action.view_type }}_view"
name="{{ menu.name }}"
id="menu_action_{{ unprefix(menu.name)|replace('.', '_') }}_{{ menu.action.view_type }}"
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %}
sequence="{{ menu.sequence }}"
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }}{% if not loop.last %},{% endif %}{% endfor %}"
/>
{% if not loop.last %}
{% endif %}
{% endfor %}
<menuitem action="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view"
name="{{ menu.name }}"
id="menu_action_{{ menu.name|replace('.', '_') }}_{{ menu.action.view_type }}"
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %}
sequence="{{ menu.sequence }}"
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }},{% endfor %}"
/>
{% endfor -%}
</data> </data>
</openerp> </openerp>

29
module_prototyper/templates/8.0/views/model_menus.xml.template~HEAD

@ -0,0 +1,29 @@
<?xml version="1.0"?>
<openerp>
<data>
{% for menu in menus %}
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}">
<field name="name">{{ unprefix(menu.action.name) }}</field>
<field name="type">{{ menu.action.type }}</field>
<field name="res_model">{{ unprefix(menu.action.res_model) }}</field>
<field name="view_type">{{ menu.action.view_type }}</field>
<field name="view_mode">{{ menu.action.view_mode }}</field>
{% if menu.action.help %}
<field name="help" type="html">{{ menu.action.help }}
</field>
{% endif %}
</record>
<menuitem action="action_{{ unprefix(menu.action.name) }}_{{ menu.action.view_type }}_view"
name="{{ menu.name }}"
id="menu_action_{{ unprefix(menu.name)|replace('.', '_') }}_{{ menu.action.view_type }}"
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %}
sequence="{{ menu.sequence }}"
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }}{% if not loop.last %},{% endif %}{% endfor %}"
/>
{% if not loop.last %}
{% endif %}
{% endfor %}
</data>
</openerp>

26
module_prototyper/templates/8.0/views/model_views.xml.template

@ -2,16 +2,22 @@
<openerp> <openerp>
<data> <data>
<!-- TODO: put here a reminder on what to do at the first edition --> <!-- TODO: put here a reminder on what to do at the first edition -->
{% for view in views %}
<record id="{{ unprefix(view.name)|replace('.', '_')}}_view" model="ir.ui.view">
<field name="name">{{ unprefix(view.name) }}.view</field>
<field name="model">{{ unprefix(view.model) }}</field>
<field name="view_type">{{ view.type }}</field>
<field name="inherit_id" ref="{{ view.inherit_id.get_xml_id(cr,1,1).values()[0] }}"/>
<field name="arch" type="xml">
{{ fixup_arch(view.arch) }}
</field>
</record>
{% for view in views -%}
<record id="{{ view.name|replace('.', '_')}}_view" model="ir.ui.view">
<field name="name">{{ view.name }}.view</field>
<field name="model">{{ view.model }}</field>
<field name="view_type">{{ view.type }}</field>
<field name="inherit_id" ref="{{ view.inherit_id.get_xml_id(cr,1,1).values()[0] }}"/>
<field name="arch" type="xml">
{# the arch given by odoo start with an xml tag that
will break the xml tree we build.
Be careful, custom field have a x_ prefix that has to be
removed
#}
{{ view.arch|replace('"', "'")|replace("<?xml version='1.0'?>", "")|replace("'x_", "'")|replace("> </field>", "/>") }}
</field>
</record>
{% endfor %} {% endfor %}
</data> </data>
</openerp> </openerp>

17
module_prototyper/templates/8.0/views/model_views.xml.template~HEAD

@ -0,0 +1,17 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- TODO: put here a reminder on what to do at the first edition -->
{% for view in views %}
<record id="{{ unprefix(view.name)|replace('.', '_')}}_view" model="ir.ui.view">
<field name="name">{{ unprefix(view.name) }}.view</field>
<field name="model">{{ unprefix(view.model) }}</field>
<field name="view_type">{{ view.type }}</field>
<field name="inherit_id" ref="{{ view.inherit_id.get_xml_id(cr,1,1).values()[0] }}"/>
<field name="arch" type="xml">
{{ fixup_arch(view.arch) }}
</field>
</record>
{% endfor %}
</data>
</openerp>

4
prototype/models/__init__.py → module_prototyper/tests/__init__.py~HEAD

@ -20,6 +20,6 @@
# #
############################################################################## ##############################################################################
from . import ( from . import (
prototype,
ir_model_fields
test_prototype_module_export,
test_prototype
) )

36
prototype/tests/test_prototype.py → module_prototyper/tests/test_prototype.py~HEAD

@ -17,15 +17,24 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import ast
import lxml.etree
try:
import pep8
except ImportError:
pep8 = None
from jinja2 import Environment from jinja2 import Environment
from jinja2.exceptions import TemplateNotFound from jinja2.exceptions import TemplateNotFound
from openerp.tests import common from openerp.tests import common
class test_prototype(common.TransactionCase):
class TestModulePrototyper(common.TransactionCase):
def setUp(self): def setUp(self):
super(test_prototype, self).setUp()
self.main_model = self.env['prototype']
super(TestModulePrototyper, self).setUp()
self.main_model = self.env['module_prototyper']
self.module_category_model = self.env['ir.module.category'] self.module_category_model = self.env['ir.module.category']
self.module_module_model = self.env['ir.module.module'] self.module_module_model = self.env['ir.module.module']
@ -59,6 +68,27 @@ class test_prototype(common.TransactionCase):
self.assertIsInstance(file_details.filename, basestring) self.assertIsInstance(file_details.filename, basestring)
self.assertIsInstance(file_details.filecontent, basestring) self.assertIsInstance(file_details.filecontent, basestring)
name, contents = file_details
if name.endswith(".py"):
# We have a "coding utf-8" line in there, we need to encode
contents = contents.encode("utf-8")
ast.parse(contents)
if pep8:
checker = pep8.Checker(
name,
contents.splitlines(True))
res = checker.check_all()
self.assertFalse(
res,
"Python file {0} has pep8 errors:\n"
"{1}\n{2}".format(name, checker.report.messages,
repr(contents))
)
elif name.endswith(".xml"):
# TODO validate valid odoo xml
lxml.etree.fromstring(contents)
def test_generate_files_raise_templatenotfound_if_not_found(self): def test_generate_files_raise_templatenotfound_if_not_found(self):
self.prototype.set_jinja_env('t_api_version') self.prototype.set_jinja_env('t_api_version')
self.assertRaises( self.assertRaises(

9
prototype/tests/test_prototype_module_export.py → module_prototyper/tests/test_prototype_module_export.py~HEAD

@ -27,8 +27,8 @@ import StringIO
class test_prototype_module_export(common.TransactionCase): class test_prototype_module_export(common.TransactionCase):
def setUp(self): def setUp(self):
super(test_prototype_module_export, self).setUp() super(test_prototype_module_export, self).setUp()
self.main_model = self.env['prototype.module.export']
self.prototype_model = self.env['prototype']
self.main_model = self.env['module_prototyper.module.export']
self.prototype_model = self.env['module_prototyper']
self.module_category_model = self.env[ self.module_category_model = self.env[
'ir.module.category' 'ir.module.category'
] ]
@ -69,10 +69,7 @@ class test_prototype_module_export(common.TransactionCase):
def test_zip_files_returns_tuple(self): def test_zip_files_returns_tuple(self):
"""Test the method return of the method that generate the zip file.""" """Test the method return of the method that generate the zip file."""
file_details = (
('test.txt', 'generated'),
)
ret = self.main_model.zip_files(file_details)
ret = self.main_model.zip_files(self.exporter, [self.prototype])
self.assertIsInstance(ret, tuple) self.assertIsInstance(ret, tuple)
self.assertIsInstance( self.assertIsInstance(
ret.zip_file, zipfile.ZipFile ret.zip_file, zipfile.ZipFile

51
module_prototyper/views/ir_model_fields_view.xml~HEAD

@ -0,0 +1,51 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_ir_model_fields_form" model="ir.ui.view">
<field name="name">view_ir_model_fields_form</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_form"/>
<field name="arch" type="xml">
<field name="groups" position="before">
<label for="helper"/>
<field name="helper"
placeholder="Text that will be set as the helper of the field..."/>
<label for="notes"/>
<field name="notes"
placeholder="Notes to help developers to understand the work or advanced features that should be added, ie: onchange, etc."/>
</field>
<field name="relation_field" position="after">
<field name="column1"
attrs="{'invisible': [('ttype', '!=', 'many2many')]}"
/>
<field name="column2"
attrs="{'invisible': [('ttype', '!=', 'many2many')]}"
/>
</field>
<field name="translate" position="after">
<field name="limit"
attrs="{'invisible': [('ttype', '!=', 'many2many')]}"
/>
<field name="client_context"
attrs="{'invisible': [('ttype', 'not in', ['many2one','one2many','many2many'])]}"
/>
</field>
</field>
</record>
<record id="view_ir_model_form" model="ir.ui.view">
<field name="name">view_ir_model_form</field>
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"/>
<field name="arch" type="xml">
<xpath expr="//page/field/form/separator[@string='Groups']"
position="before">
<separator string="Notes"/>
<field name="notes"/>
</xpath>
</field>
</record>
</data>
</openerp>

3
module_prototyper/views/module_prototyper_view.xml

@ -19,6 +19,8 @@
<field name="model">module_prototyper</field> <field name="model">module_prototyper</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Module"> <form string="Module">
<link rel="stylesheet"
href="/base/static/src/css/description.css"/>
<sheet> <sheet>
<field name="icon_image" widget="image" <field name="icon_image" widget="image"
class="oe_avatar oe_left"/> class="oe_avatar oe_left"/>
@ -140,6 +142,5 @@
sequence="4" sequence="4"
groups="base.group_system"/> groups="base.group_system"/>
</data> </data>
</openerp> </openerp>

145
module_prototyper/views/module_prototyper_view.xml~HEAD

@ -0,0 +1,145 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="module_prototyper_base_tree_view" model="ir.ui.view">
<field name="name">Base tree View for module prototypes</field>
<field name="model">module_prototyper</field>
<field name="arch" type="xml">
<tree string="Prototype">
<field name="human_name"/>
<field name="name"/>
<field name="summary"/>
</tree>
</field>
</record>
<record id="module_prototyper_base_form_view" model="ir.ui.view">
<field name="name">Base form view for module prototypes</field>
<field name="model">module_prototyper</field>
<field name="arch" type="xml">
<form string="Module">
<sheet>
<field name="icon_image" widget="image"
class="oe_avatar oe_left"/>
<div class="oe_title">
<h1>
<field name="human_name"
placeholder="ex: Module Prototyper"/>
</h1>
<div>
<button name="%(button_module_export_action)d"
string="Export" type="action"/>
</div>
</div>
<group>
<group>
<field name="name"
placeholder="ex: module_prototyper"/>
<field name="summary"
placeholder="ex: Prototype your module."/>
<field name="category_id"
placeholder="ex: Others, Sales, Website"/>
<field name="version"/>
<field name="license"/>
</group>
<group>
<field name="author"
placeholder="ex: Odoo Community Association"/>
<field name="website" widget="url"
placeholder="ex: http://odoo-community.org/"/>
<field name="maintainer"
placeholder="ex: Odoo Community Association"/>
<field name="auto_install"/>
<field name="application"/>
</group>
</group>
<notebook>
<page string="Description">
<field name="description"/>
</page>
<page string="Dependencies">
<field name="dependency_ids"/>
</page>
<page string="Fields">
<label for="field_ids"/>
<field name="field_ids"/>
</page>
<page string="Interface">
<label for="view_ids"/>
<field name="view_ids"/>
<label for="menu_ids"/>
<field name="menu_ids"/>
</page>
<page string="Data &amp; Demo">
<label for="data_ids"/>
<field name="data_ids"/>
<label for="demo_ids"/>
<field name="demo_ids"/>
</page>
<page string="Reports">
<label for="report_ids" />
<field name="report_ids" />
</page>
<page string="Security">
<label for="group_ids"/>
<field name="group_ids"/>
<label for="right_ids"/>
<field name="right_ids"/>
<label for="rule_ids"/>
<field name="rule_ids"/>
</page>
<page string="Workflows">
<label for="activity_ids" />
<field name="activity_ids" />
<label for="transition_ids" />
<field name="transition_ids" />
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="open_module_prototyper_list" model="ir.actions.act_window">
<field name="name">Prototypes</field>
<field name="res_model">module_prototyper</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="module_prototyper_base_tree_view"/>
</record>
<!--Here a menu is created to help user to have all what he needs-->
<!--under his mouse with ease-->
<menuitem id="menu_module_prototyper"
name="Module Prototypes"
parent="base.menu_administration"
sequence="1"/>
<menuitem id="menu_open_module_prototyper"
action="open_module_prototyper_list"
parent="menu_module_prototyper"
sequence="1"
groups="base.group_system"/>
<menuitem action="base.action_ui_view"
id="menu_action_ui_view"
parent="menu_module_prototyper"
sequence="2"
groups="base.group_system"/>
<menuitem action="base.grant_menu_access"
id="menu_grant_menu_access"
parent="menu_module_prototyper"
sequence="3"
groups="base.group_system"/>
<menuitem action="base.action_model_fields"
id="ir_model_model_fields"
parent="menu_module_prototyper"
sequence="4"
groups="base.group_system"/>
</data>
</openerp>

3
module_prototyper/wizard/module_prototyper_module_export.py

@ -33,9 +33,12 @@ class PrototypeModuleExport(models.TransientModel):
_name = "module_prototyper.module.export" _name = "module_prototyper.module.export"
name = fields.Char('File Name', readonly=True) name = fields.Char('File Name', readonly=True)
# It is implemented in order to manage previous and next versions
# of odoo
api_version = fields.Selection( api_version = fields.Selection(
[ [
('8.0', '8.0'), ('8.0', '8.0'),
# ('7.0', '7.0')
], ],
'API version', 'API version',
required=True, required=True,

73
prototype/wizard/prototype_module_export.py → module_prototyper/wizard/module_prototyper_module_export.py~HEAD

@ -7,8 +7,8 @@
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
# #
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
@ -19,23 +19,23 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
############################################################################## ##############################################################################
import StringIO import StringIO
import base64 import base64
import os
import zipfile import zipfile
from collections import namedtuple from collections import namedtuple
from openerp import fields, models, api from openerp import fields, models, api
class prototype_module_export(models.TransientModel):
_name = "prototype.module.export"
class PrototypeModuleExport(models.TransientModel):
_name = "module_prototyper.module.export"
name = fields.Char('File Name', readonly=True) name = fields.Char('File Name', readonly=True)
# It is implemented in order to manage previous and next versions
# of odoo
api_version = fields.Selection( api_version = fields.Selection(
[ [
('8.0', '8.0'), ('8.0', '8.0'),
# ('7.0', '7.0')
], ],
'API version', 'API version',
required=True, required=True,
@ -63,30 +63,26 @@ class prototype_module_export(models.TransientModel):
active_model = self._context.get('active_model') active_model = self._context.get('active_model')
# checking if the wizard was called by a prototype. # checking if the wizard was called by a prototype.
assert active_model == 'prototype', \
'{} has to be called from a "prototype" , not a "{}"'.format(
self, active_model
)
msg = '{} has to be called from a "module_prototyper" , not a "{}"'
assert active_model == 'module_prototyper', msg.format(
self, active_model
)
# getting the prototype of the wizard # getting the prototype of the wizard
prototype = self.env[active_model].browse(
self._context.get('active_id')
prototypes = self.env[active_model].browse(
[self._context.get('active_id')]
) )
# setting the jinja environment.
# They will help the program to find the template to render the files
# with.
prototype.set_jinja_env(wizard.api_version)
zip_details = self.zip_files(wizard, prototypes)
# generate_files ask the prototype to investigate the input
# and to generate the file templates according to it.
# zip_files, in another hand, put all the template files into a package
# ready to be saved by the user.
zip_details = self.zip_files(prototype.generate_files())
if len(prototypes) == 1:
zip_name = prototypes[0].name
else:
zip_name = "prototyper_export"
wizard.write( wizard.write(
{ {
'name': '{}.zip'.format(prototype.name),
'name': '{}.zip'.format(zip_name),
'state': 'get', 'state': 'get',
'data': base64.encodestring(zip_details.stringIO.getvalue()) 'data': base64.encodestring(zip_details.stringIO.getvalue())
} }
@ -94,7 +90,7 @@ class prototype_module_export(models.TransientModel):
return { return {
'type': 'ir.actions.act_window', 'type': 'ir.actions.act_window',
'res_model': 'prototype.module.export',
'res_model': 'module_prototyper.module.export',
'view_mode': 'form', 'view_mode': 'form',
'view_type': 'form', 'view_type': 'form',
'res_id': wizard.id, 'res_id': wizard.id,
@ -103,19 +99,34 @@ class prototype_module_export(models.TransientModel):
} }
@staticmethod @staticmethod
def zip_files(file_details):
def zip_files(wizard, prototypes):
"""Takes a set of file and zips them. """Takes a set of file and zips them.
:param file_details: tuple (filename, filecontent)
:param file_details: tuple (filename, file_content)
:return: tuple (zip_file, stringIO) :return: tuple (zip_file, stringIO)
""" """
zip_details = namedtuple('Zip_details', ['zip_file', 'stringIO']) zip_details = namedtuple('Zip_details', ['zip_file', 'stringIO'])
out = StringIO.StringIO() out = StringIO.StringIO()
with zipfile.ZipFile(out, 'w') as target: with zipfile.ZipFile(out, 'w') as target:
for filename, filecontent in file_details:
info = zipfile.ZipInfo(filename)
info.compress_type = zipfile.ZIP_DEFLATED
info.external_attr = 2175008768 # specifies mode 0644
target.writestr(info, filecontent)
for prototype in prototypes:
# setting the jinja environment.
# They will help the program to find the template to render the
# files with.
prototype.set_jinja_env(wizard.api_version)
# generate_files ask the prototype to investigate the input and
# to generate the file templates according to it. zip_files,
# in another hand, put all the template files into a package
# ready to be saved by the user.
file_details = prototype.generate_files()
for filename, file_content in file_details:
if isinstance(file_content, unicode):
file_content = file_content.encode('utf-8')
# Prefix all names with module technical name
filename = os.path.join(prototype.name, filename)
info = zipfile.ZipInfo(filename)
info.compress_type = zipfile.ZIP_DEFLATED
info.external_attr = 2175008768 # specifies mode 0644
target.writestr(info, file_content)
return zip_details(zip_file=target, stringIO=out) return zip_details(zip_file=target, stringIO=out)

2
prototype/demo/prototype.prototype.csv
File diff suppressed because it is too large
View File

272
prototype/i18n/fr.po

@ -1,272 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * prototype
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-10-08 17:58+0000\n"
"PO-Revision-Date: 2014-10-08 14:02-0500\n"
"Last-Translator: Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 1.5.4\n"
#. module: prototype
#: selection:prototype.module.export,api_version:0
msgid "7.0"
msgstr ""
#. module: prototype
#: selection:prototype.module.export,api_version:0
msgid "8.0"
msgstr ""
#. module: prototype
#: field:prototype.module.export,api_version:0
msgid "API version"
msgstr "Version de l'API"
#. module: prototype
#: field:prototype,rights:0
msgid "Access Rights"
msgstr "Liste des contrôles d'accès"
#. module: prototype
#: field:prototype,author:0
msgid "Author"
msgstr "Auteur"
#. module: prototype
#: field:prototype,auto_install:0
msgid "Auto Install"
msgstr "Installation automatique"
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Cancel"
msgstr "Annuler"
#. module: prototype
#: field:prototype,category_id:0
msgid "Category"
msgstr "Catégorie"
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Close"
msgstr "Fermer"
#. module: prototype
#: field:prototype,create_uid:0 field:prototype.module.export,create_uid:0
msgid "Created by"
msgstr "Créé par"
#. module: prototype
#: field:prototype,create_date:0 field:prototype.module.export,create_date:0
msgid "Created on"
msgstr "Créé le"
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Data & Demo"
msgstr "Données et démo"
#. module: prototype
#: field:prototype,data:0
msgid "Data filters"
msgstr "Filtres pour les données"
#. module: prototype
#: field:prototype,demo:0
msgid "Demo filters"
msgstr "Filtres pour les données de démo"
#. module: prototype
#: view:prototype:prototype.view_prototype_form field:prototype,dependencies:0
msgid "Dependencies"
msgstr "Dépendances"
#. module: prototype
#: view:prototype:prototype.view_prototype_form field:prototype,description:0
msgid "Description"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export"
msgstr "Exporter"
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Complete"
msgstr "Export terminé"
#. module: prototype
#: model:ir.actions.act_window,name:prototype.button_module_export_action
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Module"
msgstr "Exporter le module"
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Settings"
msgstr "Configuration de l'export"
#. module: prototype
#: model:ir.model,name:prototype.model_ir_model_fields
#: field:prototype,fields:0
msgid "Fields"
msgstr "Champs"
#. module: prototype
#: field:prototype.module.export,data:0
msgid "File"
msgstr "Fichier"
#. module: prototype
#: field:prototype.module.export,name:0
msgid "File Name"
msgstr "Nom du fichier"
#. module: prototype
#: field:prototype,groups:0
msgid "Groups"
msgstr "Groupes"
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Here is the exported module:"
msgstr "Voici le module exporté :"
#. module: prototype
#: field:prototype,id:0 field:prototype.module.export,id:0
msgid "ID"
msgstr ""
#. module: prototype
#: field:prototype,icon_image:0
msgid "Icon"
msgstr "Icône"
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Interface"
msgstr ""
#. module: prototype
#: field:prototype,write_uid:0 field:prototype.module.export,write_uid:0
msgid "Last Updated by"
msgstr "Mis à jour par"
#. module: prototype
#: field:prototype,write_date:0 field:prototype.module.export,write_date:0
msgid "Last Updated on"
msgstr "Mis à jour le"
#. module: prototype
#: field:prototype,maintainer:0
msgid "Maintainer"
msgstr "Mainteneur"
#. module: prototype
#: field:prototype,menu:0
msgid "Menu Items"
msgstr "Éléments du menu"
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Models"
msgstr "Modèles"
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Module"
msgstr ""
#. module: prototype
#: field:prototype,human_name:0
msgid "Module Name"
msgstr "Nom du module"
#. module: prototype
#: view:ir.model:prototype.view_ir_model_form field:ir.model.fields,notes:0
msgid "Notes"
msgstr ""
#. module: prototype
#: model:ir.actions.act_window,name:prototype.open_prototype_list
#: model:ir.model,name:prototype.model_prototype
#: model:ir.ui.menu,name:prototype.menu_open_prototype
#: view:prototype:prototype.view_prototype_tree
msgid "Prototype"
msgstr ""
#. module: prototype
#: field:prototype,rules:0
msgid "Record Rules"
msgstr "Règles sur les enregistrements"
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Security"
msgstr "Sécurité"
#. module: prototype
#: field:prototype,summary:0
msgid "Summary"
msgstr "Résumé"
#. module: prototype
#: field:prototype,name:0
msgid "Technical Name"
msgstr "Nom technique"
#. module: prototype
#: help:prototype,data:0
msgid "The records matching the filters will be added as data."
msgstr ""
"Les enregistrements correspondant aux critères des filtres seront exportées "
"dans le module comme données."
#. module: prototype
#: help:prototype,demo:0
msgid "The records matching the filters will be added as demo data."
msgstr ""
"Les enregistrements correspondant aux critères des filtres seront exportées "
"dans le module comme données de démo."
#. module: prototype
#: field:prototype,version:0
msgid "Version"
msgstr ""
#. module: prototype
#: field:prototype,views:0
msgid "Views"
msgstr "Vues"
#. module: prototype
#: field:prototype,website:0
msgid "Website"
msgstr "Site web"
#. module: prototype
#: selection:prototype.module.export,state:0
msgid "choose"
msgstr "choisir"
#. module: prototype
#: selection:prototype.module.export,state:0
msgid "get"
msgstr "récupérer"
#. module: prototype
#: field:prototype.module.export,state:0
msgid "unknown"
msgstr "inconnu"

268
prototype/i18n/prototype.pot

@ -1,268 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * prototype
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2014-10-08 17:58+0000\n"
"PO-Revision-Date: 2014-10-08 14:00-0500\n"
"Last-Translator: Maxime Chambreuil <maxime.chambreuil@savoirfairelinux.com>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 1.5.4\n"
#. module: prototype
#: selection:prototype.module.export,api_version:0
msgid "7.0"
msgstr ""
#. module: prototype
#: selection:prototype.module.export,api_version:0
msgid "8.0"
msgstr ""
#. module: prototype
#: field:prototype.module.export,api_version:0
msgid "API version"
msgstr ""
#. module: prototype
#: field:prototype,rights:0
msgid "Access Rights"
msgstr ""
#. module: prototype
#: field:prototype,author:0
msgid "Author"
msgstr ""
#. module: prototype
#: field:prototype,auto_install:0
msgid "Auto Install"
msgstr ""
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Cancel"
msgstr ""
#. module: prototype
#: field:prototype,category_id:0
msgid "Category"
msgstr ""
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Close"
msgstr ""
#. module: prototype
#: field:prototype,create_uid:0 field:prototype.module.export,create_uid:0
msgid "Created by"
msgstr ""
#. module: prototype
#: field:prototype,create_date:0 field:prototype.module.export,create_date:0
msgid "Created on"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Data & Demo"
msgstr ""
#. module: prototype
#: field:prototype,data:0
msgid "Data filters"
msgstr ""
#. module: prototype
#: field:prototype,demo:0
msgid "Demo filters"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form field:prototype,dependencies:0
msgid "Dependencies"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form field:prototype,description:0
msgid "Description"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export"
msgstr ""
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Complete"
msgstr ""
#. module: prototype
#: model:ir.actions.act_window,name:prototype.button_module_export_action
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Module"
msgstr ""
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Export Settings"
msgstr ""
#. module: prototype
#: model:ir.model,name:prototype.model_ir_model_fields
#: field:prototype,fields:0
msgid "Fields"
msgstr ""
#. module: prototype
#: field:prototype.module.export,data:0
msgid "File"
msgstr ""
#. module: prototype
#: field:prototype.module.export,name:0
msgid "File Name"
msgstr ""
#. module: prototype
#: field:prototype,groups:0
msgid "Groups"
msgstr ""
#. module: prototype
#: view:prototype.module.export:prototype.view_module_export_wizard
msgid "Here is the exported module:"
msgstr ""
#. module: prototype
#: field:prototype,id:0 field:prototype.module.export,id:0
msgid "ID"
msgstr ""
#. module: prototype
#: field:prototype,icon_image:0
msgid "Icon"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Interface"
msgstr ""
#. module: prototype
#: field:prototype,write_uid:0 field:prototype.module.export,write_uid:0
msgid "Last Updated by"
msgstr ""
#. module: prototype
#: field:prototype,write_date:0 field:prototype.module.export,write_date:0
msgid "Last Updated on"
msgstr ""
#. module: prototype
#: field:prototype,maintainer:0
msgid "Maintainer"
msgstr ""
#. module: prototype
#: field:prototype,menu:0
msgid "Menu Items"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Models"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Module"
msgstr ""
#. module: prototype
#: field:prototype,human_name:0
msgid "Module Name"
msgstr ""
#. module: prototype
#: view:ir.model:prototype.view_ir_model_form field:ir.model.fields,notes:0
msgid "Notes"
msgstr ""
#. module: prototype
#: model:ir.actions.act_window,name:prototype.open_prototype_list
#: model:ir.model,name:prototype.model_prototype
#: model:ir.ui.menu,name:prototype.menu_open_prototype
#: view:prototype:prototype.view_prototype_tree
msgid "Prototype"
msgstr ""
#. module: prototype
#: field:prototype,rules:0
msgid "Record Rules"
msgstr ""
#. module: prototype
#: view:prototype:prototype.view_prototype_form
msgid "Security"
msgstr ""
#. module: prototype
#: field:prototype,summary:0
msgid "Summary"
msgstr ""
#. module: prototype
#: field:prototype,name:0
msgid "Technical Name"
msgstr ""
#. module: prototype
#: help:prototype,data:0
msgid "The records matching the filters will be added as data."
msgstr ""
#. module: prototype
#: help:prototype,demo:0
msgid "The records matching the filters will be added as demo data."
msgstr ""
#. module: prototype
#: field:prototype,version:0
msgid "Version"
msgstr ""
#. module: prototype
#: field:prototype,views:0
msgid "Views"
msgstr ""
#. module: prototype
#: field:prototype,website:0
msgid "Website"
msgstr ""
#. module: prototype
#: selection:prototype.module.export,state:0
msgid "choose"
msgstr ""
#. module: prototype
#: selection:prototype.module.export,state:0
msgid "get"
msgstr ""
#. module: prototype
#: field:prototype.module.export,state:0
msgid "unknown"
msgstr ""

339
prototype/models/prototype.py

@ -1,339 +0,0 @@
# -*- encoding: utf-8 -*-
# #############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2010 - 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import os
import re
import base64
from datetime import date
YEAR = date.today().year
from collections import namedtuple
from jinja2 import Environment, FileSystemLoader
from openerp import models, api, fields
class Prototype(models.Model):
_name = "prototype"
_description = "Prototype"
licence = fields.Char(
'Licence',
default='AGPL-3',
)
name = fields.Char(
'Technical Name', required=True,
help=('The technical name will be used to define the name of '
'the exported module, the name of the model.')
)
category_id = fields.Many2one('ir.module.category', 'Category')
human_name = fields.Char(
'Module Name', required=True,
help=('The Module Name will be used as the displayed name of the '
'exported module.')
)
summary = fields.Char('Summary', required=True)
description = fields.Text('Description', required=True)
author = fields.Char('Author', required=True)
maintainer = fields.Char('Maintainer')
website = fields.Char('Website')
icon_image = fields.Binary(
'Icon',
help=('The icon set up here will be used as the icon '
'for the exported module also')
)
version = fields.Char('Version', size=3, default='0.1')
auto_install = fields.Boolean(
'Auto Install',
default=False,
help='Check if the module should be install by default.'
)
application = fields.Boolean(
'Application',
default=False,
help='Check if the module is an Odoo application.'
)
# Relations
dependency_ids = fields.Many2many(
'ir.module.module', 'prototype_module_rel',
'prototype_id', 'module_id',
'Dependencies'
)
data_ids = fields.Many2many(
'ir.filters',
'prototype_data_rel',
'prototype_id', 'filter_id',
'Data filters',
help="The records matching the filters will be added as data."
)
demo_ids = fields.Many2many(
'ir.filters',
'prototype_demo_rel',
'prototype_id', 'filter_id',
'Demo filters',
help="The records matching the filters will be added as demo data."
)
field_ids = fields.Many2many(
'ir.model.fields', 'prototype_fields_rel',
'prototype_id', 'field_id', 'Fields'
)
menu_ids = fields.Many2many(
'ir.ui.menu', 'prototype_menu_rel',
'prototype_id', 'menu_id', 'Menu Items'
)
view_ids = fields.Many2many(
'ir.ui.view', 'prototype_view_rel',
'prototype_id', 'view_id', 'Views'
)
group_ids = fields.Many2many(
'res.groups', 'prototype_groups_rel',
'prototype_id', 'group_id', 'Groups'
)
right_ids = fields.Many2many(
'ir.model.access', 'prototype_rights_rel',
'prototype_id', 'right_id',
'Access Rights'
)
rule_ids = fields.Many2many(
'ir.rule', 'prototype_rule_rel',
'prototype_id', 'rule_id', 'Record Rules'
)
__data_files = []
__field_descriptions = {}
_env = None
File_details = namedtuple('file_details', ['filename', 'filecontent'])
template_path = '{}/../templates/'.format(os.path.dirname(__file__))
@api.model
def set_jinja_env(self, api_version):
"""Set the Jinja2 environment.
The environment will helps the system to find the templates to render.
:param api_version: string, odoo api
:return: jinja2.Environment instance.
"""
if self._env is None:
self._env = Environment(
loader=FileSystemLoader(
os.path.join(self.template_path, api_version)
)
)
return self._env
def set_field_descriptions(self):
"""Mock the list of fields into dictionary.
It allows us to add or change attributes of the fields.
:return: None
"""
for field in self.field_ids:
field_description = {}
# This will mock a field record.
# the mock will allow us to add data or modify the data
# of the field (like for the name) with keeping all the
# attributes of the record.
field_description.update({
attr_name: getattr(field, attr_name)
for attr_name in dir(field)
if not attr_name[0] == '_'
})
# custom fields start with the prefix x_.
# it has to be removed.
field_description['name'] = re.sub(r'^x_', '', field.name)
self.__field_descriptions[field] = field_description
@api.model
def generate_files(self):
""" Generates the files from the details of the prototype.
:return: tuple
"""
assert self._env is not None, \
'Run set_env(api_version) before to generate files.'
self.set_field_descriptions()
file_details = []
file_details.extend(self.generate_models_details())
file_details.extend(self.generate_views_details())
file_details.extend(self.generate_menus_details())
file_details.append(self.generate_module_init_file_details())
# must be the last as the other generations might add information
# to put in the __openerp__: additional dependencies, views files, etc.
file_details.append(self.generate_module_openerp_file_details())
file_details.append(self.save_icon())
return file_details
@api.model
def save_icon(self):
return self.File_details(
os.path.join('static', 'description', 'icon.jpg'),
base64.b64decode(self.icon_image)
)
@api.model
def generate_module_openerp_file_details(self):
"""Wrapper to generate the __openerp__.py file of the module."""
return self.generate_file_details(
'__openerp__.py',
'__openerp__.py.template',
prototype=self,
data_files=self.__data_files,
)
@api.model
def generate_module_init_file_details(self):
"""Wrapper to generate the __init__.py file of the module."""
return self.generate_file_details(
'__init__.py',
'__init__.py.template',
# no import models if no work of fields in
# the prototype
models=bool(self.field_ids)
)
@api.model
def generate_models_details(self):
"""Finds the models from the list of fields and generates
the __init__ file and each models files (one by class).
"""
files = []
# TODO: doesn't work as need to find the module to import
# and it is not necessary the name of the model the fields
# belongs to.
# ie. field.cell_phone is defined in a model inheriting from
# res.partner.
# How do we find the module the field was defined in?
# dependencies = set([dep.id for dep in self.dependencies])
relations = {}
for field in self.__field_descriptions.itervalues():
model = field.get('model_id')
relations.setdefault(model, []).append(field)
# dependencies.add(model.id)
# blind update of dependencies.
# self.write({
# 'dependencies': [(6, 0, [id_ for id_ in dependencies])]
# })
files.append(self.generate_models_init_details(relations.keys()))
for model, fields in relations.iteritems():
files.append(self.generate_model_details(model, fields))
return files
@api.model
def generate_models_init_details(self, ir_models):
"""Wrapper to generate the __init__.py file in models folder."""
return self.generate_file_details(
'models/__init__.py',
'models/__init__.py.template',
models=[
self.friendly_name(ir_model.model)
for ir_model in ir_models
]
)
@api.model
def generate_views_details(self):
"""Wrapper to generate the views files."""
relations = {}
for view in self.view_ids:
relations.setdefault(view.model, []).append(view)
views_details = []
for model, views in relations.iteritems():
filepath = 'views/{}_view.xml'.format(
self.friendly_name(model)
)
views_details.append(
self.generate_file_details(
filepath,
'views/model_views.xml.template',
views=views
)
)
self.__data_files.append(filepath)
return views_details
@api.model
def generate_menus_details(self):
"""Wrapper to generate the menus files."""
relations = {}
for menu in self.menu_ids:
relations.setdefault(menu.action.res_model, []).append(menu)
menus_details = []
for model_name, menus in relations.iteritems():
filepath = 'views/{}_menus.xml'.format(
self.friendly_name(model_name)
)
menus_details.append(
self.generate_file_details(
filepath,
'views/model_menus.xml.template',
menus=menus,
)
)
self.__data_files.append(filepath)
return menus_details
@api.model
def generate_model_details(self, model, field_descriptions):
"""Wrapper to generate the python file for the model.
:param model: ir.model record.
:param field_descriptions: list of ir.model.fields records.
:return: FileDetails instance.
"""
python_friendly_name = self.friendly_name(model.model)
return self.generate_file_details(
'models/{}.py'.format(python_friendly_name),
'models/model_name.py.template',
name=python_friendly_name,
inherit=model.model,
fields=field_descriptions,
)
@staticmethod
def friendly_name(name):
return name.replace('.', '_')
@api.model
def generate_file_details(self, filename, template, **kwargs):
""" generate file details from jinja2 template.
:param filename: name of the file the content is related to
:param template: path to the file to render the content
:param kwargs: arguments of the template
:return: File_details instance
"""
template = self._env.get_template(template)
# keywords used in several templates.
kwargs.update(
{
'export_year': YEAR,
'author': self.author,
'website': self.website,
'cr': self._cr,
}
)
return self.File_details(filename, template.render(kwargs))

2
prototype/security/ir.model.access.csv

@ -1,2 +0,0 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_prototype_admin,prototype_system,model_prototype,base.group_system,1,1,1,1

BIN
prototype/static/description/icon.png

Before

Width: 500  |  Height: 500  |  Size: 14 KiB

8
prototype/templates/8.0/data/model_name.xml.template

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
{{ data }}
</data>
</openerp>

8
prototype/templates/8.0/demo/model_name.xml.template

@ -1,8 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
{{ demo }}
</data>
</openerp>

22
prototype/templates/8.0/header.template

@ -1,22 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Odoo, Open Source Management Solution
# This module copyright (C) {{ export_year }} {{ author }}
# ({{ website }}).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{% block body %}{% endblock %}

6
prototype/templates/8.0/models/__init__.py.template

@ -1,6 +0,0 @@
{% extends "header.template" %}
{% block body %}
{% for model in models -%}
from . import {{ model }}
{% endfor %}
{% endblock %}

21
prototype/templates/8.0/models/model_name.py.template

@ -1,21 +0,0 @@
{% extends "header.template" %}
{% block body %}
from openerp import models, fields
from openerp.tools.translate import _
class {{ name }}(models.Model):
_inherit = "{{ inherit }}"
{% if description %}_description = "{{ description }}"{% endif %}
{% for field in fields -%}
{{ field.name }} = fields.{{ field.ttype|capitalize }}(
string=_("{{ field.field_description }}"),
required={{ field.required }},
translate={{ field.translate }},
readonly={{ field.readonly }},
help=_('{{ field.notes }}'),
)
{% endfor %}
{% endblock %}

4
prototype/templates/8.0/security/ir.model.access.csv.template

@ -1,4 +0,0 @@
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 %}

10
prototype/templates/8.0/security/model_name.xml.template

@ -1,10 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
{{ groups }}
{{ rules }}
</data>
</openerp>

24
prototype/templates/8.0/views/model_menus.xml.template

@ -1,24 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
{% for menu in menus -%}
<record id="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view" model="{{ menu.action.type }}">
<field name="name">{{ menu.action.name }}</field>
<field name="type">{{ menu.action.type }}</field>
<field name="res_model">{{ menu.action.res_model }}</field>
<field name="view_type">{{ menu.action.view_type }}</field>
<field name="view_mode">{{ menu.action.view_mode }}</field>
{% if menu.action.help %}<field name="help" type="html">{{ menu.action.help }}
</field>{% endif %}
</record>
<menuitem action="action_{{ menu.action.name }}_{{ menu.action.view_type }}_view"
name="{{ menu.name }}"
id="menu_action_{{ menu.name|replace('.', '_') }}_{{ menu.action.view_type }}"
{% if menu.parent_id %}parent="{{ menu.parent_id.get_xml_id(cr,1,1).values()[0] }}"{% endif %}
sequence="{{ menu.sequence }}"
groups="{% for group in menu.groups_id %}{{ group.get_xml_id(cr,1,1).values()[0] }},{% endfor %}"
/>
{% endfor -%}
</data>
</openerp>

23
prototype/templates/8.0/views/model_views.xml.template

@ -1,23 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<!-- TODO: put here a reminder on what to do at the first edition -->
{% for view in views %}
<record id="{{ view.name|replace('.', '_')}}_view" model="ir.ui.model">
<field name="name">{{ view.name }}.view</field>
<field name="model">{{ view.model }}</field>
<field name="view_type">{{ view.type }}</field>
<field name="inherit_id" ref="{{ view.inherit_id.get_xml_id(cr,1,1).values()[0] }}"/>
<field name="arch" type="xml">
{# the arch given by odoo start with an xml tag that
will break the xml tree we build.
Be careful, custom field have a x_ prefix that has to be
removed
#}
{{ view.arch|replace('<?xml version="1.0"?>', '')|replace('"x_', '"') }}
</field>
</record>
{% endfor %}
</data>
</openerp>

28
prototype/tests/__init__.py

@ -1,28 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2010 - 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import test_prototype_module_export
from . import test_prototype
checks = [
test_prototype_module_export,
test_prototype,
]

30
prototype/views/ir_model_fields_view.xml

@ -1,30 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_ir_model_fields_form" model="ir.ui.view">
<field name="name">view_ir_model_fields_form</field>
<field name="model">ir.model.fields</field>
<field name="inherit_id" ref="base.view_model_fields_form"/>
<field name="arch" type="xml">
<field name="groups" position="before">
<label for="notes"/>
<field name="notes"/>
</field>
</field>
</record>
<record id="view_ir_model_form" model="ir.ui.view">
<field name="name">view_ir_model_form</field>
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"/>
<field name="arch" type="xml">
<xpath expr="//page/field/form/separator[@string='Groups']" position="before">
<separator string="Notes"/>
<field name="notes"/>
</xpath>
</field>
</record>
</data>
</openerp>

103
prototype/views/prototype_view.xml

@ -1,103 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_prototype_tree" model="ir.ui.view">
<field name="name">prototype.tree</field>
<field name="model">prototype</field>
<field name="arch" type="xml">
<tree string="Prototype">
<field name="human_name"/>
<field name="name"/>
<field name="summary"/>
</tree>
</field>
</record>
<record id="view_prototype_form" model="ir.ui.view">
<field name="name">prototype.form</field>
<field name="model">prototype</field>
<field name="arch" type="xml">
<form string="Module">
<link rel="stylesheet"
href="/base/static/src/css/description.css"/>
<sheet>
<field name="icon_image" widget="image"
class="oe_avatar oe_left"/>
<div class="oe_title">
<h1>
<field name="human_name"/>
</h1>
<div>
<button name="%(button_module_export_action)d"
string="Export" type="action"/>
</div>
</div>
<group>
<group>
<field name="name"/>
<field name="summary"/>
<field name="category_id"/>
<field name="version"/>
</group>
<group>
<field name="author"/>
<field name="website" widget="url"/>
<field name="maintainer"/>
<field name="auto_install"/>
<field name="application"/>
</group>
</group>
<notebook>
<page string="Description">
<field name="description"/>
</page>
<page string="Dependencies">
<field name="dependency_ids"/>
</page>
<page string="Data &amp; Demo">
<label for="data_ids"/>
<field name="data_ids"/>
<label for="demo_ids"/>
<field name="demo_ids"/>
</page>
<page string="Fields">
<label for="field_ids"/>
<field name="field_ids"/>
</page>
<page string="Interface">
<label for="menu_ids"/>
<field name="menu_ids"/>
<label for="view_ids"/>
<field name="view_ids"/>
</page>
<page string="Security">
<label for="group_ids"/>
<field name="group_ids"/>
<label for="right_ids"/>
<field name="right_ids"/>
<label for="rule_ids"/>
<field name="rule_ids"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record id="open_prototype_list" model="ir.actions.act_window">
<field name="name">Prototype</field>
<field name="res_model">prototype</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_prototype_tree"/>
</record>
<menuitem id="menu_open_prototype"
action="open_prototype_list"
parent="base.menu_management"
sequence="30"
groups="base.group_system"/>
</data>
</openerp>

22
prototype/wizard/__init__.py

@ -1,22 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# This module copyright (C) 2010 - 2014 Savoir-faire Linux
# (<http://www.savoirfairelinux.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from . import prototype_module_export

43
prototype/wizard/prototype_module_export_view.xml

@ -1,43 +0,0 @@
<?xml version="1.0"?>
<openerp>
<data>
<record id="view_module_export_wizard" model="ir.ui.view">
<field name="name">Export Module</field>
<field name="model">prototype.module.export</field>
<field name="arch" type="xml">
<form string="Export Module">
<field name="name" invisible="1"/>
<field name="state" invisible="1"/>
<group string="Export Settings" states="choose" col="6">
<group colspan="2">
<field name="api_version"/>
</group>
<group colspan="4">
</group>
</group>
<div states="get">
<h2>Export Complete</h2>
<p>Here is the exported module: <field name="data" readonly="1" filename="name"/></p>
</div>
<footer states="choose">
<button name="action_export" string="Export" type="object" class="oe_highlight"/> or
<button special="cancel" string="Cancel" type="object" class="oe_link"/>
</footer>
<footer states="get">
<button special="cancel" string="Close" type="object"/>
</footer>
</form>
</field>
</record>
<record id="button_module_export_action" model="ir.actions.act_window">
<field name="name">Export Module</field>
<field name="res_model">prototype.module.export</field>
<field name="view_type">form</field>
<field name="view_id" ref="view_module_export_wizard"/>
<field name="target">new</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save