更改
This commit is contained in:
@@ -106,7 +106,7 @@ class RestaurantController(Controller):
|
|||||||
def get_catering(self, **kwargs):
|
def get_catering(self, **kwargs):
|
||||||
user_id = int(kwargs.get('user_id'))
|
user_id = int(kwargs.get('user_id'))
|
||||||
menu_date = kwargs.get('menu_date', date.today())
|
menu_date = kwargs.get('menu_date', date.today())
|
||||||
menu_id = kwargs.get('menu_id')
|
menu_id = int(kwargs.get('menu_id'))
|
||||||
|
|
||||||
if not user_id or not menu_date or not menu_id:
|
if not user_id or not menu_date or not menu_id:
|
||||||
return json.dumps({'data': '', 'code': 500, 'message': '请求失败'})
|
return json.dumps({'data': '', 'code': 500, 'message': '请求失败'})
|
||||||
@@ -124,63 +124,11 @@ class RestaurantController(Controller):
|
|||||||
'menu_id': catering.menu_day_id.id,
|
'menu_id': catering.menu_day_id.id,
|
||||||
'breakfast': catering.breakfast,
|
'breakfast': catering.breakfast,
|
||||||
'lunch': catering.lunch,
|
'lunch': catering.lunch,
|
||||||
'state': catering.state,
|
'state': catering.state
|
||||||
'is_expatriate': False,
|
|
||||||
}
|
}
|
||||||
return json.dumps({'data': catering_data, 'code': 200, 'message': ''})
|
return json.dumps({'data': catering_data, 'code': 200, 'message': ''})
|
||||||
|
|
||||||
# 没有用餐记录时,判断当前员工是否处于外派期间;
|
|
||||||
# 若处于外派期间,默认早餐和午餐均为不就餐(False)。
|
|
||||||
is_expatriate = self._check_expatriation(employee, menu_date)
|
|
||||||
if is_expatriate:
|
|
||||||
catering_data = {
|
|
||||||
'id': 0,
|
|
||||||
'user_id': employee.user_id.id,
|
|
||||||
'menu_id': int(menu_id),
|
|
||||||
'breakfast': False,
|
|
||||||
'lunch': False,
|
|
||||||
'state': 'unconfirmed',
|
|
||||||
'is_expatriate': True,
|
|
||||||
}
|
|
||||||
return json.dumps({'data': catering_data, 'code': 200, 'message': ''})
|
|
||||||
|
|
||||||
return json.dumps({'data': '', 'code': 200, 'message': '没有查询到数据'})
|
return json.dumps({'data': '', 'code': 200, 'message': '没有查询到数据'})
|
||||||
|
|
||||||
def _check_expatriation(self, employee, menu_date):
|
|
||||||
"""判断员工在指定日期是否处于外派期间。
|
|
||||||
|
|
||||||
规则:
|
|
||||||
1. 存在审批结束且未作废、未失效、未结束的外派审批记录,员工在 expatriates_ids 中;
|
|
||||||
2. 外派开始日期 <= 当前日期;
|
|
||||||
3. 已填写返回日期时,当前日期 <= 返回日期;
|
|
||||||
4. 未填写返回日期时,从外派开始日期起即视为外派中。
|
|
||||||
"""
|
|
||||||
if not employee:
|
|
||||||
return False
|
|
||||||
WorkflowRecord = request.env['soong.workflow.record'].sudo()
|
|
||||||
# 先找出审批结束且未作废的外派审批单 ID
|
|
||||||
workflow_records = WorkflowRecord.search([
|
|
||||||
('res_model', '=', 'expatriation.approval'),
|
|
||||||
('approve_state', '=', 'end'),
|
|
||||||
('reclaim_state', '=', False),
|
|
||||||
])
|
|
||||||
expatriation_ids = workflow_records.mapped('res_id')
|
|
||||||
if not expatriation_ids:
|
|
||||||
return False
|
|
||||||
Expatriation = request.env['expatriation.approval'].sudo()
|
|
||||||
domain = [
|
|
||||||
('id', 'in', expatriation_ids),
|
|
||||||
('expatriates_ids', 'in', [employee.id]),
|
|
||||||
('start_date', '!=', False),
|
|
||||||
('start_date', '<=', menu_date),
|
|
||||||
('is_effect', '=', False),
|
|
||||||
('work_end', '=', False),
|
|
||||||
'|',
|
|
||||||
('return_date', '=', False),
|
|
||||||
('return_date', '>=', menu_date),
|
|
||||||
]
|
|
||||||
return bool(Expatriation.search(domain, limit=1))
|
|
||||||
|
|
||||||
@route('/phone/restaurant/get_catering_statistics', methods=['POST'], type='http', auth="none", csrf=False, cors='*')
|
@route('/phone/restaurant/get_catering_statistics', methods=['POST'], type='http', auth="none", csrf=False, cors='*')
|
||||||
@exception_handle
|
@exception_handle
|
||||||
def get_catering_statistics(self, **kwargs):
|
def get_catering_statistics(self, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user