Accept Merge Request #1533: (feature/优化外协采购和出入库单(工艺退回调整) -> develop)

Merge Request: 优化外协采购和出入库单(工艺退回调整)

Created By: @杨金灵
Reviewed By: @胡尧
Approved By: @胡尧 
Accepted By: @杨金灵
URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1533
This commit is contained in:
杨金灵
2024-11-21 17:23:18 +08:00
committed by Coding
13 changed files with 494 additions and 430 deletions

View File

@@ -145,7 +145,7 @@ class ResMrpWorkOrder(models.Model):
tag_type = fields.Selection([("重新加工", "重新加工")], string="标签", tracking=True)
def _compute_default_construction_period_status(self):
need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected','done']
need_list = ['pending', 'waiting', 'ready', 'progress', 'to be detected', 'done']
try:
if self.state not in need_list:
return False
@@ -154,9 +154,9 @@ class ResMrpWorkOrder(models.Model):
hours = self.get_hours_diff()
if hours >= 12:
return '正常'
elif hours > 0 and hours < 12 and self.state!='done':
elif hours > 0 and hours < 12 and self.state != 'done':
return '预警'
elif hours > 0 and hours < 12 and self.state=='done':
elif hours > 0 and hours < 12 and self.state == 'done':
return '正常'
else:
return '已逾期'
@@ -168,7 +168,7 @@ class ResMrpWorkOrder(models.Model):
def _compute_construction_period_status(self):
for worker in self:
construction_period_status = worker._compute_default_construction_period_status()
if construction_period_status and worker.construction_period_status!=construction_period_status:
if construction_period_status and worker.construction_period_status != construction_period_status:
worker.construction_period_status = construction_period_status
construction_period_status = fields.Selection([('正常', '正常'), ('预警', '预警'), ('已逾期', '已逾期')],
@@ -199,14 +199,17 @@ class ResMrpWorkOrder(models.Model):
func(records)
# 增加页码
page_number += 1
def run_compute_construction_period_status(self,records):
def run_compute_construction_period_status(self, records):
records._compute_construction_period_status()
def _corn_update_construction_period_status(self):
need_list=['pending', 'waiting', 'ready', 'progress', 'to be detected']
need_list = ['pending', 'waiting', 'ready', 'progress', 'to be detected']
# need_list = [
# 'progress',
# 'to be detected']
self.get_page_all_records('mrp.workorder',self.run_compute_construction_period_status,[('state', 'in', need_list)],100)
self.get_page_all_records('mrp.workorder', self.run_compute_construction_period_status,
[('state', 'in', need_list)], 100)
def get_hours_diff(self):
# 获取当前日期和时间
@@ -230,16 +233,16 @@ class ResMrpWorkOrder(models.Model):
def _compute_surface_technics_picking_ids(self):
for workorder in self:
if workorder.routing_type == '表面工艺':
domain = [('origin', '=', workorder.production_id.name), ('state', 'not in', ['cancel'])]
domain = [('origin', '=', workorder.production_id.name), ('state', 'not in', ['cancel']),
('partner_id', '!=', False)]
previous_workorder = self.env['mrp.workorder'].search(
[('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'),
('production_id', '=', workorder.production_id.id)])
if previous_workorder:
process_product = self.env['product.template']._get_process_parameters_product(
previous_workorder.surface_technics_parameters_id)
domain += [('partner_id', '=', process_product.partner_id.id)]
else:
domain += [('surface_technics_parameters_id', '=', workorder.surface_technics_parameters_id.id)]
if previous_workorder.supplier_id != workorder.supplier_id:
process_product = self.env['product.template']._get_process_parameters_product(
previous_workorder.surface_technics_parameters_id)
domain += [('partner_id', '=', process_product.partner_id.id)]
picking_ids = self.env['stock.picking'].search(domain, order='id asc')
workorder.surface_technics_picking_count = len(picking_ids)
workorder.picking_ids = picking_ids.ids
@@ -782,7 +785,7 @@ class ResMrpWorkOrder(models.Model):
routing_types = ['切割', '装夹预调', 'CNC加工', '解除装夹']
if route.route_id.routing_type in routing_types:
routing_workcenter = self.env['mrp.routing.workcenter'].sudo().search(
[('name', '=', route.route_id.routing_type)])
[('name', '=', oute.routing_type if hasattr(route, 'routing_type') else route.route_id.routing_type)])
duration_expected = routing_workcenter.time_cycle
reserved_duration = routing_workcenter.reserved_duration
else:
@@ -792,14 +795,15 @@ class ResMrpWorkOrder(models.Model):
'product_uom_id': production.product_uom_id.id,
'qty_producing': 0,
'operation_id': False,
'name': route.route_id.name,
'processing_panel': route.panel,
'name': route.name if hasattr(route, 'routing_type') else route.route_id.name,
'processing_panel': False if hasattr(route, 'routing_type') else route.panel,
'sequence': route.sequence,
'quality_point_ids': route.route_id.quality_point_ids,
'routing_type': route.route_id.routing_type,
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.route_id.workcenter_ids.ids,
route.route_id.routing_type,
production.product_id),
'quality_point_ids': False if hasattr(route, 'routing_type') else route.route_id.quality_point_ids,
'routing_type': route.routing_type if hasattr(route, 'routing_type') else route.route_id.routing_type,
'workcenter_id': False if hasattr(route, 'routing_type') else self.env[
'mrp.routing.workcenter'].get_workcenter(route.route_id.workcenter_ids.ids,
route.route_id.routing_type,
production.product_id),
# 设定初始化值避免出现变成bool问题
'date_planned_start': datetime.now(),
'date_planned_finished': datetime.now() + timedelta(days=1),
@@ -1004,7 +1008,7 @@ class ResMrpWorkOrder(models.Model):
return workorders_values_str
@api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state',
'production_id.tool_state', 'production_id.schedule_state')
'production_id.tool_state', 'production_id.schedule_state', 'sequence')
def _compute_state(self):
# super()._compute_state()
for workorder in self:
@@ -1015,10 +1019,13 @@ class ResMrpWorkOrder(models.Model):
if workorder.state == 'pending':
if all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
if workorder.production_id.reservation_state == 'assigned' and workorder.production_id.schedule_state == '已排':
if (workorder.sequence == 1 and not workorder.blocked_by_workorder_ids) or (
workorder.blocked_by_workorder_ids.state in ('done', 'cancel')) or (
previous_workorder.state in (
'done', 'cancel') and not workorder.blocked_by_workorder_ids):
if ((workorder.sequence == 1 and not workorder.blocked_by_workorder_ids)
or (workorder.blocked_by_workorder_ids.state in ('done', 'cancel')
and workorder.blocked_by_workorder_ids.test_results not in ['报废', '返工'])
or (previous_workorder.state in ('done', 'cancel')
and not workorder.blocked_by_workorder_ids
and previous_workorder.test_results not in ['报废', '返工'])
):
workorder.state = 'ready'
continue
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
@@ -1045,147 +1052,115 @@ class ResMrpWorkOrder(models.Model):
workorder.state = 'ready'
elif workorder.production_id.reservation_state != 'assigned' and workorder.state == 'ready':
workorder.state = 'waiting'
re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
cnc_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
('test_results', '=', '返工')])
cnc_workorder_pending = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
unclamp_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('sequence', '=', workorder.sequence - 1),
('state', 'in', ['done'])])
if workorder.state not in ['cancel', 'progress', 'rework']:
if workorder.production_id.state == 'rework':
if workorder.routing_type == '装夹预调' and workorder.state not in ['done', 'rework',
'cancel']:
# # 有返工工单
# if re_work:
# 新工单
if workorder.is_rework is False:
if workorder.production_id.programming_state == '已编程' and workorder.production_id.is_rework is False:
if re_work or cnc_workorder:
workorder.state = 'ready'
else:
if workorder.production_id.is_rework is True:
if re_work or cnc_workorder:
workorder.state = 'waiting'
elif workorder.routing_type == 'CNC加工' and workorder.state not in ['done', 'rework', 'cancel']:
pre_workorder = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id),
('processing_panel', '=', workorder.processing_panel),
('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
if pre_workorder:
if re_work:
workorder.state = 'waiting'
elif workorder.routing_type == '解除装夹' and workorder.state not in ['done', 'rework', 'cancel']:
if cnc_workorder:
if not cnc_workorder_pending or unclamp_workorder.test_results == '报废':
workorder.state = 'waiting'
# else:
# if workorder.production_id.is_rework is True:
# workorder.state = 'waiting'
elif workorder.production_id.state == 'progress':
if workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程' and \
workorder.is_rework is False and workorder.state not in [
'done', 'rework',
'cancel']:
if workorder.production_id.is_rework is False:
if re_work or cnc_workorder or unclamp_workorder:
workorder.state = 'ready'
# if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# workorder.state = 'ready'
if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
if unclamp_workorder:
if workorder.is_subcontract is False:
workorder.state = 'ready'
else:
production_programming = self.env['mrp.production'].search(
[('origin', '=', self.production_id.origin)], order='name asc')
production_no_remanufacture = production_programming.filtered(
lambda a: a.is_remanufacture is False)
production_list = [production.name for production in production_programming]
purchase_orders = self.env['purchase.order'].search(
[('origin', 'ilike', ','.join(production_list))])
for line in purchase_orders.order_line:
if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len(
production_no_remanufacture):
if purchase_orders.state == 'purchase':
workorder.state = 'ready'
else:
workorder.state = 'waiting'
elif workorder.production_id.state == 'scrap':
if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废':
workorder.state = 'waiting'
# if workorder.routing_type == '装夹预调' and workorder.state in ['waiting', 'ready', 'pending']:
# workorder_ids = workorder.production_id.workorder_ids
# work_bo = True
# for wo in workorder_ids.filtered(lambda a: a.routing_type == '装夹预调' and a.state == 'rework'):
# if not workorder_ids.filtered(
# lambda a: (a.routing_type == '装夹预调' and a.state not in ['rework', 'cancel']
# and a.processing_panel == wo.processing_panel)):
# work_bo = False
# break
# if (workorder.production_id.programming_state == '已编程' and work_bo
# and not workorder_ids.filtered(lambda a: a.sequence == 0)):
# # 当工单对应制造订单的功能刀具状态为 【无效刀】时,先对的第一个装夹预调工单状态设置为 【等待组件】
# if workorder.production_id.tool_state in ['1', '2']:
# if workorder.state in ['ready']:
# workorder.state = 'waiting'
# continue
# elif workorder.state in ['waiting']:
# continue
# elif workorder.state == 'pending' and workorder == self.search(
# [('production_id', '=', workorder.production_id.id),
# ('routing_type', '=', '装夹预调'),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence"):
# workorder.state = 'waiting'
# continue
# elif workorder.production_id.tool_state in ['0']:
# if workorder_ids.filtered(lambda a: a.state == 'rework'):
# if not workorder_ids.filtered(
# lambda a: (a.routing_type not in ['装夹预调'] and
# a.state not in ['pending', 'done', 'rework', 'cancel'])):
# # 查询工序最小的非完工、非返工的装夹预调工单
# work_id = self.search(
# [('production_id', '=', workorder.production_id.id),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence")
# if work_id.routing_type == '装夹预调':
# if workorder == work_id:
# if workorder.production_id.reservation_state == 'assigned':
# workorder.state = 'ready'
# elif workorder.production_id.reservation_state != 'assigned':
# workorder.state = 'waiting'
# continue
# elif (workorder.name == '装夹预调' and
# workorder.state not in ['rework', 'done', 'cancel']):
# if workorder.state != 'pending':
# workorder.state = 'pending'
# if workorder.production_id.tool_state in ['1', '2'] and workorder.state == 'ready':
# workorder.state = 'waiting'
# continue
# if (workorder.production_id.tool_state in ['1', '2']
# and not workorder.production_id.workorder_ids.filtered(lambda a: a.sequence == 0)
# and workorder.production_id.programming_state == '编程中' and workorder.name == '装夹预调'):
# if workorder.state == 'pending' and workorder == self.search(
# [('production_id', '=', workorder.production_id.id),
# ('routing_type', '=', '装夹预调'),
# ('state', 'not in', ['rework', 'done', 'cancel'])],
# limit=1,
# order="sequence"):
# workorder.state = 'waiting'
# continue
for workorder in self:
# 如果工单的工序没有进行排序则跳出循环
if workorder.production_id.workorder_ids.filtered(lambda wk: wk.sequence == 0):
continue
# ===== 对所有按序号排序的非[进行中、完成、返工、取消]状态的工单,除了第一条之外的工单状态都设置为[等待其他工单] =====
logging.info(workorder.state)
work_ids = workorder.production_id.workorder_ids.filtered(
lambda wk: wk.state not in ['done', 'rework', 'cancel'])
if not work_ids:
continue
min_sequence_wk = min(work_ids, key=lambda wk: wk.sequence)
if workorder.state in ['done', 'rework', 'cancel', 'progress', 'to be detected']:
continue
else:
if workorder != min_sequence_wk:
if workorder.state != 'pending':
workorder.state = 'pending'
continue
# ================= 如果制造订单刀具状态为[无效刀、缺刀] 或者 制造订单状态为[返工]==========================
if (workorder.production_id.tool_state in ['1', '2'] or workorder.production_id.state == 'rework'
or workorder.production_id.schedule_state != '已排'
or workorder.production_id.reservation_state != 'assigned'
or workorder.production_id.workorder_ids.filtered(
lambda wk: wk.sequence == workorder.sequence - 1).test_results in ['报废', '返工']):
if workorder.state != 'waiting':
workorder.state = 'waiting'
continue
if workorder.production_id.programming_state == '已编程':
workorder.state = 'ready'
elif workorder.state != 'waiting':
workorder.state = 'waiting'
# re_work = self.env['mrp.workorder'].search([('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('is_rework', '=', True), ('state', 'in', ['done', 'rework'])])
# cnc_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', 'CNC加工'), ('state', 'in', ['done', 'rework']),
# ('test_results', '=', '返工')])
# cnc_workorder_pending = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', 'CNC加工'), ('state', 'in', ['pending'])])
# unclamp_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('sequence', '=', workorder.sequence - 1),
# ('state', 'in', ['done'])])
# if workorder.state not in ['cancel', 'progress', 'rework']:
# if workorder.production_id.state == 'rework':
# if workorder.routing_type == '装夹预调':
# # # 有返工工单
# # if re_work:
# # 新工单
# if workorder.is_rework is False:
# if (workorder.production_id.programming_state == '已编程'
# and workorder.production_id.is_rework is False):
# if re_work or cnc_workorder:
# workorder.state = 'ready'
# else:
# if workorder.production_id.is_rework is True:
# if re_work or cnc_workorder:
# workorder.state = 'waiting'
#
# elif workorder.routing_type == 'CNC加工':
# pre_workorder = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id),
# ('processing_panel', '=', workorder.processing_panel),
# ('routing_type', '=', '装夹预调'), ('state', '=', 'done')])
# if pre_workorder:
# if re_work:
# workorder.state = 'waiting'
# elif workorder.routing_type == '解除装夹':
# if cnc_workorder:
# if not cnc_workorder_pending or unclamp_workorder.test_results == '报废':
# workorder.state = 'waiting'
# # else:
# # if workorder.production_id.is_rework is True:
# # workorder.state = 'waiting'
# elif workorder.production_id.state == 'progress':
# if (workorder.routing_type == '装夹预调' and workorder.production_id.programming_state == '已编程'
# and workorder.is_rework is False and workorder.state not in ['done', 'rework', 'cancel']):
# if workorder.production_id.is_rework is False:
# if re_work or cnc_workorder or unclamp_workorder:
# workorder.state = 'ready'
# # if (re_work or cnc_workorder) and workorder.production_id.is_rework is False:
# # workorder.state = 'ready'
# if workorder.routing_type == '表面工艺' and workorder.state not in ['done', 'progress']:
# if unclamp_workorder:
# if workorder.is_subcontract is False:
# workorder.state = 'ready'
# else:
# production_programming = self.env['mrp.production'].search(
# [('origin', '=', self.production_id.origin)], order='name asc')
# production_no_remanufacture = production_programming.filtered(
# lambda a: a.is_remanufacture is False)
# production_list = [production.name for production in production_programming]
# purchase_orders = self.env['purchase.order'].search(
# [('origin', 'ilike', ','.join(production_list))])
# for line in purchase_orders.order_line:
# if line.product_id.server_product_process_parameters_id == workorder.surface_technics_parameters_id and line.product_qty == len(
# production_no_remanufacture):
# if purchase_orders.state == 'purchase':
# workorder.state = 'ready'
# else:
# workorder.state = 'waiting'
# elif workorder.production_id.state == 'scrap':
# if workorder.routing_type == '解除装夹' and unclamp_workorder.test_results == '报废':
# workorder.state = 'waiting'
# 重写工单开始按钮方法
def button_start(self):
@@ -2032,7 +2007,7 @@ class CMMprogram(models.Model):
}))
return cmm_program
def update_work_start_end(self,date_planned_start,date_planned_end):
def update_work_start_end(self, date_planned_start, date_planned_end):
self.leave_id.write({
'date_from': date_planned_start,
'date_to': date_planned_end,
@@ -2070,7 +2045,8 @@ class CMMprogram(models.Model):
date_planned_end = date_planned_start + duration_expected
last_time = date_planned_end
return date_planned_start, date_planned_end, last_time
def manual_offline_process(self,last_time,is_first):
def manual_offline_process(self, last_time, is_first):
date_planned_end = None
date_planned_start = None
duration_expected = datetime.timedelta(minutes=self.duration_expected)
@@ -2082,4 +2058,4 @@ class CMMprogram(models.Model):
else:
date_planned_start = last_time + reserve_time
date_planned_end = date_planned_start + duration_expected
return date_planned_start, date_planned_end,last_time
return date_planned_start, date_planned_end, last_time