diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py
index fc4ccbeb..45808521 100644
--- a/sf_manufacturing/models/mrp_production.py
+++ b/sf_manufacturing/models/mrp_production.py
@@ -315,7 +315,7 @@ class MrpProduction(models.Model):
production.fetchCNC(', '.join(product_id_to_production_names[production.product_id.id]))
else:
production.write({'programming_no': production_programming.programming_no,
- 'programming_state': '编程中'})
+ 'programming_state': '已编程' if production_programming.programming_state == '已编程' else '编程中'})
# # 根据加工面板的面数及对应的工序模板生成工单
i = 0
processing_panel_len = len(production.product_id.model_processing_panel.split(','))
@@ -406,20 +406,15 @@ class MrpProduction(models.Model):
# 工单排序
def _reset_work_order_sequence1(self, k):
- sequen = 0
for rec in self:
- current_sequence = 10
+ cnc_workorder = rec.workorder_ids.filtered(lambda wo: wo.name == "CNC加工")
+ cnc_back_workorder = rec.workorder_ids.filtered(lambda wo: wo.name == "CNC加工(返工)")
for work in rec.workorder_ids:
- work.sequence = current_sequence
- current_sequence += 10
- if work.name == '后置三元质量检测' and work.processing_panel == k:
- sequen = work.sequence
-
- for work in rec.workorder_ids:
- if work.name == '后置三元质量检测(返工)' and work.processing_panel == k:
- work.sequence = sequen + 2
- if work.name == 'CNC加工(返工)' and work.processing_panel == k:
- work.sequence = sequen + 1
+ if work.name == cnc_workorder.name and work.processing_panel == k:
+ cnc_back_workorder.write({'sequence': work.sequence + 1})
+ print(cnc_back_workorder.sequence)
+ elif work.routing_type not in ['装夹预调'] and work != cnc_back_workorder:
+ work.sequence += 1
# 在制造订单上新增工单
def _create_workorder1(self, k):
@@ -459,13 +454,7 @@ class MrpProduction(models.Model):
order='sequence asc'
)
i += 1
-
for route in routingworkcenter:
-
- # if route.routing_type == '后置三元质量检测':
- # workorders_values.append(
- # self.env['mrp.workorder'].json_workorder_str1(k, production, route)
- # )
if route.routing_type == 'CNC加工':
workorders_values.append(
self.env['mrp.workorder'].json_workorder_str1(k, production, route))
diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py
index 522c8c02..d389ba80 100644
--- a/sf_manufacturing/models/mrp_workorder.py
+++ b/sf_manufacturing/models/mrp_workorder.py
@@ -677,13 +677,59 @@ class ResMrpWorkOrder(models.Model):
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(
self.production_id.company_id).create(
values)
- self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
+ # self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
productions._create_workorder()
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and
not p.move_raw_ids and not p.workorder_ids)).action_confirm()
+ for production_item in productions:
+ process_parameter_workorder = self.env['mrp.workorder'].search(
+ [('surface_technics_parameters_id', '!=', False), ('production_id', '=', production_item.id),
+ ('is_subcontract', '=', True)])
+ if process_parameter_workorder:
+ is_pick = False
+ consecutive_workorders = []
+ m = 0
+ sorted_workorders = sorted(process_parameter_workorder, key=lambda w: w.id)
+ for i in range(len(sorted_workorders) - 1):
+ if m == 0:
+ is_pick = False
+ if sorted_workorders[i].supplier_id.id == sorted_workorders[i + 1].supplier_id.id and \
+ sorted_workorders[i].is_subcontract == sorted_workorders[i + 1].is_subcontract and \
+ sorted_workorders[i].id == sorted_workorders[i + 1].id - 1:
+ if sorted_workorders[i] not in consecutive_workorders:
+ consecutive_workorders.append(sorted_workorders[i])
+ consecutive_workorders.append(sorted_workorders[i + 1])
+ m += 1
+ continue
+ else:
+ if m == len(consecutive_workorders) - 1 and m != 0:
+ self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
+ production_item)
+ if sorted_workorders[i] in consecutive_workorders:
+ is_pick = True
+ consecutive_workorders = []
+ m = 0
+ # 当前面的连续工序生成对应的外协出入库单再生成当前工序的外协出入库单
+ if is_pick is False:
+ self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i],
+ production_item)
+ if m == len(consecutive_workorders) - 1 and m != 0:
+ self.env['stock.picking'].create_outcontract_picking(consecutive_workorders,
+ production_item)
+ if sorted_workorders[i] in consecutive_workorders:
+ is_pick = True
+ consecutive_workorders = []
+ m = 0
+ if m == len(consecutive_workorders) - 1 and m != 0:
+ self.env['stock.picking'].create_outcontract_picking(consecutive_workorders, production_item)
+ if is_pick is False and m == 0:
+ if len(sorted_workorders) == 1:
+ self.env['stock.picking'].create_outcontract_picking(sorted_workorders, production_item)
+ else:
+ self.env['stock.picking'].create_outcontract_picking(sorted_workorders[i], production_item)
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[
@@ -704,6 +750,28 @@ class ResMrpWorkOrder(models.Model):
'mail.message_origin_link',
values={'self': production, 'origin': origin_production},
subtype_id=self.env.ref('mail.mt_note').id)
+
+ '''
+ 创建生产计划
+ '''
+ # 工单耗时
+ workorder_duration = 0
+ for workorder in productions.workorder_ids:
+ workorder_duration += workorder.duration_expected
+
+ sale_order = self.env['sale.order'].sudo().search([('name', '=', productions.origin)])
+ if sale_order:
+ # sale_order.write({'schedule_status': 'to schedule'})
+ self.env['sf.production.plan'].sudo().with_company(self.production_id.company_id).create({
+ 'name': productions.name,
+ 'order_deadline': sale_order.deadline_of_delivery,
+ 'production_id': productions.id,
+ 'date_planned_start': productions.date_planned_start,
+ 'origin': productions.origin,
+ 'product_qty': productions.product_qty,
+ 'product_id': productions.product_id.id,
+ 'state': 'draft',
+ })
if self.test_results == '返工':
productions = self.production_id
# self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
@@ -720,7 +788,6 @@ class ResMrpWorkOrder(models.Model):
'name': '%s(返工)' % route.route_workcenter_id.name,
'processing_panel': k,
'routing_type': route.routing_type,
- 'work_state': '' if not route.routing_type == '获取CNC加工程序' else '待发起',
'workcenter_id': self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids,
route.routing_type,
production.product_id),
@@ -728,10 +795,38 @@ class ResMrpWorkOrder(models.Model):
'date_planned_finished': datetime.now() + timedelta(days=1),
'duration_expected': 60,
'duration': 0,
-
+ 'manual_quotation': production.workorder_ids.filtered(
+ lambda t: t.routing_type == 'CNC加工').manual_quotation,
+ 'rfid_code': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').rfid_code,
+ 'cnc_ids': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').cnc_ids,
+ 'cmm_ids': production.workorder_ids.filtered(lambda t: t.routing_type == 'CNC加工').cmm_ids,
}]
return workorders_values_str
+ @api.depends('production_availability', 'blocked_by_workorder_ids', 'blocked_by_workorder_ids.state')
+ def _compute_state(self):
+ super(ResMrpWorkOrder, self)._compute_state()
+ for item in self:
+ scrap_workorder = self.env['mrp.workorder'].search(
+ [('production_id', '=', item.production_id.id), ('routing_type', '=', 'CNC加工'),
+ ('state', '=', 'done'), ('is_remanufacture', '=', True)])
+ print(item.name)
+ print(item.state)
+ if item.name == 'CNC加工(返工)' and item.state not in ['ready', 'progress', 'done']:
+ item.state = 'ready'
+ if item.routing_type == '解除装夹':
+ last_workorder = self.env['mrp.workorder'].search(
+ [('production_id', '=', item.production_id.id), ('name', '=', 'CNC加工(返工)'),
+ ('state', '!=', 'done')])
+ if item.state != 'pending':
+ if last_workorder:
+ item.state = 'pending'
+ if scrap_workorder:
+ item.state = 'cancel'
+ elif item.routing_type == '表面工艺':
+ if scrap_workorder:
+ item.state = 'cancel'
+
# 重写工单开始按钮方法
def button_start(self):
if self.routing_type == '装夹预调':
@@ -895,6 +990,8 @@ class ResMrpWorkOrder(models.Model):
record.write({
'date_planned_finished': tem_date_planned_finished # 保持原值
})
+ if record.routing_type == 'CNC加工' and record.test_results in ['返工', '报废']:
+ record.recreateManufacturingOrWorkerOrder()
is_production_id = True
for workorder in record.production_id.workorder_ids:
if workorder.state != 'done':
diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml
index 94f469ea..30801086 100644
--- a/sf_manufacturing/views/mrp_workorder_view.xml
+++ b/sf_manufacturing/views/mrp_workorder_view.xml
@@ -80,7 +80,7 @@
tree,form
-
+
current
[('state', '!=', 'cancel'),('schedule_state', '=', '已排')]
@@ -477,7 +477,7 @@
-
+
diff --git a/sf_mrs_connect/models/ftp_operate.py b/sf_mrs_connect/models/ftp_operate.py
index 3a09a305..8b547bb3 100644
--- a/sf_mrs_connect/models/ftp_operate.py
+++ b/sf_mrs_connect/models/ftp_operate.py
@@ -32,6 +32,9 @@ class FtpController():
logging.error(f"Error checking file: {e}")
return False
+
+
+
# # 检测字符串的编码
# def detect_encoding(self, s):
# result = chardet.detect(s)