1、优化刀具物料序列号、刀具物料注册接口;2、优化功能刀具、功能刀具出入库记录接口;3、优化刀具物料搜索模型

This commit is contained in:
yuxianghui
2024-03-11 17:34:03 +08:00
parent 61b0b57b87
commit fbce395321
4 changed files with 55 additions and 51 deletions

View File

@@ -25,29 +25,24 @@ class StockLot(models.Model):
val = {
'name': item.name,
'tool_material_status': item.tool_material_status,
'location': item.quant_ids[-1].location_id.name,
'tool_material_search_code': item.tool_material_search_id.code,
'location': [] if not item.quant_ids else item.quant_ids[-1].location_id.name,
'tool_material_search_id': item.tool_material_search_id.id,
}
tool_material_stock_list.append(val)
kw = json.dumps(tool_material_stock_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
if r == 200:
if ret.get('code') == 200:
return '刀具物料序列号注册成功'
else:
raise UserError("没有注册刀具物料序列号信息")
@api.onchange('quant_ids')
def _onchange_quant_ids(self):
for item in self:
if item.product_id.categ_id == '刀具':
item.enroll_tool_material_stock()
@api.model_create_multi
def create(self, vals_list):
records = super(StockLot, self).create(vals_list)
for record in records:
if record.product_id.categ_id == '刀具':
if record.product_id.categ_id.name == '刀具':
record.tool_material_status = '可用'
record.enroll_tool_material_stock()
return records
@@ -74,11 +69,11 @@ class ToolMaterial(models.Model):
barcode_names.append(barcode_id.name)
val = {
'name': item.name,
'code': item.code,
'id': item.id,
'cutting_tool_material_code': item.cutting_tool_material_id.code,
'cutting_tool_standard_library_code': item.cutting_tool_standard_library_id.code,
'specification_name': item.specification_id.name,
'image': item.image,
'image': '' if not item.image else base64.b64encode(item.image).decode('utf-8'),
'number': item.number,
'usable_num': item.usable_num,
'have_been_used_num': item.have_been_used_num,
@@ -95,6 +90,14 @@ class ToolMaterial(models.Model):
else:
raise UserError("没有注册刀具物料信息")
@api.model_create_multi
def create(self, vals_list):
records = super(ToolMaterial, self).create(vals_list)
for record in records:
if record:
record.enroll_tool_material()
return records
class FunctionalCuttingToolEntity(models.Model):
_inherit = 'sf.functional.cutting.tool.entity'
@@ -113,6 +116,18 @@ class FunctionalCuttingToolEntity(models.Model):
functional_tool_list = []
if objs_all:
for item in objs_all:
suitable_machining_method_names = []
cutting_direction_names = []
suitable_coolant_names = []
for suitable_machining_method_id in item.suitable_machining_method_ids:
if suitable_machining_method_id:
suitable_machining_method_names.append(suitable_machining_method_id.name)
for cutting_direction_id in item.cutting_direction_ids:
if cutting_direction_id:
cutting_direction_names.append(cutting_direction_id.name)
for suitable_coolant_id in item.suitable_coolant_ids:
if suitable_coolant_id:
suitable_coolant_names.append(suitable_coolant_id.name)
val = {
'id': item.id,
'code': item.code,
@@ -143,21 +158,24 @@ class FunctionalCuttingToolEntity(models.Model):
'cut_time': item.cut_time,
'cut_length': item.cut_length,
'cut_number': item.cut_number,
'cutting_tool_integral_model_code': item.cutting_tool_integral_model_id.code,
'cutting_tool_blade_model_code': item.cutting_tool_blade_model_id.code,
'cutting_tool_cutterbar_model_code': item.cutting_tool_cutterbar_model_id.code,
'cutting_tool_cutterpad_model_code': item.cutting_tool_cutterpad_model_id.code,
'cutting_tool_cutterhandle_model_code': item.cutting_tool_cutterhandle_model_id.code,
'cutting_tool_cutterhead_model_code': item.cutting_tool_cutterhead_model_id.code,
'cutting_tool_integral_model_id': item.cutting_tool_integral_model_id.tool_material_id,
'cutting_tool_blade_model_id': item.cutting_tool_blade_model_id.tool_material_id,
'cutting_tool_cutterbar_model_id': item.cutting_tool_cutterbar_model_id.tool_material_id,
'cutting_tool_cutterpad_model_id': item.cutting_tool_cutterpad_model_id.tool_material_id,
'cutting_tool_cutterhandle_model_id': item.cutting_tool_cutterhandle_model_id.tool_material_id,
'cutting_tool_cutterhead_model_id': item.cutting_tool_cutterhead_model_id.tool_material_id,
'suitable_machining_method_names': suitable_machining_method_names,
'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name,
'handle_type_name': item.handle_type_id.name,
'cutting_direction_names': cutting_direction_names,
'suitable_coolant_names': suitable_coolant_names,
'active': item.active,
}
functional_tool_list.append(val)
kw = json.dumps(functional_tool_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
# self.code = ret['data']
# self.state_zc = "已注册"
if r == 200:
if ret.get('code') == 200:
return "功能刀具注册成功"
else:
raise UserError("没有注册功能刀具信息")
@@ -192,6 +210,7 @@ class FunctionalToolWarning(models.Model):
'id': item.id,
'name': item.name,
'code': item.code,
'rfid': item.rfid,
'tool_groups_name': item.tool_groups_id.name,
'production_line': item.production_line_id.name,
'machine_tool_id': item.maintenance_equipment_id.code,
@@ -218,9 +237,7 @@ class FunctionalToolWarning(models.Model):
kw = json.dumps(tool_warning_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
# self.code = ret['data']
# self.state_zc = "已注册"
if r == 200:
if ret.get('code') == 200:
return "功能刀具预警注册成功"
else:
raise UserError("没有注册功能刀具预警信息")
@@ -255,6 +272,7 @@ class StockMoveLine(models.Model):
'id': item.id,
'name': item.functional_tool_name_id.name,
'code': item.code,
'rfid': item.rfid,
'tool_groups_name': item.tool_groups_id.name,
'reference': item.reference,
'barcode': item.lot_id.name,
@@ -271,9 +289,7 @@ class StockMoveLine(models.Model):
kw = json.dumps(tool_stock_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
# self.code = ret['data']
# self.state_zc = "已注册"
if r == 200:
if ret.get('code') == 200:
return "功能刀具出入库记录注册成功"
else:
raise UserError("没有注册功能刀具出入库记录信息")
@@ -310,8 +326,9 @@ class RealTimeDistributionFunctionalTools(models.Model):
val = {
'id': item.id,
'name': item.name,
'rfid': item.rfid,
'tool_groups_name': item.tool_groups_id.name,
'sf_cutting_tool_type_code': item.sf_cutting_tool_type_id.code,
'cutting_tool_type_code': item.sf_cutting_tool_type_id.code,
'diameter': item.diameter,
'knife_tip_r_angle': item.knife_tip_r_angle,
'tool_stock_num': item.tool_stock_num,
@@ -332,9 +349,7 @@ class RealTimeDistributionFunctionalTools(models.Model):
kw = json.dumps(tool_distribution_list, ensure_ascii=False)
r = requests.post(str_url, json={}, data={'kw': kw, 'token': token}, headers=headers)
ret = r.json()
# self.code = ret['data']
# self.state_zc = "已注册"
if r == 200:
if ret.get('code') == 200:
return "功能刀具出入库记录注册成功"
else:
raise UserError("没有注册功能刀具出入库记录信息")
@@ -344,10 +359,5 @@ class RealTimeDistributionFunctionalTools(models.Model):
records = super(RealTimeDistributionFunctionalTools, self).create(vals_list)
for record in records:
if record.functional_tool_name_id:
record.enroll_functional_tool_move()
record.enroll_functional_tool_real_time_distribution()
return records
def write(self, vals):
res = super().write(vals)
self.enroll_functional_tool_move()
return res