diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 27b75ff9..d2b63cb9 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -1101,67 +1101,19 @@ class MrpProduction(models.Model): ('is_subcontract', '=', True)]) if scarp_process_parameter_workorder: production_programming = self.env['mrp.production'].search( - [('programming_no', '=', self.programming_no)], order='name asc') + [('programming_no', '=', self.programming_no), ('id', '!=', productions.id)], order='name asc') production_list = [production.name for production in production_programming] - purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))]) + purchase_orders = self.env['purchase.order'].search([('origin', 'ilike', ','.join(production_list))]) for purchase_item in purchase_orders.order_line: for process_item in scarp_process_parameter_workorder: if purchase_item.product_id.categ_type == '表面工艺': if purchase_item.product_id.server_product_process_parameters_id == process_item.surface_technics_parameters_id: - print(purchase_orders.find(productions.name)) - if purchase_orders.find(productions.name) == -1: - purchase_orders.origin += productions.name + print(purchase_orders.origin.find(productions.name)) + 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 = '已编程' - 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) else: productions.programming_state = '编程中' return productions diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 63ff1551..485eb290 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -58,6 +58,7 @@ class ResMrpWorkOrder(models.Model): ('cancel', '取消')], string='Status', compute='_compute_state', store=True, default='pending', copy=False, readonly=True, recursive=True, index=True, tracking=True) + # state = fields.Selection(selection_add=[('to be detected', "待检测"), ('rework', '返工')], tracking=True) @api.depends('production_id.manual_quotation') @@ -183,17 +184,12 @@ class ResMrpWorkOrder(models.Model): 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) production_list = [production.name for production in production_programming] purchase = self.env['purchase.order'].search([('origin', '=', ','.join(production_list))]) 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_programming): - # server_product = self.env['product.template'].search( - # [('server_product_process_parameters_id', '=', pp.id), - # ('detailed_type', '=', 'service')]) - # purchase_order_line = self.env['purchase.order.line'].search( - # [('product_id', '=', server_product.id), ('product_qty', '=', len(production_programming))]) - # if purchase_order_line: + production_no_remanufacture): order.surface_technics_purchase_count = len(purchase) else: order.surface_technics_purchase_count = 0 @@ -243,6 +239,7 @@ class ResMrpWorkOrder(models.Model): store=True, compute='_compute_tool_state') tool_state_remark = fields.Text(string='功能刀具状态备注(缺刀)', compute='_compute_tool_state_remark', store=True) reserved_duration = fields.Float('预留时长', default=30, tracking=True) + @api.depends('cnc_ids.tool_state') def _compute_tool_state_remark(self): for item in self: @@ -651,7 +648,7 @@ class ResMrpWorkOrder(models.Model): # 拼接工单对象属性值 def json_workorder_str(self, k, production, route, item): # 计算预计时长duration_expected - routing_types = ['切割', '装夹预调', 'CNC加工','解除装夹'] + routing_types = ['切割', '装夹预调', 'CNC加工', '解除装夹'] if route.routing_type in routing_types: routing_workcenter = self.env['mrp.routing.workcenter'].sudo().search( [('name', '=', route.routing_type)]) @@ -704,7 +701,7 @@ class ResMrpWorkOrder(models.Model): item), # 'workpiece_delivery_ids': False if not route.routing_type == '装夹预调' else self._json_workpiece_delivery_list( # production) - 'reserved_duration': reserved_duration, + 'reserved_duration': reserved_duration, }] return workorders_values_str @@ -1169,8 +1166,9 @@ class ResMrpWorkOrder(models.Model): if record.routing_type == '装夹预调': if not record.rfid_code and record.is_rework is False: raise UserError("请扫RFID码进行绑定") - if not record.material_center_point and record.X_deviation_angle > 0: - raise UserError("坯料中心点为空或X偏差角度小于等于0") + if record.is_rework is False: + if not record.material_center_point or record.X_deviation_angle <= 0: + raise UserError("请对前置三元检测定位参数进行计算定位") record.process_state = '待加工' # record.write({'process_state': '待加工'}) record.production_id.process_state = '待加工' diff --git a/sf_manufacturing/models/stock.py b/sf_manufacturing/models/stock.py index 76c51cff..b9483a17 100644 --- a/sf_manufacturing/models/stock.py +++ b/sf_manufacturing/models/stock.py @@ -288,28 +288,46 @@ class StockRule(models.Model): # 为同一个product_id创建一个生产订单名称列表 product_id_to_production_names[product_id] = [production.name for production in all_production] for production_item in productions: + production_programming = self.env['mrp.production'].search( + [('product_id.id', '=', production_item.product_id.id), + ('origin', '=', production_item.origin)], + limit=1, order='id asc') if production_item.product_id.id in product_id_to_production_names: - if production_item.product_id.model_process_parameters_ids: - is_purchase = False - sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, - key=lambda w: w.id) + if not production_programming.programming_no: + if production_item.product_id.model_process_parameters_ids: + is_purchase = False + sorted_process_parameters = sorted(production_item.product_id.model_process_parameters_ids, + key=lambda w: w.id) - consecutive_process_parameters = [] - m = 0 - for i in range(len(sorted_process_parameters) - 1): - if m == 0: - is_purchase = False - if self.env['product.template']._get_process_parameters_product( - sorted_process_parameters[i]).partner_id == self.env[ - 'product.template']._get_process_parameters_product(sorted_process_parameters[ - i + 1]).partner_id and \ - sorted_process_parameters[i].gain_way == '外协': - if sorted_process_parameters[i] not in consecutive_process_parameters: - consecutive_process_parameters.append(sorted_process_parameters[i]) - consecutive_process_parameters.append(sorted_process_parameters[i + 1]) - m += 1 - continue - else: + consecutive_process_parameters = [] + m = 0 + for i in range(len(sorted_process_parameters) - 1): + if m == 0: + is_purchase = False + if self.env['product.template']._get_process_parameters_product( + sorted_process_parameters[i]).partner_id == self.env[ + 'product.template']._get_process_parameters_product(sorted_process_parameters[ + i + 1]).partner_id and \ + sorted_process_parameters[i].gain_way == '外协': + if sorted_process_parameters[i] not in consecutive_process_parameters: + consecutive_process_parameters.append(sorted_process_parameters[i]) + consecutive_process_parameters.append(sorted_process_parameters[i + 1]) + m += 1 + continue + else: + if m == len(consecutive_process_parameters) - 1 and m != 0: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + production_item, + product_id_to_production_names) + if sorted_process_parameters[i] in consecutive_process_parameters: + is_purchase = True + consecutive_process_parameters = [] + m = 0 + # 当前面的连续外协采购单生成再生成当前外协采购单 + if is_purchase is False: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, + production_item, + product_id_to_production_names) if m == len(consecutive_process_parameters) - 1 and m != 0: self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, production_item, @@ -318,39 +336,22 @@ class StockRule(models.Model): is_purchase = True consecutive_process_parameters = [] m = 0 - # 当前面的连续外协采购单生成再生成当前外协采购单 - if is_purchase is False: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if m == len(consecutive_process_parameters) - 1 and m != 0: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if sorted_process_parameters[i] in consecutive_process_parameters: - is_purchase = True - consecutive_process_parameters = [] - m = 0 - if m == len(consecutive_process_parameters) - 1 and m != 0: - self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, - production_item, - product_id_to_production_names) - if is_purchase is False and m == 0: - if len(sorted_process_parameters) == 1: - self.env['purchase.order'].get_purchase_order(sorted_process_parameters, - production_item, - product_id_to_production_names) - else: - self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], + if m == len(consecutive_process_parameters) - 1 and m != 0: + self.env['purchase.order'].get_purchase_order(consecutive_process_parameters, production_item, product_id_to_production_names) + if is_purchase is False and m == 0: + if len(sorted_process_parameters) == 1: + self.env['purchase.order'].get_purchase_order(sorted_process_parameters, + production_item, + product_id_to_production_names) + else: + self.env['purchase.order'].get_purchase_order(sorted_process_parameters[i], + production_item, + product_id_to_production_names) # # 同一个产品多个制造订单对应一个编程单和模型库 # # 只调用一次fetchCNC,并将所有生产订单的名称作为字符串传递 if not production_item.programming_no: - production_programming = self.env['mrp.production'].search( - [('product_id.id', '=', production_item.product_id.id), - ('origin', '=', production_item.origin)], - limit=1, order='id asc') if not production_programming.programming_no: production_item.fetchCNC( ', '.join(product_id_to_production_names[production_item.product_id.id])) @@ -544,7 +545,7 @@ class StockPicking(models.Model): # 设置外协出入单的名称 def _get_name_Res(self, rescode): - last_picking = self.sudo().search([('name', 'like', rescode)], order='create_date desc,id desc', limit=1) + last_picking = self.sudo().search([('name', 'ilike', rescode)], order='create_date desc,id desc', limit=1) if not last_picking: num = "%04d" % 1 else: diff --git a/sf_manufacturing/views/mrp_production_addional_change.xml b/sf_manufacturing/views/mrp_production_addional_change.xml index 6fa14a6f..58dc1513 100644 --- a/sf_manufacturing/views/mrp_production_addional_change.xml +++ b/sf_manufacturing/views/mrp_production_addional_change.xml @@ -437,6 +437,12 @@