Merge branch 'refs/heads/develop' into feature/delivery_status
# Conflicts: # sf_manufacturing/models/mrp_production.py
This commit is contained in:
@@ -38,13 +38,10 @@ class ResMrpWorkOrder(models.Model):
|
||||
processing_panel = fields.Char('加工面')
|
||||
sequence = fields.Integer(string='工序')
|
||||
routing_type = fields.Selection([
|
||||
# ('获取CNC加工程序', '获取CNC加工程序'),
|
||||
('装夹预调', '装夹预调'),
|
||||
# ('前置三元定位检测', '前置三元定位检测'),
|
||||
('CNC加工', 'CNC加工'),
|
||||
# ('后置三元质量检测', '后置三元质量检测'),
|
||||
('解除装夹', '解除装夹'),
|
||||
('切割', '切割'), ('表面工艺', '表面工艺')
|
||||
('切割', '切割'), ('表面工艺', '表面工艺'), ('线切割', '线切割')
|
||||
], string="工序类型")
|
||||
results = fields.Char('结果')
|
||||
state = fields.Selection([
|
||||
@@ -233,7 +230,7 @@ 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)]
|
||||
domain = [('origin', '=', workorder.production_id.name), ('state', 'not in', ['cancel'])]
|
||||
previous_workorder = self.env['mrp.workorder'].search(
|
||||
[('sequence', '=', workorder.sequence - 1), ('routing_type', '=', '表面工艺'),
|
||||
('production_id', '=', workorder.production_id.id)])
|
||||
@@ -267,24 +264,47 @@ class ResMrpWorkOrder(models.Model):
|
||||
def _compute_surface_technics_purchase_ids(self):
|
||||
for order in self:
|
||||
if order.routing_type == '表面工艺':
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', order.production_id.programming_no)], order='name asc')
|
||||
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
||||
if order.production_id.production_type == '自动化产线加工':
|
||||
domain = [('programming_no', '=', order.production_id.programming_no)]
|
||||
else:
|
||||
domain = [('origin', '=', order.production_id.origin)]
|
||||
production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
|
||||
production_no_remanufacture = production_programming.filtered(lambda a: a.is_remanufacture is False)
|
||||
technology_design = self.env['sf.technology.design'].search(
|
||||
[('process_parameters_id', '=', order.surface_technics_parameters_id.id),
|
||||
('production_id', '=', order.production_id.id)])
|
||||
if technology_design.is_auto is False:
|
||||
domain = [('origin', '=', order.production_id.name)]
|
||||
else:
|
||||
domain = [('origin', '=', ','.join(production_list))]
|
||||
purchase = self.env['purchase.order'].search(domain)
|
||||
if not purchase:
|
||||
order.surface_technics_purchase_count = 0
|
||||
for line in purchase.order_line:
|
||||
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id and line.product_qty == len(
|
||||
production_no_remanufacture):
|
||||
order.surface_technics_purchase_count = len(purchase)
|
||||
if line.product_id.server_product_process_parameters_id == order.surface_technics_parameters_id:
|
||||
if (line.product_qty == len(production_no_remanufacture)) or technology_design.is_auto is False:
|
||||
order.surface_technics_purchase_count = len(purchase)
|
||||
else:
|
||||
order.surface_technics_purchase_count = 0
|
||||
|
||||
def action_view_surface_technics_purchase(self):
|
||||
self.ensure_one()
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
|
||||
if self.routing_type == '表面工艺':
|
||||
if self.production_id.production_type == '自动化产线加工':
|
||||
domain = [('programming_no', '=', self.production_id.programming_no)]
|
||||
else:
|
||||
domain = [('origin', '=', self.production_id.origin)]
|
||||
production_programming = self.env['mrp.production'].search(domain, order='name asc')
|
||||
production_list = [production.name for production in production_programming]
|
||||
purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))])
|
||||
technology_design = self.env['sf.technology.design'].search(
|
||||
[('process_parameters_id', '=', self.surface_technics_parameters_id.id),
|
||||
('production_id', '=', self.production_id.id)])
|
||||
if technology_design.is_auto is False:
|
||||
domain = [('origin', '=', self.production_id.name)]
|
||||
else:
|
||||
domain = [('origin', '=', ','.join(production_list))]
|
||||
purchase_orders = self.env['purchase.order'].search(domain)
|
||||
result = {
|
||||
"type": "ir.actions.act_window",
|
||||
"res_model": "purchase.order",
|
||||
@@ -410,7 +430,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
|
||||
@api.constrains('blocked_by_workorder_ids')
|
||||
def _check_no_cyclic_dependencies(self):
|
||||
if self.production_id.state not in ['rework'] and self.state not in ['rework']:
|
||||
if self.production_id.state not in ['rework', 'technology_to_confirmed', 'confirmed'] and self.state not in [
|
||||
'rework']:
|
||||
if not self._check_m2m_recursion('blocked_by_workorder_ids'):
|
||||
raise ValidationError(_("您不能创建周期性的依赖关系."))
|
||||
|
||||
@@ -421,8 +442,9 @@ class ResMrpWorkOrder(models.Model):
|
||||
for workorder in self.blocked_by_workorder_ids:
|
||||
if workorder.state in ['done', 'cancel', 'rework']:
|
||||
continue
|
||||
workorder._plan_workorder(replan)
|
||||
start_date = max(start_date, workorder.date_planned_finished)
|
||||
if workorder.production_id.state not in ['technology_to_confirmed', 'confirmed']:
|
||||
workorder._plan_workorder(replan)
|
||||
start_date = max(start_date, workorder.date_planned_finished)
|
||||
# Plan only suitable workorders
|
||||
if self.state not in ['pending', 'waiting', 'ready']:
|
||||
return
|
||||
@@ -769,6 +791,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
'operation_id': False,
|
||||
'name': route.route_id.name,
|
||||
'processing_panel': 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,
|
||||
@@ -817,6 +840,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
'operation_id': False,
|
||||
'name': route.process_parameters_id.display_name,
|
||||
'processing_panel': '',
|
||||
'sequence': route.sequence,
|
||||
'routing_type': '表面工艺',
|
||||
'surface_technics_parameters_id': route.process_parameters_id.id,
|
||||
'work_state': '',
|
||||
@@ -977,10 +1001,47 @@ 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.tool_state', 'production_id.schedule_state')
|
||||
def _compute_state(self):
|
||||
super()._compute_state()
|
||||
# super()._compute_state()
|
||||
for workorder in self:
|
||||
if workorder.sequence != 1:
|
||||
previous_workorder = self.env['mrp.workorder'].search(
|
||||
[('production_id', '=', workorder.production_id.id),
|
||||
('sequence', '=', workorder.sequence - 1)])
|
||||
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):
|
||||
workorder.state = 'ready'
|
||||
continue
|
||||
if workorder.production_id.schedule_state == '未排' and workorder.state in ('waiting', 'ready'):
|
||||
if workorder.sequence != 1:
|
||||
workorder.state = 'pending'
|
||||
continue
|
||||
if workorder.state not in ('waiting', 'ready'):
|
||||
continue
|
||||
if workorder.state in (
|
||||
'waiting') and workorder.sequence == 1 and workorder.production_id.schedule_state == '已排':
|
||||
workorder.state = 'ready'
|
||||
continue
|
||||
if not all([wo.state in ('done', 'cancel') for wo in workorder.blocked_by_workorder_ids]):
|
||||
workorder.state = 'pending'
|
||||
if workorder.state in ['waiting']:
|
||||
if previous_workorder.state == 'waiting':
|
||||
workorder.state = 'pending'
|
||||
if workorder.sequence == 1 and workorder.state == 'pending':
|
||||
workorder.state = 'waiting'
|
||||
continue
|
||||
if workorder.production_id.reservation_state not in ('waiting', 'confirmed', 'assigned'):
|
||||
continue
|
||||
if workorder.production_id.reservation_state == 'assigned' and workorder.state == 'waiting' and workorder.production_id.schedule_state == '已排':
|
||||
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'])])
|
||||
@@ -1044,7 +1105,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
workorder.state = 'ready'
|
||||
else:
|
||||
production_programming = self.env['mrp.production'].search(
|
||||
[('programming_no', '=', self.production_id.programming_no)], order='name asc')
|
||||
[('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]
|
||||
@@ -1060,68 +1121,68 @@ class ResMrpWorkOrder(models.Model):
|
||||
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
|
||||
# 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
|
||||
|
||||
# 重写工单开始按钮方法
|
||||
def button_start(self):
|
||||
@@ -1131,7 +1192,7 @@ class ResMrpWorkOrder(models.Model):
|
||||
'actual_start_time': datetime.now()
|
||||
})
|
||||
|
||||
if self.routing_type == '装夹预调':
|
||||
if self.sequence == 1:
|
||||
# 判断是否有坯料的序列号信息
|
||||
boolean = False
|
||||
if self.production_id.move_raw_ids:
|
||||
@@ -1242,8 +1303,8 @@ class ResMrpWorkOrder(models.Model):
|
||||
if record.is_rework is False:
|
||||
if not record.material_center_point:
|
||||
raise UserError("坯料中心点为空,请检查")
|
||||
# if record.X_deviation_angle <= 0:
|
||||
# raise UserError("X偏差角度小于等于0,请检查!本次计算的X偏差角度为:%s" % record.X_deviation_angle)
|
||||
# if record.X_deviation_angle <= 0:
|
||||
# raise UserError("X偏差角度小于等于0,请检查!本次计算的X偏差角度为:%s" % record.X_deviation_angle)
|
||||
record.process_state = '待加工'
|
||||
# record.write({'process_state': '待加工'})
|
||||
record.production_id.process_state = '待加工'
|
||||
@@ -1273,23 +1334,10 @@ class ResMrpWorkOrder(models.Model):
|
||||
'''
|
||||
record.date_finished = datetime.now()
|
||||
if record.routing_type == '表面工艺':
|
||||
logging.info('record.picking_ids:%s' % record.picking_ids)
|
||||
logging.info('record.picking_out:%s' % record.picking_ids[0])
|
||||
if record.picking_ids:
|
||||
for pick_item in record.picking_ids:
|
||||
if pick_item.state not in ['done']:
|
||||
raise UserError(
|
||||
'请先完成该工单的工艺外协再进行操作')
|
||||
picking_out = record.env['stock.move.line'].search(
|
||||
[('picking_id', '=', record.picking_ids[0].id)])
|
||||
logging.info('picking_out:%s' % picking_out.picking_id.name)
|
||||
# if picking_out:
|
||||
# order_line_ids = []
|
||||
# logging.info('surface_technics_parameters_id:%s' % record.surface_technics_parameters_id.name)
|
||||
#
|
||||
# else:
|
||||
# raise UserError(
|
||||
# '请先在产品中配置表面工艺为%s相关的外协服务产品' % item.surface_technics_parameters_id.name)
|
||||
picks = record.picking_ids.filtered(lambda p: p.state not in ('done'))
|
||||
if picks:
|
||||
raise UserError('请先完成该工单的工艺外协再进行操作')
|
||||
tem_date_planned_finished = record.date_planned_finished
|
||||
tem_date_finished = record.date_finished
|
||||
logging.info('routing_type:%s' % record.routing_type)
|
||||
|
||||
Reference in New Issue
Block a user