From a008dbb76a082cbc093c93b22df9b98233c07463 Mon Sep 17 00:00:00 2001 From: "jinling.yang" Date: Thu, 30 Mar 2023 17:52:05 +0800 Subject: [PATCH] =?UTF-8?q?1.sf=E7=9A=84=E5=B7=A5=E4=BD=9C=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=E6=96=B0=E5=A2=9E=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B7=A5=E5=BA=8F=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=EF=BC=8C=E4=B8=94=E5=BD=93=E5=B7=A5=E5=BA=8F=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=BA=E8=A1=A8=E9=9D=A2=E5=B7=A5=E8=89=BA=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=88=99=E6=98=BE=E7=A4=BA=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=EF=BC=8C=E5=85=B6=E4=BB=96=E5=88=99=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=202.sf=E7=9A=84=E5=B7=A5=E4=BD=9C=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=B7=A5=E8=89=BA=E5=A4=96=E5=8D=8F=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E8=AF=A5=E5=AD=97=E6=AE=B5=E8=8B=A5=E8=A2=AB?= =?UTF-8?q?=E5=8B=BE=E9=80=89=E5=88=99=E4=B8=BA=E8=A1=A8=E9=9D=A2=E5=B7=A5?= =?UTF-8?q?=E8=89=BA=E7=9A=84=E5=A4=96=E5=8D=8F=E5=8A=A0=E5=B7=A5=E4=B8=AD?= =?UTF-8?q?=E5=BF=83=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=84=E5=80=BC?= =?UTF-8?q?=E6=9D=A5=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_base/models/common.py | 8 ++- sf_manufacturing/models/model_type.py | 6 +- sf_manufacturing/models/mrp_production.py | 58 +++++++++++++------ .../models/mrp_routing_workcenter.py | 13 ++++- sf_manufacturing/models/mrp_workcenter.py | 7 ++- sf_manufacturing/models/mrp_workorder.py | 12 ++-- .../views/mrp_routing_workcenter_view.xml | 2 + .../views/mrp_workcenter_views.xml | 3 + 8 files changed, 79 insertions(+), 30 deletions(-) diff --git a/sf_base/models/common.py b/sf_base/models/common.py index 02d1237b..758a9950 100644 --- a/sf_base/models/common.py +++ b/sf_base/models/common.py @@ -66,7 +66,6 @@ class MrsProductionProcess(models.Model): # workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_process', required=True) - class MrsProcessingTechnology(models.Model): _name = 'sf.processing.technology' _description = '加工工艺' @@ -123,4 +122,9 @@ class MrsProductionProcessParameter(models.Model): # price = fields.Float('单价') process_id = fields.Many2one('sf.production.process', string='表面工艺') materials_model_ids = fields.Many2many('sf.materials.model', 'applicable_material', string='适用材料') - active = fields.Boolean('有效', default=True) \ No newline at end of file + active = fields.Boolean('有效', default=True) + + # 获取表面工艺的获取方式 + def get_gain_way(self, item): + process_parameter = self.env['sf.production.process.parameter'].search([('id', '=', item.id)]) + return process_parameter diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py index 2787d28e..c37711ed 100644 --- a/sf_manufacturing/models/model_type.py +++ b/sf_manufacturing/models/model_type.py @@ -29,7 +29,7 @@ class ProductModelTypeRoutingSort(models.Model): ('前置三元定位检测', '前置三元定位检测'), ('CNC加工', 'CNC加工'), ('后置三元质量检测', '后置三元质量检测'), - ('解除装夹', '解除装夹'), ('切割', '切割'), ('绑定表面工艺', '绑定表面工艺') + ('解除装夹', '解除装夹'), ('切割', '切割'), ('表面工艺', '表面工艺') ], string="工序类型", related='route_workcenter_id.routing_type') workcenter_ids = fields.Many2many('mrp.workcenter', required=False, related='route_workcenter_id.workcenter_ids') product_model_type_id = fields.Many2one('sf.model.type') @@ -52,7 +52,7 @@ class EmbryoModelTypeRoutingSort(models.Model): ('前置三元定位检测', '前置三元定位检测'), ('CNC加工', 'CNC加工'), ('后置三元质量检测', '后置三元质量检测'), - ('解除装夹', '解除装夹'), ('切割', '切割'), ('绑定表面工艺', '绑定表面工艺') + ('解除装夹', '解除装夹'), ('切割', '切割'), ('表面工艺', '表面工艺') ], string="工序类型", related='route_workcenter_id.routing_type') workcenter_ids = fields.Many2many('mrp.workcenter', required=False, related='route_workcenter_id.workcenter_ids') embryo_model_type_id = fields.Many2one('sf.model.type') @@ -75,7 +75,7 @@ class SurfaceTechnicsModelTypeRoutingSort(models.Model): ('前置三元定位检测', '前置三元定位检测'), ('CNC加工', 'CNC加工'), ('后置三元质量检测', '后置三元质量检测'), - ('解除装夹', '解除装夹'), ('切割', '切割'), ('绑定表面工艺', '绑定表面工艺') + ('解除装夹', '解除装夹'), ('切割', '切割'), ('表面工艺', '表面工艺') ], string="工序类型", related='route_workcenter_id.routing_type') workcenter_ids = fields.Many2many('mrp.workcenter', required=False, related='route_workcenter_id.workcenter_ids') surface_technics_model_type_id = fields.Many2one('sf.model.type') diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index b371fd29..d027b157 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -23,7 +23,7 @@ class MrpProduction(models.Model): for production in self: production.maintenance_count = len(production.request_ids) - #维修模块按钮 + # 维修模块按钮 def button_maintenance_req(self): self.ensure_one() return { @@ -37,7 +37,8 @@ class MrpProduction(models.Model): }, 'domain': [('production_id', '=', self.id)], } - #打开维修模块请求 + + # 打开维修模块请求 def open_maintenance_request_mo(self): self.ensure_one() action = { @@ -59,7 +60,8 @@ class MrpProduction(models.Model): def action_generate_serial(self): self.ensure_one() - iot_code = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env['ir.sequence'].next_by_code('stock.lot.serial') + iot_code = self.env['stock.lot']._get_next_serial(self.company_id, self.product_id) or self.env[ + 'ir.sequence'].next_by_code('stock.lot.serial') iot_code_name = re.sub('[\u4e00-\u9fa5]', "", iot_code) self.lot_producing_id = self.env['stock.lot'].create({ 'product_id': self.product_id.id, @@ -127,10 +129,33 @@ class MrpProduction(models.Model): if i == processing_panel_len and route.routing_type == '解除装夹': workorders_values.append( self.env['mrp.workorder'].json_workorder_str(k, production, route)) - # 表面工艺 - # for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: - # workorders_values.append( - # self.env['mrp.workorder']._json_workorder_surface_process_str(production, item)) + # 表面工艺工序 + # 获取表面工艺id + surface_technics_arr = [] + #工序id + route_workcenter_arr = [] + for item in production.product_id.product_model_type_id.surface_technics_routing_tmpl_ids: + surface_technics_arr.append(item.route_workcenter_id.surface_technics_id.id) + route_workcenter_arr.append(item.route_workcenter_id) + if surface_technics_arr: + production_process = self.env['sf.production.process.category'].search( + [('production_process_ids.id', 'in', surface_technics_arr)], + order='sequence asc' + ) + if production_process: + for p in production_process: + for pitem in p.production_process_ids: + if pitem.id in surface_technics_arr: + process_parameter = self.env['sf.production.process.parameter'].search( + [('id', '=', pitem.id)]) + for ritem in route_workcenter_arr: + route_production_process = self.env['mrp.routing.workcenter'].search( + [('surface_technics_id', '=', pitem.id), ('id', '=', ritem)]) + if route_production_process: + workorders_values.append( + self.env['mrp.workorder']._json_workorder_surface_process_str( + production, route_production_process, + process_parameter)) 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)], @@ -143,8 +168,7 @@ class MrpProduction(models.Model): for workorder in production.workorder_ids: workorder.duration_expected = workorder._get_duration_expected() - - #在之前的销售单上重新生成制造订单 + # 在之前的销售单上重新生成制造订单 def create_production1_values(self, production): production_values_str = {'origin': production.origin, 'product_id': production.product_id.id, @@ -166,7 +190,7 @@ class MrpProduction(models.Model): 'user_id': production.user_id.id} return production_values_str - #工单排序 + # 工单排序 def _reset_work_order_sequence1(self, k): sequen = 0 for rec in self: @@ -183,7 +207,7 @@ class MrpProduction(models.Model): if work.name == 'CNC加工(返工)' and work.processing_panel == k: work.sequence = sequen + 1 - #在制造订单上新增工单 + # 在制造订单上新增工单 def _create_workorder1(self, k): for production in self: if not production.bom_id or not production.product_id: @@ -217,9 +241,9 @@ class MrpProduction(models.Model): production.product_id.model_processing_panel = k for k in (production.product_id.model_processing_panel.split(',')): routingworkcenter = self.env['sf.product.model.type.routing.sort'].search( - [('product_model_type_id', '=', production.product_id.product_model_type_id.id)], - order='sequence asc' - ) + [('product_model_type_id', '=', production.product_id.product_model_type_id.id)], + order='sequence asc' + ) i += 1 for route in routingworkcenter: @@ -251,10 +275,10 @@ class MrpProduction(models.Model): current_sequence += 1 if work.name == '获取CNC加工程序': work.button_start() - #work.button_finish() - #work.fetchCNC() + # work.button_finish() + # work.fetchCNC() - #创建工单并进行排序 + # 创建工单并进行排序 def _create_workorder(self): res = self._create_workorder3() self._reset_work_order_sequence() diff --git a/sf_manufacturing/models/mrp_routing_workcenter.py b/sf_manufacturing/models/mrp_routing_workcenter.py index 8eb22ca5..7f7a98d7 100644 --- a/sf_manufacturing/models/mrp_routing_workcenter.py +++ b/sf_manufacturing/models/mrp_routing_workcenter.py @@ -1,4 +1,5 @@ from odoo import fields, models +import logging class ResMrpRoutingWorkcenter(models.Model): @@ -12,12 +13,13 @@ class ResMrpRoutingWorkcenter(models.Model): ('后置三元质量检测', '后置三元质量检测'), ('解除装夹', '解除装夹'), ('切割', '切割'), - ('绑定表面工艺', '绑定表面工艺') + ('表面工艺', '表面工艺') ], string="工序类型") is_repeat = fields.Boolean('重复', default=False) workcenter_id = fields.Many2one('mrp.workcenter', required=False) workcenter_ids = fields.Many2many('mrp.workcenter', 'rel_workcenter_route', required=True) bom_id = fields.Many2one('mrp.bom', required=False) + surface_technics_id = fields.Many2one('sf.production.process', string="表面工艺") # 获得当前登陆者公司 def get_company_id(self): @@ -25,6 +27,7 @@ class ResMrpRoutingWorkcenter(models.Model): company_id = fields.Many2one('res.company', compute="get_company_id", related=False) + # 排产的时候, 根据胚料的长宽高比对一下机床的最大加工尺寸.不符合就不要分配给这个加工中心(机床). # 工单对应的工作中心,根据工序中的工作中心去匹配, # 如果只配置了一个工作中心,则默认采用该工作中心; @@ -40,7 +43,7 @@ class ResMrpRoutingWorkcenter(models.Model): workcenter = self.env['mrp.workcenter'].search([('id', 'in', workcenter_ids)]) workcenter_ids = [] for item in workcenter: - print(item.name) + logging.info('get_workcenter-vals:%s' % item.machine_tool_id.name) if item.machine_tool_id: machine_tool = self.env['sf.machine_tool'].search( [('x_axis', '>', product.bom_ids.bom_line_ids.product_id.length), @@ -55,5 +58,9 @@ class ResMrpRoutingWorkcenter(models.Model): SELECT workcenter_id FROM mrp_workorder where workcenter_id in %s group by workcenter_id order by count(*),workcenter_id asc limit 1 """, [tuple(workcenter_ids)]) - workcenter_id = self.env.cr.dictfetchall()[0].get('workcenter_id') + res = self.env.cr.fetchone() + if res: + workcenter_id = self.env.cr.dictfetchall()[0].get('workcenter_id') + else: + workcenter_id = workcenter_ids[0] return workcenter_id diff --git a/sf_manufacturing/models/mrp_workcenter.py b/sf_manufacturing/models/mrp_workcenter.py index 5b266a20..fcfe04ce 100644 --- a/sf_manufacturing/models/mrp_workcenter.py +++ b/sf_manufacturing/models/mrp_workcenter.py @@ -7,13 +7,18 @@ from odoo.addons.resource.models.resource import Intervals class ResWorkcenter(models.Model): _inherit = "mrp.workcenter" machine_tool_id = fields.Many2one('sf.machine_tool', '机床') - + is_process_outsourcing = fields.Boolean('工艺外协') users_ids = fields.Many2many("res.users", 'users_workcenter') equipment_ids = fields.One2many( 'maintenance.equipment', 'workcenter_id', string="Maintenance Equipment", check_company=True) + # 查询工艺外协加工中心 + def get_process_outsourcing_workcenter(self): + outsourcing_workcenter = self.env['mrp.workcenter'].search([('is_process_outsourcing', '=', True)]) + return outsourcing_workcenter.id + @api.onchange('machine_tool_id') def update_machine_tool_is_binding(self): machine_tool = self.env["sf.machine_tool"].search([('is_binding', '=', True)]) diff --git a/sf_manufacturing/models/mrp_workorder.py b/sf_manufacturing/models/mrp_workorder.py index 6b0d5b2a..5a049d0d 100644 --- a/sf_manufacturing/models/mrp_workorder.py +++ b/sf_manufacturing/models/mrp_workorder.py @@ -29,7 +29,7 @@ class ResMrpWorkOrder(models.Model): ('CNC加工', 'CNC加工'), ('后置三元质量检测', '后置三元质量检测'), ('解除装夹', '解除装夹'), - ('切割', '切割'), ('绑定表面工艺', '绑定表面工艺') + ('切割', '切割'), ('表面工艺', '表面工艺') ], string="工序类型") results = fields.Char('检测结果') @@ -158,16 +158,20 @@ class ResMrpWorkOrder(models.Model): return workorders_values_str # 拼接工单对象属性值(表面工艺) - def _json_workorder_surface_process_str(self, production, route): + def _json_workorder_surface_process_str(self, production, route, process_parameter): workorders_values_str = [0, '', { 'product_uom_id': production.product_uom_id.id, 'qty_producing': 0, 'operation_id': False, 'name': route.name, 'processing_panel': '', - 'routing_type': '绑定表面工艺', + 'routing_type': '表面工艺', 'work_state': '', - 'workcenter_id': '', + 'workcenter_id': self.env[ + 'mrp.workcenter'].get_process_outsourcing_workcenter() if process_parameter.gain_way == '外协' else + self.env['mrp.routing.workcenter'].get_workcenter(route.workcenter_ids.ids, + route.routing_type, + production.product_id), 'date_planned_start': False, 'date_planned_finished': False, 'duration_expected': 60, diff --git a/sf_manufacturing/views/mrp_routing_workcenter_view.xml b/sf_manufacturing/views/mrp_routing_workcenter_view.xml index b854160a..d0db3a7b 100644 --- a/sf_manufacturing/views/mrp_routing_workcenter_view.xml +++ b/sf_manufacturing/views/mrp_routing_workcenter_view.xml @@ -8,6 +8,8 @@ + diff --git a/sf_manufacturing/views/mrp_workcenter_views.xml b/sf_manufacturing/views/mrp_workcenter_views.xml index cc6f1ba9..8c16f783 100644 --- a/sf_manufacturing/views/mrp_workcenter_views.xml +++ b/sf_manufacturing/views/mrp_workcenter_views.xml @@ -109,6 +109,9 @@ + + +