From 821a7a63be53927637ede9ea675fe7e415966da1 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Wed, 28 Aug 2024 17:30:46 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=B7=A5=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/models/mrp_production.py | 56 +---------- sf_manufacturing/models/mrp_workorder.py | 11 ++- sf_manufacturing/models/product_template.py | 4 +- sf_manufacturing/models/stock.py | 99 ++++++++++--------- .../views/mrp_production_addional_change.xml | 6 ++ sf_manufacturing/views/mrp_workorder_view.xml | 2 +- sf_mrs_connect/controllers/controllers.py | 2 +- sf_sale/models/quick_easy_order.py | 4 +- sf_sale/models/quick_easy_order_old.py | 4 +- 9 files changed, 75 insertions(+), 113 deletions(-) diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index 118bb0ff..3b72702d 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -1097,67 +1097,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), ('is_remanufacture', '=', False)], order='name asc') production_list = [production.name for production in production_programming] purchase_orders = self.env['purchase.order'].search([('origin', '=', ','.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 8bce60d6..baf516a3 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') @@ -243,6 +244,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 +653,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 +706,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 +1171,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 or record.X_deviation_angle <= 0: - raise UserError("请对前置三元检测定位参数进行计算定位") + # 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/product_template.py b/sf_manufacturing/models/product_template.py index 071f1167..37fa02bd 100644 --- a/sf_manufacturing/models/product_template.py +++ b/sf_manufacturing/models/product_template.py @@ -9,8 +9,8 @@ from odoo.exceptions import ValidationError, UserError from odoo.modules import get_resource_path -from OCC.Extend.DataExchange import read_step_file -from OCC.Extend.DataExchange import write_stl_file +# from OCC.Extend.DataExchange import read_step_file +# from OCC.Extend.DataExchange import write_stl_file class ResProductMo(models.Model): 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 @@