[IMP] Improve ospp_base and ospp_slide modules
							parent
							
								
									3c69065731
								
							
						
					
					
						commit
						3eacffc1f7
					
				|  | @ -43,7 +43,7 @@ class OSPPInstance(models.Model): | ||||||
|         tracking=True) |         tracking=True) | ||||||
|     management_api = fields.Char('Management Api', required=True, tracking=True) |     management_api = fields.Char('Management Api', required=True, tracking=True) | ||||||
|     management_key = fields.Char('Management Key', tracking=True) |     management_key = fields.Char('Management Key', tracking=True) | ||||||
|     management_secret = fields.Char('Management Secret', tracking=True) |     management_secret = fields.Char('Management Secret') | ||||||
|     service_base_host = fields.Char('Service Base Host', tracking=True) |     service_base_host = fields.Char('Service Base Host', tracking=True) | ||||||
|     service_scheme = fields.Selection( |     service_scheme = fields.Selection( | ||||||
|         [('http', 'HTTP'), ('https', 'HTTPS'), ('ws', 'WS'), ('wss', 'WSS')], |         [('http', 'HTTP'), ('https', 'HTTPS'), ('ws', 'WS'), ('wss', 'WSS')], | ||||||
|  |  | ||||||
|  | @ -37,7 +37,7 @@ | ||||||
|               <group> |               <group> | ||||||
|                 <field name="management_api"/> |                 <field name="management_api"/> | ||||||
|                 <field name="management_key"/> |                 <field name="management_key"/> | ||||||
|                 <field name="management_secret"/> |                 <field name="management_secret" password="True"/> | ||||||
|               </group> |               </group> | ||||||
|               <group> |               <group> | ||||||
|                 <field name="service_base_host"/> |                 <field name="service_base_host"/> | ||||||
|  |  | ||||||
|  | @ -1,6 +1,8 @@ | ||||||
| # -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||||||
| 
 | 
 | ||||||
| import random | import random | ||||||
|  | import requests | ||||||
|  | from urllib.parse import urlencode | ||||||
| import uuid | import uuid | ||||||
| from odoo import models, fields, api, _ | from odoo import models, fields, api, _ | ||||||
| from odoo.exceptions import UserError, ValidationError | from odoo.exceptions import UserError, ValidationError | ||||||
|  | @ -157,6 +159,43 @@ class ChannelInstance(models.Model): | ||||||
|     demo_data = fields.Boolean('Demo Data', default=True) |     demo_data = fields.Boolean('Demo Data', default=True) | ||||||
|     is_notified = fields.Boolean('Is Notified', default=False) |     is_notified = fields.Boolean('Is Notified', default=False) | ||||||
| 
 | 
 | ||||||
|  |     def action_generate_instance(self): | ||||||
|  |         for rec in self: | ||||||
|  |             if rec.instance_created: | ||||||
|  |                 return True | ||||||
|  | 
 | ||||||
|  |             url = f"{rec.instance_id.management_api}/web/database/create" | ||||||
|  |             master_pwd = f"{rec.instance_id.management_secret}" | ||||||
|  |             dbname = rec.service_name | ||||||
|  |             login = rec.admin_account | ||||||
|  |             password = rec.admin_password | ||||||
|  |             phone = '' | ||||||
|  |             lang = 'zh_CN' | ||||||
|  |             country_code = 'cn' | ||||||
|  |             demo = 1 if rec.demo_data else 0 | ||||||
|  | 
 | ||||||
|  |             headers = { | ||||||
|  |                 'Content-Type': 'application/x-www-form-urlencoded', | ||||||
|  |                 'Cookie': 'frontend_lang=en_US; session_id=645c41edf8f8c7e1e983ba0f5bd9e94d9a3bd4bc' | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             payload = { | ||||||
|  |                 'master_pwd': master_pwd, | ||||||
|  |                 'name': dbname, | ||||||
|  |                 'login': login, | ||||||
|  |                 'password': password, | ||||||
|  |                 'phone': phone, | ||||||
|  |                 'lang': lang, | ||||||
|  |                 'country_code': country_code, | ||||||
|  |                 'demo': demo | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             response = requests.request("POST", url, headers=headers, data=urlencode(payload)) | ||||||
|  |             rec.message = response.text | ||||||
|  |             if response.status_code == 200 and 'error' not in response.text: | ||||||
|  |                 rec.instance_created = True | ||||||
|  |             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']) | ||||||
|  |  | ||||||
|  | @ -34,6 +34,9 @@ | ||||||
|                             <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" | ||||||
|  |                                      string="Generate Instance" type="object" | ||||||
|  |                                      attrs="{'invisible': [('instance_created', '=', True)]}"/> | ||||||
|                         </tree> |                         </tree> | ||||||
|                         <form> |                         <form> | ||||||
|                             <group> |                             <group> | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Oliver Yuan
						Oliver Yuan