diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py index ff3f1bed..3a9f3264 100644 --- a/sf_tool_management/models/base.py +++ b/sf_tool_management/models/base.py @@ -733,10 +733,12 @@ class CAMWorkOrderProgramKnifePlan(models.Model): class FunctionalToolAssembly(models.Model): _name = 'sf.functional.tool.assembly' - _description = '功能刀具组装' + _description = '功能刀具组装单' _order = 'use_tool_time asc' - functional_tool_code = fields.Char(string='功能刀具编码', readonly=True) + assembly_order_code = fields.Char(string='编码', compute='_get_code', readonly=True) + functional_tool_code = fields.Char(string='功能刀具编码', invisible=True) + barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True) name = fields.Many2one('sf.functional.cutting.tool', string='功能刀具名称', readonly=True) functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True, group_expand='_read_group_functional_tool_type_ids') @@ -787,6 +789,58 @@ class FunctionalToolAssembly(models.Model): chuck_name = fields.Char('夹头名称', readonly=True) sf_tool_brand_id_6 = fields.Many2one('sf.machine.brand', '夹头品牌', readonly=True) + @api.depends('integral_code_id', 'blade_code_id', 'bar_code_id', 'pad_code_id', 'handle_code_id', 'chuck_code_id') + def _compute_auto_fill(self): + for record in self: + if record.integral_code_id: + record.cutting_tool_integral_model_id = record.integral_code_id.product_id.cutting_tool_material_id.id + record.integral_name = record.integral_code_id.product_id.name + record.sf_tool_brand_id_1 = record.integral_code_id.product_id.brand_id.id + else: + record.cutting_tool_integral_model_id = None + record.integral_name = None + record.sf_tool_brand_id_1 = None + if record.blade_code_id: + record.cutting_tool_blade_model_id = record.blade_code_id.product_id.cutting_tool_material_id.id + record.blade_name = record.blade_code_id.product_id.name + record.sf_tool_brand_id_2 = record.blade_code_id.product_id.brand_id.id + else: + record.cutting_tool_blade_model_id = None + record.blade_name = None + record.sf_tool_brand_id_2 = None + if record.bar_code_id: + record.cutting_tool_cutterbar_model_id = record.bar_code_id.product_id.cutting_tool_material_id.id + record.bar_name = record.bar_code_id.product_id.name + record.sf_tool_brand_id_3 = record.bar_code_id.product_id.brand_id.id + else: + record.cutting_tool_cutterbar_model_id = None + record.bar_name = None + record.sf_tool_brand_id_3 = None + if record.pad_code_id: + record.cutting_tool_cutterpad_model_id = record.pad_code_id.product_id.cutting_tool_material_id.id + record.pad_name = record.pad_code_id.product_id.name + record.sf_tool_brand_id_4 = record.pad_code_id.product_id.brand_id.id + else: + record.cutting_tool_cutterpad_model_id = None + record.pad_name = None + record.sf_tool_brand_id_4 = None + if record.handle_code_id: + record.cutting_tool_cutterhandle_model_id = record.handle_code_id.product_id.cutting_tool_material_id.id + record.handle_name = record.handle_code_id.product_id.name + record.sf_tool_brand_id_5 = record.handle_code_id.product_id.brand_id.id + else: + record.cutting_tool_cutterhandle_model_id = None + record.handle_name = None + record.sf_tool_brand_id_5 = None + if record.chuck_code_id: + record.cutting_tool_cutterhead_model_id = record.chuck_code_id.product_id.cutting_tool_material_id.id + record.chuck_name = record.chuck_code_id.product_id.name + record.sf_tool_brand_id_6 = record.chuck_code_id.product_id.brand_id.id + else: + record.cutting_tool_cutterhead_model_id = None + record.chuck_name = None + record.sf_tool_brand_id_6 = None + coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=True) tool_loading_length = fields.Char(string='装刀长(mm)', readonly=True) new_former = fields.Selection([('0', '新'), ('1', '旧')], string='新/旧', readonly=True) @@ -795,11 +849,12 @@ class FunctionalToolAssembly(models.Model): cut_length = fields.Char(string='已切削长度(mm)', readonly=True) cut_number = fields.Char(string='已切削次数', readonly=True) - loading_task_source = fields.Selection([('0', 'CAM装刀'), ('1', '机台换刀')], string='装刀任务来源', readonly=True) + loading_task_source = fields.Selection([('0', 'CAM装刀'), ('1', '机台换刀'), ('2', '按库存组装')], + string='装刀任务来源', readonly=True) applicant = fields.Char(string='申请人', readonly=True) reason_for_applying = fields.Char(string='申请原因', readonly=True) apply_time = fields.Datetime(string='申请时间', default=fields.Datetime.now(), readonly=True) - assemble_status = fields.Selection([('0', '待组装'), ('1', '已组装'), ('2', '已出库')], string='组装状态', + assemble_status = fields.Selection([('0', '待组装'), ('1', '已组装')], string='组装状态', default='0', readonly=True) use_tool_time = fields.Datetime(string='用刀时间', readonly=True) production_line_name_id = fields.Many2one('sf.production.line', string='产线名称', readonly=False) @@ -818,155 +873,29 @@ class FunctionalToolAssembly(models.Model): sf_cam_work_order_program_knife_plan_id = fields.Many2one('sf.cam.work.order.program.knife.plan', 'CAM工单程序用刀计划') - def open_sf_cam_work_order_program_knife_plan(self): + @api.depends('loading_task_source') + def _get_code(self): """ - 跳转到CAM工单程序用刀计划界面按钮功能 + 自动生成组装单编码 """ - action = self.env.ref('sf_tool_management.sf_cam_work_order_program_knife_plan_view_act') - result = action.read()[0] - result['domain'] = [('sf_functional_tool_assembly_id', '=', self.id)] - return result - - def open_sf_machine_table_tool_changing_apply(self): - """ - 跳转到机床换刀申请界面按钮功能 - """ - action = self.env.ref('sf_tool_management.sf_machine_table_tool_changing_apply_view_act') - result = action.read()[0] - result['domain'] = [('sf_functional_tool_assembly_id', '=', self.id)] - return result - - def cancel_functional_tool_assembly(self): - """ - 取消功能刀具组装 - :return: - """ - if self.new_former == '0': - # 如果是新刀,则删除功能刀具列表、功能刀具预警、功能刀具实时分布、功能刀具出入库记录的记录 - record = self.env['sf.functional.cutting.tool.entity'].search([ - ('code', '=', self.functional_tool_code)]) - self.env['sf.functional.tool.warning'].search( - [('functional_cutting_tool_id', '=', record.id)]).unlink() - self.env['sf.real.time.distribution.of.functional.tools'].search( - [('functional_cutting_tool_id', '=', record.id)]).unlink() - self.env['sf.inbound.and.outbound.records.of.functional.tools'].search( - [('functional_cutting_tool_id', '=', record.id)]).unlink() - record.unlink() - else: - # 获取功能刀具缓存信息 - record = self.env['sf.functional.cutting.tool.entity.cache'].search([ - ('code', '=', self.functional_tool_code)], limit=1) - # # 删除现有功能刀具列表记录 - # self.env['sf.functional.cutting.tool.entity'].search([ - # ('code', '=', self.functional_tool_code)]).unlink() - # 修改功能刀具列表信息 - self.env['sf.functional.cutting.tool.entity'].search([ - ('code', '=', self.functional_tool_code)]).sudo().write({ - 'code': record.code, - 'name': record.name, - 'mrs_cutting_tool_type_id': record.mrs_cutting_tool_type_id.id, - 'mrs_cutting_tool_model_id': record.mrs_cutting_tool_model_id.id, - 'cutting_tool_integral_model_id': record.cutting_tool_integral_model_id.id, - 'cutting_tool_blade_model_id': record.cutting_tool_blade_model_id.id, - 'cutting_tool_cutterbar_model_id': record.cutting_tool_cutterbar_model_id.id, - 'cutting_tool_cutterpad_model_id': record.cutting_tool_cutterpad_model_id.id, - 'cutting_tool_cutterhandle_model_id': record.cutting_tool_cutterhandle_model_id.id, - 'cutting_tool_cutterhead_model_id': record.cutting_tool_cutterhead_model_id.id, - 'diameter': record.diameter, - 'tool_grade': record.tool_grade, - 'machining_accuracy': record.machining_accuracy, - 'tool_length': record.tool_length, - 'blade_number': record.blade_number, - 'integral_blade_length': record.integral_blade_length, - 'effective_blade_length': record.effective_blade_length, - 'max_life': record.max_life, - 'is_standard': record.is_standard, - 'applicable_range': record.applicable_range, - 'image': record.image, - }) - # 删除功能刀具缓存信息 - self.env['sf.functional.cutting.tool.entity.cache'].search([ - ('code', '=', self.functional_tool_code)]).unlink() - - # 修改功能刀具组装的组装信息 - self.env['sf.functional.tool.assembly'].search([ - ('machine_tool_name_id', '=', self.machine_tool_name_id.id), - ('cutter_spacing_code', '=', self.cutter_spacing_code), - ('assemble_status', '=', '1') - ]).write({ - 'cutting_tool_integral_model_id': None, - 'integral_code_id': None, - 'integral_name': None, - 'sf_tool_brand_id_1': None, - 'cutting_tool_blade_model_id': None, - 'blade_code_id': None, - 'blade_name': None, - 'sf_tool_brand_id_2': None, - 'cutting_tool_cutterbar_model_id': None, - 'bar_code_id': None, - 'bar_name': None, - 'sf_tool_brand_id_3': None, - 'cutting_tool_cutterpad_model_id': None, - 'pad_code_id': None, - 'pad_name': None, - 'sf_tool_brand_id_4': None, - 'cutting_tool_cutterhandle_model_id': None, - 'handle_code_id': None, - 'handle_name': None, - 'sf_tool_brand_id_5': None, - 'cutting_tool_cutterhead_model_id': None, - 'chuck_code_id': None, - 'chuck_name': None, - 'sf_tool_brand_id_6': None, - 'coarse_middle_thin': None, - 'tool_loading_length': None, - 'new_former': None, - 'reference_length': None, - 'cut_time': None, - 'cut_length': None, - 'cut_number': None, - 'assemble_status': '0', - 'tool_loading_person': None, - 'tool_loading_time': None - }) - - def show_popup(self): - """ - 单个功能刀具出库 - :return: - """ - self.env['sf.delivery.of.cargo.from.storage'].search([]).unlink() - - vals = self.env['sf.functional.tool.assembly'].search( - [('check_box_1', '=', True), ('assemble_status', '=', '1')]) - if vals: - for val in vals: - self.env['sf.delivery.of.cargo.from.storage'].create({ - 'functional_tool_code': val.functional_tool_code, - 'name': val.name.id, - 'functional_tool_type_id': val.functional_tool_type_id.id, - 'production_line_name_id': val.production_line_name_id.id, - 'machine_tool_code': val.machine_tool_code, - 'receive_person': val.receive_person, - 'receive_time': val.receive_time}) - else: - self.env['sf.delivery.of.cargo.from.storage'].create({ - 'functional_tool_code': self.functional_tool_code, - 'name': self.name.id, - 'functional_tool_type_id': self.functional_tool_type_id.id, - 'production_line_name_id': self.production_line_name_id.id, - 'machine_tool_code': self.machine_tool_code, - 'receive_person': self.receive_person, - 'receive_time': self.receive_time}) - - return { - 'type': 'ir.actions.act_window', - 'name': '功能刀具出库', - 'res_model': 'sf.delivery.of.cargo.from.storage', - 'view_mode': 'tree', - 'view_type': 'tree', - 'target': 'new' - } + for record in self: + new_time = str(fields.Date.today()) + datetime = new_time[2:4] + new_time[5:7] + new_time[-2:] + functional_tool_assembly = record.env['sf.functional.tool.assembly'].sudo().search( + [('loading_task_source', '=', record.loading_task_source), + ('assembly_order_code', 'like', new_time)], limit=1, order="id desc") + print(functional_tool_assembly) + if not functional_tool_assembly: + num = "%03d" % 1 + else: + m = int(functional_tool_assembly.name[-3:]) + 1 + num = "%03d" % m + if record.loading_task_source == '0': + record.assembly_order_code = 'CAMZZD' + datetime + str(num) + if record.loading_task_source == '1': + record.assembly_order_code = 'JTZZD' + datetime + str(num) + if record.loading_task_source == '2': + record.assembly_order_code = 'MTSZZD' + datetime + str(num) def automated_assembly(self): """ diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml index 077cb027..6ed278af 100644 --- a/sf_tool_management/views/tool_base_views.xml +++ b/sf_tool_management/views/tool_base_views.xml @@ -997,10 +997,11 @@ sf.functional.tool.assembly + - + @@ -1034,13 +1035,8 @@ 'default_whether_standard_tool': None}" attrs="{'invisible': [('assemble_status', '!=', '0')]}" class="btn-primary"/> -