Accept Merge Request #1077: (hotfix/功能刀具出入库处理 -> develop)
Merge Request: 新增功能刀具出入库线边刀库记录 Created By: @禹翔辉 Reviewed By: @马广威 Approved By: @马广威 Accepted By: @禹翔辉 URL: https://jikimo-hn.coding.net/p/jikimo_sfs/d/jikimo_sf/git/merge/1077
This commit is contained in:
@@ -305,7 +305,7 @@
|
||||
<field name="cutting_tool_blade_type"
|
||||
attrs="{'invisible': [('cutting_tool_type', '!=', '整体式刀具')],'readonly': [('id', '!=', False)]}"/>
|
||||
<field name="cutting_tool_coarse_medium_fine" string="粗/中/精" placeholder="请选择"
|
||||
attrs="{'required': [('cutting_tool_type','=','整体式刀具')],'invisible': [('cutting_tool_type', 'not in', ('整体式刀具','刀片'))],'readonly': [('id', '!=', False)]}"/>
|
||||
attrs="{'invisible': [('cutting_tool_type', 'not in', ('整体式刀具','刀片'))],'readonly': [('id', '!=', False)]}"/>
|
||||
<!--整体式刀具-->
|
||||
<field name="cutting_tool_shank_diameter" string="柄部直径(mm)" class="diameter"
|
||||
attrs="{'invisible': [('cutting_tool_type', '!=', '整体式刀具')],'readonly': [('id', '!=', False)]}"/>
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
'views/tool_material_search.xml',
|
||||
'views/fixture_material_search_views.xml',
|
||||
'views/menu_view.xml',
|
||||
'views/stock.xml',
|
||||
'data/tool_data.xml',
|
||||
],
|
||||
'demo': [
|
||||
|
||||
@@ -7,4 +7,5 @@ from . import functional_tool_enroll
|
||||
from . import fixture_material_search
|
||||
from . import fixture_enroll
|
||||
from . import temporary_data_processing_methods
|
||||
from . import stock
|
||||
|
||||
|
||||
@@ -34,15 +34,17 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
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='刀具房数量', readonly=True)
|
||||
line_edge_knife_library_num = fields.Integer(string='线边刀库数量', readonly=True)
|
||||
machine_knife_library_num = fields.Integer(string='机内刀库数量', 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='当前位置', readonly=True)
|
||||
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)
|
||||
@@ -51,44 +53,113 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
safe_inventory_id = fields.Many2one('sf.real.time.distribution.of.functional.tools',
|
||||
string='功能刀具安全库存', readonly=True)
|
||||
|
||||
@api.depends('barcode_id.quant_ids', 'functional_tool_status')
|
||||
@api.depends('barcode_id.quant_ids', 'functional_tool_status', 'current_shelf_location_id')
|
||||
def _compute_current_location_id(self):
|
||||
for record in self:
|
||||
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 == '制造前':
|
||||
record.current_location = '机内刀库'
|
||||
else:
|
||||
record.current_location = quant_id.location_id.name
|
||||
if record.current_location_id:
|
||||
record.sudo().get_location_num()
|
||||
else:
|
||||
record.current_location_id = False
|
||||
record.current_location = False
|
||||
if record.functional_tool_status == '已拆除':
|
||||
record.current_location_id = False
|
||||
record.current_location = False
|
||||
record.tool_room_num = 0
|
||||
record.line_edge_knife_library_num = 0
|
||||
record.machine_knife_library_num = 0
|
||||
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
|
||||
|
||||
def get_location_num(self):
|
||||
@api.depends('current_location', 'functional_tool_status')
|
||||
def _compute_num(self):
|
||||
"""
|
||||
计算库存位置数量
|
||||
"""
|
||||
for obj in self:
|
||||
if obj.current_location_id:
|
||||
if obj.functional_tool_status == '已拆除':
|
||||
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
|
||||
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):
|
||||
@@ -191,12 +262,14 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
机床当前刀库实时信息接口,功能刀具出库
|
||||
"""
|
||||
# 获取位置对象
|
||||
location_inventory_id = self.current_location_id
|
||||
stock_location_id = self.env['stock.location'].search([('name', '=', '制造前')])
|
||||
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
||||
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)
|
||||
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):
|
||||
@@ -304,7 +377,7 @@ class StockMoveLine(models.Model):
|
||||
functional_tool_name = fields.Char('刀具名称')
|
||||
diameter = fields.Float(string='刀具直径(mm)')
|
||||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
|
||||
install_tool_time = fields.Datetime("刀具组装时间", default=fields.Datetime.now())
|
||||
install_tool_time = fields.Datetime("刀具组装时间")
|
||||
code = fields.Char('编码')
|
||||
rfid = fields.Char('Rfid')
|
||||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组')
|
||||
@@ -327,12 +400,12 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
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='刀具房数量')
|
||||
side_shelf_num = fields.Integer(string='线边刀库数量')
|
||||
on_tool_stock_num = fields.Integer(string='机内刀库数量')
|
||||
tool_stock_total = fields.Integer(string='当前库存量', readonly=True)
|
||||
min_stock_num = fields.Integer('最低库存量', tracking=True)
|
||||
max_stock_num = fields.Integer('最高库存量', tracking=True)
|
||||
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('单位', default="件")
|
||||
@@ -403,10 +476,6 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
def _compute_batch_replenishment_num(self):
|
||||
for tool in self:
|
||||
if tool:
|
||||
# 计算刀具房数量、线边刀库数量、机内刀库数量
|
||||
tool.sudo().get_stock_num(tool)
|
||||
# 计算当前库存量
|
||||
tool.sudo().tool_stock_total = tool.tool_stock_num + tool.side_shelf_num + tool.on_tool_stock_num
|
||||
# 如果当前库存量小于最低库存量,计算批次补货量
|
||||
tool.sudo().open_batch_replenishment_num(tool)
|
||||
|
||||
@@ -425,6 +494,38 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
else:
|
||||
tool.sudo().batch_replenishment_num = 0
|
||||
|
||||
@api.depends('sf_functional_tool_entity_ids', '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):
|
||||
"""
|
||||
创建功能刀具组装单
|
||||
@@ -445,27 +546,6 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
})
|
||||
tool.sudo().sf_functional_tool_assembly_ids = [(4, functional_tool_assembly.id)]
|
||||
|
||||
def get_stock_num(self, tool):
|
||||
"""
|
||||
计算刀具房数量、线边刀库数量、机内刀库数量
|
||||
"""
|
||||
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
|
||||
|
||||
def create_or_edit_safety_stock(self, vals, sf_functional_tool_entity_ids):
|
||||
"""
|
||||
根据传入的信息新增或者更新功能刀具安全库存的信息
|
||||
|
||||
@@ -44,71 +44,79 @@ class SfMaintenanceEquipment(models.Model):
|
||||
|
||||
# ==========机床当前刀库实时信息接口==========
|
||||
def register_equipment_tool(self):
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||
headers = {'Authorization': config['center_control_Authorization']}
|
||||
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetToolInfos"
|
||||
params = {"DeviceId": self.name}
|
||||
r = requests.get(crea_url, params=params, headers=headers)
|
||||
ret = r.json()
|
||||
logging.info('register_equipment_tool:%s' % ret)
|
||||
datas = ret['Datas']
|
||||
self.write_maintenance_equipment_tool(datas)
|
||||
if ret['Succeed']:
|
||||
return "机床当前刀库实时信息指令发送成功"
|
||||
else:
|
||||
raise ValidationError("机床当前刀库实时信息指令发送失败")
|
||||
try:
|
||||
config = self.env['res.config.settings'].get_values()
|
||||
# token = sf_sync_config['token'Ba F2CF5DCC-1A00-4234-9E95-65603F70CC8A]
|
||||
headers = {'Authorization': config['center_control_Authorization']}
|
||||
crea_url = config['center_control_url'] + "/AutoDeviceApi/GetToolInfos"
|
||||
params = {"DeviceId": self.name}
|
||||
r = requests.get(crea_url, params=params, headers=headers)
|
||||
ret = r.json()
|
||||
logging.info('register_equipment_tool:%s' % ret)
|
||||
datas = ret['Datas']
|
||||
self.write_maintenance_equipment_tool(datas)
|
||||
if ret['Succeed']:
|
||||
return "机床当前刀库实时信息指令发送成功"
|
||||
else:
|
||||
raise ValidationError("机床当前刀库实时信息指令发送失败")
|
||||
except Exception as e:
|
||||
logging.info("register_equipment_tool()捕获错误信息:%s" % e)
|
||||
|
||||
def write_maintenance_equipment_tool(self, datas):
|
||||
if datas:
|
||||
# 清除设备机床刀位的刀具信息
|
||||
for obj in self.product_template_ids:
|
||||
obj.write({
|
||||
'functional_tool_name_id': False,
|
||||
'tool_install_time': None
|
||||
})
|
||||
for data in datas:
|
||||
maintenance_equipment_id = self.search([('name', '=', data['DeviceId'])])
|
||||
if maintenance_equipment_id:
|
||||
tool_id = '%s%s' % (data['ToolId'][0:1], data['ToolId'][1:].zfill(2))
|
||||
equipment_tool_id = self.env['maintenance.equipment.tool'].sudo().search(
|
||||
[('equipment_id', '=', maintenance_equipment_id.id), ('code', '=', tool_id)])
|
||||
functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('rfid', '=', data['RfidCode'])])
|
||||
if functional_tool_id:
|
||||
# 查询该功能刀具是否已经装在机床内其他位置,如果是就删除
|
||||
equipment_tools = self.env['maintenance.equipment.tool'].sudo().search(
|
||||
[('functional_tool_name_id', '=', functional_tool_id.id), ('code', '!=', tool_id)])
|
||||
if equipment_tools:
|
||||
for item in equipment_tools:
|
||||
item.write({
|
||||
'functional_tool_name_id': False,
|
||||
'tool_install_time': None
|
||||
})
|
||||
try:
|
||||
if datas:
|
||||
# 清除设备机床刀位的刀具信息
|
||||
for obj in self.product_template_ids:
|
||||
obj.write({
|
||||
'functional_tool_name_id': False,
|
||||
'tool_install_time': None
|
||||
})
|
||||
for data in datas:
|
||||
maintenance_equipment_id = self.search([('name', '=', data['DeviceId'])])
|
||||
if maintenance_equipment_id:
|
||||
tool_id = '%s%s' % (data['ToolId'][0:1], data['ToolId'][1:].zfill(2))
|
||||
equipment_tool_id = self.env['maintenance.equipment.tool'].sudo().search(
|
||||
[('equipment_id', '=', maintenance_equipment_id.id), ('code', '=', tool_id)])
|
||||
functional_tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('rfid', '=', data['RfidCode'])])
|
||||
if functional_tool_id:
|
||||
if len(functional_tool_id) > 1:
|
||||
functional_tool_id = functional_tool_id[-1]
|
||||
# 查询该功能刀具是否已经装在机床内其他位置,如果是就删除
|
||||
equipment_tools = self.env['maintenance.equipment.tool'].sudo().search(
|
||||
[('functional_tool_name_id', '=', functional_tool_id.id), ('code', '!=', tool_id)])
|
||||
if equipment_tools:
|
||||
for item in equipment_tools:
|
||||
item.write({
|
||||
'functional_tool_name_id': False,
|
||||
'tool_install_time': None
|
||||
})
|
||||
else:
|
||||
logging.info('Rfid为【%s】的功能刀具不存在!' % data['RfidCode'])
|
||||
time = None
|
||||
if data['AddDatetime']:
|
||||
datatime = str(data['AddDatetime'])
|
||||
time = fields.Datetime.from_string(datatime[0:10] + ' ' + datatime[11:19])
|
||||
if equipment_tool_id and functional_tool_id:
|
||||
tool_install_time = {'Nomal': '正常', 'Warning': '报警'}
|
||||
equipment_tool_id.write({
|
||||
'functional_tool_name_id': functional_tool_id.id,
|
||||
'tool_install_time': time
|
||||
})
|
||||
if functional_tool_id.current_location != '机内刀库':
|
||||
# 对功能刀具进行移动到生产线
|
||||
functional_tool_id.tool_inventory_displacement_out()
|
||||
functional_tool_id.write({
|
||||
'max_lifetime_value': data['MaxLife'],
|
||||
'used_value': data['UseLife'],
|
||||
'functional_tool_status': tool_install_time.get(data['State'])
|
||||
})
|
||||
else:
|
||||
logging.info('Rfid为【%s】的功能刀具不存在!' % data['RfidCode'])
|
||||
time = None
|
||||
if data['AddDatetime']:
|
||||
datatime = str(data['AddDatetime'])
|
||||
time = fields.Datetime.from_string(datatime[0:10] + ' ' + datatime[11:19])
|
||||
if equipment_tool_id and functional_tool_id:
|
||||
tool_install_time = {'Nomal': '正常', 'Warning': '报警'}
|
||||
equipment_tool_id.write({
|
||||
'functional_tool_name_id': functional_tool_id.id,
|
||||
'tool_install_time': time
|
||||
})
|
||||
if functional_tool_id.current_location_id.name != '制造前':
|
||||
# 对功能刀具进行出库到生产线
|
||||
functional_tool_id.tool_inventory_displacement_out()
|
||||
functional_tool_id.write({
|
||||
'max_lifetime_value': data['MaxLife'],
|
||||
'used_value': data['UseLife'],
|
||||
'functional_tool_status': tool_install_time.get(data['State'])
|
||||
})
|
||||
else:
|
||||
raise ValidationError('获取的【%s】设备不存在!!!' % data['DeviceId'])
|
||||
else:
|
||||
raise ValidationError('没有获取到刀具库信息!!!')
|
||||
logging.info('获取的【%s】设备不存在!!!' % data['DeviceId'])
|
||||
else:
|
||||
logging.info('没有获取到【%s】设备的刀具库信息!!!' % self.name)
|
||||
except Exception as e:
|
||||
logging.info("write_maintenance_equipment_tool()捕获错误信息:%s" % e)
|
||||
|
||||
|
||||
class StockLot(models.Model):
|
||||
|
||||
23
sf_tool_management/models/stock.py
Normal file
23
sf_tool_management/models/stock.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from odoo import api, fields, models, _
|
||||
|
||||
|
||||
class ShelfLocation(models.Model):
|
||||
_inherit = 'sf.shelf.location'
|
||||
|
||||
tool_rfid = fields.Char('Rfid', compute='_compute_tool', store=True)
|
||||
tool_name_id = fields.Many2one('sf.functional.cutting.tool.entity', string='功能刀具名称', compute='_compute_tool',
|
||||
store=True)
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_tool(self):
|
||||
for item in self:
|
||||
if item.product_id:
|
||||
if item.product_id.categ_id.name == '功能刀具':
|
||||
tool_id = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('barcode_id', '=', item.product_sn_id.id)])
|
||||
if tool_id:
|
||||
item.tool_rfid = tool_id.rfid
|
||||
item.tool_name_id = tool_id.id
|
||||
continue
|
||||
item.tool_rfid = ''
|
||||
item.tool_name_id = False
|
||||
@@ -29,6 +29,7 @@
|
||||
<field name="current_location" string="当前位置"/>
|
||||
|
||||
<field name="current_location_id" invisible="1"/>
|
||||
<field name="current_location" optional="hide"/>
|
||||
<field name="sf_cutting_tool_type_id" invisible="True"/>
|
||||
</tree>
|
||||
</field>
|
||||
@@ -173,7 +174,10 @@
|
||||
<field name="cut_time" attrs="{'invisible': [('new_former','=','0')]}"/>
|
||||
<field name="cut_length" attrs="{'invisible': [('new_former','=','0')]}"/>
|
||||
<field name="cut_number" attrs="{'invisible': [('new_former','=','0')]}"/>
|
||||
<field name="current_location_id" string="当前位置"/>
|
||||
<field name="current_location" string="当前位置"/>
|
||||
<field name="current_shelf_location_id" string="当前货位"
|
||||
attrs="{'invisible': [('current_shelf_location_id', '=', False)]}"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
@@ -189,6 +193,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="rfid"/>
|
||||
<field name="barcode_id"/>
|
||||
<field name="tool_name_id"/>
|
||||
<field name="functional_tool_diameter"/>
|
||||
<field name="knife_tip_r_angle"/>
|
||||
@@ -204,8 +209,8 @@
|
||||
domain="[('functional_tool_status', '!=', '已拆除')]"/>
|
||||
<filter string="已拆除" name="state_removed" domain="[('functional_tool_status', '=', '已拆除')]"/>
|
||||
<searchpanel>
|
||||
<field name="functional_tool_status" icon="fa-building" enable_counters="1"/>
|
||||
<field name="current_location" icon="fa-building" enable_counters="1"/>
|
||||
<field name="functional_tool_status" icon="fa-building" enable_counters="1"/>
|
||||
<field name="sf_cutting_tool_type_id" icon="fa-building" enable_counters="1"/>
|
||||
</searchpanel>
|
||||
<group expand="0">
|
||||
@@ -482,7 +487,9 @@
|
||||
<field name="knife_tip_r_angle"/>
|
||||
<field name="install_tool_time"/>
|
||||
<field name="location_id"/>
|
||||
<field name="current_location_id"/>
|
||||
<field name="location_dest_id"/>
|
||||
<field name="destination_location_id"/>
|
||||
<field name="date"/>
|
||||
<field name="qty_done" string="数量"/>
|
||||
<field name="functional_tool_type_id" invisible="True"/>
|
||||
@@ -497,21 +504,20 @@
|
||||
<field name="model">stock.move.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="reference"/>
|
||||
<field name="lot_id"/>
|
||||
<field name="rfid"/>
|
||||
<field name="functional_tool_name"/>
|
||||
<field name="diameter"/>
|
||||
<field name="knife_tip_r_angle"/>
|
||||
<field name="install_tool_time"/>
|
||||
<field name="location_id"/>
|
||||
<field name="location_dest_id"/>
|
||||
<field name="date"/>
|
||||
<field name="qty_done"/>
|
||||
<field name="functional_tool_type_id" invisible="True"/>
|
||||
<field name="reference"/>
|
||||
<field name="lot_id"/>
|
||||
<searchpanel>
|
||||
<field name="functional_tool_type_id" enable_counters="1" icon="fa-building"/>
|
||||
</searchpanel>
|
||||
<group expand="0">
|
||||
<filter string="功能刀具名称" name="functional_tool_name" domain="[]"
|
||||
context="{'group_by': 'functional_tool_name'}"/>
|
||||
<filter string="日期" name="date" domain="[]" context="{'group_by': 'date'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
@@ -525,7 +531,7 @@
|
||||
ref="sf_tool_management.sf_inbound_and_outbound_records_of_functional_tools_view_tree"/>
|
||||
<field name="search_view_id"
|
||||
ref="sf_tool_management.sf_inbound_and_outbound_records_of_functional_tools_view_search"/>
|
||||
<field name="domain">[('functional_tool_name_id', '!=', False)]</field>
|
||||
<field name="domain">[('functional_tool_name', '!=', False)]</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
|
||||
14
sf_tool_management/views/stock.xml
Normal file
14
sf_tool_management/views/stock.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="view_shelf_location_tool" model="ir.ui.view">
|
||||
<field name="name">sf.shelf.location.form.tool</field>
|
||||
<field name="model">sf.shelf.location</field>
|
||||
<field name="inherit_id" ref="sf_warehouse.view_shelf_location_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='product_id']" position="after">
|
||||
<field name="tool_rfid" attrs="{'invisible': [('tool_name_id', '=', False)]}"/>
|
||||
<field name="tool_name_id" attrs="{'invisible': [('tool_name_id', '=', False)]}"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -95,17 +95,34 @@ class MrsShelfLocationDataSync(models.Model):
|
||||
return code_pair[0]
|
||||
return None # 如果没有找到对应的值,返回None或适当的默认值
|
||||
|
||||
# 定时更新所有设备机床刀库信息
|
||||
equipment_ids = self.env['maintenance.equipment'].search(
|
||||
[('equipment_type', '=', '机床'), ('function_type', '!=', False)])
|
||||
for equipment_id in equipment_ids:
|
||||
if equipment_id:
|
||||
equipment_id.register_equipment_tool()
|
||||
|
||||
shelfinfo = self.env['sf.shelf.location'].get_sf_shelf_location_info()
|
||||
print('shelfinfo:', shelfinfo)
|
||||
for item in shelfinfo:
|
||||
shelf_barcode = find_our_code(item['Postion'], total_data)
|
||||
location_id = self.env['sf.shelf.location'].search([('barcode', '=', shelf_barcode)], limit=1)
|
||||
if location_id:
|
||||
stock_lot_obj = self.env['stock.lot'].search([('rfid', '=', item['RfidCode'])], limit=1)
|
||||
if stock_lot_obj:
|
||||
location_id.product_sn_id = stock_lot_obj.id
|
||||
# 如果是线边刀库信息,则对功能刀具移动生成记录
|
||||
if 'Tool' in item['Postion']:
|
||||
tool = self.env['sf.functional.cutting.tool.entity'].sudo().search(
|
||||
[('rfid', '=', item['RfidCode']), ('functional_tool_status', '!=', '已拆除')])
|
||||
tool.tool_in_out_stock_location(location_id)
|
||||
if tool:
|
||||
location_id.product_sn_id = tool.barcode_id.id
|
||||
else:
|
||||
location_id.product_sn_id = False
|
||||
else:
|
||||
location_id.product_sn_id = False
|
||||
stock_lot_obj = self.env['stock.lot'].search([('rfid', '=', item['RfidCode'])], limit=1)
|
||||
if stock_lot_obj:
|
||||
location_id.product_sn_id = stock_lot_obj.id
|
||||
else:
|
||||
location_id.product_sn_id = False
|
||||
|
||||
logging.info('货架已获取信息:%s' % item)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user