Files
test/sf_tool_management/wizard/wizard.py

586 lines
33 KiB
Python

from datetime import timedelta
from odoo import fields, models, api
from odoo.exceptions import ValidationError
class ToolChangeRequirementInformation(models.TransientModel):
_name = 'sf.tool.change.requirement.information'
_description = '换刀需求信息'
name = fields.Char('名称', related='maintenance_equipment_id.name', store=True, readonly=True)
maintenance_equipment_id = fields.Many2one('maintenance.equipment', string='CNC机床', readonly=True)
production_line_id = fields.Many2one('sf.production.line', string='生产线', readonly=True)
machine_table_type_id = fields.Many2one('maintenance.equipment.category', string='机床类型', readonly=True)
machine_tool_code = fields.Char(string='机台号', store=True, invisible=True, readonly=True)
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', readonly=True)
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
functional_tool_name = fields.Char(string='功能刀具名称', readonly=True)
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
tool_position_interface_type = fields.Selection(
[('BT刀柄式', 'BT刀柄式'), ('SK刀柄式', 'SK刀柄式'), ('HSK刀柄式', 'HSK刀柄式'),
('CAT刀柄式', 'CAT刀柄式'), ('ISO刀盘式', 'ISO刀盘式'), ('DIN刀盘式', 'DIN刀盘式'),
('直装固定式', '直装固定式')], string='刀位接口型号', readonly=True)
diameter = fields.Integer(string='刀具直径(mm)', readonly=True)
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True)
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
used_value = fields.Integer(string='已使用值(min)', readonly=True)
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
extension_length = fields.Float(string='伸出长(mm)', readonly=True)
effective_length = fields.Float(string='有效长(mm)', readonly=True)
# 待换功能刀具信息
replacement_tool_name = fields.Char(string='待换功能刀具名称', required=True)
replacement_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='待换功能刀具类型')
replacement_diameter = fields.Integer(string='待换刀具直径(mm)')
replacement_knife_tip_r_angle = fields.Float(string='待换刀具刀尖R角(mm)')
replacement_tool_setting_length = fields.Float(string='待换刀具装刀长(mm)')
replacement_extension_length = fields.Float(string='待换刀具伸出长(mm)')
replacement_effective_length = fields.Float(string='待换刀具有效长(mm)')
replacement_tool_coarse_middle_thin = fields.Selection([("1", ""), ('2', ''), ('3', '')],
string='待换刀具粗/中/精', default='3')
replacement_max_lifetime_value = fields.Integer(string='待换刀具最大寿命值(min)')
replacement_alarm_value = fields.Integer(string='待换刀具报警值(min)')
replacement_used_value = fields.Integer(string='待换刀具已使用值(min)')
new_former = fields.Selection([('0', ''), ('1', '')], string='新/旧', default='0')
replacement_whether_standard_knife = fields.Boolean(string='待换刀具是否标准刀', default=True)
used_tool_time = fields.Datetime(string='用刀时间',
default=lambda self: fields.Datetime.now() + timedelta(hours=4))
applicant = fields.Char(string='申请人', default=lambda self: self.env.user.name, readonly=True)
reason_for_applying = fields.Char(string='申请原因')
def tool_changing_apply(self):
"""
确认换刀申请(按键)
:return:
"""
record = 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)
])
# 功能刀具组装创建新任务(new_assembly_task)
sf_functional_tool_assembly = self.env['sf.functional.tool.assembly'].sudo().create({
'functional_tool_name': self.replacement_tool_name,
'functional_tool_type_id': self.replacement_tool_type_id.id,
'functional_tool_diameter': self.replacement_diameter,
'knife_tip_r_angle': self.replacement_knife_tip_r_angle,
'coarse_middle_thin': self.replacement_tool_coarse_middle_thin,
'new_former': self.new_former,
'tool_loading_length': self.replacement_tool_setting_length,
'functional_tool_length': self.replacement_extension_length,
'effective_length': self.replacement_effective_length,
'loading_task_source': '1',
'use_tool_time': self.used_tool_time,
'production_line_name_id': self.production_line_id.id,
'machine_tool_name_id': self.maintenance_equipment_id.id,
'applicant': self.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': self.reason_for_applying,
'sf_machine_table_tool_changing_apply_id': record.id
})
# 修改机床换刀申请状态
record.write({
'status': '1',
'sf_functional_tool_assembly_id': sf_functional_tool_assembly.id
})
# 关闭弹出窗口
return {'type': 'ir.actions.act_window_close'}
class ToolTransferRequestInformation(models.TransientModel):
_name = 'sf.tool.transfer.request.information'
_description = '刀具转移申请信息'
name = fields.Char('名称', related='maintenance_equipment_id.name', store=True, readonly=True)
maintenance_equipment_id = fields.Many2one('maintenance.equipment', string='CNC机床', readonly=True)
production_line_id = fields.Many2one('sf.production.line', string='生产线', readonly=True)
machine_table_type_id = fields.Many2one('maintenance.equipment.category', string='机床类型', readonly=True)
machine_tool_code = fields.Char(string='机台号', store=True, invisible=True, readonly=True)
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', readonly=True)
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
functional_tool_name = fields.Char(string='功能刀具名称', readonly=True)
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=True)
tool_position_interface_type = fields.Selection(
[('BT刀柄式', 'BT刀柄式'), ('SK刀柄式', 'SK刀柄式'), ('HSK刀柄式', 'HSK刀柄式'),
('CAT刀柄式', 'CAT刀柄式'), ('ISO刀盘式', 'ISO刀盘式'), ('DIN刀盘式', 'DIN刀盘式'),
('直装固定式', '直装固定式')], string='刀位接口型号', readonly=True)
diameter = fields.Integer(string='刀具直径(mm)', readonly=True)
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True)
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
used_value = fields.Integer(string='已使用值(min)', readonly=True)
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
extension_length = fields.Float(string='伸出长(mm)', readonly=True)
effective_length = fields.Float(string='有效长(mm)', readonly=True)
# 转移刀具信息
transfer_target = fields.Selection([('机台', '机台'),
('线边刀库', '线边刀库'),
('刀具房', '刀具房')], string='转移到:', default='线边刀库')
new_cnc_machine_table_id = fields.Many2one('sf.machine_tool', string='机床名称')
new_production_line_id = fields.Many2one('sf.production.line', 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):
"""
todo 刀具转移申请信息确定按钮
:return:
"""
self.env['sf.machine.table.tool.changing.apply'].search(
[('name', '=', self.CNC_machine_table_id.id)]).write({'status': '2'})
class FunctionalToolAssemblyOrder(models.TransientModel):
_name = 'sf.functional.tool.assembly.order'
_inherit = ["barcodes.barcode_events_mixin"]
_description = '功能刀具组装单'
assembly_order_code = fields.Char(string='编码', readonly=True)
functional_tool_name_id = fields.Many2one('product.product', string='功能刀具', readonly=True)
functional_tool_name = fields.Char(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')
functional_tool_diameter = fields.Integer(string='功能刀具直径(mm)', readonly=True)
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True)
coarse_middle_thin = fields.Selection([("1", ""), ('2', ''), ('3', '')], string='粗/中/精', readonly=True)
new_former = fields.Selection([('0', ''), ('1', '')], string='新/旧', readonly=True)
tool_loading_length = fields.Float(string='装刀长(mm)', readonly=True)
functional_tool_length = fields.Float(string='伸出长(mm)', readonly=True)
effective_length = fields.Float(string='有效长(mm)', readonly=True)
loading_task_source = fields.Selection([('0', 'CAM装刀'), ('1', '机台换刀'), ('2', '按库存组装')],
string='装刀任务来源', readonly=True)
use_tool_time = fields.Datetime(string='用刀时间', readonly=True)
production_line_name_id = fields.Many2one('sf.production.line', string='申请产线', readonly=True)
machine_tool_name_id = fields.Many2one('maintenance.equipment', string='申请机台', readonly=True)
machine_tool_code = fields.Char(string='机台号', readonly=True)
applicant = fields.Char(string='申请人', readonly=True)
apply_time = fields.Datetime(string='申请时间', default=fields.Datetime.now(), readonly=True)
assemble_status = fields.Selection([('0', '待组装'), ('1', '已组装')], string='组装状态', default='0',
readonly=True)
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号', readonly=True)
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
reason_for_applying = fields.Char(string='申请原因', readonly=True)
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
used_value = fields.Integer(string='已使用值(min)', readonly=True)
# 功能刀具组装信息
# 整体式刀具型号
integral_code_id = fields.Many2one('stock.lot', string='整体式刀具序列号',
domain=[('product_id.cutting_tool_material_id.name', '=', '整体式刀具'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_integral_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='整体式刀具型号',
readonly=True)
integral_name = fields.Char('整体式刀具名称', readonly=True)
sf_tool_brand_id_1 = fields.Many2one('sf.machine.brand', string='整体式刀具品牌', readonly=True)
# 刀片型号
blade_code_id = fields.Many2one('stock.lot', '刀片序列号',
domain=[('product_id.cutting_tool_material_id.name', '=', '刀片'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_blade_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀片型号', readonly=True)
blade_name = fields.Char('刀片名称', readonly=True)
sf_tool_brand_id_2 = fields.Many2one('sf.machine.brand', '刀片品牌', readonly=True)
# 刀杆型号
bar_code_id = fields.Many2one('stock.lot', '刀杆序列号',
domain=[('product_id.cutting_tool_material_id.name', '=', '刀杆'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_cutterbar_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀杆型号',
readonly=True)
bar_name = fields.Char('刀杆名称', readonly=True)
sf_tool_brand_id_3 = fields.Many2one('sf.machine.brand', '刀杆品牌', readonly=True)
# 刀盘型号
pad_code_id = fields.Many2one('stock.lot', '刀盘序列号',
domain=[('product_id.cutting_tool_material_id.name', '=', '刀盘'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_cutterpad_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀盘型号',
readonly=True)
pad_name = fields.Char('刀盘名称', readonly=True)
sf_tool_brand_id_4 = fields.Many2one('sf.machine.brand', '刀盘品牌', readonly=True)
# 刀柄型号
handle_code_id = fields.Many2one('stock.lot', '刀柄序列号', required=True,
domain=[('product_id.cutting_tool_material_id.name', '=', '刀柄'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_cutterhandle_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀柄型号',
readonly=True)
handle_name = fields.Char('刀柄名称', readonly=True)
sf_tool_brand_id_5 = fields.Many2one('sf.machine.brand', '刀柄品牌', readonly=True)
# 夹头型号
chuck_code_id = fields.Many2one('stock.lot', '夹头序列号', required=True,
domain=[('product_id.cutting_tool_material_id.name', '=', '夹头'),
('quant_ids.location_id.name', 'in', ['刀具房'])])
cutting_tool_cutterhead_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='夹头型号',
readonly=True)
chuck_name = fields.Char('夹头名称', readonly=True, compute='_compute_auto_fill')
sf_tool_brand_id_6 = fields.Many2one('sf.machine.brand', '夹头品牌', readonly=True)
def on_barcode_scanned(self, barcode):
"""
智能工厂组装单处扫码绑定刀具物料')
"""
for record in self:
records = record.env['stock.lot'].search([('name', '=', barcode)])
if not records:
raise ValidationError('扫描的条形码数据不存在,请重新扫描!')
for record_stock_lot in records:
tool_material_name = record_stock_lot.product_id.cutting_tool_material_id.name
if tool_material_name == '整体式刀具':
record.integral_code_id = record_stock_lot.id
elif tool_material_name == '刀片':
record.blade_code_id = record_stock_lot.id
elif tool_material_name == '刀杆':
record.bar_code_id = record_stock_lot.id
elif tool_material_name == '刀盘':
record.pad_code_id = record_stock_lot.id
elif tool_material_name == '刀柄':
record.handle_code_id = record_stock_lot.id
elif tool_material_name == '夹头':
record.chuck_code_id = record_stock_lot.id
else:
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
@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_model_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_model_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_model_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_model_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_model_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_model_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
# 组装功能刀具参数信息
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号')
after_assembly_functional_tool_name = fields.Char(string='组装后功能刀具名称', required=True)
after_assembly_functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model',
string='组装后功能刀具类型')
after_assembly_functional_tool_diameter = fields.Integer(string='组装后功能刀具直径(mm)')
after_assembly_knife_tip_r_angle = fields.Float(string='组装后刀尖R角(mm)')
after_assembly_new_former = fields.Selection([('0', ''), ('1', '')], string='组装后新/旧')
cut_time = fields.Integer(string='已切削时间(min)')
cut_length = fields.Float(string='已切削长度(mm)')
cut_number = fields.Integer(string='已切削次数')
after_assembly_whether_standard_knife = fields.Boolean(string='组装后是否标准刀', default=True)
after_assembly_coarse_middle_thin = fields.Selection([("1", ""), ('2', ''), ('3', '')],
string='组装后粗/中/精')
after_assembly_max_lifetime_value = fields.Integer(string='组装后最大寿命值(min)')
after_assembly_alarm_value = fields.Integer(string='组装后报警值(min)')
after_assembly_used_value = fields.Integer(string='组装后已使用值(min)')
after_assembly_tool_loading_length = fields.Float(string='组装后装刀长(mm)')
after_assembly_functional_tool_length = fields.Float(string='组装后伸出长(mm)')
after_assembly_effective_length = fields.Float(string='组装后有效长(mm)')
L_D_number = fields.Float(string='L/D值(mm)')
hiding_length = fields.Float(string='避空长(mm)')
functional_tool_cutting_type = fields.Char(string='功能刀具切削类型', readonly=False)
def functional_tool_assembly(self):
"""
功能刀具组装
:return:
"""
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()
# # 刀具物料出库
# if self.integral_code_id:
# print("已运行1111")
# self.tool_material_out_of_store(self.integral_code_id)
# 创建组装入库单
# 创建功能刀具批次/序列号记录
stock_lot = self.create_assemble_warehouse_receipt(functional_tool_assembly)
# 创建刀具组装入库单
self.create_stocking_picking(stock_lot)
# 封装功能刀具数据
desc_1 = self.get_desc_1(stock_lot)
# 创建功能刀具列表记录
# 封装功能刀具数据
desc_2 = self.get_desc_2(stock_lot, functional_tool_assembly)
# 创建功能刀具列表记录
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({
'name': self.after_assembly_functional_tool_name,
'sf_cutting_tool_type_id': self.after_assembly_functional_tool_type_id.id,
'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,
}, record_1)
# 修改功能刀具组装单信息
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工单程序用刀计划状态
self.env['sf.cam.work.order.program.knife.plan'].sudo().search([
('id', '=', functional_tool_assembly.sf_cam_work_order_program_knife_plan_id.id)
]).write({'plan_execute_status': '2'})
# 关闭弹出窗口
return {'type': 'ir.actions.act_window_close'}
def materials_must_be_judged(self):
"""
功能刀具组装物料必填判断
"""
if not self.integral_code_id and not self.blade_code_id:
raise ValidationError('【整体式刀具】和【刀片】必须填写一个!')
if self.blade_code_id:
if not self.bar_code_id and not self.pad_code_id:
raise ValidationError('【刀盘】和【刀杆】必须填写一个!')
def create_stocking_picking(self, stock_lot):
"""
创建刀具组装入库单
"""
# 获取名称为刀具组装入库的作业类型
picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '刀具组装入库')])
# 创建刀具组装入库单
picking_id = self.env['stock.picking'].create({
'picking_type_id': picking_type_id.id
})
# 创建作业详情对象记录,并绑定到刀具组装入库单
self.env['stock.move.line'].create({
'picking_id': picking_id.id,
'product_id': stock_lot.product_id.id,
'lot_id': stock_lot.id
})
# 将刀具组装入库单的状态更改为就绪
picking_id.action_confirm()
def create_assemble_warehouse_receipt(self, functional_tool_assembly):
"""
创建功能刀具批次/序列号记录
"""
product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
stock_lot = self.env['stock.lot'].create({
'name': self.get_stock_lot_name(),
'product_id': product_id.id,
'company_id': self.env.company.id
})
# 创建功能刀具该批次/序列号 库存移动和移动历史
self.create_stock_quant(product_id, stock_lot, functional_tool_assembly)
return stock_lot
# def tool_material_out_of_store(self, tool_material_serial_id):
# """
# 刀具物料出库
# """
# # 获取位置
# location_id = self.env['stock.location'].search([('name', '=', 'Stock')])
# location_dest_id = self.env['stock.location'].search([('name', '=', '刀具组装位置')])
# print("已运行2222")
# # 创建库存移动
# stock_move_id = self.env['stock.move'].create({
# 'name': '刀具物料出库',
# 'lot_id': tool_material_serial_id.id,
# 'product_id': tool_material_serial_id.product_id.id,
# 'location_id': location_id.id,
# 'location_dest_id': location_dest_id.id,
# 'product_uom_qty': 1.00,
# 'state': 'done'
# })
# print("已运行3333")
# print(stock_move_id)
# # 创建移动历史
# stock_move_line_id = self.env['stock.move.line'].create({
# 'product_id': tool_material_serial_id.product_id.id,
# 'lot_id': tool_material_serial_id.id,
# 'move_id': stock_move_id.id,
# 'install_tool_time': fields.Datetime.now(),
# 'qty_done': 1.0,
# 'state': 'done'
# })
#
# return stock_move_id, stock_move_line_id
def create_stock_quant(self, product_id, stock_lot, functional_tool_assembly):
"""
创建功能刀具该批次/序列号 库存移动和移动历史
"""
# 获取位置对象
stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
location_inventory_id = self.env['stock.location'].search([('name', '=', 'Inventory adjustment')])
# 创建库存移动
stock_move_id = self.env['stock.move'].create({
'name': '功能刀具组装出库',
'product_id': product_id.id,
'location_id': location_inventory_id.id,
'location_dest_id': stock_location_id.id,
'product_uom_qty': 1.00,
'state': 'done'
})
# 创建移动历史
stock_move_line_id = self.env['stock.move.line'].create({
'product_id': product_id.id,
'functional_tool_name_id': functional_tool_assembly.id,
'lot_id': stock_lot.id,
'move_id': stock_move_id.id,
'install_tool_time': fields.Datetime.now(),
'qty_done': 1.0,
'state': 'done'
})
return stock_move_id, stock_move_line_id
def get_stock_lot_name(self):
"""
生成功能刀具序列号
"""
code = 'JKM-T-' + str(self.functional_tool_type_id.code) + '-' + str(self.functional_tool_diameter) + '-'
new_time = fields.Date.today()
code += str(new_time) + '-'
stock_lot_id = self.env['stock.lot'].sudo().search(
[('name', 'like', new_time), ('product_id.name', '=', '功能刀具')],
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 code + str(num)
def get_desc_1(self, stock_lot):
return {
'barcode_id': stock_lot.id,
'integral_code_id': self.integral_code_id.id,
'blade_code_id': self.blade_code_id.id,
'bar_code_id': self.bar_code_id.id,
'pad_code_id': self.pad_code_id.id,
'handle_code_id': self.handle_code_id.id,
'chuck_code_id': self.chuck_code_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_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,
'tool_loading_time': fields.Datetime.now()
}
def get_desc_2(self, stock_lot, functional_tool_assembly_id):
return {
'barcode_id': stock_lot.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_code_id.product_id.id,
'cutting_tool_blade_model_id': self.blade_code_id.product_id.id,
'cutting_tool_cutterbar_model_id': self.bar_code_id.product_id.id,
'cutting_tool_cutterpad_model_id': self.pad_code_id.product_id.id,
'cutting_tool_cutterhandle_model_id': self.handle_code_id.product_id.id,
'cutting_tool_cutterhead_model_id': self.chuck_code_id.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,
'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,
'current_location_id': stock_lot.quant_ids.location_id.ids[-1],
}