Files
gzth/yuthon_will_task/controllers/main.py
T
2025-08-29 02:01:36 +08:00

58 lines
2.2 KiB
Python

import base64
import json
from odoo import http, fields
from odoo.http import request
from odoo.tools import float_is_zero,float_round
class YuthonWillTask(http.Controller):
@http.route('/yuthon/yuthon/will/task', methods=['POST'], type='http', auth='none', csrf=False)
def index2(self, **kwargs):
id = kwargs.get('id')
data = request.env['yuthon.will.task'].sudo().search(domain = [("id", "=", int(id))])
employee_ids = []
for em in data.employee_ids:
employee_ids.append({
'id':em.id,
'name':em.name,
'image_1920':em.image_128.decode('utf-8') if em.image_128 else '',
})
result = {
'id':data.id,
'name':data.name,
'code':data.code,
'start_date':fields.Date.to_string(data.start_date),
'request_hour_from':data.request_hour_from,
'request_hour_to':data.request_hour_to,
'priority':data.priority,
'user_id':data.user_id.name,
'user_avatar':base64.b64decode(data.user_id.avatar_128).decode('utf-8') if data.user_id.avatar_128 else '',
'remarks':data.remarks,
'address':data.address,
'employee_ids':employee_ids,
}
# 转换 request_hour_from 和 request_hour_to 取模型 yuthon.will.task 的 request_hour_from 的selection
request_hour_from_selection = request.env['yuthon.will.task'].sudo().fields_get(allfields=['request_hour_from'])['request_hour_from']['selection']
request_hour_to_selection = request.env['yuthon.will.task'].sudo().fields_get(allfields=['request_hour_to'])['request_hour_to']['selection']
for f in request_hour_from_selection:
if f[0] == data.request_hour_from:
result['request_hour_from'] = f[1]
for f in request_hour_to_selection:
if f[0] == data.request_hour_to:
result['request_hour_to'] = f[1]
# 计算 start_date 星期几
result['start_date_week'] = fields.Date.from_string(result['start_date']).strftime('%A')
return json.dumps({
'data':result,
'code':200,
'message':'success'
})