44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
from odoo import http
|
|
from odoo.http import request
|
|
|
|
|
|
class CateringController(http.Controller):
|
|
|
|
@http.route(['/catering/portal/<int:employee_id>'], type='http', auth='public', website=True)
|
|
def catering_portal(self, employee_id, **kw):
|
|
"""
|
|
渲染 catering_portal_page 这个 QWeb 模板。
|
|
页面内部包含一个挂载 OWL 的区域。
|
|
"""
|
|
employee = request.env['hr.employee'].sudo().browse(employee_id)
|
|
# 渲染 QWeb 模板
|
|
return request.render('yuthon_catering.yuthon_catering_template', {'employee': employee})
|
|
|
|
@http.route(['/catering/create'], type='http', auth='public', methods=['POST'], csrf=False)
|
|
def catering_create(self, **post):
|
|
"""
|
|
前端 OWL 调用此接口创建 yuthon.catering 记录。
|
|
接受字段:date, employee_id, breakfast, lunch, amount, note
|
|
"""
|
|
qcontext = post
|
|
try:
|
|
employee_id = int(post.get('employee_id'))
|
|
vals = {
|
|
'date': post.get('date'),
|
|
'employee_id': employee_id,
|
|
'breakfast': post.get('breakfast') == 'true',
|
|
'lunch': post.get('lunch') == 'true',
|
|
'amount': float(post.get('amount') or 0),
|
|
'note': post.get('note') or '',
|
|
}
|
|
request.env['yuthon.catering'].sudo().create(vals)
|
|
employee = request.env['hr.employee'].sudo().browse(employee_id)
|
|
qcontext['employee'] = employee
|
|
qcontext['tips'] = '提交成功!'
|
|
return request.render('yuthon_catering.yuthon_catering_template', qcontext)
|
|
|
|
except Exception as e:
|
|
qcontext['error'] = str(e)
|
|
return request.render('yuthon_catering.yuthon_catering_template', qcontext)
|