[IMP] Improve ospp_base and ospp_slide modules
parent
35d436b0ff
commit
ca94474a2f
|
@ -1,7 +1,9 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
import random
|
||||
import uuid
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import UserError, ValidationError
|
||||
|
||||
|
||||
class SlideChannel(models.Model):
|
||||
|
@ -18,6 +20,30 @@ class SlideChannel(models.Model):
|
|||
instance_base = fields.Many2one('ospp.instance', string="Instance Base")
|
||||
instance_ids = fields.One2many('channel.instance', 'channel_id', string="Instances")
|
||||
|
||||
# @api.depends('slide_partner_ids')
|
||||
def action_generate_instance(self):
|
||||
instance_obj = self.env['channel.instance'].sudo()
|
||||
for rec in self:
|
||||
if rec.instance_arrangement not in ['no_need'] and not (rec.instance_arrangement and rec.instance_base):
|
||||
raise ValidationError(_("No Instance Arrangement or Base provided!"))
|
||||
|
||||
if not rec.instance_ids:
|
||||
if rec.instance_arrangement in ['share']:
|
||||
vals = []
|
||||
for i in range(rec.shared_instance_count):
|
||||
val = {
|
||||
"name": rec.id,
|
||||
"channel_id": rec.id,
|
||||
"instance_id": rec.instance_base and rec.instance_base.id,
|
||||
"service_name": f"{rec.code}",
|
||||
"service_url": f"{rec.service_scheme}://{rec.code}-{i}.{rec.instance_base.service_base_host}",
|
||||
"admin_account": f"{rec.user_id.email}",
|
||||
"admin_password": f"{random.randint(10000000,99999999)}",
|
||||
"type": "share",
|
||||
}
|
||||
vals.append(val)
|
||||
instance_obj.create(vals)
|
||||
|
||||
def name_get(self):
|
||||
# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
|
||||
self.browse(self.ids).read(['name', 'code'])
|
||||
|
@ -51,7 +77,10 @@ class ChannelInstance(models.Model):
|
|||
service_name = fields.Char('Service Name', required=True)
|
||||
service_url = fields.Char('Service URL', required=True)
|
||||
user_scope = fields.Many2many('slide.channel.partner', string="User Scope")
|
||||
admin_account = fields.Char('Admin Account')
|
||||
admin_password = fields.Char('Admin Password')
|
||||
active = fields.Boolean('Active', default=True)
|
||||
type = fields.Selection([('share', 'Share'), ('exclude', 'Exclude')], string="Type", required=True, default='share')
|
||||
|
||||
def name_get(self):
|
||||
# Prefetch the fields used by the `name_get`, so `browse` doesn't fetch other fields
|
||||
|
|
|
@ -15,9 +15,12 @@
|
|||
</group>
|
||||
<group>
|
||||
<field name="instance_base"/>
|
||||
<button name="action_generate_instance" data-hotkey="v"
|
||||
string="Generate Instance" type="object"
|
||||
attrs="{'invisible': [('instance_arrangement', 'in', ['no_need'])]}"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="instance_ids" mode="tree,form">
|
||||
<field name="instance_ids" mode="tree,form" readonly="1">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="code"/>
|
||||
|
@ -30,13 +33,16 @@
|
|||
<group>
|
||||
<field name="code"/>
|
||||
<field name="name"/>
|
||||
<field name="instance_id"/>
|
||||
<field name="type"/>
|
||||
<field name="admin_account"/>
|
||||
<field name="admin_password"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="instance_id"/>
|
||||
<field name="service_name"/>
|
||||
<field name="service_url"/>
|
||||
<field name="active"/>
|
||||
<field name="uuid" invisible="1"/>
|
||||
<field name="uuid" invisible="0"/>
|
||||
</group>
|
||||
</group>
|
||||
<field name="user_scope"/>
|
||||
|
|
Loading…
Reference in New Issue