餐饮
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from . import controllers
|
||||
from . import restaurant
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import json
|
||||
import logging
|
||||
from datetime import date
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT as DATE_FORMAT
|
||||
from odoo.http import request, Controller, route
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RestaurantController(Controller):
|
||||
|
||||
@route('/phone/restaurant/menus', methods=['POST'], type='http', auth="none", csrf=False, cors='*')
|
||||
def get_menus(self, **kwargs):
|
||||
menu_date = kwargs.get('menu_date', date.today())
|
||||
Menu = request.env['yuthon.menu.setting'].sudo()
|
||||
|
||||
record = Menu.search([('menu_date', '=', menu_date)], limit=1, order='id desc')
|
||||
result = {}
|
||||
if record:
|
||||
result = {
|
||||
'id': record.id,
|
||||
'menu_date': record.menu_date.strftime(DATE_FORMAT) if record.menu_date else '',
|
||||
'breakfast': ','.join(record.breakfast_ids.mapped('name')) if record.breakfast_ids else '',
|
||||
'lunch': ','.join(record.lunch_ids.mapped('name')) if record.lunch_ids else '',
|
||||
'remark': record.remake or ''
|
||||
}
|
||||
|
||||
return json.dumps({'data': result, 'code': 200, 'message': ''})
|
||||
|
||||
@route('/phone/restaurant/collect_catering', methods=['POST'], type='http', auth="none", csrf=False, cors='*')
|
||||
def collect_catering(self, **kwargs):
|
||||
user_id = int(kwargs.get('user_id'))
|
||||
user = request.env['res.users'].sudo().browse(user_id).exists()
|
||||
employee = request.env['hr.employee'].sudo().search([('user_id', '=', user_id)])
|
||||
Catering = request.env['yuthon.catering'].with_user(user)
|
||||
|
||||
record = Catering.create({
|
||||
'date': date.today(),
|
||||
'employee_id': employee.id,
|
||||
'breakfast': kwargs.get('breakfast') == 'true',
|
||||
'lunch': kwargs.get('lunch') == 'true',
|
||||
'menu_day_id': kwargs.get('menu_id')
|
||||
})
|
||||
if record:
|
||||
return json.dumps({'data': record.id, 'code': 200, 'message': '提交成功'})
|
||||
return json.dumps({'data': '', 'code': 500, 'message': '提交失败'})
|
||||
|
||||
@route('/phone/restaurant/get_catering', methods=['POST'], type='http', auth="none", csrf=False, cors='*')
|
||||
def get_catering(self, **kwargs):
|
||||
user_id = int(kwargs.get('user_id'))
|
||||
menu_date = kwargs.get('menu_date', date.today())
|
||||
menu_id = kwargs.get('menu_id')
|
||||
|
||||
if not user_id or not menu_date or not menu_id:
|
||||
return json.dumps({'data': '', 'code': 500, 'message': '请求失败'})
|
||||
|
||||
employee = request.env['hr.employee'].sudo().search([('user_id', '=', user_id)])
|
||||
catering = request.env['yuthon.catering'].sudo().search([
|
||||
('employee_id', '=', employee.id),
|
||||
('date', '=', menu_date),
|
||||
('menu_day_id', '=', menu_id),
|
||||
])
|
||||
if catering:
|
||||
return json.dumps({'data': catering.id, 'code': 200, 'message': ''})
|
||||
return json.dumps({'data': '', 'code': 200, 'message': ''})
|
||||
@@ -14,6 +14,10 @@ class YuthonCatering(models.Model):
|
||||
menu_day_id = fields.Many2one('yuthon.menu.setting', string='菜单')
|
||||
amount = fields.Float(string='结算费用')
|
||||
note = fields.Text(string='备注')
|
||||
state = fields.Selection([
|
||||
('unconfirmed', '未确认'),
|
||||
('confirmed', '已确认'),
|
||||
], default='unconfirmed', string='状态')
|
||||
|
||||
def catering_task(self):
|
||||
conf_records = self.env['yuthon.catering.conf'].search([])
|
||||
|
||||
Reference in New Issue
Block a user