Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds the ability to setup demo plans #174

Open
wants to merge 1 commit into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions saas_portal_demo_template/README.rst
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions saas_portal_demo_template/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import models
14 changes: 14 additions & 0 deletions saas_portal_demo_template/__openerp__.py
Original file line number Diff line number Diff line change
@@ -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,
}
17 changes: 17 additions & 0 deletions saas_portal_demo_template/data/ir_cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data noupdate="1">
<record id="ir_cron_spurn_demo_database" model="ir.cron">
<field name="name">Spurn Demo database</field>
<field name="user_id" ref="base.user_root"/>
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field name="numbercall">-1</field>
<field eval="(DateTime.now() + timedelta(days= +1)).strftime('%Y-%m-%d 3:30:00')" name="nextcall"/>
<field eval="False" name="doall"/>
<field eval="'saas_portal.client'" name="model"/>
<field eval="'try_spurn_demo_instance'" name="function"/>
<field eval="'()'" name="args"/>
</record>
</data>
</openerp>
3 changes: 3 additions & 0 deletions saas_portal_demo_template/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import saas_portal
import res_config
import res_company
15 changes: 15 additions & 0 deletions saas_portal_demo_template/models/res_company.py
Original file line number Diff line number Diff line change
@@ -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,
)
27 changes: 27 additions & 0 deletions saas_portal_demo_template/models/res_config.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions saas_portal_demo_template/models/saas_portal.py
Original file line number Diff line number Diff line change
@@ -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()

18 changes: 18 additions & 0 deletions saas_portal_demo_template/views/res_config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_saas_portal_config_settings">
<field name="name">saas_portal.config.settings.inherit</field>
<field name="model">saas_portal.config.settings</field>
<field name="inherit_id" ref="saas_portal.view_saas_portal__config_settings" />
<field name="arch" type="xml">
<group string="Domain" position="after">
<group string="Demonstration Database">
<field name="demo_client_name" />
<field name="demo_plan_id" />
</group>
</group>
</field>
</record>
</data>
</openerp>