diff --git a/sf_manufacturing/__manifest__.py b/sf_manufacturing/__manifest__.py index 56b8514b..985b87a4 100644 --- a/sf_manufacturing/__manifest__.py +++ b/sf_manufacturing/__manifest__.py @@ -14,6 +14,7 @@ 'data': [ 'data/stock_data.xml', 'data/empty_racks_data.xml', + 'data/panel_data.xml', 'security/group_security.xml', 'security/ir.model.access.csv', 'wizard/workpiece_delivery_views.xml', diff --git a/sf_manufacturing/data/panel_data.xml b/sf_manufacturing/data/panel_data.xml new file mode 100644 index 00000000..0bdf4aa3 --- /dev/null +++ b/sf_manufacturing/data/panel_data.xml @@ -0,0 +1,24 @@ + + + + + ZM + + + + FM + + + YC + + + ZC + + + QC + + + HC + + + \ No newline at end of file diff --git a/sf_manufacturing/models/mrp_production.py b/sf_manufacturing/models/mrp_production.py index f0b88d63..cf9708f9 100644 --- a/sf_manufacturing/models/mrp_production.py +++ b/sf_manufacturing/models/mrp_production.py @@ -691,7 +691,17 @@ class MrpProduction(models.Model): # 返工 def button_rework(self): - return True + return { + 'name': _('返工'), + 'type': 'ir.actions.act_window', + 'view_mode': 'form', + 'res_model': 'sf.rework.wizard', + 'target': 'new', + 'context': { + 'default_production_id': [(6, 0, [self.id])], + 'default_product_id': self.product_id.id + } + } # 报废 def button_scrap_new(self): @@ -733,3 +743,26 @@ class sf_detection_result(models.Model): # }, 'target': 'new' } + + +class sf_processing_panel(models.Model): + _name = 'sf.processing.panel' + _description = "加工面" + + name = fields.Char('加工面') + active = fields.Boolean('有效', default=True) + + # @api.model + # def name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None): + # if self.env.user.has_group('sf_base.group_sf_order_user'): + # if self._context.get('product_id'): + # product = self.env['product.product'].search([('id', '=', self._context.get('product_id'))]) + # if product: + # panel = self.env['sf.processing.panel'].search([('name', 'ilike', 'ZM')]) + # if panel: + # ids = [t.id for t in panel] + # domain = [('id', 'in', ids)] + # else: + # domain = [('id', '=', False)] + # return self._search(domain, limit=limit, access_rights_uid=name_get_uid) + # return super()._name_search(name, args, operator, limit, name_get_uid) diff --git a/sf_manufacturing/security/ir.model.access.csv b/sf_manufacturing/security/ir.model.access.csv index 20a58086..5cdb72b7 100644 --- a/sf_manufacturing/security/ir.model.access.csv +++ b/sf_manufacturing/security/ir.model.access.csv @@ -143,4 +143,6 @@ access_mrp_bom_byproduct_group_sf_stock_manager,mrp_bom_byproduct_group_sf_mrp_m access_sf_rework_wizard_group_sf_order_user,sf_rework_wizard_group_sf_order_user,model_sf_rework_wizard,sf_base.group_sf_order_user,1,1,1,0 access_sf_detection_result_group_sf_order_user,sf_detection_result_group_sf_order_user,model_sf_detection_result,sf_base.group_sf_order_user,1,1,1,0 +access_sf_processing_panel_group_sf_order_user,sf_processing_panel_group_sf_order_user,model_sf_processing_panel,sf_base.group_sf_order_user,1,1,1,0 + diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index 1e4dd81b..42aa5891 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -184,7 +184,7 @@ - @@ -217,11 +217,11 @@ attrs="{'invisible': [('routing_type', '!=', 'CNC加工')]}"/> - - diff --git a/sf_manufacturing/wizard/rework_wizard.py b/sf_manufacturing/wizard/rework_wizard.py index 63b50507..38637482 100644 --- a/sf_manufacturing/wizard/rework_wizard.py +++ b/sf_manufacturing/wizard/rework_wizard.py @@ -11,6 +11,7 @@ class ReworkWizard(models.TransientModel): _description = '返工向导' workorder_id = fields.Many2one('mrp.workorder', string='工单') + product_id = fields.Many2one('product.product') production_ids = fields.Many2many('mrp.production', string='制造订单号') rework_reason = fields.Selection( [("programming", "编程"), ("cutter", "刀具"), ("clamping", "装夹"), @@ -20,13 +21,33 @@ class ReworkWizard(models.TransientModel): routing_type = fields.Selection([ ('装夹预调', '装夹预调'), ('CNC加工', 'CNC加工')], string="工序类型") + # 根据工单的加工面来显示 + processing_panel_id = fields.Many2one('sf.processing.panel', string="加工面") def confirm(self): - self.workorder_id.is_rework = True + if len(self.production_ids) == 1: + self.workorder_id.is_rework = True self.production_ids.write({'detection_result_ids': [(0, 0, { 'rework_reason': self.rework_reason, 'detailed_reason': self.detailed_reason, - 'processing_panel': self.workorder_id.processing_panel, + # 'processing_panel': self.workorder_id.processing_panel, 'routing_type': self.workorder_id.routing_type, 'test_results': self.workorder_id.test_results, 'test_report': self.workorder_id.detection_report})]}) + + @api.onchange('product_id') + def onchange_processing_panel_id(self): + for item in self: + domain = [('id', '=', False)] + product_id = item.product_id + if product_id: + if self.env.user.has_group('sf_base.group_sf_order_user'): + panel_ids = [] + for p in product_id.model_processing_panel.split(','): + panel = self.env['sf.processing.panel'].search( + [('name', 'ilike', p)]) + if panel: + panel_ids.append(panel.id) + domain = {'processing_panel_id': [('id', 'in', panel_ids)]} + return {'domain': domain} + diff --git a/sf_manufacturing/wizard/rework_wizard_views.xml b/sf_manufacturing/wizard/rework_wizard_views.xml index b369acfc..975004d3 100644 --- a/sf_manufacturing/wizard/rework_wizard_views.xml +++ b/sf_manufacturing/wizard/rework_wizard_views.xml @@ -8,7 +8,9 @@ + + diff --git a/sf_mrs_connect/controllers/controllers.py b/sf_mrs_connect/controllers/controllers.py index f32dedea..eb2337b1 100644 --- a/sf_mrs_connect/controllers/controllers.py +++ b/sf_mrs_connect/controllers/controllers.py @@ -29,21 +29,21 @@ class Sf_Mrs_Connect(http.Controller): [('programming_no', '=', ret['programming_no'])]) if productions: # # 拉取所有加工面的程序文件 - for r in ret['processing_panel'].split(','): - program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) - if os.path.exists(program_path_tmp_r): - files_r = os.listdir(program_path_tmp_r) - if files_r: - for file_name in files_r: - file_path = os.path.join(program_path_tmp_r, file_name) - os.remove(file_path) - download_state = request.env['sf.cnc.processing'].with_user( - request.env.ref("base.user_admin")).download_file_tmp( - ret['folder_name'], r) - if download_state is False: - res['status'] = -2 - res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) - return json.JSONEncoder().encode(res) + # for r in ret['processing_panel'].split(','): + # program_path_tmp_r = os.path.join('/tmp', ret['folder_name'], 'return', r) + # if os.path.exists(program_path_tmp_r): + # files_r = os.listdir(program_path_tmp_r) + # if files_r: + # for file_name in files_r: + # file_path = os.path.join(program_path_tmp_r, file_name) + # os.remove(file_path) + # download_state = request.env['sf.cnc.processing'].with_user( + # request.env.ref("base.user_admin")).download_file_tmp( + # ret['folder_name'], r) + # if download_state is False: + # res['status'] = -2 + # res['message'] = '编程单号为%s的CNC程序文件从FTP拉取失败' % (ret['programming_no']) + # return json.JSONEncoder().encode(res) for production in productions: if not production.workorder_ids: production.product_id.model_processing_panel = ret['processing_panel'] @@ -82,31 +82,31 @@ class Sf_Mrs_Connect(http.Controller): # if pre_workorder: # pre_workorder.write( # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) - for panel in ret['processing_panel'].split(','): - # 查询状态为进行中且工序类型为CNC加工的工单 - cnc_workorder = productions.workorder_ids.filtered( - lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', - 'cancel'] and ac.processing_panel == panel) - if cnc_workorder: - # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', - # panel) - program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) - logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) - files_panel = os.listdir(program_path_tmp_panel) - if files_panel: - for file in files_panel: - file_extension = os.path.splitext(file)[1] - logging.info('file_extension:%s' % file_extension) - if file_extension.lower() == '.pdf': - panel_file_path = os.path.join(program_path_tmp_panel, file) - logging.info('panel_file_path:%s' % panel_file_path) - cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) - pre_workorder = productions.workorder_ids.filtered( - lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', - 'cancel'] and ap.processing_panel == panel) - if pre_workorder: - pre_workorder.write( - {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) + # for panel in ret['processing_panel'].split(','): + # # 查询状态为进行中且工序类型为CNC加工的工单 + # cnc_workorder = productions.workorder_ids.filtered( + # lambda ac: ac.routing_type == 'CNC加工' and ac.state not in ['progress', 'done', + # 'cancel'] and ac.processing_panel == panel) + # if cnc_workorder: + # # program_path_tmp_panel = os.path.join('C://Users//43484//Desktop//fsdownload//test', + # # panel) + # program_path_tmp_panel = os.path.join('/tmp', ret['folder_name'], 'return', panel) + # logging.info('program_path_tmp_panel:%s' % program_path_tmp_panel) + # files_panel = os.listdir(program_path_tmp_panel) + # if files_panel: + # for file in files_panel: + # file_extension = os.path.splitext(file)[1] + # logging.info('file_extension:%s' % file_extension) + # if file_extension.lower() == '.pdf': + # panel_file_path = os.path.join(program_path_tmp_panel, file) + # logging.info('panel_file_path:%s' % panel_file_path) + # cnc_workorder.write({'cnc_worksheet': base64.b64encode(open(panel_file_path, 'rb').read())}) + # pre_workorder = productions.workorder_ids.filtered( + # lambda ap: ap.routing_type == '装夹预调' and ap.state not in ['done', + # 'cancel'] and ap.processing_panel == panel) + # if pre_workorder: + # pre_workorder.write( + # {'processing_drawing': base64.b64encode(open(panel_file_path, 'rb').read())}) productions.write({'programming_state': '已编程', 'work_state': '已编程'}) cnc_program_ids = [item.id for item in productions] workpiece_delivery = request.env['sf.workpiece.delivery'].sudo().search(