1、将功能刀具组装弹窗模型的组装流程以及其中相关的业务逻辑,移动到组装单模型并进行优化;2、功能刀具组装单模型新增部分字段的自动计算方法;新增部分物料字段;
This commit is contained in:
@@ -598,361 +598,175 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
else:
|
||||
record.L_D_number = 0
|
||||
|
||||
def functional_tool_assembly(self):
|
||||
"""
|
||||
功能刀具组装
|
||||
:return:
|
||||
"""
|
||||
logging.info('功能刀具开始组装!')
|
||||
# 获取组装单对象
|
||||
functional_tool_assembly = self.env['sf.functional.tool.assembly'].search([
|
||||
('assembly_order_code', '=', self.assembly_order_code),
|
||||
('machine_tool_name_id', '=', self.machine_tool_name_id.id),
|
||||
('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id),
|
||||
('assemble_status', '=', '0'),
|
||||
])
|
||||
# 对物料做必填判断
|
||||
self.materials_must_be_judged()
|
||||
|
||||
product_id = self.env['product.product']
|
||||
# 创建组装入库单
|
||||
# 创建功能刀具批次/序列号记录
|
||||
stock_lot = product_id.create_assemble_warehouse_receipt(self.id, functional_tool_assembly, self)
|
||||
# 封装功能刀具数据,用于更新组装单信息
|
||||
desc_1 = self.get_desc_1(stock_lot)
|
||||
# 封装功能刀具数据,用于创建功能刀具记录
|
||||
desc_2 = self.get_desc_2(stock_lot, functional_tool_assembly)
|
||||
# 创建功能刀具组装入库单
|
||||
self.env['stock.picking'].create_tool_stocking_picking(stock_lot, functional_tool_assembly, self)
|
||||
# 创建刀具物料出库单
|
||||
self.env['stock.picking'].create_tool_stocking_picking1(self)
|
||||
|
||||
# ============================创建功能刀具列表、安全库存记录===============================
|
||||
# 创建功能刀具列表记录
|
||||
record_1 = self.env['sf.functional.cutting.tool.entity'].create(desc_2)
|
||||
# 创建安全库存信息
|
||||
self.env['sf.real.time.distribution.of.functional.tools'].create_or_edit_safety_stock({
|
||||
'functional_name_id': self.after_name_id.id
|
||||
}, record_1)
|
||||
|
||||
# =====================修改功能刀具组装单、机床换刀申请、CAM工单程序用刀计划的状态==============
|
||||
# 修改功能刀具组装单信息
|
||||
functional_tool_assembly.write(desc_1)
|
||||
if functional_tool_assembly.sf_machine_table_tool_changing_apply_id:
|
||||
# 修改机床换刀申请的状态
|
||||
self.env['sf.machine.table.tool.changing.apply'].sudo().search([
|
||||
('id', '=', functional_tool_assembly.sf_machine_table_tool_changing_apply_id.id)
|
||||
]).write({'status': '3'})
|
||||
elif functional_tool_assembly.sf_cam_work_order_program_knife_plan_id:
|
||||
# 修改CAM工单程序用刀计划状态
|
||||
cam_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().search([
|
||||
('id', '=', functional_tool_assembly.sf_cam_work_order_program_knife_plan_id.id)
|
||||
])
|
||||
cam_plan.write({'plan_execute_status': '2'})
|
||||
|
||||
logging.info('功能刀具组装完成!')
|
||||
|
||||
# 关闭弹出窗口
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
def materials_must_be_judged(self):
|
||||
"""
|
||||
功能刀具组装必填判断
|
||||
"""
|
||||
# 物料必填校验
|
||||
if not self.handle_code_id:
|
||||
raise ValidationError('缺少【刀柄】物料信息!')
|
||||
if not self.integral_product_id and not self.blade_product_id:
|
||||
raise ValidationError('【整体式刀具】和【刀片】必须填写一个!')
|
||||
if self.blade_product_id:
|
||||
if not self.bar_product_id and not self.pad_product_id:
|
||||
raise ValidationError('【刀盘】和【刀杆】必须填写一个!')
|
||||
# 组装参数必填校验
|
||||
if self.after_assembly_functional_tool_length == 0:
|
||||
raise ValidationError('组装参数信息【伸出长】不能为0!')
|
||||
if self.after_assembly_max_lifetime_value == 0:
|
||||
raise ValidationError('组装参数信息【最大寿命值】不能为0!')
|
||||
if self.after_assembly_alarm_value == 0:
|
||||
raise ValidationError('组装参数信息【报警值】不能为0!')
|
||||
# if self.after_assembly_effective_length == 0:
|
||||
# raise ValidationError('组装参数信息【有效长】不能为0!!!')
|
||||
# if self.hiding_length == 0:
|
||||
# raise ValidationError('组装参数信息【避空长】不能为0!!!')
|
||||
if self.after_assembly_functional_tool_diameter == 0:
|
||||
raise ValidationError('组装参数信息【刀具直径】不能为0!')
|
||||
if self.after_assembly_tool_loading_length == 0:
|
||||
raise ValidationError('组装参数信息【总长度】不能为0!!!')
|
||||
if self.after_assembly_handle_length == 0:
|
||||
raise ValidationError('组装参数信息【刀柄长度】不能为0!')
|
||||
if self.after_assembly_tool_loading_length < self.after_assembly_handle_length:
|
||||
raise ValidationError('组装参数信息【刀柄长度】不能大于【总长度】!')
|
||||
|
||||
def get_desc_1(self, stock_lot):
|
||||
return {
|
||||
'start_preset_bool': False,
|
||||
'barcode_id': stock_lot.id,
|
||||
'code': self.code,
|
||||
'rfid': self.rfid,
|
||||
'tool_groups_id': self.after_tool_groups_id.id,
|
||||
'handle_code_id': self.handle_code_id.id,
|
||||
'integral_freight_barcode_id': self.integral_freight_barcode_id.id,
|
||||
'integral_lot_id': self.integral_freight_lot_id.lot_id.id,
|
||||
'blade_freight_barcode_id': self.blade_freight_barcode_id.id,
|
||||
'blade_lot_id': self.blade_freight_lot_id.lot_id.id,
|
||||
'bar_freight_barcode_id': self.bar_freight_barcode_id.id,
|
||||
'bar_lot_id': self.bar_freight_lot_id.lot_id.id,
|
||||
'pad_freight_barcode_id': self.pad_freight_barcode_id.id,
|
||||
'pad_lot_id': self.pad_freight_lot_id.lot_id.id,
|
||||
'chuck_freight_barcode_id': self.chuck_freight_barcode_id.id,
|
||||
'chuck_lot_id': self.chuck_freight_lot_id.lot_id.id,
|
||||
|
||||
'after_assembly_functional_tool_name': self.after_assembly_functional_tool_name,
|
||||
'after_assembly_functional_tool_type_id': self.after_assembly_functional_tool_type_id.id,
|
||||
'after_assembly_functional_tool_diameter': self.after_assembly_functional_tool_diameter,
|
||||
'after_assembly_knife_tip_r_angle': self.after_assembly_knife_tip_r_angle,
|
||||
'after_assembly_new_former': self.after_assembly_new_former,
|
||||
'cut_time': self.cut_time,
|
||||
'cut_length': self.cut_length,
|
||||
'cut_number': self.cut_number,
|
||||
'after_assembly_whether_standard_knife': self.after_assembly_whether_standard_knife,
|
||||
'after_assembly_coarse_middle_thin': self.after_assembly_coarse_middle_thin,
|
||||
'after_assembly_max_lifetime_value': self.after_assembly_max_lifetime_value,
|
||||
'after_assembly_alarm_value': self.after_assembly_alarm_value,
|
||||
'after_assembly_used_value': self.after_assembly_used_value,
|
||||
'after_assembly_tool_loading_length': self.after_assembly_tool_loading_length,
|
||||
'after_assembly_handle_length': self.after_assembly_handle_length,
|
||||
'after_assembly_functional_tool_length': self.after_assembly_functional_tool_length,
|
||||
'after_assembly_effective_length': self.after_assembly_effective_length,
|
||||
'L_D_number': self.L_D_number,
|
||||
'hiding_length': self.hiding_length,
|
||||
'assemble_status': '2',
|
||||
'tool_loading_person': self.env.user.name,
|
||||
'image': self.image,
|
||||
'tool_loading_time': fields.Datetime.now()
|
||||
}
|
||||
|
||||
def get_desc_2(self, stock_lot, functional_tool_assembly_id):
|
||||
return {
|
||||
'barcode_id': stock_lot.id,
|
||||
'code': self.code,
|
||||
'name': self.after_name_id.name,
|
||||
'tool_name_id': self.after_name_id.id,
|
||||
'rfid': self.rfid,
|
||||
'tool_groups_id': self.after_tool_groups_id.id,
|
||||
'functional_tool_name_id': functional_tool_assembly_id.id,
|
||||
'sf_cutting_tool_type_id': self.after_assembly_functional_tool_type_id.id,
|
||||
'cutting_tool_integral_model_id': self.integral_product_id.id,
|
||||
'cutting_tool_blade_model_id': self.blade_product_id.id,
|
||||
'cutting_tool_cutterbar_model_id': self.bar_product_id.id,
|
||||
'cutting_tool_cutterpad_model_id': self.pad_product_id.id,
|
||||
'cutting_tool_cutterhandle_model_id': self.handle_product_id.id,
|
||||
'cutting_tool_cutterhead_model_id': self.chuck_product_id.id,
|
||||
|
||||
'functional_tool_diameter': self.after_assembly_functional_tool_diameter,
|
||||
'knife_tip_r_angle': self.after_assembly_knife_tip_r_angle,
|
||||
'coarse_middle_thin': self.after_assembly_coarse_middle_thin,
|
||||
'new_former': self.after_assembly_new_former,
|
||||
'tool_loading_length': self.after_assembly_tool_loading_length,
|
||||
'handle_length': self.after_assembly_handle_length,
|
||||
'functional_tool_length': self.after_assembly_functional_tool_length,
|
||||
'effective_length': self.after_assembly_effective_length,
|
||||
|
||||
'max_lifetime_value': self.after_assembly_max_lifetime_value,
|
||||
'alarm_value': self.after_assembly_alarm_value,
|
||||
'used_value': self.after_assembly_used_value,
|
||||
'whether_standard_knife': self.after_assembly_whether_standard_knife,
|
||||
'L_D_number': self.L_D_number,
|
||||
'hiding_length': self.hiding_length,
|
||||
'cut_time': self.cut_time,
|
||||
'cut_length': self.cut_length,
|
||||
'cut_number': self.cut_number,
|
||||
'image': self.image,
|
||||
}
|
||||
# def functional_tool_assembly(self):
|
||||
# """
|
||||
# 功能刀具组装
|
||||
# :return:
|
||||
# """
|
||||
# logging.info('功能刀具开始组装!')
|
||||
# # 获取组装单对象
|
||||
# functional_tool_assembly = self.env['sf.functional.tool.assembly'].search([
|
||||
# ('assembly_order_code', '=', self.assembly_order_code),
|
||||
# ('machine_tool_name_id', '=', self.machine_tool_name_id.id),
|
||||
# ('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id),
|
||||
# ('assemble_status', '=', '0'),
|
||||
# ])
|
||||
# # 对物料做必填判断
|
||||
# self.materials_must_be_judged()
|
||||
#
|
||||
# product_id = self.env['product.product']
|
||||
# # 创建组装入库单
|
||||
# # 创建功能刀具批次/序列号记录
|
||||
# stock_lot = product_id.create_assemble_warehouse_receipt(self.id, functional_tool_assembly, self)
|
||||
# # 封装功能刀具数据,用于更新组装单信息
|
||||
# desc_1 = self.get_desc_1(stock_lot)
|
||||
# # 封装功能刀具数据,用于创建功能刀具记录
|
||||
# desc_2 = self.get_desc_2(stock_lot, functional_tool_assembly)
|
||||
# # 创建功能刀具组装入库单
|
||||
# self.env['stock.picking'].create_tool_stocking_picking(stock_lot, functional_tool_assembly, self)
|
||||
# # 创建刀具物料出库单
|
||||
# self.env['stock.picking'].create_tool_stocking_picking1(self)
|
||||
#
|
||||
# # ============================创建功能刀具列表、安全库存记录===============================
|
||||
# # 创建功能刀具列表记录
|
||||
# record_1 = self.env['sf.functional.cutting.tool.entity'].create(desc_2)
|
||||
# # 创建安全库存信息
|
||||
# self.env['sf.real.time.distribution.of.functional.tools'].create_or_edit_safety_stock({
|
||||
# 'functional_name_id': self.after_name_id.id
|
||||
# }, record_1)
|
||||
#
|
||||
# # =====================修改功能刀具组装单、机床换刀申请、CAM工单程序用刀计划的状态==============
|
||||
# # 修改功能刀具组装单信息
|
||||
# functional_tool_assembly.write(desc_1)
|
||||
# if functional_tool_assembly.sf_machine_table_tool_changing_apply_id:
|
||||
# # 修改机床换刀申请的状态
|
||||
# self.env['sf.machine.table.tool.changing.apply'].sudo().search([
|
||||
# ('id', '=', functional_tool_assembly.sf_machine_table_tool_changing_apply_id.id)
|
||||
# ]).write({'status': '3'})
|
||||
# elif functional_tool_assembly.sf_cam_work_order_program_knife_plan_id:
|
||||
# # 修改CAM工单程序用刀计划状态
|
||||
# cam_plan = self.env['sf.cam.work.order.program.knife.plan'].sudo().search([
|
||||
# ('id', '=', functional_tool_assembly.sf_cam_work_order_program_knife_plan_id.id)
|
||||
# ])
|
||||
# cam_plan.write({'plan_execute_status': '2'})
|
||||
#
|
||||
# logging.info('功能刀具组装完成!')
|
||||
#
|
||||
# # 关闭弹出窗口
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
#
|
||||
# def materials_must_be_judged(self):
|
||||
# """
|
||||
# 功能刀具组装必填判断
|
||||
# """
|
||||
# # 物料必填校验
|
||||
# if not self.handle_code_id:
|
||||
# raise ValidationError('缺少【刀柄】物料信息!')
|
||||
# if not self.integral_product_id and not self.blade_product_id:
|
||||
# raise ValidationError('【整体式刀具】和【刀片】必须填写一个!')
|
||||
# if self.blade_product_id:
|
||||
# if not self.bar_product_id and not self.pad_product_id:
|
||||
# raise ValidationError('【刀盘】和【刀杆】必须填写一个!')
|
||||
# # 组装参数必填校验
|
||||
# if self.after_assembly_functional_tool_length == 0:
|
||||
# raise ValidationError('组装参数信息【伸出长】不能为0!')
|
||||
# if self.after_assembly_max_lifetime_value == 0:
|
||||
# raise ValidationError('组装参数信息【最大寿命值】不能为0!')
|
||||
# if self.after_assembly_alarm_value == 0:
|
||||
# raise ValidationError('组装参数信息【报警值】不能为0!')
|
||||
# # if self.after_assembly_effective_length == 0:
|
||||
# # raise ValidationError('组装参数信息【有效长】不能为0!!!')
|
||||
# # if self.hiding_length == 0:
|
||||
# # raise ValidationError('组装参数信息【避空长】不能为0!!!')
|
||||
# if self.after_assembly_functional_tool_diameter == 0:
|
||||
# raise ValidationError('组装参数信息【刀具直径】不能为0!')
|
||||
# if self.after_assembly_tool_loading_length == 0:
|
||||
# raise ValidationError('组装参数信息【总长度】不能为0!!!')
|
||||
# if self.after_assembly_handle_length == 0:
|
||||
# raise ValidationError('组装参数信息【刀柄长度】不能为0!')
|
||||
# if self.after_assembly_tool_loading_length < self.after_assembly_handle_length:
|
||||
# raise ValidationError('组装参数信息【刀柄长度】不能大于【总长度】!')
|
||||
#
|
||||
# def get_desc_1(self, stock_lot):
|
||||
# return {
|
||||
# 'start_preset_bool': False,
|
||||
# 'barcode_id': stock_lot.id,
|
||||
# 'code': self.code,
|
||||
# 'rfid': self.rfid,
|
||||
# 'tool_groups_id': self.after_tool_groups_id.id,
|
||||
# 'handle_code_id': self.handle_code_id.id,
|
||||
# 'integral_freight_barcode_id': self.integral_freight_barcode_id.id,
|
||||
# 'integral_lot_id': self.integral_freight_lot_id.lot_id.id,
|
||||
# 'blade_freight_barcode_id': self.blade_freight_barcode_id.id,
|
||||
# 'blade_lot_id': self.blade_freight_lot_id.lot_id.id,
|
||||
# 'bar_freight_barcode_id': self.bar_freight_barcode_id.id,
|
||||
# 'bar_lot_id': self.bar_freight_lot_id.lot_id.id,
|
||||
# 'pad_freight_barcode_id': self.pad_freight_barcode_id.id,
|
||||
# 'pad_lot_id': self.pad_freight_lot_id.lot_id.id,
|
||||
# 'chuck_freight_barcode_id': self.chuck_freight_barcode_id.id,
|
||||
# 'chuck_lot_id': self.chuck_freight_lot_id.lot_id.id,
|
||||
#
|
||||
# 'after_assembly_functional_tool_name': self.after_assembly_functional_tool_name,
|
||||
# 'after_assembly_functional_tool_type_id': self.after_assembly_functional_tool_type_id.id,
|
||||
# 'after_assembly_functional_tool_diameter': self.after_assembly_functional_tool_diameter,
|
||||
# 'after_assembly_knife_tip_r_angle': self.after_assembly_knife_tip_r_angle,
|
||||
# 'after_assembly_new_former': self.after_assembly_new_former,
|
||||
# 'cut_time': self.cut_time,
|
||||
# 'cut_length': self.cut_length,
|
||||
# 'cut_number': self.cut_number,
|
||||
# 'after_assembly_whether_standard_knife': self.after_assembly_whether_standard_knife,
|
||||
# 'after_assembly_coarse_middle_thin': self.after_assembly_coarse_middle_thin,
|
||||
# 'after_assembly_max_lifetime_value': self.after_assembly_max_lifetime_value,
|
||||
# 'after_assembly_alarm_value': self.after_assembly_alarm_value,
|
||||
# 'after_assembly_used_value': self.after_assembly_used_value,
|
||||
# 'after_assembly_tool_loading_length': self.after_assembly_tool_loading_length,
|
||||
# 'after_assembly_handle_length': self.after_assembly_handle_length,
|
||||
# 'after_assembly_functional_tool_length': self.after_assembly_functional_tool_length,
|
||||
# 'after_assembly_effective_length': self.after_assembly_effective_length,
|
||||
# 'L_D_number': self.L_D_number,
|
||||
# 'hiding_length': self.hiding_length,
|
||||
# 'assemble_status': '1',
|
||||
# 'tool_loading_person': self.env.user.name,
|
||||
# 'image': self.image,
|
||||
# 'tool_loading_time': fields.Datetime.now()
|
||||
# }
|
||||
#
|
||||
# def get_desc_2(self, stock_lot, functional_tool_assembly_id):
|
||||
# return {
|
||||
# 'barcode_id': stock_lot.id,
|
||||
# 'code': self.code,
|
||||
# 'name': self.after_name_id.name,
|
||||
# 'tool_name_id': self.after_name_id.id,
|
||||
# 'rfid': self.rfid,
|
||||
# 'tool_groups_id': self.after_tool_groups_id.id,
|
||||
# 'functional_tool_name_id': functional_tool_assembly_id.id,
|
||||
# 'sf_cutting_tool_type_id': self.after_assembly_functional_tool_type_id.id,
|
||||
# 'cutting_tool_integral_model_id': self.integral_product_id.id,
|
||||
# 'cutting_tool_blade_model_id': self.blade_product_id.id,
|
||||
# 'cutting_tool_cutterbar_model_id': self.bar_product_id.id,
|
||||
# 'cutting_tool_cutterpad_model_id': self.pad_product_id.id,
|
||||
# 'cutting_tool_cutterhandle_model_id': self.handle_product_id.id,
|
||||
# 'cutting_tool_cutterhead_model_id': self.chuck_product_id.id,
|
||||
#
|
||||
# 'functional_tool_diameter': self.after_assembly_functional_tool_diameter,
|
||||
# 'knife_tip_r_angle': self.after_assembly_knife_tip_r_angle,
|
||||
# 'coarse_middle_thin': self.after_assembly_coarse_middle_thin,
|
||||
# 'new_former': self.after_assembly_new_former,
|
||||
# 'tool_loading_length': self.after_assembly_tool_loading_length,
|
||||
# 'handle_length': self.after_assembly_handle_length,
|
||||
# 'functional_tool_length': self.after_assembly_functional_tool_length,
|
||||
# 'effective_length': self.after_assembly_effective_length,
|
||||
#
|
||||
# 'max_lifetime_value': self.after_assembly_max_lifetime_value,
|
||||
# 'alarm_value': self.after_assembly_alarm_value,
|
||||
# 'used_value': self.after_assembly_used_value,
|
||||
# 'whether_standard_knife': self.after_assembly_whether_standard_knife,
|
||||
# 'L_D_number': self.L_D_number,
|
||||
# 'hiding_length': self.hiding_length,
|
||||
# 'cut_time': self.cut_time,
|
||||
# 'cut_length': self.cut_length,
|
||||
# 'cut_number': self.cut_number,
|
||||
# 'image': self.image,
|
||||
# }
|
||||
|
||||
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def create_tool_stocking_picking(self, stock_lot, functional_tool_assembly, obj):
|
||||
"""
|
||||
创建功能刀具组装入库单
|
||||
"""
|
||||
# 获取名称为刀具组装入库的作业类型
|
||||
picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '刀具组装入库')])
|
||||
# 创建刀具组装入库单
|
||||
picking_id = self.env['stock.picking'].create({
|
||||
'name': self._get_name_stock(picking_type_id),
|
||||
'picking_type_id': picking_type_id.id,
|
||||
'location_id': picking_type_id.default_location_src_id.id,
|
||||
'location_dest_id': picking_type_id.default_location_dest_id.id,
|
||||
'origin': obj.assembly_order_code
|
||||
})
|
||||
# 创建作业详情对象记录,并绑定到刀具组装入库单
|
||||
self.env['stock.move.line'].create({
|
||||
'picking_id': picking_id.id,
|
||||
'product_id': stock_lot.product_id.id,
|
||||
'location_id': picking_id.location_id.id,
|
||||
'location_dest_id': picking_id.location_dest_id.id,
|
||||
'lot_id': stock_lot.id,
|
||||
'install_tool_time': fields.Datetime.now(),
|
||||
'qty_done': 1,
|
||||
'functional_tool_name_id': functional_tool_assembly.id,
|
||||
'functional_tool_type_id': obj.functional_tool_type_id.id,
|
||||
'diameter': obj.after_assembly_functional_tool_diameter,
|
||||
'knife_tip_r_angle': obj.after_assembly_knife_tip_r_angle,
|
||||
'code': obj.code,
|
||||
'rfid': obj.rfid,
|
||||
'functional_tool_name': obj.after_assembly_functional_tool_name,
|
||||
'tool_groups_id': obj.after_tool_groups_id.id
|
||||
})
|
||||
# 将刀具组装入库单的状态更改为就绪
|
||||
picking_id.action_confirm()
|
||||
picking_id.button_validate()
|
||||
|
||||
def _get_name_stock(self, picking_type_id):
|
||||
name = picking_type_id.sequence_id.prefix + str(
|
||||
datetime.strptime(str(fields.Date.today()), "%Y-%m-%d").strftime("%Y%m%d"))
|
||||
stock_id = self.env['stock.picking'].sudo().search(
|
||||
[('name', 'like', name), ('picking_type_id', '=', picking_type_id.id)],
|
||||
limit=1,
|
||||
order="id desc"
|
||||
)
|
||||
if not stock_id:
|
||||
num = "%03d" % 1
|
||||
else:
|
||||
m = int(stock_id.name[-3:]) + 1
|
||||
num = "%03d" % m
|
||||
return name + str(num)
|
||||
|
||||
def create_tool_stocking_picking1(self, obj):
|
||||
"""
|
||||
创建刀具物料出库单
|
||||
"""
|
||||
# 获取名称为内部调拨的作业类型
|
||||
picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '内部调拨')])
|
||||
# 创建刀具物料出库单
|
||||
picking_id = self.env['stock.picking'].create({
|
||||
'name': self._get_name_stock1(picking_type_id),
|
||||
'picking_type_id': picking_type_id.id,
|
||||
'location_id': self.env['stock.location'].search([('name', '=', '刀具房')]).id,
|
||||
'location_dest_id': self.env['stock.location'].search([('name', '=', '刀具组装位置')]).id,
|
||||
'origin': obj.assembly_order_code
|
||||
})
|
||||
# =============刀具物料出库===================
|
||||
stock_move_id = self.env['stock.move']
|
||||
datas = {'data': [], 'picking_id': picking_id}
|
||||
if obj.handle_code_id:
|
||||
# 修改刀柄序列号状态为【在用】
|
||||
obj.handle_code_id.sudo().write({'tool_material_status': '在用'})
|
||||
datas['data'].append(
|
||||
{'current_location_id': self.env['sf.shelf.location'], 'lot_id': obj.handle_code_id})
|
||||
if obj.integral_product_id:
|
||||
datas['data'].append(
|
||||
{'current_location_id': obj.integral_freight_barcode_id, 'lot_id': obj.integral_freight_lot_id.lot_id})
|
||||
if obj.blade_product_id:
|
||||
datas['data'].append(
|
||||
{'current_location_id': obj.blade_freight_barcode_id, 'lot_id': obj.blade_freight_lot_id.lot_id})
|
||||
if obj.bar_product_id:
|
||||
datas['data'].append(
|
||||
{'current_location_id': obj.bar_freight_barcode_id, 'lot_id': obj.bar_freight_lot_id.lot_id})
|
||||
if obj.pad_product_id:
|
||||
datas['data'].append(
|
||||
{'current_location_id': obj.pad_freight_barcode_id, 'lot_id': obj.pad_freight_lot_id.lot_id})
|
||||
if obj.chuck_product_id:
|
||||
datas['data'].append(
|
||||
{'current_location_id': obj.chuck_freight_barcode_id, 'lot_id': obj.chuck_freight_lot_id.lot_id})
|
||||
# 创建刀具物料出库库存移动记录
|
||||
stock_move_id.create_tool_material_stock_moves(datas)
|
||||
# 将刀具物料出库库单的状态更改为就绪
|
||||
picking_id.action_confirm()
|
||||
# 修改刀具物料出库移动历史记录
|
||||
stock_move_id.write_tool_material_stock_move_lines(datas)
|
||||
# 设置数量,并验证完成
|
||||
picking_id.action_set_quantities_to_reservation()
|
||||
picking_id.button_validate()
|
||||
logging.info(f'刀具物料调拨单状态:{picking_id.state}')
|
||||
|
||||
def _get_name_stock1(self, picking_type_id):
|
||||
name = f'{picking_type_id.sequence_id.prefix}DJ/{date.today().strftime("%y")}'
|
||||
stock_id = self.env['stock.picking'].sudo().search(
|
||||
[('name', 'like', name), ('picking_type_id', '=', picking_type_id.id)],
|
||||
limit=1,
|
||||
order="id desc"
|
||||
)
|
||||
if not stock_id:
|
||||
num = "%05d" % 1
|
||||
else:
|
||||
m = int(stock_id.name[-5:]) + 1
|
||||
num = "%05d" % m
|
||||
return name + str(num)
|
||||
|
||||
|
||||
class StockMove(models.Model):
|
||||
_inherit = 'stock.move'
|
||||
|
||||
def create_tool_material_stock_moves(self, datas):
|
||||
picking_id = datas['picking_id']
|
||||
data = datas['data']
|
||||
stock_move_ids = []
|
||||
for res in data:
|
||||
if res:
|
||||
# 创建库存移动记录
|
||||
stock_move_id = self.env['stock.move'].sudo().create({
|
||||
'name': picking_id.name,
|
||||
'picking_id': picking_id.id,
|
||||
'product_id': res['lot_id'].product_id.id,
|
||||
'location_id': picking_id.location_id.id,
|
||||
'location_dest_id': picking_id.location_dest_id.id,
|
||||
'product_uom_qty': 1.00,
|
||||
'reserved_availability': 1.00
|
||||
})
|
||||
stock_move_ids.append(stock_move_id)
|
||||
return stock_move_ids
|
||||
|
||||
def write_tool_material_stock_move_lines(self, datas):
|
||||
picking_id = datas['picking_id']
|
||||
data = datas['data']
|
||||
move_line_ids = picking_id.move_line_ids
|
||||
for move_line_id in move_line_ids:
|
||||
for res in data:
|
||||
if move_line_id.lot_id.product_id == res['lot_id'].product_id:
|
||||
move_line_id.write({
|
||||
'current_location_id': res.get('current_location_id').id,
|
||||
'lot_id': res.get('lot_id').id
|
||||
})
|
||||
return True
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def create_assemble_warehouse_receipt(self, tool_assembly_order_id, functional_tool_assembly, obj):
|
||||
"""
|
||||
创建功能刀具批次/序列号记录
|
||||
"""
|
||||
product_id = self.env['product.product'].search([('categ_type', '=', '功能刀具'), ('tracking', '=', 'serial')])
|
||||
if not product_id:
|
||||
logging.info('没有搜索到功能刀具产品:%s' % product_id)
|
||||
raise ValidationError('没有找到按唯一序列号追溯的功能刀具产品信息!')
|
||||
stock_lot = self.env['stock.lot'].create({
|
||||
'name': self.get_stock_lot_name(obj),
|
||||
'product_id': product_id[0].id,
|
||||
'company_id': self.env.company.id
|
||||
})
|
||||
return stock_lot
|
||||
|
||||
def get_stock_lot_name(self, obj):
|
||||
"""
|
||||
生成功能刀具序列号
|
||||
"""
|
||||
company = obj.cutting_tool_cutterhandle_model_id.code.split('-', 1)[0]
|
||||
new_time = datetime.strptime(str(fields.Date.today()), "%Y-%m-%d").strftime("%Y%m%d")
|
||||
code = '%s-GNDJ-%s-%s' % (company, obj.after_assembly_functional_tool_type_id.code, new_time)
|
||||
stock_lot_id = self.env['stock.lot'].sudo().search(
|
||||
[('name', 'like', code)], limit=1, order="id desc")
|
||||
if not stock_lot_id:
|
||||
num = "%03d" % 1
|
||||
else:
|
||||
m = int(stock_lot_id.name[-3:]) + 1
|
||||
num = "%03d" % m
|
||||
return '%s-%s' % (code, num)
|
||||
|
||||
@@ -427,10 +427,10 @@
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button string="确定" name="functional_tool_assembly" type="object" class="btn-primary"
|
||||
attrs="{'invisible': [('obtain_measurement_status', '=', False),('enable_tool_presetter', '=', True)]}"
|
||||
confirm="是否确认申请组装"/>
|
||||
<button string="取消" class="btn-secondary" special="cancel"/>
|
||||
<!-- <button string="确定" name="functional_tool_assembly" type="object" class="btn-primary"-->
|
||||
<!-- attrs="{'invisible': [('obtain_measurement_status', '=', False),('enable_tool_presetter', '=', True)]}"-->
|
||||
<!-- confirm="是否确认申请组装"/>-->
|
||||
<!-- <button string="取消" class="btn-secondary" special="cancel"/>-->
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user