Merge branch 'feature/优化外协采购和出入库单(工艺退回调整)' into develop
This commit is contained in:
@@ -56,6 +56,7 @@ class MrpProduction(models.Model):
|
||||
production.deadline_of_delivery = False
|
||||
else:
|
||||
production.deadline_of_delivery = False
|
||||
|
||||
def _compute_default_delivery_status(self):
|
||||
try:
|
||||
if self.state == 'cancel':
|
||||
@@ -250,6 +251,7 @@ class MrpProduction(models.Model):
|
||||
remanufacture_count = fields.Integer("重新制造订单数量", compute='_compute_remanufacture_production_ids')
|
||||
remanufacture_production_id = fields.Many2one('mrp.production', string='')
|
||||
technology_design_ids = fields.One2many('sf.technology.design', 'production_id', string='工艺设计')
|
||||
is_adjust = fields.Boolean('是否退回调整', default=False)
|
||||
|
||||
@api.depends('remanufacture_production_id')
|
||||
def _compute_remanufacture_production_ids(self):
|
||||
@@ -276,7 +278,7 @@ class MrpProduction(models.Model):
|
||||
|
||||
@api.depends(
|
||||
'move_raw_ids.state', 'move_raw_ids.quantity_done', 'move_finished_ids.state', 'tool_state',
|
||||
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state')
|
||||
'workorder_ids.state', 'product_qty', 'qty_producing', 'schedule_state', 'programming_state')
|
||||
def _compute_state(self):
|
||||
for production in self:
|
||||
if not production.state or not production.product_uom_id:
|
||||
@@ -309,7 +311,7 @@ class MrpProduction(models.Model):
|
||||
# 新添加的状态逻辑
|
||||
if (
|
||||
production.state == 'to_close' or production.state == 'progress') and production.schedule_state == '未排':
|
||||
if not production.workorder_ids:
|
||||
if not production.workorder_ids or production.is_adjust is True:
|
||||
production.state = 'technology_to_confirmed'
|
||||
else:
|
||||
production.state = 'confirmed'
|
||||
@@ -675,27 +677,22 @@ class MrpProduction(models.Model):
|
||||
'operation_id': operation.id,
|
||||
'state': 'pending',
|
||||
}]
|
||||
if production.product_id.categ_id.type == '成品':
|
||||
if production.product_id.categ_id.type in ['成品', '坯料']:
|
||||
# # 根据工序设计生成工单
|
||||
for route in production.technology_design_ids:
|
||||
if route.route_id.routing_type not in ['表面工艺']:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(production, route))
|
||||
else:
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', route.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route, product_production_process.seller_ids[0].partner_id.id))
|
||||
elif production.product_id.categ_id.type == '坯料':
|
||||
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
||||
[('embryo_model_type_id', '=', production.product_id.embryo_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
)
|
||||
for route_embryo in embryo_routing_workcenter:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str('', production, route_embryo))
|
||||
workorder_has = self.env['mrp.workorder'].search(
|
||||
[('name', '=', route.route_id.name), ('production_id', '=', production.id)])
|
||||
if not workorder_has:
|
||||
if route.route_id.routing_type not in ['表面工艺']:
|
||||
workorders_values.append(
|
||||
self.env['mrp.workorder'].json_workorder_str(production, route))
|
||||
else:
|
||||
product_production_process = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', route.process_parameters_id.id)])
|
||||
workorders_values.append(
|
||||
self.env[
|
||||
'mrp.workorder']._json_workorder_surface_process_str(
|
||||
production, route, product_production_process.seller_ids[0].partner_id.id))
|
||||
production.workorder_ids = workorders_values
|
||||
for workorder in production.workorder_ids:
|
||||
workorder.duration_expected = workorder._get_duration_expected()
|
||||
@@ -717,7 +714,7 @@ class MrpProduction(models.Model):
|
||||
sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.sequence)
|
||||
for i, workorder in enumerate(sorted_workorders):
|
||||
# 检查当前工作订单和下一个工作订单是否连续,并且供应商相同
|
||||
if workorder.sequence == 1:
|
||||
if i == 0:
|
||||
consecutive_workorders.append(workorder)
|
||||
elif workorder.sequence == sorted_workorders[
|
||||
i - 1].sequence + 1 and workorder.supplier_id.id == sorted_workorders[i - 1].supplier_id.id:
|
||||
@@ -725,7 +722,7 @@ class MrpProduction(models.Model):
|
||||
else:
|
||||
# 处理连续组,如果它不为空
|
||||
if consecutive_workorders:
|
||||
# 创建出库拣货单和采购订单
|
||||
# 创建外协出入库单和采购订单
|
||||
self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production)
|
||||
self.env['purchase.order'].get_purchase_order(consecutive_workorders, production,
|
||||
product_id_to_production_names)
|
||||
@@ -739,7 +736,7 @@ class MrpProduction(models.Model):
|
||||
i - 1].supplier_id.id:
|
||||
consecutive_workorders = [workorder]
|
||||
else:
|
||||
# 立即创建出库拣货单和采购订单
|
||||
# 立即创建外协出入库单和采购订单
|
||||
self.env['stock.picking'].create_outcontract_picking(workorder, production)
|
||||
self.env['purchase.order'].get_purchase_order(workorder, production,
|
||||
product_id_to_production_names)
|
||||
@@ -817,6 +814,36 @@ class MrpProduction(models.Model):
|
||||
self._reset_work_order_sequence1(k)
|
||||
return True
|
||||
|
||||
# 需对不连续工单对应的采购单和外协出入库单做处理
|
||||
def _reset_subcontract_pick_purchase(self):
|
||||
production_all = self.sorted(lambda x: x.id)
|
||||
product_id_to_production_names = {}
|
||||
grouped_product_ids = {k: list(g) for k, g in
|
||||
groupby(production_all, key=lambda x: x.product_id.id)}
|
||||
for product_id, pd in grouped_product_ids.items():
|
||||
product_id_to_production_names[product_id] = [p.name for p in pd]
|
||||
for item in production_all:
|
||||
production_process = product_id_to_production_names.get(item.product_id.id)
|
||||
workorder_sf = item.workorder_ids.filtered(lambda sf: sf.routing_type == '表面工艺')
|
||||
for i, workorder in enumerate(workorder_sf):
|
||||
if i == 0:
|
||||
continue
|
||||
elif workorder.sequence != workorder_sf[i - 1].sequence + 1:
|
||||
# workorder.picking_ids.move_ids = False
|
||||
workorder.picking_ids = False
|
||||
purchase_order = self.env['purchase.order'].search(
|
||||
[('state', '=', 'draft'), ('origin', '=', ','.join(production_process)),
|
||||
('purchase_type', '=', 'consignment')])
|
||||
for line in purchase_order.order_line:
|
||||
server_template = self.env['product.template'].search(
|
||||
[('server_product_process_parameters_id', '=', workorder.surface_technics_parameters_id.id),
|
||||
('detailed_type', '=', 'service')])
|
||||
purchase_order_line = self.env['purchase.order.line'].search(
|
||||
[('product_id', '=', server_template.product_variant_id.id), ('id', '=', line.id),
|
||||
('product_qty', '=', len(production_process))], limit=1, order='id desc')
|
||||
if purchase_order_line:
|
||||
line.unlink()
|
||||
|
||||
def _reset_work_order_sequence(self):
|
||||
"""
|
||||
工单工序排序方法(新)
|
||||
@@ -834,7 +861,8 @@ class MrpProduction(models.Model):
|
||||
work_id.sequence = order_id.sequence + 1
|
||||
break
|
||||
# 对该工单之后的工单工序进行加一
|
||||
work_order_ids = rec.workorder_ids.filtered(lambda item: item.sequence >= work_id.sequence)
|
||||
work_order_ids = rec.workorder_ids.filtered(
|
||||
lambda item: item.sequence >= work_id.sequence and item.id != work_id.id)
|
||||
for work in work_order_ids:
|
||||
work.sequence = work.sequence + 1
|
||||
|
||||
@@ -954,15 +982,17 @@ class MrpProduction(models.Model):
|
||||
last_time = pro_plan.date_planned_start
|
||||
# 预置时间
|
||||
works = self.workorder_ids
|
||||
for index,work in enumerate(works):
|
||||
for index, work in enumerate(works):
|
||||
count = type_map.get(work.routing_type)
|
||||
date_planned_end = None
|
||||
date_planned_start = None
|
||||
if self.production_type=='自动化产线加工':
|
||||
date_planned_start,date_planned_end,last_time = work.auto_production_process(last_time,count,type_map)
|
||||
elif self.production_type=='':
|
||||
date_planned_start,date_planned_end,last_time = work.manual_offline_process(last_time,index)
|
||||
work.update_work_start_end(date_planned_start,date_planned_end)
|
||||
if self.production_type == '自动化产线加工':
|
||||
date_planned_start, date_planned_end, last_time = work.auto_production_process(last_time, count,
|
||||
type_map)
|
||||
elif self.production_type == '':
|
||||
date_planned_start, date_planned_end, last_time = work.manual_offline_process(last_time, index)
|
||||
work.update_work_start_end(date_planned_start, date_planned_end)
|
||||
|
||||
# def
|
||||
def process_range_time(self):
|
||||
for production in self:
|
||||
@@ -1104,6 +1134,7 @@ class MrpProduction(models.Model):
|
||||
'target': 'new',
|
||||
'context': {
|
||||
'default_production_id': self.id,
|
||||
'default_workorder_ids': self.workorder_ids.filtered(lambda wk: wk.state == 'done').ids,
|
||||
'default_reprogramming_num': cloud_programming['reprogramming_num'],
|
||||
'default_programming_state': cloud_programming['programming_state'],
|
||||
'default_is_reprogramming': True if cloud_programming['programming_state'] in ['已下发'] else False
|
||||
@@ -1229,6 +1260,7 @@ class MrpProduction(models.Model):
|
||||
重新生成制造订单
|
||||
"""
|
||||
if self.is_scrap is True:
|
||||
technology_design_values = []
|
||||
procurement_requests = []
|
||||
sale_order = self.env['sale.order'].sudo().search([('name', '=', self.origin)])
|
||||
values = self.env['mrp.production'].create_production1_values(self)
|
||||
@@ -1259,11 +1291,13 @@ class MrpProduction(models.Model):
|
||||
[('origin', '=', self.origin)], order='id desc', limit=1)
|
||||
move = self.env['stock.move'].search([('origin', '=', productions.name)], order='id desc')
|
||||
for mo in move:
|
||||
domain = []
|
||||
if mo.procure_method == 'make_to_order' and mo.name != productions.name:
|
||||
if mo.name == '/':
|
||||
domain = [('barcode', '=', 'WH-PC'), ('sequence_code', '=', 'PC')]
|
||||
elif mo.name == '拉':
|
||||
domain = [('barcode', '=', 'WH-INTERNAL'), ('sequence_code', '=', 'INT')]
|
||||
if domain:
|
||||
picking_type = self.env['stock.picking.type'].search(domain)
|
||||
mo.write({'picking_type_id': picking_type.id})
|
||||
mo._assign_picking()
|
||||
@@ -1315,10 +1349,72 @@ class MrpProduction(models.Model):
|
||||
if purchase_orders.origin.find(productions.name) == -1:
|
||||
purchase_orders.origin += ',' + productions.name
|
||||
if item['is_reprogramming'] is False:
|
||||
productions._create_workorder(item)
|
||||
productions.programming_state = '已编程'
|
||||
else:
|
||||
productions.programming_state = '编程中'
|
||||
if not technology_design_values:
|
||||
i = 0
|
||||
if self.product_id.categ_id.type == '成品':
|
||||
# 根据加工面板的面数及成品工序模板生成工序设计
|
||||
for k in (self.product_id.model_processing_panel.split(',')):
|
||||
if self.production_type == '自动化产线加工':
|
||||
product_routing_workcenter = self.env['sf.product.model.type.routing.sort'].search(
|
||||
[('product_model_type_id', '=',
|
||||
self.product_id.product_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
)
|
||||
else:
|
||||
product_routing_workcenter = self.env[
|
||||
'sf.manual.product.model.type.routing.sort'].search(
|
||||
[('manual_product_model_type_id', '=',
|
||||
self.product_id.product_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
)
|
||||
for route in product_routing_workcenter:
|
||||
i += 1
|
||||
technology_design_values.append(
|
||||
self.env['sf.technology.design'].json_technology_design_str(k, route, i, False))
|
||||
elif self.product_id.categ_id.type == '坯料':
|
||||
i = 0
|
||||
embryo_routing_workcenter = self.env['sf.embryo.model.type.routing.sort'].search(
|
||||
[('embryo_model_type_id', '=', self.product_id.embryo_model_type_id.id)],
|
||||
order='sequence asc'
|
||||
)
|
||||
for route_embryo in embryo_routing_workcenter:
|
||||
i += 1
|
||||
technology_design_values.append(
|
||||
self.env['sf.technology.design'].json_technology_design_str(False, route_embryo, i,
|
||||
False))
|
||||
surface_technics_arr = []
|
||||
route_workcenter_arr = []
|
||||
for item in self.product_id.product_model_type_id.surface_technics_routing_tmpl_ids:
|
||||
if item.route_workcenter_id.surface_technics_id.id:
|
||||
for process_param in self.product_id.model_process_parameters_ids:
|
||||
if item.route_workcenter_id.surface_technics_id == process_param.process_id:
|
||||
surface_technics_arr.append(
|
||||
item.route_workcenter_id.surface_technics_id.id)
|
||||
route_workcenter_arr.append(item.route_workcenter_id.id)
|
||||
if surface_technics_arr:
|
||||
production_process = self.env['sf.production.process'].search(
|
||||
[('id', 'in', surface_technics_arr)],
|
||||
order='sequence asc'
|
||||
)
|
||||
for p in production_process:
|
||||
# logging.info('production_process:%s' % p.name)
|
||||
process_parameter = self.product_id.model_process_parameters_ids.filtered(
|
||||
lambda pm: pm.process_id.id == p.id)
|
||||
if process_parameter:
|
||||
i += 1
|
||||
route_production_process = self.env[
|
||||
'mrp.routing.workcenter'].search(
|
||||
[('surface_technics_id', '=', p.id),
|
||||
('id', 'in', route_workcenter_arr)])
|
||||
technology_design_values.append(
|
||||
self.env['sf.technology.design'].json_technology_design_str(False,
|
||||
route_production_process,
|
||||
i,
|
||||
process_parameter))
|
||||
productions.technology_design_ids = technology_design_values
|
||||
return productions
|
||||
|
||||
# 在之前的销售单上重新生成制造订单
|
||||
|
||||
Reference in New Issue
Block a user