diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index b4fa41c8..1f304950 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -187,6 +187,23 @@ class ResMrpWorkOrder(models.Model): # 拼接工单对象属性值 def json_workorder_str(self, k, production, route): + # 计算预计时长duration_expected + if route.routing_type == '切割': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '切割')]).time_cycle + elif route.routing_type == '获取CNC加工程序': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '获取CNC加工程序')]).time_cycle + elif route.routing_type == '工件装夹': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '工件装夹')]).time_cycle + elif route.routing_type == '前置三元定位检测': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '前置三元定位检测')]).time_cycle + elif route.routing_type == 'CNC加工': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', 'CNC加工')]).time_cycle + elif route.routing_type == '后置三元质量检测': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '后置三元质量检测')]).time_cycle + elif route.routing_type == '解除装夹': + duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', '解除装夹')]).time_cycle + else: + duration_expected = 60 workorders_values_str = [0, '', { 'product_uom_id': production.product_uom_id.id, 'qty_producing': 0, @@ -201,7 +218,7 @@ class ResMrpWorkOrder(models.Model): production.product_id), 'date_planned_start': False, 'date_planned_finished': False, - 'duration_expected': 60, + 'duration_expected': duration_expected, 'duration': 0, }] diff --git a/sf_plan/models/custom_plan.py b/sf_plan/models/custom_plan.py index e80a7783..9c94fa22 100644 --- a/sf_plan/models/custom_plan.py +++ b/sf_plan/models/custom_plan.py @@ -11,6 +11,7 @@ class sf_production_plan(models.Model): _name = 'sf.production.plan' # _inherit = 'mrp.production' _description = 'sf_production_plan' + _order = 'create_date desc' state = fields.Selection([ ('draft', '待排程'), @@ -41,18 +42,12 @@ class sf_production_plan(models.Model): actual_end_time = fields.Datetime(string='实际结束时间') shift = fields.Char(string='班次') - # 序号、坯料编号、坯料名称、材质、数量、长度、宽度、厚度、直径、计划开始时间、计划结束时间、状态(已产出与待产出)、操作、创建人、创建时间、客户名称、订单号、行号、长度、宽度、厚度、直径、交货数量、交货日期 # sequence = fields.Integer(string='序号', required=True, copy=False, readonly=True, index=True, # default=lambda self: self.env['ir.sequence'].sudo().next_by_code('sf.pl.plan')) sequence = fields.Integer(string='序号', copy=False, readonly=True, index=True) current_operation_name = fields.Char(string='当前工序名称', size=64, default='生产计划') - - - - - # state = fields.Selection([ # ('未排程', '未排程'), ('已排程', '已排程')], string='State', copy=False, index=True, readonly=True, # store=True, tracking=True) @@ -179,16 +174,62 @@ class sf_production_plan(models.Model): else: aa = self.env['mrp.production'].sudo().search([('name', '=', self.name)]) workorder_time = 0 - print(aa.workorder_ids) - print(type(aa.workorder_ids)) - if aa.workorder_ids: - for item in aa.workorder_ids: - current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)]) - workorder_time += current_workorder.duration_expected - print(workorder_time) + workorder_id_list = self.production_id.workorder_ids.ids + print(workorder_id_list) + print(type(self.production_id.workorder_ids)) + if self.production_id.workorder_ids: + for item in self.production_id.workorder_ids: + if item.name == 'CNC加工': + item.date_planned_start = self.date_planned_start + item.date_planned_finished = item.date_planned_start + timedelta( + minutes=self.env['mrp.routing.workcenter'].sudo().search( + [('name', '=', 'CNC加工')]).time_cycle) + item.duration_expected = self.env['mrp.routing.workcenter'].sudo().search( + [('name', '=', 'CNC加工')]).time_cycle + # print(item.id) + sequence = workorder_id_list.index(item.id) - 1 + # print('sequence', sequence) + # print('total', len(workorder_id_list)) + # 计算CNC加工之前工单的开始结束时间 + for i in range(sequence): + current_workorder_id = (item.id - (i + 1)) + current_workorder_obj = self.env['mrp.workorder'].sudo().search( + [('id', '=', current_workorder_id)]) + old_workorder_obj = self.env['mrp.workorder'].sudo().search( + [('id', '=', (current_workorder_id + 1))]) + work_order = self.env['mrp.workorder'].sudo().search( + [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)]) + work_order.date_planned_finished = old_workorder_obj.date_planned_start + work_order.date_planned_start = old_workorder_obj.date_planned_start - timedelta( + minutes=self.env['mrp.routing.workcenter'].sudo().search( + [('name', '=', current_workorder_obj.name)]).time_cycle) + # work_order.duration_expected = self.env['mrp.routing.workcenter'].sudo().search([('name', '=', current_workorder_obj.name)]).time_cycle + # 计算CNC加工之后工单的开始结束时间 + for j in range(len(workorder_id_list) - sequence - 2): + current_workorder_id = (item.id + (j + 1)) + current_workorder_obj = self.env['mrp.workorder'].sudo().search( + [('id', '=', current_workorder_id)]) + old_workorder_obj = self.env['mrp.workorder'].sudo().search( + [('id', '=', (current_workorder_id - 1))]) + work_order = self.env['mrp.workorder'].sudo().search( + [('production_id', '=', self.production_id.id), ('id', '=', current_workorder_id)]) + try: + work_order.date_planned_start = old_workorder_obj.date_planned_finished + print('work_order.data_start', work_order.date_planned_start) + work_order.date_planned_finished = old_workorder_obj.date_planned_finished + timedelta( + minutes=self.env['mrp.routing.workcenter'].sudo().search( + [('name', '=', current_workorder_obj.name)]).time_cycle) + except ValueError as e: + print('时间设置失败,请检查是否为工序分配工作中心,%s' % e) + + current_workorder = self.env['mrp.workorder'].sudo().search([('id', '=', item.id)]) + workorder_time += current_workorder.duration_expected + print('workorder_time', workorder_time) self.date_planned_finished = self.date_planned_start + timedelta(minutes=workorder_time) self.state = 'done' - aa.schedule_state = '已排' + self.production_id.schedule_state = '已排' + # self.production_id.date_planned_start = self.date_planned_start + # self.production_id.date_planned_finished = self.date_planned_finished else: raise ValidationError("未找到工单") # self.date_planned_finished = self.date_planned_start + timedelta(days=3) diff --git a/sf_plan/static/src/xlsx/sf_production_plan.xlsx b/sf_plan/static/src/xlsx/sf_production_plan.xlsx index a82cab58..901d4beb 100644 Binary files a/sf_plan/static/src/xlsx/sf_production_plan.xlsx and b/sf_plan/static/src/xlsx/sf_production_plan.xlsx differ diff --git a/sf_plan_management/views/operations_rename_menu.xml b/sf_plan_management/views/operations_rename_menu.xml index 659df6dd..1af2ba72 100644 --- a/sf_plan_management/views/operations_rename_menu.xml +++ b/sf_plan_management/views/operations_rename_menu.xml @@ -50,39 +50,39 @@ - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - 应收应付 - - + + + + - - - + + +