[IMP] Improve ospp_slide module
parent
fef9552b33
commit
f36692f414
|
@ -31,13 +31,13 @@ class SlideChannel(models.Model):
|
||||||
|
|
||||||
channel_ids = channel_obj.search([('instance_arrangement', 'not in', ['no_need']), ('instance_base', '!=', False)])
|
channel_ids = channel_obj.search([('instance_arrangement', 'not in', ['no_need']), ('instance_base', '!=', False)])
|
||||||
for channel_id in channel_ids:
|
for channel_id in channel_ids:
|
||||||
channel_id.action_generate_instance()
|
channel_id.action_create_instance()
|
||||||
|
|
||||||
self.env.cr.commit()
|
self.env.cr.commit()
|
||||||
|
|
||||||
instance_ids = instance_obj.search([('instance_created', '!=', True)])
|
instance_ids = instance_obj.search([('instance_created', '!=', True)])
|
||||||
for instance_id in instance_ids:
|
for instance_id in instance_ids:
|
||||||
instance_id.action_generate_instance()
|
instance_id.action_create_instance()
|
||||||
|
|
||||||
self.env.cr.commit()
|
self.env.cr.commit()
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class SlideChannel(models.Model):
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def action_generate_instance(self):
|
def action_create_instance(self):
|
||||||
instance_obj = self.env['channel.instance'].sudo()
|
instance_obj = self.env['channel.instance'].sudo()
|
||||||
partner_obj = self.env['slide.channel.partner'].sudo()
|
partner_obj = self.env['slide.channel.partner'].sudo()
|
||||||
for rec in self:
|
for rec in self:
|
||||||
|
@ -217,7 +217,7 @@ class ChannelInstance(models.Model):
|
||||||
rec.is_notified = True
|
rec.is_notified = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def action_generate_instance(self):
|
def action_create_instance(self):
|
||||||
for rec in self:
|
for rec in self:
|
||||||
if rec.instance_created:
|
if rec.instance_created:
|
||||||
return True
|
return True
|
||||||
|
@ -254,6 +254,31 @@ class ChannelInstance(models.Model):
|
||||||
rec.instance_created = True
|
rec.instance_created = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def action_drop_instance(self):
|
||||||
|
for rec in self:
|
||||||
|
if not rec.instance_created:
|
||||||
|
return True
|
||||||
|
|
||||||
|
url = f"{rec.instance_id.management_api}/web/database/drop"
|
||||||
|
master_pwd = f"{rec.instance_id.management_secret}"
|
||||||
|
dbname = rec.service_name
|
||||||
|
|
||||||
|
headers = {
|
||||||
|
'Content-Type': 'application/x-www-form-urlencoded',
|
||||||
|
'Cookie': 'frontend_lang=en_US; session_id=645c41edf8f8c7e1e983ba0f5bd9e94d9a3bd4bc'
|
||||||
|
}
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
'master_pwd': master_pwd,
|
||||||
|
'name': dbname,
|
||||||
|
}
|
||||||
|
|
||||||
|
response = requests.request("POST", url, headers=headers, data=urlencode(payload), verify=False)
|
||||||
|
rec.message = response.text
|
||||||
|
if response.status_code == 200 and 'error' not in response.text:
|
||||||
|
rec.instance_created = False
|
||||||
|
return True
|
||||||
|
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
|
# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
|
||||||
self.browse(self.ids).read(['name', 'code'])
|
self.browse(self.ids).read(['name', 'code'])
|
||||||
|
|
|
@ -19,6 +19,8 @@
|
||||||
<field name="sequence">14</field>
|
<field name="sequence">14</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!--模型权限-->
|
||||||
|
|
||||||
<record id="group_model_channel_instance_read" model="res.groups">
|
<record id="group_model_channel_instance_read" model="res.groups">
|
||||||
<field name="name">channel.instance read</field>
|
<field name="name">channel.instance read</field>
|
||||||
<field name="category_id" ref="module_category_model_channel_instance"/>
|
<field name="category_id" ref="module_category_model_channel_instance"/>
|
||||||
|
@ -46,4 +48,12 @@
|
||||||
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
|
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
|
<!--按钮权限-->
|
||||||
|
|
||||||
|
<record id="group_button_action_drop_instance" model="res.groups">
|
||||||
|
<field name="name">Action Drop Instance</field>
|
||||||
|
<field name="category_id" ref="module_category_button_channel_instance"/>
|
||||||
|
<field name="users" eval="[(4, ref('base.user_root')), (4, ref('base.user_admin'))]"/>
|
||||||
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -10,14 +10,14 @@
|
||||||
<page string="Instance" name="instance">
|
<page string="Instance" name="instance">
|
||||||
<group>
|
<group>
|
||||||
<group>
|
<group>
|
||||||
<field name="instance_arrangement"/>
|
<field name="instance_arrangement" attrs="{'readonly': [('instance_ids', '!=', [])]}"/>
|
||||||
<field name="shared_instance_count" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
<field name="shared_instance_count" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])], 'readonly': [('instance_ids', '!=', [])]}"/>
|
||||||
<field name="shared_instance_demo_data" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
<field name="shared_instance_demo_data" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])], 'readonly': [('instance_ids', '!=', [])]}"/>
|
||||||
</group>
|
</group>
|
||||||
<group>
|
<group>
|
||||||
<field name="instance_base" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
<field name="instance_base" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])], 'readonly': [('instance_ids', '!=', [])]}"/>
|
||||||
<field name="excluded_instance_demo_data" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
<field name="excluded_instance_demo_data" attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])], 'readonly': [('instance_ids', '!=', [])]}"/>
|
||||||
<button name="action_generate_instance" data-hotkey="v"
|
<button name="action_create_instance" data-hotkey="v"
|
||||||
string="Generate Instance" type="object"
|
string="Generate Instance" type="object"
|
||||||
attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
||||||
</group>
|
</group>
|
||||||
|
@ -34,10 +34,14 @@
|
||||||
<field name="instance_created" optional="hide"/>
|
<field name="instance_created" optional="hide"/>
|
||||||
<field name="is_notified" optional="hide"/>
|
<field name="is_notified" optional="hide"/>
|
||||||
<field name="user_scope" widget="many2many_tags" invisible="1"/>
|
<field name="user_scope" widget="many2many_tags" invisible="1"/>
|
||||||
<button name="action_generate_instance" data-hotkey="v"
|
<button name="action_create_instance" data-hotkey="v"
|
||||||
string="Create" type="object"
|
string="Create" type="object"
|
||||||
attrs="{'invisible': [('instance_created', '=', True)]}"/>
|
attrs="{'invisible': [('instance_created', '=', True)]}"/>
|
||||||
<button name="action_post_instance" data-hotkey="v"
|
<button name="action_drop_instance" data-hotkey="f"
|
||||||
|
groups="ospp_slide.group_button_action_drop_instance"
|
||||||
|
string="Drop" type="object"
|
||||||
|
attrs="{'invisible': [('instance_created', '!=', True)]}"/>
|
||||||
|
<button name="action_post_instance" data-hotkey="g"
|
||||||
string="Notify" type="object"
|
string="Notify" type="object"
|
||||||
attrs="{'invisible': [('instance_created', '!=', True)]}"/>
|
attrs="{'invisible': [('instance_created', '!=', True)]}"/>
|
||||||
</tree>
|
</tree>
|
||||||
|
|
Loading…
Reference in New Issue