OdooDigitizationService/tx_opentekr_survey/models/models.py

120 lines
3.9 KiB
Python

# -*- coding: utf-8 -*-
import uuid
from odoo import models, fields, api
from odoo.exceptions import ValidationError
class surveySettingBase(models.Model):
_name = "tx.survey.setting.base"
name = fields.Char(string="名称", required=True)
class RecommendCompany(models.Model):
_name = "tx.recommend.company"
_inherit = "tx.survey.setting.base"
_description = "推荐单位"
class Industry(models.Model):
_name = "tx.industry"
_inherit = "tx.survey.setting.base"
_description = "所属行业"
class BusinessLink(models.Model):
_name = "tx.business.link"
_inherit = "tx.survey.setting.base"
_description = "业务环节"
class AppliedTechnology(models.Model):
_name = "tx.applied.technology"
_inherit = "tx.survey.setting.base"
_description = "应用技术"
class SceneLocation(models.Model):
_name = "tx.scene.location"
_inherit = "tx.survey.setting.base"
_description = "场景所在地"
class SASACSurvey(models.Model):
_name = "tx.sasac.survey"
_description = "国资委投票"
_order = "id desc"
code = fields.Char(string="业务编码", default="New", copy=False)
name = fields.Char(string="标题")
img = fields.Image(string="图片")
rule_content = fields.Html(string="投票规则")
start_date = fields.Date(string="开始日期")
end_date = fields.Date(string="结束日期")
scene_ids = fields.One2many("tx.sasac.survey.scene", "survey_id", string="场景")
access_token = fields.Char('Access Token', default=lambda self: str(uuid.uuid4()), copy=False)
@api.model
def create(self, vals):
vals['code'] = self.env['ir.sequence'].next_by_code('tx.sasac.survey') or 'New'
return super().create(vals)
@api.onchange("start_date", "end_date")
def onchange_date(self):
for r in self:
if r.start_date is False or r.end_date is False:
continue
if r.start_date >= r.end_date:
raise ValidationError("开始日期必须早于结束日期")
def action_test_survey(self):
self.ensure_one()
return {
'type': 'ir.actions.act_url',
'name': "Test Survey",
'target': 'self',
'url': '/tx/survey/test/%s' % self.access_token,
}
class SASACSurveyScene(models.Model):
_name = "tx.sasac.survey.scene"
_description = "国资委投票场景"
_order = "id desc"
survey_id = fields.Many2one("tx.sasac.survey", string="投票需求")
vod = fields.Binary(string="视频")
vod_file_name = fields.Char(string="文件名称")
code = fields.Char(string="场景编号", default="New", copy=False)
name = fields.Char(string="场景标题")
company_name = fields.Char(string="企业名称")
rc_id = fields.Many2one("tx.recommend.company", string="推荐单位")
industry_id = fields.Many2one("tx.industry", string="所属行业")
link_id = fields.Many2one("tx.business.link", string="业务环节")
technology_ids = fields.Many2many("tx.applied.technology", string="应用技术")
location_id = fields.Many2one("tx.scene.location", string="场景所在地")
get_ids = fields.One2many("tx.sasac.survey.scene.get", "scene_id", string="得票明细")
@api.model
def create(self, vals):
vals['code'] = self.env['ir.sequence'].next_by_code('tx.sasac.survey.scene') or 'New'
return super().create(vals)
class SASACSurveySceneGet(models.Model):
_name = "tx.sasac.survey.scene.get"
_description = "场景得票"
_order = "id desc"
user_id = fields.Many2one("res.users", string="投票用户")
survey_id = fields.Many2one("tx.sasac.survey", string="投票需求")
scene_id = fields.Many2one("tx.sasac.survey.scene", string="投票场景")
get_date = fields.Date(string="投票日期")
@api.model
def create(self, vals):
res = super().create(vals)
res.survey_id = res.scene_id.survey_id.id
return res