137 lines
4.8 KiB
Python
137 lines
4.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
import json
|
|
import logging
|
|
import datetime
|
|
from odoo import http
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
def _get_option_data(option_obj):
|
|
options = [{"id": 0, "name": option_obj._description}]
|
|
result = option_obj.search([])
|
|
for r in result:
|
|
options.append({"id": r.id, "name": r.name})
|
|
return options
|
|
|
|
|
|
class SASACSurvey(http.Controller):
|
|
|
|
@http.route('/tx/survey/test/<string:access_token>', type='http', auth='public', website=True)
|
|
def index(self, access_token, **kw):
|
|
user = http.request.env.user
|
|
user_id = 0
|
|
user_name = ""
|
|
if user.id != 4:
|
|
user_id = user.id
|
|
user_name = user.name
|
|
|
|
survey_sudo = http.request.env["tx.sasac.survey"].sudo()
|
|
recommend_sudo = http.request.env["tx.recommend.company"].sudo()
|
|
industry_sudo = http.request.env["tx.industry"].sudo()
|
|
link_sudo = http.request.env["tx.business.link"].sudo()
|
|
location_sudo = http.request.env["tx.scene.location"].sudo()
|
|
|
|
survey_id = survey_sudo.search([("access_token", "=", access_token)])
|
|
recommend_options = _get_option_data(recommend_sudo)
|
|
industry_options = _get_option_data(industry_sudo)
|
|
link_options = _get_option_data(link_sudo)
|
|
location_options = _get_option_data(location_sudo)
|
|
|
|
scene_list = survey_id.scene_ids
|
|
|
|
return http.request.render("tx_opentekr_survey.sasac_survey_page", {
|
|
"userId": user_id,
|
|
"userName": user_name,
|
|
"survey": survey_id,
|
|
"imgUrl": http.request.website.image_url(survey_id, 'img'),
|
|
"recommendOptions": recommend_options,
|
|
"industryOptions": industry_options,
|
|
"linkOptions": link_options,
|
|
"locationOptions": location_options,
|
|
"sceneList": scene_list,
|
|
})
|
|
|
|
@http.route('/tx/survey/read_scene', type='json', auth='user')
|
|
def read_scene_list(self, **kw):
|
|
scene_sudo = http.request.env["tx.sasac.survey.scene"].sudo()
|
|
scene_list = scene_sudo
|
|
try:
|
|
record_id = kw.get("recordId", False)
|
|
recommend_id = kw.get("recommend", False)
|
|
industry_id = kw.get("industry", False)
|
|
link_id = kw.get("link", False)
|
|
location_id = kw.get("location", False)
|
|
|
|
domain = [("survey_id", "=", record_id)]
|
|
if recommend_id:
|
|
domain.append(("rc_id", "=", recommend_id))
|
|
if industry_id:
|
|
domain.append(("industry_id", "=", industry_id))
|
|
if link_id:
|
|
domain.append(("link_id", "=", link_id))
|
|
if location_id:
|
|
domain.append(("location_id", "=", location_id))
|
|
|
|
scene_list = scene_sudo.search(domain)
|
|
|
|
except Exception as e:
|
|
_logger.error(e)
|
|
finally:
|
|
return {"sceneList": scene_list.read(['id', 'name'])}
|
|
|
|
@http.route('/tx/survey/form_scene', type='json', auth='public')
|
|
def form_scene_data(self, **kw):
|
|
scene_sudo = http.request.env["tx.sasac.survey.scene"].sudo()
|
|
scene_data = {"httpCode": 0}
|
|
uid = http.request.env.uid
|
|
if uid == 4:
|
|
return {"sceneData": scene_data}
|
|
try:
|
|
record_id = kw.get("recordId", False)
|
|
domain = [("id", "=", record_id)]
|
|
scene_id = scene_sudo.search(domain)
|
|
|
|
technology_ids = [technology_id.name for technology_id in scene_id.technology_ids]
|
|
|
|
scene_data = {
|
|
"httpCode": 1,
|
|
"id": scene_id.id,
|
|
"code": scene_id.code,
|
|
"name": scene_id.name,
|
|
"companyName": scene_id.company_name,
|
|
"vodUrl": f"{scene_id.get_base_url()}/web/content?model={scene_id._name}&id={scene_id.id}&field=vod",
|
|
"rcName": scene_id.rc_id.name,
|
|
"industryName": scene_id.industry_id.name,
|
|
"linkName": scene_id.link_id.name,
|
|
"locationName": scene_id.location_id.name,
|
|
"technologyList": ", ".join(technology_ids),
|
|
}
|
|
|
|
except Exception as e:
|
|
_logger.error(e)
|
|
finally:
|
|
return {"sceneData": scene_data}
|
|
|
|
@http.route('/tx/survey/scene_get/create', type='json', auth='user')
|
|
def scene_get_create(self, **kw):
|
|
get_sudo = http.request.env["tx.sasac.survey.scene.get"].sudo()
|
|
scene_sudo = http.request.env["tx.sasac.survey.scene"].sudo()
|
|
record_id = kw.get("recordId", False)
|
|
code = 0
|
|
scene_id = scene_sudo.browse([record_id])
|
|
get_id = get_sudo.create({
|
|
"user_id": http.request.env.user.id,
|
|
"scene_id": scene_id.id,
|
|
"get_date": datetime.date.today()
|
|
})
|
|
if get_id.__len__():
|
|
code = 1
|
|
return code
|
|
|
|
|
|
|
|
|
|
|
|
|