Compare commits
9 Commits
72f737c370
...
feature/67
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4615f1576f | ||
|
|
c8f1676de9 | ||
|
|
f165bec662 | ||
|
|
133eac4a5c | ||
|
|
9922402b3b | ||
|
|
0a79a4e336 | ||
|
|
00922e3674 | ||
|
|
2a330a4bd8 | ||
|
|
33647fa3e0 |
@@ -31,12 +31,20 @@ class PurchaseOrder(models.Model):
|
|||||||
|
|
||||||
def button_cancel(self):
|
def button_cancel(self):
|
||||||
"""
|
"""
|
||||||
将取消的采购订单关联的库存移动撤销
|
1. 先将采购订单行与目标库存移动断开链接,避免采购单取消后,调拨单被调整为mts的问题
|
||||||
|
2. 取消采购订单
|
||||||
|
3. 将采购订单行与目标库存移动重新建立链接
|
||||||
"""
|
"""
|
||||||
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
created_purchase_request_line_ids = {}
|
||||||
|
if self.order_line.move_dest_ids.created_purchase_request_line_id:
|
||||||
|
move_ids = self.order_line.move_dest_ids.filtered(lambda move: move.state != 'done' and not move.scrapped)
|
||||||
|
created_purchase_request_line_ids = {move.id: move.created_purchase_request_line_id for move in move_ids}
|
||||||
|
self.order_line.write({'move_dest_ids': [(5, 0, 0)]})
|
||||||
res =super(PurchaseOrder, self).button_cancel()
|
res =super(PurchaseOrder, self).button_cancel()
|
||||||
if move_ids.mapped('created_purchase_request_line_id'):
|
for move_id, created_purchase_request_line_id in created_purchase_request_line_ids.items():
|
||||||
move_ids.write({'state': 'waiting', 'is_done': False})
|
self.env['stock.move'].browse(move_id).created_purchase_request_line_id = created_purchase_request_line_id
|
||||||
|
# if move_ids.mapped('created_purchase_request_line_id'):
|
||||||
|
# move_ids.write({'state': 'waiting', 'is_done': False})
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def write(self, vals):
|
def write(self, vals):
|
||||||
|
|||||||
@@ -707,9 +707,11 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
interval_plan_orders = plan_order_messages.filtered(
|
interval_plan_orders = plan_order_messages.filtered(
|
||||||
lambda o: o.create_date >= start_time
|
lambda o: o.create_date >= start_time
|
||||||
and o.create_date <= end_time
|
and o.create_date <= end_time
|
||||||
)
|
)
|
||||||
|
|
||||||
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_plan_orders.mapped('res_id'))
|
interval_order_ids = set(interval_plan_orders.mapped('res_id'))
|
||||||
|
|
||||||
|
interval_orders = request.env['mrp.workorder'].sudo().browse(interval_order_ids)
|
||||||
if line == '业绩总览':
|
if line == '业绩总览':
|
||||||
interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
|
interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
|
||||||
elif line == '人工线下加工中心':
|
elif line == '人工线下加工中心':
|
||||||
@@ -862,33 +864,37 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
"""
|
"""
|
||||||
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
|
# res = {'status': 1, 'message': '成功', 'not_done_data': [], 'done_data': []}
|
||||||
res = {'status': 1, 'message': '成功', 'data': {}}
|
res = {'status': 1, 'message': '成功', 'data': {}}
|
||||||
|
# 解决产品名称取到英文的问题
|
||||||
|
request.update_context(lang='zh_CN')
|
||||||
plan_obj = request.env['sf.production.plan'].sudo()
|
plan_obj = request.env['sf.production.plan'].sudo()
|
||||||
work_order_obj = request.env['mrp.workorder'].sudo()
|
work_order_obj = request.env['mrp.workorder'].sudo()
|
||||||
|
# 获取mrp.workorder的state字段的selection内容
|
||||||
|
state_dict = dict(request.env['mrp.workorder'].sudo()._fields['state'].selection)
|
||||||
line_list = ast.literal_eval(kw['line_list'])
|
line_list = ast.literal_eval(kw['line_list'])
|
||||||
begin_time_str = kw['begin_time'].strip('"')
|
begin_time_str = kw['begin_time'].strip('"')
|
||||||
end_time_str = kw['end_time'].strip('"')
|
end_time_str = kw['end_time'].strip('"')
|
||||||
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
begin_time = datetime.strptime(begin_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
end_time = datetime.strptime(end_time_str, '%Y-%m-%d %H:%M:%S')
|
||||||
# print('line_list: %s' % line_list)
|
# print('line_list: %s' % line_list)
|
||||||
not_done_data = []
|
|
||||||
done_data = []
|
|
||||||
final_data = {}
|
final_data = {}
|
||||||
not_done_index = 1
|
|
||||||
done_index = 1
|
|
||||||
|
|
||||||
# 获取当前时间,并计算24小时前的时间
|
# 获取当前时间,并计算24小时前的时间
|
||||||
current_time = datetime.now()
|
current_time = datetime.now()
|
||||||
time_48_hours_ago = current_time - timedelta(hours=48)
|
time_48_hours_ago = current_time - timedelta(hours=48)
|
||||||
|
|
||||||
# 计划量,目前只能从mail.message中筛选出
|
# # 计划量,目前只能从mail.message中筛选出
|
||||||
plan_order_messages = request.env['mail.message'].sudo().search([
|
# plan_order_messages = request.env['mail.message'].sudo().search([
|
||||||
('model', '=', 'mrp.workorder'),
|
# ('model', '=', 'mrp.workorder'),
|
||||||
('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')),
|
# ('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')),
|
||||||
('tracking_value_ids.field_desc', '=', '状态'),
|
# ('tracking_value_ids.field_desc', '=', '状态'),
|
||||||
('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中'])
|
# ('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中'])
|
||||||
])
|
# ])
|
||||||
|
|
||||||
for line in line_list:
|
for line in line_list:
|
||||||
|
not_done_data = []
|
||||||
|
done_data = []
|
||||||
|
not_done_index = 1
|
||||||
|
done_index = 1
|
||||||
|
|
||||||
if line == '业绩总览':
|
if line == '业绩总览':
|
||||||
work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
|
work_order_domain = [('routing_type', 'in', ['人工线下加工', 'CNC加工'])]
|
||||||
@@ -904,17 +910,12 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
|
# [('production_line_id.name', '=', line), ('state', 'not in', ['finished']),
|
||||||
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
|
# ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True)
|
||||||
# ])
|
# ])
|
||||||
# not_done_orders = work_order_obj.search(work_order_domain +
|
not_done_orders = work_order_obj.search(work_order_domain + [
|
||||||
# [('state', 'in', ['ready', 'progress'])], order='id asc'
|
('state', 'in', ['ready', 'progress']),
|
||||||
# )
|
('date_planned_start', '>=', time_48_hours_ago),
|
||||||
not_done_orders = request.env['mrp.workorder'].sudo().browse(plan_order_messages.mapped('res_id'))
|
('date_planned_start', '<=', current_time)
|
||||||
if line == '业绩总览':
|
], order='id asc'
|
||||||
not_done_orders = not_done_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工'])
|
)
|
||||||
elif line == '人工线下加工中心':
|
|
||||||
not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == '人工线下加工')
|
|
||||||
else:
|
|
||||||
not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line)
|
|
||||||
|
|
||||||
|
|
||||||
# 完成订单
|
# 完成订单
|
||||||
# 获取当前时间,并计算24小时前的时间
|
# 获取当前时间,并计算24小时前的时间
|
||||||
@@ -922,11 +923,11 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
# time_24_hours_ago = current_time - timedelta(hours=24)
|
# time_24_hours_ago = current_time - timedelta(hours=24)
|
||||||
|
|
||||||
finish_orders = work_order_obj.search(work_order_domain + [
|
finish_orders = work_order_obj.search(work_order_domain + [
|
||||||
('state', 'in', ['finished']),
|
('state', 'in', ['done']),
|
||||||
('production_id.state', 'not in', ['cancel']),
|
('production_id.state', 'not in', ['cancel']),
|
||||||
('date_finished', '>=', time_48_hours_ago)
|
('date_finished', '>=', time_48_hours_ago)
|
||||||
], order='id asc')
|
], order='id asc')
|
||||||
# print(finish_orders)
|
# logging.info('完成订单: %s' % finish_orders)
|
||||||
|
|
||||||
# 获取所有未完成订单的ID列表
|
# 获取所有未完成订单的ID列表
|
||||||
order_ids = [order.id for order in not_done_orders]
|
order_ids = [order.id for order in not_done_orders]
|
||||||
@@ -962,14 +963,6 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
material_match = re.search(material_pattern, blank_name)
|
material_match = re.search(material_pattern, blank_name)
|
||||||
material = material_match.group(1) if material_match else 'No match found'
|
material = material_match.group(1) if material_match else 'No match found'
|
||||||
|
|
||||||
state_dict = {
|
|
||||||
'draft': '待排程',
|
|
||||||
'done': '已排程',
|
|
||||||
'processing': '生产中',
|
|
||||||
'finished': '已完成',
|
|
||||||
'ready': '待加工',
|
|
||||||
'progress': '生产中',
|
|
||||||
}
|
|
||||||
|
|
||||||
line_dict = {
|
line_dict = {
|
||||||
'sequence': not_done_index,
|
'sequence': not_done_index,
|
||||||
@@ -985,8 +978,6 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
not_done_index += 1
|
not_done_index += 1
|
||||||
|
|
||||||
for finish_order in finish_orders:
|
for finish_order in finish_orders:
|
||||||
if not finish_order.actual_end_time:
|
|
||||||
continue
|
|
||||||
blank_name = ''
|
blank_name = ''
|
||||||
try:
|
try:
|
||||||
blank_name = finish_order.production_id.move_raw_ids[0].product_id.name
|
blank_name = finish_order.production_id.move_raw_ids[0].product_id.name
|
||||||
@@ -1002,13 +993,13 @@ class Sf_Dashboard_Connect(http.Controller):
|
|||||||
|
|
||||||
line_dict = {
|
line_dict = {
|
||||||
'sequence': done_index,
|
'sequence': done_index,
|
||||||
'workorder_name': finish_order.name,
|
'workorder_name': finish_order.production_id.name,
|
||||||
'blank_name': blank_name,
|
'blank_name': blank_name,
|
||||||
'material': material,
|
'material': material,
|
||||||
'dimensions': dimensions,
|
'dimensions': dimensions,
|
||||||
'order_qty': order.qty_produced,
|
'order_qty': finish_order.qty_produced,
|
||||||
'finish_time': finish_order.actual_end_time.strftime(
|
'finish_time': finish_order.date_finished.strftime(
|
||||||
'%Y-%m-%d %H:%M:%S') if finish_order.actual_end_time else ' '
|
'%Y-%m-%d %H:%M:%S') if finish_order.date_finished else ' '
|
||||||
|
|
||||||
}
|
}
|
||||||
done_data.append(line_dict)
|
done_data.append(line_dict)
|
||||||
|
|||||||
Reference in New Issue
Block a user