From e6ca4c27ac8998b42f7b6ccc9af6876fc274ef6f Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Fri, 9 Aug 2024 17:19:03 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=BA=93=E4=BD=8D=E5=8F=98=E6=9B=B4?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E3=80=81=E5=BA=93=E4=BD=8D=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=BC=98=E5=8C=96=EF=BC=9B2=E3=80=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E9=A2=84=E8=AD=A6=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=BC=98=E5=8C=96=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_manufacturing/controllers/controllers.py | 88 +++++++++++++------ sf_tool_management/models/base.py | 82 ++++++++--------- sf_tool_management/models/functional_tool.py | 63 ++++++++----- .../views/functional_tool_views.xml | 41 ++++----- sf_warehouse/models/model.py | 4 +- sf_warehouse/models/sync_common.py | 29 +++--- 6 files changed, 173 insertions(+), 134 deletions(-) diff --git a/sf_manufacturing/controllers/controllers.py b/sf_manufacturing/controllers/controllers.py index babda164..8075f126 100644 --- a/sf_manufacturing/controllers/controllers.py +++ b/sf_manufacturing/controllers/controllers.py @@ -396,34 +396,66 @@ class Manufacturing_Connect(http.Controller): OldDeciveStart = ret['OldDeciveStart'] OldDeciveEnd = ret['OldDeciveEnd'] - temp_val_sn_id = None - old_localtion = None - # if ChangeType == 'Part' or ChangeType == 'Tool': - stock_lot_obj = request.env['stock.lot'].sudo().search( - [('rfid', '=', RfidCode)], limit=1) - logging.info('stock_lot_obj===========:%s' % stock_lot_obj) - if not stock_lot_obj: - res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该产品'} - return json.JSONEncoder().encode(res) - if OldPosition: - old_localtion = request.env['sf.shelf.location'].sudo().search( - [('barcode', '=', OldPosition)], limit=1) - logging.info('old_localtion===========:%s' % old_localtion) - new_localtion = request.env['sf.shelf.location'].sudo().search( - [('barcode', '=', NewPosition)], limit=1) - logging.info('new_localtion===========:%s' % new_localtion) - if not new_localtion: - res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'} - return json.JSONEncoder().encode(res) - if old_localtion: - temp_val_sn_id = old_localtion.product_sn_id - logging.info('temp_val_sn_id===========:%s' % temp_val_sn_id) - old_localtion.product_sn_id = None - new_localtion.product_sn_id = temp_val_sn_id - logging.info('====1======') - else: - new_localtion.product_sn_id = stock_lot_obj.id - logging.info('=====2======') + if ChangeType == 'Part': + temp_val_sn_id = None + old_localtion = None + # if ChangeType == 'Part' or ChangeType == 'Tool': + stock_lot_obj = request.env['stock.lot'].sudo().search( + [('rfid', '=', RfidCode)], limit=1) + logging.info('stock_lot_obj===========:%s' % stock_lot_obj) + if not stock_lot_obj: + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '未根据RfidCode找到该产品'} + return json.JSONEncoder().encode(res) + if OldPosition: + old_localtion = request.env['sf.shelf.location'].sudo().search( + [('barcode', '=', OldPosition)], limit=1) + logging.info('old_localtion===========:%s' % old_localtion) + new_localtion = request.env['sf.shelf.location'].sudo().search( + [('barcode', '=', NewPosition)], limit=1) + logging.info('new_localtion===========:%s' % new_localtion) + if not new_localtion: + res = {'Succeed': False, 'ErrorCode': 202, 'Error': '没有该目标位置'} + return json.JSONEncoder().encode(res) + if old_localtion: + temp_val_sn_id = old_localtion.product_sn_id + logging.info('temp_val_sn_id===========:%s' % temp_val_sn_id) + old_localtion.product_sn_id = None + new_localtion.product_sn_id = temp_val_sn_id + logging.info('====1======') + else: + new_localtion.product_sn_id = stock_lot_obj.id + logging.info('=====2======') + elif ChangeType == 'Tool': + # 对功能刀具库位变更信息进行更改 + def write_tool(DeciveId): + if 'Tool' in DeciveId: + shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info(DeciveId) + for item in shelfinfo: + shelf_barcode = self.env['sf.shelf.location.datasync'].find_our_code(item['Postion']) + location_id = self.env['sf.shelf.location'].search([('barcode', '=', shelf_barcode)], + limit=1) + if location_id: + # 如果是线边刀库信息,则对功能刀具移动生成记录 + if 'Tool' in item['Postion']: + tool = self.env['sf.functional.cutting.tool.entity'].sudo().search( + [('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')]) + tool.tool_in_out_stock_location(location_id) + if tool: + location_id.product_sn_id = tool.barcode_id.id + else: + location_id.product_sn_id = False + else: + equipment_id = self.env['maintenance.equipment'].search([('name', '=', DeciveId)]) + if equipment_id: + equipment_id.register_equipment_tool() + else: + res_1 = {'Succeed': False, 'ErrorCode': 202, 'Error': f'设备【{DeciveId}】不存在'} + return json.JSONEncoder().encode(res_1) + + if OldDeciveId: + write_tool(OldDeciveId) + elif NewDeciveId: + write_tool(NewDeciveId) except Exception as e: res = {'Succeed': False, 'ErrorCode': 202, 'Error': e} logging.info('LocationChange error:%s' % e) diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index 65475333..e756899b 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -94,47 +94,47 @@ class MachineTableToolChangingApply(models.Model): if len(records) > 1: raise ValidationError('该刀位号已存在,请重新选择!!!') - @api.constrains('functional_tool_status') - def automation_apply_for_tool_change(self): - """ - 自动申请换刀 - :return: - """ - # 更新数据到机台换刀申请界面 - if self.functional_tool_status == '报警' and not self.sf_functional_tool_assembly_id: - machine_table_tool_changing_apply = self.env['sf.machine.table.tool.changing.apply'].search( - [('maintenance_equipment_id', '=', self.maintenance_equipment_id.id), - ('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id) - ]) - - # 创建功能刀具预警记录 - self.env['sf.functional.tool.warning'].create_tool_warning_record({'tool_changing_apply_id': self}) - - # 新建组装任务 - sf_functional_tool_assembly = self.env['sf.functional.tool.assembly'].create({ - 'functional_tool_name': self.functional_tool_name, - 'functional_tool_type_id': self.functional_tool_type_id.id, - 'functional_tool_diameter': self.diameter, - 'knife_tip_r_angle': self.knife_tip_r_angle, - 'coarse_middle_thin': '3', - 'new_former': '0', - 'functional_tool_length': self.extension_length, - 'effective_length': self.effective_length, - 'loading_task_source': '1', - 'use_tool_time': fields.Datetime.now() + timedelta(hours=4), - 'production_line_name_id': self.production_line_id.id, - 'machine_tool_name_id': self.maintenance_equipment_id.id, - 'applicant': '系统自动', - 'apply_time': fields.Datetime.now(), - 'cutter_spacing_code_id': self.cutter_spacing_code_id.id, - 'whether_standard_knife': self.whether_standard_knife, - 'reason_for_applying': '机台报警自动换刀', - 'sf_machine_table_tool_changing_apply_id': self.id - }) - - machine_table_tool_changing_apply.write( - {'status': '1', - 'sf_functional_tool_assembly_id': sf_functional_tool_assembly.id}) + # @api.constrains('functional_tool_status') + # def automation_apply_for_tool_change(self): + # """ + # 自动申请换刀 + # :return: + # """ + # # 更新数据到机台换刀申请界面 + # if self.functional_tool_status == '报警' and not self.sf_functional_tool_assembly_id: + # machine_table_tool_changing_apply = self.env['sf.machine.table.tool.changing.apply'].search( + # [('maintenance_equipment_id', '=', self.maintenance_equipment_id.id), + # ('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id) + # ]) + # + # # 创建功能刀具预警记录 + # self.env['sf.functional.tool.warning'].create_tool_warning_record({'tool_changing_apply_id': self}) + # + # # 新建组装任务 + # sf_functional_tool_assembly = self.env['sf.functional.tool.assembly'].create({ + # 'functional_tool_name': self.functional_tool_name, + # 'functional_tool_type_id': self.functional_tool_type_id.id, + # 'functional_tool_diameter': self.diameter, + # 'knife_tip_r_angle': self.knife_tip_r_angle, + # 'coarse_middle_thin': '3', + # 'new_former': '0', + # 'functional_tool_length': self.extension_length, + # 'effective_length': self.effective_length, + # 'loading_task_source': '1', + # 'use_tool_time': fields.Datetime.now() + timedelta(hours=4), + # 'production_line_name_id': self.production_line_id.id, + # 'machine_tool_name_id': self.maintenance_equipment_id.id, + # 'applicant': '系统自动', + # 'apply_time': fields.Datetime.now(), + # 'cutter_spacing_code_id': self.cutter_spacing_code_id.id, + # 'whether_standard_knife': self.whether_standard_knife, + # 'reason_for_applying': '机台报警自动换刀', + # 'sf_machine_table_tool_changing_apply_id': self.id + # }) + # + # machine_table_tool_changing_apply.write( + # {'status': '1', + # 'sf_functional_tool_assembly_id': sf_functional_tool_assembly.id}) def revocation_1(self): """ diff --git a/sf_tool_management/models/functional_tool.py b/sf_tool_management/models/functional_tool.py index 0d9473ca..2c677e60 100644 --- a/sf_tool_management/models/functional_tool.py +++ b/sf_tool_management/models/functional_tool.py @@ -53,6 +53,21 @@ class FunctionalCuttingToolEntity(models.Model): safe_inventory_id = fields.Many2one('sf.real.time.distribution.of.functional.tools', string='功能刀具安全库存', readonly=True) + @api.onchange('functional_tool_status') + def _onchange_functional_tool_status(self): + for item in self: + if item: + if item.functional_tool_status == '报警': + # 创建报警刀具拆解单 + self.env['sf.functional.tool.dismantle'].sudo().create({ + 'functional_tool_id': item.id, + 'dismantle_cause': '寿命到期报废' + }) + # 创建刀具报警记录 + # self.env['sf.functional.tool.warning'].sudo().create({ + # '' + # }) + @api.depends('barcode_id.quant_ids', 'barcode_id.quant_ids.location_id', 'functional_tool_status', 'current_shelf_location_id') def _compute_current_location_id(self): @@ -324,7 +339,7 @@ class FunctionalToolWarning(models.Model): _description = '功能刀具预警' code = fields.Char('编码', related='functional_tool_name_id.code') - rfid = fields.Char('Rfid', related='functional_tool_name_id.rfid') + rfid = fields.Char('Rfid') tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id') name = fields.Char('名称', invisible=True, readonly=True, related='functional_tool_name_id.name') # 机床信息 @@ -338,7 +353,7 @@ class FunctionalToolWarning(models.Model): domain="[('equipment_id', '=', maintenance_equipment_id)]") # 功能刀具信息 functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具名称') - barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', related='functional_tool_name_id.barcode_id') + barcode_id = fields.Many2one('stock.lot', string='序列号', related='functional_tool_name_id.barcode_id') mrs_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型') diameter = fields.Float(string='刀具直径(mm)') knife_tip_r_angle = fields.Float(string='刀尖R角(mm)') @@ -361,28 +376,28 @@ class FunctionalToolWarning(models.Model): machine_table_name_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID) return categories.browse(machine_table_name_ids) - def create_tool_warning_record(self, obj): - """ - 机台换刀申请报警状态时,创建功能刀具预警记录 - """ - if obj: - for tool in obj.get('tool_changing_apply_id'): - self.env['sf.functional.tool.warning'].create({ - 'production_line_id': tool.production_line_id.id, - 'maintenance_equipment_id': tool.maintenance_equipment_id.id, - 'machine_tool_code': tool.machine_tool_code, - 'machine_table_type_id': tool.machine_table_type_id.id, - 'cutter_spacing_code_id': tool.cutter_spacing_code_id.id, - 'functional_tool_name_id': tool.functional_tool_name_id.id, - 'barcode_id': tool.barcode_id.id, - 'diameter': tool.diameter, - 'knife_tip_r_angle': tool.knife_tip_r_angle, - 'max_lifetime_value': tool.max_lifetime_value, - 'alarm_value': tool.alarm_value, - 'used_value': tool.used_value, - 'functional_tool_status': tool.functional_tool_status, - 'alarm_time': fields.Datetime.now(), - }) + # def create_tool_warning_record(self, obj): + # """ + # 机台换刀申请报警状态时,创建功能刀具预警记录 + # """ + # if obj: + # for tool in obj.get('tool_changing_apply_id'): + # self.env['sf.functional.tool.warning'].create({ + # 'production_line_id': tool.production_line_id.id, + # 'maintenance_equipment_id': tool.maintenance_equipment_id.id, + # 'machine_tool_code': tool.machine_tool_code, + # 'machine_table_type_id': tool.machine_table_type_id.id, + # 'cutter_spacing_code_id': tool.cutter_spacing_code_id.id, + # 'functional_tool_name_id': tool.functional_tool_name_id.id, + # 'barcode_id': tool.barcode_id.id, + # 'diameter': tool.diameter, + # 'knife_tip_r_angle': tool.knife_tip_r_angle, + # 'max_lifetime_value': tool.max_lifetime_value, + # 'alarm_value': tool.alarm_value, + # 'used_value': tool.used_value, + # 'functional_tool_status': tool.functional_tool_status, + # 'alarm_time': fields.Datetime.now(), + # }) class StockMoveLine(models.Model): diff --git a/sf_tool_management/views/functional_tool_views.xml b/sf_tool_management/views/functional_tool_views.xml index 103583c2..70edbafe 100644 --- a/sf_tool_management/views/functional_tool_views.xml +++ b/sf_tool_management/views/functional_tool_views.xml @@ -236,25 +236,26 @@ sf.functional.tool.warning - - - - - + + + + + + + - - + + + - - - + @@ -266,31 +267,19 @@ sf.functional.tool.warning - - - - - - - - - - - - - - - - + + + diff --git a/sf_warehouse/models/model.py b/sf_warehouse/models/model.py index 5beeebc5..d3f9c585 100644 --- a/sf_warehouse/models/model.py +++ b/sf_warehouse/models/model.py @@ -507,13 +507,13 @@ class ShelfLocation(models.Model): print('eeeeeee空闲', e) # 调取获取货位信息接口 - def get_sf_shelf_location_info(self): + def get_sf_shelf_location_info(self, device_id='Cabinet-AL'): config = self.env['res.config.settings'].get_values() headers = {'Authorization': config['center_control_Authorization']} crea_url = config['center_control_url'] + "/AutoDeviceApi/GetLocationInfos" - params = {'DeviceId': 'Cabinet-AL'} + params = {'DeviceId': device_id} r = requests.get(crea_url, params=params, headers=headers) ret = r.json() diff --git a/sf_warehouse/models/sync_common.py b/sf_warehouse/models/sync_common.py index 3df97423..32632eac 100644 --- a/sf_warehouse/models/sync_common.py +++ b/sf_warehouse/models/sync_common.py @@ -13,13 +13,14 @@ class MrsShelfLocationDataSync(models.Model): _name = 'sf.shelf.location.datasync' _description = '同步库存信息' - def _cron_shelf_location_datasync(self): - try: - # 建立对应关系的函数 - def align_data(my_data, their_data): - paired_data = list(zip(my_data, their_data)) - return paired_data + def find_our_code(self, their_code): + # 建立对应关系的函数 + def align_data(my_data, their_data): + paired_data = list(zip(my_data, their_data)) + return paired_data + + def get_total_data(): shelf_1_obj = self.env['sf.shelf'].search([('name', '=', '一号产线-一号线边刀架')], limit=1) tool_location_objs_1 = self.env['sf.shelf.location'].search([('shelf_id', '=', shelf_1_obj.id)], order='id') @@ -82,19 +83,21 @@ class MrsShelfLocationDataSync(models.Model): total_data = aligned_data_1 + aligned_data_2 + aligned_data_3 + aligned_data_4 + aligned_data_5 print(total_data) logging.info(f"total_data: {total_data}") + return total_data + for code_pair in get_total_data(): + if code_pair[1] == their_code: + return code_pair[0] + return None # 如果没有找到对应的值,返回None或适当的默认值 + + def _cron_shelf_location_datasync(self): + try: def find_their_code(my_code, aligned_data): for code_pair in aligned_data: if code_pair[0] == my_code: return code_pair[1] return None # 如果没有找到对应的值,返回None或适当的默认值 - def find_our_code(their_code, aligned_data): - for code_pair in aligned_data: - if code_pair[1] == their_code: - return code_pair[0] - return None # 如果没有找到对应的值,返回None或适当的默认值 - # 定时更新所有设备机床刀库信息 equipment_ids = self.env['maintenance.equipment'].search( [('equipment_type', '=', '机床'), ('function_type', '!=', False)]) @@ -105,7 +108,7 @@ class MrsShelfLocationDataSync(models.Model): shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info() print('shelfinfo:', shelfinfo) for item in shelfinfo: - shelf_barcode = find_our_code(item['Postion'], total_data) + shelf_barcode = self.find_our_code(item['Postion']) location_id = self.env['sf.shelf.location'].search([('barcode', '=', shelf_barcode)], limit=1) if location_id: # 如果是线边刀库信息,则对功能刀具移动生成记录