diff --git a/saas_portal_demo_template/README.rst b/saas_portal_demo_template/README.rst new file mode 100644 index 000000000..d5c2cbde9 --- /dev/null +++ b/saas_portal_demo_template/README.rst @@ -0,0 +1,5 @@ +SaaS Portal Demo Template +========================= + +With this module you can specify a demo template from which a demonstration +client is created and refreshed daily diff --git a/saas_portal_demo_template/__init__.py b/saas_portal_demo_template/__init__.py new file mode 100644 index 000000000..bff786c08 --- /dev/null +++ b/saas_portal_demo_template/__init__.py @@ -0,0 +1 @@ +import models diff --git a/saas_portal_demo_template/__openerp__.py b/saas_portal_demo_template/__openerp__.py new file mode 100644 index 000000000..fff74e78a --- /dev/null +++ b/saas_portal_demo_template/__openerp__.py @@ -0,0 +1,14 @@ +{ + 'name': 'SaaS Portal Demo Template', + 'version': '0.1', + 'author': 'Salton Massally', + 'license': 'AGPL-3', + 'category': 'SaaS', + 'website': 'http://idtlabs.sl', + 'depends': ['saas_portal'], + 'data': [ + 'views/res_config.xml', + 'data/ir_cron.xml' + ], + 'installable': True, +} diff --git a/saas_portal_demo_template/data/ir_cron.xml b/saas_portal_demo_template/data/ir_cron.xml new file mode 100644 index 000000000..ff8abee84 --- /dev/null +++ b/saas_portal_demo_template/data/ir_cron.xml @@ -0,0 +1,17 @@ + + + + + Spurn Demo database + + 1 + days + -1 + + + + + + + + diff --git a/saas_portal_demo_template/models/__init__.py b/saas_portal_demo_template/models/__init__.py new file mode 100644 index 000000000..380893d29 --- /dev/null +++ b/saas_portal_demo_template/models/__init__.py @@ -0,0 +1,3 @@ +import saas_portal +import res_config +import res_company diff --git a/saas_portal_demo_template/models/res_company.py b/saas_portal_demo_template/models/res_company.py new file mode 100644 index 000000000..cd8b548e8 --- /dev/null +++ b/saas_portal_demo_template/models/res_company.py @@ -0,0 +1,15 @@ +from openerp import models, fields, api + + +class ResCompany(models.Model): + _inherit = 'res.company' + + demo_client_name = fields.Char( + 'Demo Client Name', + required=True + ) + demo_plan_id = fields.Many2one( + 'saas_portal.plan', + 'Demo Plan', + required=True, + ) \ No newline at end of file diff --git a/saas_portal_demo_template/models/res_config.py b/saas_portal_demo_template/models/res_config.py new file mode 100644 index 000000000..3c03b8ffe --- /dev/null +++ b/saas_portal_demo_template/models/res_config.py @@ -0,0 +1,27 @@ +from openerp import models, fields, api + + +class SaasPortalConfigWizard(models.TransientModel): + _inherit = 'saas_portal.config.settings' + + demo_client_name = fields.Char( + 'Demo Client Name', + required=True + ) + demo_plan_id = fields.Many2one( + 'saas_portal.plan', + 'Demo Plan', + required=True, + ) + @api.multi + def get_default_demo_details(self): + company = self.env.user.company_id + return {'demo_client_name': company.demo_client_name, + 'demo_plan_id': company.demo_plan_id.id, + } + + @api.multi + def set_demo_details(self): + company = self.env.user.company_id + company.demo_client_name = self.demo_client_name + company.demo_plan_id = self.demo_plan_id.id diff --git a/saas_portal_demo_template/models/saas_portal.py b/saas_portal_demo_template/models/saas_portal.py new file mode 100644 index 000000000..fe8611022 --- /dev/null +++ b/saas_portal_demo_template/models/saas_portal.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +from openerp import models, fields, api + +class SaasPortalClient(models.Model): + _inherit = 'saas_portal.client' + + @api.model + def try_spurn_demo_instance(self): + company = self.env.user.company_id + if not company.demo_client_name or not company.demo_plan_id: + return + + existing = self.search([('name', '=', company.demo_client_name)]) + if existing: + existing.delete_database_server() + + res = company.demo_plan_id.create_new_database( + dbname=company.demo_client_name) + client = self.browse(res.get('id')) + client.server_id.action_sync_server() + \ No newline at end of file diff --git a/saas_portal_demo_template/views/res_config.xml b/saas_portal_demo_template/views/res_config.xml new file mode 100644 index 000000000..d5068671c --- /dev/null +++ b/saas_portal_demo_template/views/res_config.xml @@ -0,0 +1,18 @@ + + + + + saas_portal.config.settings.inherit + saas_portal.config.settings + + + + + + + + + + + +