571 lines
31 KiB
Python
571 lines
31 KiB
Python
# -*- coding: utf-8 -*-
|
|
import logging
|
|
|
|
import re
|
|
from datetime import timedelta
|
|
from odoo import SUPERUSER_ID
|
|
from odoo import fields, models, api
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class FunctionalCuttingToolEntity(models.Model):
|
|
_name = 'sf.functional.cutting.tool.entity'
|
|
_description = '功能刀具列表'
|
|
|
|
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具组装单', readonly=True)
|
|
|
|
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
|
code = fields.Char('编码')
|
|
rfid = fields.Char('Rfid', readonly=True)
|
|
rfid_dismantle = fields.Char('Rfid(已拆解)', readonly=True)
|
|
name = fields.Char('名称')
|
|
tool_name_id = fields.Many2one('sf.tool.inventory', '功能刀具名称')
|
|
sf_cutting_tool_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀具型号')
|
|
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
|
sf_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型',
|
|
group_expand='_read_group_mrs_cutting_tool_type_id', compute_sudo=True)
|
|
|
|
functional_tool_diameter = fields.Float(string='刀具直径(mm)', readonly=True, digits=(10, 3))
|
|
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=True, digits=(10, 3))
|
|
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, digits=(10, 3))
|
|
handle_length = fields.Float(string='刀柄长度(mm)', readonly=True, digits=(10, 3))
|
|
functional_tool_length = fields.Float(string='伸出长(mm)', readonly=True, digits=(10, 3))
|
|
effective_length = fields.Float(string='有效长(mm)', readonly=True)
|
|
tool_room_num = fields.Integer(string='刀具房数量', compute='_compute_num', store=True)
|
|
line_edge_knife_library_num = fields.Integer(string='线边刀库数量', compute='_compute_num', store=True)
|
|
machine_knife_library_num = fields.Integer(string='机内刀库数量', compute='_compute_num', store=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)
|
|
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警'), ('已拆除', '已拆除')],
|
|
string='状态', store=True, default='正常')
|
|
current_location_id = fields.Many2one('stock.location', string='当前位置', compute='_compute_current_location_id',
|
|
store=True)
|
|
current_shelf_location_id = fields.Many2one('sf.shelf.location', string='当前货位', readonly=True)
|
|
current_location = fields.Selection(
|
|
[('组装后', '组装后'), ('刀具房', '刀具房'), ('线边刀库', '线边刀库'), ('机内刀库', '机内刀库')],
|
|
string='位置', compute='_compute_current_location_id', store=True)
|
|
image = fields.Binary('图片', readonly=True)
|
|
|
|
active = fields.Boolean(string='已归档', default=True)
|
|
|
|
safe_inventory_id = fields.Many2one('sf.real.time.distribution.of.functional.tools',
|
|
string='功能刀具安全库存', readonly=True)
|
|
|
|
@api.depends('barcode_id.quant_ids', 'functional_tool_status')
|
|
def _compute_current_location_id(self):
|
|
for record in self:
|
|
if record.functional_tool_status == '已拆除':
|
|
record.current_location_id = False
|
|
record.current_location = False
|
|
else:
|
|
if record.barcode_id.quant_ids:
|
|
for quant_id in record.barcode_id.quant_ids:
|
|
if quant_id.inventory_quantity_auto_apply > 0:
|
|
record.current_location_id = quant_id.location_id
|
|
if quant_id.location_id.name == '制造前':
|
|
if not record.current_shelf_location_id:
|
|
record.current_location = '机内刀库'
|
|
else:
|
|
record.current_location = '线边刀库'
|
|
else:
|
|
record.current_location = '刀具房'
|
|
else:
|
|
record.current_location_id = False
|
|
record.current_location = False
|
|
|
|
@api.depends('current_location', 'functional_tool_status')
|
|
def _compute_num(self):
|
|
"""
|
|
计算库存位置数量
|
|
"""
|
|
for obj in self:
|
|
if obj.functional_tool_status == '已拆除':
|
|
obj.tool_room_num = 0
|
|
obj.line_edge_knife_library_num = 0
|
|
obj.machine_knife_library_num = 0
|
|
else:
|
|
if obj.current_location_id:
|
|
obj.tool_room_num = 0
|
|
obj.line_edge_knife_library_num = 0
|
|
obj.machine_knife_library_num = 0
|
|
if obj.current_location in ['刀具房']:
|
|
obj.tool_room_num = 1
|
|
elif "线边刀库" in obj.current_location:
|
|
obj.line_edge_knife_library_num = 1
|
|
elif "机内刀库" in obj.current_location:
|
|
obj.machine_knife_library_num = 1
|
|
|
|
def tool_in_out_stock_location(self, location_id):
|
|
tool_room_id = self.env['stock.location'].search([('name', '=', '刀具房')])
|
|
pre_manufacturing_id = self.env['stock.location'].search([('name', '=', '制造前')])
|
|
for item in self:
|
|
# 中控反馈该位置有刀
|
|
if item:
|
|
# 系统该位置有刀
|
|
if location_id.product_sn_id:
|
|
# 中控反馈和系统中,该位置是同一把刀
|
|
if item.barcode_id == location_id.product_sn_id:
|
|
return True
|
|
# 中控反馈和系统中,该位置不是同一把刀
|
|
else:
|
|
# 原刀从线边出库
|
|
item.tool_in_out_stock_location_1(location_id, tool_room_id)
|
|
# 新刀入库到线边
|
|
item.create_stock_move(pre_manufacturing_id, location_id)
|
|
item.current_shelf_location_id = location_id.id
|
|
|
|
# 中控反馈该位置没有刀
|
|
else:
|
|
# 系统该位置有刀
|
|
if location_id.product_sn_id:
|
|
item.tool_in_out_stock_location_1(location_id, tool_room_id)
|
|
|
|
def tool_in_out_stock_location_1(self, location_id, tool_room_id):
|
|
tool = self.env['sf.functional.cutting.tool.entity'].search(
|
|
[('barcode_id', '=', location_id.product_sn_id.id)])
|
|
if tool.current_location == '线边刀库':
|
|
tool.create_stock_move(tool_room_id, False)
|
|
# 修改功能刀具的当前位置
|
|
tool.current_shelf_location_id = False
|
|
|
|
def create_stock_move(self, location_dest_id, destination_location_id):
|
|
|
|
# 创建库存移动记录
|
|
stock_move_id = self.env['stock.move'].sudo().create({
|
|
'name': '/',
|
|
'product_id': self.barcode_id.product_id.id,
|
|
'location_id': self.current_location_id.id,
|
|
'location_dest_id': location_dest_id.id,
|
|
'product_uom_qty': 1.00,
|
|
'state': 'done'
|
|
})
|
|
|
|
# 创建移动历史记录
|
|
stock_move_line_id = self.env['stock.move.line'].sudo().create({
|
|
'product_id': self.barcode_id.product_id.id,
|
|
'lot_id': self.barcode_id.id,
|
|
'move_id': stock_move_id.id,
|
|
'current_location_id': False if not self.current_shelf_location_id else self.current_shelf_location_id.id,
|
|
'destination_location_id': False if not destination_location_id else destination_location_id.id,
|
|
'qty_done': 1.0,
|
|
'state': 'done',
|
|
'functional_tool_type_id': self.sf_cutting_tool_type_id.id,
|
|
'diameter': self.functional_tool_diameter,
|
|
'knife_tip_r_angle': self.knife_tip_r_angle,
|
|
'code': self.code,
|
|
'rfid': self.rfid,
|
|
'functional_tool_name': self.name,
|
|
'tool_groups_id': self.tool_groups_id.id
|
|
})
|
|
return stock_move_id, stock_move_line_id
|
|
|
|
@api.model
|
|
def _read_group_mrs_cutting_tool_type_id(self, categories, domain, order):
|
|
mrs_cutting_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
|
return categories.browse(mrs_cutting_tool_type_ids)
|
|
|
|
# 整体式刀具型号
|
|
cutting_tool_integral_model_id = fields.Many2one('product.product', string='整体式刀具型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '整体式刀具')])
|
|
# 刀片型号
|
|
cutting_tool_blade_model_id = fields.Many2one('product.product', string='刀片型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '刀片')])
|
|
# 刀杆型号
|
|
cutting_tool_cutterbar_model_id = fields.Many2one('product.product', string='刀杆型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '刀杆')])
|
|
# 刀盘型号
|
|
cutting_tool_cutterpad_model_id = fields.Many2one('product.product', string='刀盘型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '刀盘')])
|
|
# 刀柄型号
|
|
cutting_tool_cutterhandle_model_id = fields.Many2one('product.product', string='刀柄型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '刀柄')])
|
|
# 夹头型号
|
|
cutting_tool_cutterhead_model_id = fields.Many2one('product.product', string='夹头型号', readonly=True,
|
|
domain=[('cutting_tool_material_id', '=', '夹头')])
|
|
|
|
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=True)
|
|
L_D_number = fields.Float(string='L/D值(mm)', readonly=True)
|
|
hiding_length = fields.Float(string='避空长(mm)', readonly=True)
|
|
cut_time = fields.Integer(string='已切削时间(min)', readonly=True)
|
|
cut_length = fields.Float(string='已切削长度(mm)', readonly=True)
|
|
cut_number = fields.Integer(string='已切削次数', readonly=True)
|
|
|
|
suitable_machining_method_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_machining_product_template_tool_entity', '适合加工方式',
|
|
domain=[('type', '=', '加工能力')], compute='_compute_maintenance_equipment_image')
|
|
blade_tip_characteristics_id = fields.Many2one(
|
|
'maintenance.equipment.image', '刀尖特征',
|
|
domain=[('type', '=', '刀尖特征')])
|
|
handle_type_id = fields.Many2one(
|
|
'maintenance.equipment.image', '柄部类型',
|
|
domain=[('type', '=', '柄部类型')])
|
|
cutting_direction_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_cutting_product_template_tool_entity', '走刀方向',
|
|
domain=[('type', '=', '走刀方向')])
|
|
suitable_coolant_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_coolants_product_template_tool_entity', '适合冷却方式',
|
|
domain=[('type', '=', '冷却方式')])
|
|
|
|
@api.depends('cutting_tool_integral_model_id', 'cutting_tool_blade_model_id')
|
|
def _compute_maintenance_equipment_image(self):
|
|
for record in self:
|
|
if record.cutting_tool_integral_model_id:
|
|
record.sudo().suitable_machining_method_ids = record.cutting_tool_integral_model_id.suitable_machining_method_ids.ids
|
|
record.sudo().blade_tip_characteristics_id = record.cutting_tool_integral_model_id.blade_tip_characteristics_id.id
|
|
record.sudo().handle_type_id = record.cutting_tool_integral_model_id.handle_type_id.id
|
|
record.sudo().cutting_direction_ids = record.cutting_tool_integral_model_id.cutting_direction_ids.ids
|
|
record.sudo().suitable_coolant_ids = record.cutting_tool_integral_model_id.suitable_coolant_ids.ids
|
|
elif record.cutting_tool_blade_model_id:
|
|
record.sudo().suitable_machining_method_ids = record.cutting_tool_blade_model_id.suitable_machining_method_ids.ids
|
|
record.sudo().blade_tip_characteristics_id = record.cutting_tool_blade_model_id.blade_tip_characteristics_id.id
|
|
record.sudo().handle_type_id = record.cutting_tool_blade_model_id.handle_type_id.id
|
|
record.sudo().cutting_direction_ids = record.cutting_tool_blade_model_id.cutting_direction_ids.ids
|
|
record.sudo().suitable_coolant_ids = record.cutting_tool_blade_model_id.suitable_coolant_ids.ids
|
|
else:
|
|
record.sudo().suitable_machining_method_ids = []
|
|
record.sudo().blade_tip_characteristics_id = None
|
|
record.sudo().handle_type_id = None
|
|
record.sudo().cutting_direction_ids = []
|
|
record.sudo().suitable_coolant_ids = []
|
|
|
|
def _get_functional_tool_model_ids(self, functional_tool_model_code):
|
|
functional_tool_model_ids = []
|
|
for item in functional_tool_model_code:
|
|
functional_tool_model = self.env['sf.cutting_tool.standard.library'].search([('code', '=', item)])
|
|
functional_tool_model_ids.append(functional_tool_model.id)
|
|
return [(6, 0, functional_tool_model_ids)]
|
|
|
|
def open_functional_tool_warning(self):
|
|
action = self.env.ref('sf_tool_management.action_sf_functional_tool_warning')
|
|
result = action.read()[0]
|
|
result['domain'] = [('functional_tool_name_id', '=', self.functional_tool_name_id.id)]
|
|
return result
|
|
|
|
def open_stock_move_line(self):
|
|
action = self.env.ref('sf_tool_management.sf_inbound_and_outbound_records_of_functional_tools_view_act')
|
|
result = action.read()[0]
|
|
result['domain'] = [('lot_id', '=', self.barcode_id.id), ('qty_done', '>', 0)]
|
|
return result
|
|
|
|
def open_safety_stock(self):
|
|
action = self.env.ref('sf_tool_management.sf_real_time_distribution_of_functional_tools_view_act')
|
|
result = action.read()[0]
|
|
result['domain'] = [('name', '=', self.name), ('diameter', '=', self.functional_tool_diameter),
|
|
('knife_tip_r_angle', '=', self.knife_tip_r_angle),
|
|
('coarse_middle_thin', '=', self.coarse_middle_thin)]
|
|
return result
|
|
|
|
def tool_inventory_displacement_out(self):
|
|
"""
|
|
机床当前刀库实时信息接口,功能刀具出库
|
|
"""
|
|
# 获取位置对象
|
|
stock_location_id = self.env['stock.location'].search([('name', '=', '制造前')])
|
|
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
|
self.create_stock_move(stock_location_id, False)
|
|
self.current_location_id = stock_location_id.id
|
|
self.current_shelf_location_id = False
|
|
# self.barcode_id.create_stock_quant(location_inventory_id, stock_location_id,
|
|
# self.functional_tool_name_id.id, '机床装刀', self.functional_tool_name_id,
|
|
# self.functional_tool_name_id.tool_groups_id)
|
|
|
|
# ==========刀具组接口==========
|
|
# def _register_functional_tool_groups(self, obj):
|
|
# create_url = '/AutoDeviceApi/ToolGroup'
|
|
# sf_sync_config = self.env['res.config.settings'].get_values()
|
|
# token = sf_sync_config['token']
|
|
# sf_secret_key = sf_sync_config['sf_secret_key']
|
|
# headers = Common.get_headers(obj, token, sf_secret_key)
|
|
# strurl = sf_sync_config['sf_url'] + create_url
|
|
# val = {
|
|
# 'ToolName': obj.name,
|
|
# 'GroupName': obj.tool_groups_id.name,
|
|
# 'ToolId': obj.code
|
|
# }
|
|
# kw = json.dumps(val, ensure_ascii=False)
|
|
# r = requests.post(strurl, json={}, data={'kw': kw, 'token': token}, headers=headers)
|
|
# ret = r.json()
|
|
# if r == 200:
|
|
# return "刀具组发送成功"
|
|
# else:
|
|
# raise ValidationError("刀具组发送失败")
|
|
|
|
# @api.model_create_multi
|
|
# def create(self, vals):
|
|
# obj = super(FunctionalCuttingToolEntity, self).create(vals)
|
|
# # 调用刀具组接口
|
|
# self._register_functional_tool_groups(obj)
|
|
# return obj
|
|
|
|
|
|
class FunctionalToolWarning(models.Model):
|
|
_name = 'sf.functional.tool.warning'
|
|
_description = '功能刀具预警'
|
|
|
|
code = fields.Char('编码', related='functional_tool_name_id.code')
|
|
rfid = fields.Char('Rfid', related='functional_tool_name_id.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')
|
|
# 机床信息
|
|
production_line_id = fields.Many2one('sf.production.line', string='生产线',
|
|
group_expand='_read_group_machine_table_name_ids')
|
|
maintenance_equipment_id = fields.Many2one('maintenance.equipment', string='CNC机床')
|
|
machine_tool_code = fields.Char(string='机台号', related='maintenance_equipment_id.name')
|
|
machine_table_type_id = fields.Many2one('maintenance.equipment.category', string='机床类型',
|
|
related='maintenance_equipment_id.category_id')
|
|
cutter_spacing_code_id = fields.Many2one('maintenance.equipment.tool', string='刀位号',
|
|
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')
|
|
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)')
|
|
# 其他信息
|
|
install_tool_time = fields.Datetime("刀具组装时间", related='functional_tool_name_id.tool_loading_time')
|
|
on_board_time = fields.Datetime('上机装刀时间')
|
|
max_lifetime_value = fields.Integer(string='最大寿命值(min)')
|
|
alarm_value = fields.Integer(string='报警值(min)')
|
|
used_value = fields.Integer(string='已使用值(min)')
|
|
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警'), ('已拆除', '已拆除')], string='状态')
|
|
alarm_time = fields.Datetime('报警时间')
|
|
dispose_user = fields.Char('处理人')
|
|
dispose_time = fields.Char('处理时间')
|
|
dispose_func = fields.Char('处理方法/措施', readonly=False)
|
|
|
|
active = fields.Boolean(string='已归档', default=True)
|
|
|
|
@api.model
|
|
def _read_group_machine_table_name_ids(self, categories, domain, order):
|
|
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(),
|
|
})
|
|
|
|
|
|
class StockMoveLine(models.Model):
|
|
_inherit = 'stock.move.line'
|
|
_description = '功能刀具出入库记录'
|
|
_order = 'date desc'
|
|
|
|
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具组装单')
|
|
functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', store=True,
|
|
group_expand='_read_group_functional_tool_type_id')
|
|
functional_tool_name = fields.Char('刀具名称')
|
|
diameter = fields.Float(string='刀具直径(mm)')
|
|
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
|
|
install_tool_time = fields.Datetime("刀具组装时间")
|
|
code = fields.Char('编码')
|
|
rfid = fields.Char('Rfid')
|
|
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组')
|
|
|
|
@api.model
|
|
def _read_group_functional_tool_type_id(self, categories, domain, order):
|
|
names = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
|
return categories.browse(names)
|
|
|
|
|
|
class RealTimeDistributionOfFunctionalTools(models.Model):
|
|
_name = 'sf.real.time.distribution.of.functional.tools'
|
|
_description = '功能刀具安全库存'
|
|
|
|
name = fields.Char('名称', readonly=True, compute='_compute_name', store=True)
|
|
functional_name_id = fields.Many2one('sf.tool.inventory', string='功能刀具名称', required=True)
|
|
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', readonly=False, required=True)
|
|
sf_cutting_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model', string='功能刀具类型', readonly=False,
|
|
group_expand='_read_mrs_cutting_tool_type_ids', store=True)
|
|
diameter = fields.Float(string='刀具直径(mm)', readonly=False)
|
|
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', readonly=False)
|
|
tool_stock_num = fields.Integer(string='刀具房数量', compute='_compute_stock_num', store=True)
|
|
side_shelf_num = fields.Integer(string='线边刀库数量', compute='_compute_stock_num', store=True)
|
|
on_tool_stock_num = fields.Integer(string='机内刀库数量', compute='_compute_stock_num', store=True)
|
|
tool_stock_total = fields.Integer(string='当前库存量', compute='_compute_tool_stock_total', store=True)
|
|
min_stock_num = fields.Integer('最低库存量')
|
|
max_stock_num = fields.Integer('最高库存量')
|
|
batch_replenishment_num = fields.Integer('批次补货量', readonly=True, compute='_compute_batch_replenishment_num',
|
|
store=True)
|
|
unit = fields.Char('单位')
|
|
image = fields.Binary('图片', readonly=False)
|
|
|
|
coarse_middle_thin = fields.Selection([("1", "粗"), ('2', '中'), ('3', '精')], string='粗/中/精', readonly=False)
|
|
whether_standard_knife = fields.Boolean(string='是否标准刀', default=True, readonly=False)
|
|
# 能力特征信息
|
|
suitable_machining_method_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_machining_product_template_distribution', '适合加工方式',
|
|
domain=[('type', '=', '加工能力')],
|
|
related='sf_functional_tool_entity_ids.suitable_machining_method_ids')
|
|
blade_tip_characteristics_id = fields.Many2one(
|
|
'maintenance.equipment.image', '刀尖特征',
|
|
domain=[('type', '=', '刀尖特征')],
|
|
related='sf_functional_tool_entity_ids.blade_tip_characteristics_id')
|
|
handle_type_id = fields.Many2one(
|
|
'maintenance.equipment.image', '柄部类型',
|
|
domain=[('type', '=', '柄部类型')], related='sf_functional_tool_entity_ids.handle_type_id')
|
|
cutting_direction_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_cutting_product_template_distribution', '走刀方向',
|
|
domain=[('type', '=', '走刀方向')], related='sf_functional_tool_entity_ids.cutting_direction_ids')
|
|
suitable_coolant_ids = fields.Many2many(
|
|
'maintenance.equipment.image', 'rel_coolants_product_template_distribution', '适合冷却方式',
|
|
domain=[('type', '=', '冷却方式')], related='sf_functional_tool_entity_ids.suitable_coolant_ids')
|
|
|
|
sf_functional_cutting_tool_entity_ids = fields.Many2many('sf.functional.cutting.tool.entity',
|
|
'sf_functional_cutting_tool_entity_ref',
|
|
string='功能刀具列表信息')
|
|
|
|
sf_functional_tool_assembly_ids = fields.Many2many('sf.functional.tool.assembly', 'sf_functional_tool_assembly_ref',
|
|
'功能刀具组装单', readonly=True)
|
|
|
|
sf_functional_tool_entity_ids = fields.One2many('sf.functional.cutting.tool.entity', 'safe_inventory_id',
|
|
string='功能刀具信息')
|
|
|
|
active = fields.Boolean(string='已归档', default=True)
|
|
|
|
@api.onchange('functional_name_id')
|
|
def _onchange_num(self):
|
|
for item in self:
|
|
if item.functional_name_id:
|
|
item.tool_groups_id = item.functional_name_id.tool_groups_id.id
|
|
item.sf_cutting_tool_type_id = item.functional_name_id.functional_cutting_tool_model_id.id
|
|
item.diameter = item.functional_name_id.diameter
|
|
item.knife_tip_r_angle = item.functional_name_id.angle
|
|
|
|
@api.depends('functional_name_id')
|
|
def _compute_name(self):
|
|
for obj in self:
|
|
if obj.tool_groups_id:
|
|
obj.name = obj.functional_name_id.name
|
|
else:
|
|
obj.sudo().name = ''
|
|
|
|
@api.constrains('min_stock_num', 'max_stock_num')
|
|
def _check_stock_num(self):
|
|
for obj in self:
|
|
if obj.min_stock_num > obj.max_stock_num:
|
|
raise ValidationError('【最低安全库存】不能高于【最高安全库存】!!!')
|
|
|
|
@api.model
|
|
def _read_mrs_cutting_tool_type_ids(self, categories, domain, order):
|
|
mrs_cutting_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
|
|
return categories.browse(mrs_cutting_tool_type_ids)
|
|
|
|
@api.depends('sf_functional_tool_entity_ids', 'min_stock_num', 'max_stock_num')
|
|
def _compute_batch_replenishment_num(self):
|
|
for tool in self:
|
|
if tool:
|
|
# 如果当前库存量小于最低库存量,计算批次补货量
|
|
tool.sudo().open_batch_replenishment_num(tool)
|
|
|
|
def open_batch_replenishment_num(self, tool):
|
|
"""
|
|
计算批次补货量
|
|
"""
|
|
if tool.tool_stock_total < tool.min_stock_num:
|
|
# 根据判断创建功能刀具组装单
|
|
if not tool.sf_functional_tool_assembly_ids.filtered(lambda item: item.assemble_status == '0') and re.match(
|
|
r'^\d+$', str(tool.id)):
|
|
tool.sudo().batch_replenishment_num = tool.max_stock_num - tool.tool_stock_total
|
|
for i in range(tool.batch_replenishment_num):
|
|
tool.sudo().create_functional_tool_assembly(tool)
|
|
print(i, ": ", tool.sf_functional_tool_assembly_ids)
|
|
else:
|
|
tool.sudo().batch_replenishment_num = 0
|
|
|
|
@api.depends('sf_functional_tool_entity_ids.tool_room_num',
|
|
'sf_functional_tool_entity_ids.line_edge_knife_library_num',
|
|
'sf_functional_tool_entity_ids.machine_knife_library_num')
|
|
def _compute_stock_num(self):
|
|
"""
|
|
计算刀具房数量、线边刀库数量、机内刀库数量
|
|
"""
|
|
for tool in self:
|
|
if tool:
|
|
tool.tool_stock_num = 0
|
|
tool.side_shelf_num = 0
|
|
tool.on_tool_stock_num = 0
|
|
if tool.sf_functional_tool_entity_ids:
|
|
for cutting_tool in tool.sf_functional_tool_entity_ids:
|
|
if cutting_tool.tool_room_num > 0:
|
|
tool.tool_stock_num += 1
|
|
elif cutting_tool.line_edge_knife_library_num > 0:
|
|
tool.side_shelf_num += 1
|
|
elif cutting_tool.machine_knife_library_num > 0:
|
|
tool.on_tool_stock_num += 1
|
|
else:
|
|
tool.tool_stock_num = 0
|
|
tool.side_shelf_num = 0
|
|
tool.on_tool_stock_num = 0
|
|
|
|
@api.depends('tool_stock_num', 'side_shelf_num', 'on_tool_stock_num')
|
|
def _compute_tool_stock_total(self):
|
|
for tool in self:
|
|
if tool:
|
|
# 计算当前库存量
|
|
tool.tool_stock_total = tool.tool_stock_num + tool.side_shelf_num + tool.on_tool_stock_num
|
|
|
|
def create_functional_tool_assembly(self, tool):
|
|
"""
|
|
创建功能刀具组装单
|
|
"""
|
|
functional_tool_assembly = tool.env['sf.functional.tool.assembly'].sudo().create({
|
|
'functional_tool_name': tool.name,
|
|
'functional_tool_type_id': tool.sf_cutting_tool_type_id.id,
|
|
'tool_groups_id': tool.tool_groups_id.id,
|
|
'functional_tool_diameter': tool.diameter,
|
|
'knife_tip_r_angle': tool.knife_tip_r_angle,
|
|
'coarse_middle_thin': tool.coarse_middle_thin,
|
|
'loading_task_source': '2',
|
|
'use_tool_time': fields.Datetime.now() + timedelta(hours=4),
|
|
'applicant': '系统自动',
|
|
'apply_time': fields.Datetime.now(),
|
|
'whether_standard_knife': tool.whether_standard_knife,
|
|
'reason_for_applying': '安全库存',
|
|
})
|
|
tool.sudo().sf_functional_tool_assembly_ids = [(4, functional_tool_assembly.id)]
|
|
|
|
def create_or_edit_safety_stock(self, vals, sf_functional_tool_entity_ids):
|
|
"""
|
|
根据传入的信息新增或者更新功能刀具安全库存的信息
|
|
"""
|
|
# 根据功能刀具名称、刀具组、直径或尖刀R角、粗/中/精查询该功能刀具是否已经存在
|
|
record = self.env['sf.real.time.distribution.of.functional.tools'].search(
|
|
[('functional_name_id', '=', vals['functional_name_id'])])
|
|
if len(record) > 0:
|
|
for obj in record:
|
|
obj.write({'sf_functional_tool_entity_ids': [(4, sf_functional_tool_entity_ids.id)]})
|
|
else:
|
|
vals['sf_functional_tool_entity_ids'] = sf_functional_tool_entity_ids.ids
|
|
self.env['sf.real.time.distribution.of.functional.tools'].create(vals)
|
|
|
|
status_create = fields.Boolean('是否是新增状态', default=True)
|
|
|
|
@api.model_create_multi
|
|
def create(self, vals_list):
|
|
for vals in vals_list:
|
|
vals['status_create'] = False
|
|
records = super(RealTimeDistributionOfFunctionalTools, self).create(vals_list)
|
|
return records
|