from odoo import fields, models, api class ToolChangeRequirementInformation(models.TransientModel): _name = 'sf.tool.change.requirement.information' _description = '换刀需求信息' tool_change_to_apply_id = fields.Many2one('sf.machine.table.tool.changing.apply', string='机床换刀申请') CNC_machine_table = fields.Char(string='CNC机床', readonly=True) machine_tool_code = fields.Char(string='机台号', readonly=True) cutter_spacing_code = fields.Char(string='刀位号', readonly=True) replacement_tool_code = fields.Char(string='待换刀具编码') replacement_tool_name = fields.Char(string='待换刀具名称') replacement_tool_type = fields.Char(string='待换刀具类型') replacement_tool_coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精') new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧') applicant = fields.Char(string='申请人') used_tool_time = fields.Datetime(string='用刀时间') reason_for_applying = fields.Char(string='申请原因') remark = fields.Char(string='备注说明') def tool_changing_apply(self): """ 确认换刀申请(按键) :return: """ # 封装数据 desc = { 'CNC_machine_table': self.CNC_machine_table, 'machine_tool_code': self.machine_tool_code, 'cutter_spacing_code': self.cutter_spacing_code, 'replacement_tool_code': self.replacement_tool_code, 'replacement_tool_name': self.replacement_tool_name, 'replacement_tool_type': self.replacement_tool_type, 'replacement_tool_coarse_middle_thin': self.replacement_tool_coarse_middle_thin, 'new_former': self.new_former, 'applicant': self.applicant, 'used_tool_time': self.used_tool_time, 'reason_for_applying': self.reason_for_applying, 'remark': self.new_former, 'status': '1' } # 将数据更新到机台换刀申请界面 self.env['sf.machine.table.tool.changing.apply'].search( [('CNC_machine_table', '=', desc.get('CNC_machine_table'))]).write(desc) # 功能刀具组装创建新任务 self.env['sf.machine.table.tool.changing.apply'].new_assembly_task({ 'functional_tool_code': self.replacement_tool_code, 'functional_tool_name': self.replacement_tool_name, 'functional_tool_type': self.replacement_tool_type, 'loading_task_source': '1', 'applicant': self.applicant, 'reason_for_applying': self.reason_for_applying, 'use_tool_time': self.used_tool_time, 'machine_tool_name': self.CNC_machine_table, 'machine_tool_code': self.machine_tool_code, 'cutter_spacing_code': self.cutter_spacing_code }) # 关闭弹出窗口 return {'type': 'ir.actions.act_window_close'} class ToolTransferRequestInformation(models.TransientModel): _name = 'sf.tool.transfer.request.information' _description = '刀具转移申请信息' CNC_machine_table = fields.Char(string='CNC机床', readonly=True) machine_tool_code = fields.Char(string='机台号', readonly=True) cutter_spacing_code = fields.Char(string='刀位号', readonly=True) functional_tool_code = fields.Char(string='功能刀具编码', readonly=True) functional_tool_name = fields.Char(string='功能刀具名称', readonly=True) # todo 功能刀具类型为 Many2one functional_tool_type = fields.Char(string='功能刀具类型', readonly=True) transfer_target = fields.Selection([('机台', '机台'), ('线边刀库', '线边刀库'), ('刀具房', '刀具房')], string='转移到:', default='线边刀库') new_cnc_machine_table = fields.Char(string='机床名称') new_machine_tool_code = fields.Char(string='机床号') new_cutter_spacing_code = fields.Char(string='刀位号') magazine_tool_warehouse_district = fields.Char(string='库区') magazine_tool_warehouse_position = fields.Char(string='库位') tool_room_warehouse_district = fields.Char(string='库区') tool_room_warehouse_position = fields.Char(string='库位') def tool_transfer_apply(self): """ 刀具转移申请信息确定按钮 :return: """ self.env['sf.machine.table.tool.changing.apply'].search( [('CNC_machine_table', '=', self.CNC_machine_table)]).write({'status': '2'}) class ApplyForTooling(models.TransientModel): _name = 'sf.apply.for.tooling' _description = '申请装刀' ticket_task_code = fields.Char(string='工单任务编号', readonly=True) cam_procedure_code = fields.Char(string='CAM程序编号', readonly=True) machine_table_name = fields.Char(string='机床名称', readonly=True) cam_cutter_spacing_code = fields.Char(string='CAM刀位号', readonly=True) functional_tool_code = fields.Char(string='功能刀具编码', readonly=True) functional_tool_name = fields.Char(string='功能刀具名称', readonly=True) functional_tool_type = fields.Char(string='功能刀具类型', readonly=True) diameter = fields.Char(string='直径(程式)', readonly=True) tool_loading_length = fields.Char(string='装刀长', readonly=True) clearance_length = fields.Char(string='避空长', readonly=True) tool_included_angle = fields.Char(string='刀尖角(R角)', readonly=True) L_D = fields.Char(string='L/D', readonly=True) coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=True) whether_standard_tool = fields.Boolean(string='是否标准刀', readonly=True) need_knife_time = fields.Datetime(string='需要用刀时间', readonly=True) required_cutting_time = fields.Char(string='需要切割时间', readonly=True) reason_for_applying = fields.Char(string='申请原因', readonly=True) applicant = fields.Char(string='申请人', invisible='1') def apply_for_tooling(self): """ 申请装刀 :return: """ self.env['sf.functional.tool.assembly'].create({ 'functional_tool_code': self.functional_tool_code, 'functional_tool_name': self.functional_tool_name, 'functional_tool_type': self.functional_tool_type, 'functional_tool_diameter': self.diameter, 'functional_tool_length': self.tool_loading_length, 'loading_task_source': '0', 'coarse_middle_thin': None, 'tool_loading_length': None, 'applicant': self.applicant, 'reason_for_applying': self.reason_for_applying, 'use_tool_time': self.need_knife_time, 'machine_tool_name': self.machine_table_name, 'machine_tool_code': self.cam_procedure_code, 'cutter_spacing_code': self.cam_cutter_spacing_code }) # 将计划执行状态改为执行中 self.env['sf.cam.work.order.program.knife.plan'].search( [('functional_tool_code', '=', self.functional_tool_code)]).write({'plan_execute_status': '1'}) # 关闭弹出窗口 return {'type': 'ir.actions.act_window_close'} class FunctionalToolAssemblyOrder(models.TransientModel): _name = 'sf.functional.tool.assembly.order' _description = '功能刀具组装单' # 功能刀具申请信息 machine_tool_name = fields.Char(string='机床名称', readonly=True) cutter_spacing_code = fields.Char(string='刀位号', readonly=True) functional_tool_name = fields.Char(string='功能刀具名称', readonly=True) functional_tool_type = fields.Char(string='功能刀具类型', readonly=True) functional_tool_length = fields.Char(string='功能刀具伸出长', readonly=True) effective_length = fields.Char(string='有效长', readonly=True) functional_tool_diameter = fields.Char(string='功能刀具直径', readonly=True) tool_included_angle = fields.Char(string='刀尖角(R角)', readonly=True) functional_tool_cutting_type = fields.Char(string='功能刀具切削类型', readonly=True) required_cutting_time = fields.Char(string='需要切割时间', readonly=True) whether_standard_tool = fields.Boolean(string='是否标准刀', readonly=True) # 功能刀具组装信息 tool_name = fields.Char(string='刀具名称') tool_code = fields.Char(string='刀具编码') tool_brand = fields.Char(string='品牌') tool_type = fields.Char(string='型号') knife_handle_name = fields.Char(string='刀柄名称') knife_handle_code = fields.Char(string='刀柄编码') knife_handle_brand = fields.Char(string='品牌') knife_handle_type = fields.Char(string='型号') coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精') tool_loading_length = fields.Char(string='装刀长') new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧') reference_length = fields.Char(string='参考伸出长') cut_time = fields.Char(string='已切削时间') cut_length = fields.Char(string='已切削长度') cut_number = fields.Char(string='已切削次数') def functional_tool_assembly(self): """ 功能刀具组装 :return: """ self.env['sf.functional.tool.assembly'].search([ ('machine_tool_name', '=', self.machine_tool_name), ('cutter_spacing_code', '=', self.cutter_spacing_code) ]).write({ 'tool_name': self.tool_name, 'tool_brand': self.tool_brand, 'tool_type': self.tool_type, 'knife_handle_name': self.knife_handle_name, 'knife_handle_brand': self.knife_handle_brand, 'knife_handle_type': self.knife_handle_type, 'coarse_middle_thin': self.coarse_middle_thin, 'tool_loading_length': self.tool_loading_length, 'new_former': self.new_former, 'reference_length': self.reference_length, 'cut_time': self.cut_time, 'cut_length': self.cut_length, 'cut_number': self.cut_number, 'assemble_status': '1', 'tool_loading_person': self.env.user.name, 'tool_loading_time': fields.Datetime.now() }) # 关闭弹出窗口 return {'type': 'ir.actions.act_window_close'} class DeliveryOfCargoFromStorage(models.TransientModel): _name = 'sf.delivery.of.cargo.from.storage' _description = '出库' functional_tool_code = fields.Char(string='功能刀具编码') functional_tool_name = fields.Char(string='功能刀具名称') functional_tool_type = fields.Char(string='功能刀具类型') production_line_name = fields.Char(string='产线名称') machine_tool_code = fields.Char(string='机台号') receive_person = fields.Char(string='领用人') receive_time = fields.Datetime(string='领用出库时间') def stock_removal(self): """ 出库 :return: """