Merge branch 'feature/功能刀具注册优化' into feature/刀具注册
This commit is contained in:
@@ -16,7 +16,7 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
tool_groups_id = fields.Many2one('sf.tool.groups', '刀具组', related='functional_tool_name_id.tool_groups_id')
|
||||
code = fields.Char('编码', related='functional_tool_name_id.code')
|
||||
rfid = fields.Char('rfid', readonly=True)
|
||||
name = fields.Char(related='functional_tool_name_id.name')
|
||||
name = fields.Char('名称')
|
||||
functional_tool_name_id = fields.Many2one('sf.functional.tool.assembly', string='功能刀具名称', readonly=True)
|
||||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号', readonly=True)
|
||||
sf_cutting_tool_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀具型号')
|
||||
@@ -69,22 +69,15 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
"""
|
||||
for obj in self:
|
||||
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
|
||||
obj.line_edge_knife_library_num = 0
|
||||
obj.machine_knife_library_num = 0
|
||||
elif "线边刀库" in obj.current_location:
|
||||
obj.tool_room_num = 0
|
||||
obj.line_edge_knife_library_num = 1
|
||||
obj.machine_knife_library_num = 0
|
||||
elif "机内刀库" in obj.current_location:
|
||||
obj.tool_room_num = 0
|
||||
obj.line_edge_knife_library_num = 0
|
||||
obj.machine_knife_library_num = 1
|
||||
else:
|
||||
obj.tool_room_num = 0
|
||||
obj.line_edge_knife_library_num = 0
|
||||
obj.machine_knife_library_num = 0
|
||||
|
||||
@api.model
|
||||
def _read_group_mrs_cutting_tool_type_id(self, categories, domain, order):
|
||||
@@ -136,7 +129,6 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
@api.depends('cutting_tool_integral_model_id', 'cutting_tool_blade_model_id')
|
||||
def _compute_maintenance_equipment_image(self):
|
||||
for record in self:
|
||||
print('111')
|
||||
if record.cutting_tool_integral_model_id:
|
||||
print(record.cutting_tool_integral_model_id)
|
||||
record.sudo().suitable_machining_method_ids = record.cutting_tool_integral_model_id.suitable_machining_method_ids.ids
|
||||
@@ -194,36 +186,35 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
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.id, '机床装刀', self.functional_tool_name_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("刀具组发送失败")
|
||||
|
||||
# ==========刀具组接口==========
|
||||
# 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
|
||||
# @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):
|
||||
@@ -239,7 +230,8 @@ class FunctionalToolWarning(models.Model):
|
||||
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='机床类型')
|
||||
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)]")
|
||||
# 功能刀具信息
|
||||
@@ -298,14 +290,14 @@ class StockMoveLine(models.Model):
|
||||
|
||||
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',
|
||||
related='functional_tool_name_id.functional_tool_type_id')
|
||||
diameter = fields.Integer(string='刀具直径(mm)', related='functional_tool_name_id.functional_tool_diameter')
|
||||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)', related='functional_tool_name_id.knife_tip_r_angle')
|
||||
install_tool_time = fields.Datetime("刀具组装时间", related='functional_tool_name_id.tool_loading_time')
|
||||
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')
|
||||
group_expand='_read_group_functional_tool_type_id')
|
||||
functional_tool_name = fields.Char('刀具名称')
|
||||
diameter = fields.Integer(string='刀具直径(mm)')
|
||||
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
|
||||
install_tool_time = fields.Datetime("刀具组装时间", default=fields.Datetime.now())
|
||||
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):
|
||||
@@ -442,17 +434,17 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
计算刀具房数量、线边刀库数量、机内刀库数量
|
||||
"""
|
||||
if tool:
|
||||
tool.sudo().tool_stock_num = 0
|
||||
tool.sudo().side_shelf_num = 0
|
||||
tool.sudo().on_tool_stock_num = 0
|
||||
tool.tool_stock_num = 0
|
||||
tool.side_shelf_num = 0
|
||||
tool.on_tool_stock_num = 0
|
||||
if tool.sf_functional_cutting_tool_entity_ids:
|
||||
for cutting_tool in tool.sf_functional_cutting_tool_entity_ids:
|
||||
if cutting_tool.tool_room_num > 0:
|
||||
tool.sudo().tool_stock_num += 1
|
||||
tool.tool_stock_num += 1
|
||||
elif cutting_tool.line_edge_knife_library_num > 0:
|
||||
tool.sudo().side_shelf_num += 1
|
||||
tool.side_shelf_num += 1
|
||||
elif cutting_tool.machine_knife_library_num > 0:
|
||||
tool.sudo().on_tool_stock_num += 1
|
||||
tool.on_tool_stock_num += 1
|
||||
|
||||
def create_or_edit_safety_stock(self, vals, sf_functional_cutting_tool_entity_ids):
|
||||
"""
|
||||
@@ -479,6 +471,14 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
|
||||
records = super(RealTimeDistributionOfFunctionalTools, self).create(vals_list)
|
||||
return records
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
for item in self:
|
||||
if item:
|
||||
if vals.get('min_stock_num') or vals.get('max_stock_num'):
|
||||
item.enroll_functional_tool_real_time_distribution()
|
||||
return res
|
||||
|
||||
|
||||
class MachineTableToolChangingApply(models.Model):
|
||||
_name = 'sf.machine.table.tool.changing.apply'
|
||||
|
||||
@@ -6,6 +6,30 @@ from odoo.addons.sf_base.commons.common import Common
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
def get_suitable_machining_method_names(item):
|
||||
suitable_machining_method_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)
|
||||
return suitable_machining_method_names
|
||||
|
||||
|
||||
def get_cutting_direction_names(item):
|
||||
cutting_direction_names = []
|
||||
for cutting_direction_id in item.cutting_direction_ids:
|
||||
if cutting_direction_id:
|
||||
cutting_direction_names.append(cutting_direction_id.name)
|
||||
return cutting_direction_names
|
||||
|
||||
|
||||
def get_suitable_coolant_names(item):
|
||||
suitable_coolant_names = []
|
||||
for suitable_coolant_id in item.suitable_coolant_ids:
|
||||
if suitable_coolant_id:
|
||||
suitable_coolant_names.append(suitable_coolant_id.name)
|
||||
return suitable_coolant_names
|
||||
|
||||
|
||||
class StockLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
_description = '刀具物料序列号注册'
|
||||
@@ -25,28 +49,24 @@ class StockLot(models.Model):
|
||||
val = {
|
||||
'name': item.name,
|
||||
'tool_material_status': item.tool_material_status,
|
||||
'location': item.quant_ids[-1].location_id.name
|
||||
'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
|
||||
|
||||
@@ -73,11 +93,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,
|
||||
@@ -89,11 +109,19 @@ class ToolMaterial(models.Model):
|
||||
kw = json.dumps(tool_material_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.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'
|
||||
@@ -116,6 +144,7 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
'id': item.id,
|
||||
'code': item.code,
|
||||
'name': item.name,
|
||||
'rfid': item.rfid,
|
||||
'tool_groups_name': item.tool_groups_id.name,
|
||||
'barcode': item.barcode_id.name,
|
||||
'cutting_tool_type_code': item.sf_cutting_tool_type_id.code,
|
||||
@@ -126,9 +155,6 @@ class FunctionalCuttingToolEntity(models.Model):
|
||||
'tool_loading_length': item.tool_loading_length,
|
||||
'functional_tool_length': item.functional_tool_length,
|
||||
'effective_length': item.effective_length,
|
||||
'tool_room_num': item.tool_room_num,
|
||||
'line_edge_knife_library_num': item.line_edge_knife_library_num,
|
||||
'machine_knife_library_num': item.machine_knife_library_num,
|
||||
'max_lifetime_value': item.max_lifetime_value,
|
||||
'alarm_value': item.alarm_value,
|
||||
'used_value': item.used_value,
|
||||
@@ -141,21 +167,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': get_suitable_machining_method_names(item),
|
||||
'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name,
|
||||
'handle_type_name': item.handle_type_id.name,
|
||||
'cutting_direction_names': get_cutting_direction_names(item),
|
||||
'suitable_coolant_names': get_suitable_coolant_names(item),
|
||||
'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("没有注册功能刀具信息")
|
||||
@@ -190,11 +219,11 @@ 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,
|
||||
'machine_tool_code': item.machine_tool_code,
|
||||
'machine_table_type_code': item.machine_table_type_id.code,
|
||||
'cutter_spacing_code': item.cutter_spacing_code_id.code,
|
||||
'functional_tool_name': item.name,
|
||||
'barcode': item.barcode_id.name,
|
||||
@@ -207,18 +236,16 @@ class FunctionalToolWarning(models.Model):
|
||||
'alarm_value': item.alarm_value,
|
||||
'used_value': item.used_value,
|
||||
'functional_tool_status': item.functional_tool_status,
|
||||
'alarm_time': item.alarm_time,
|
||||
'alarm_time': item.alarm_time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'dispose_user': item.dispose_user,
|
||||
'dispose_time': item.dispose_time.strftime('%Y-%m-%d %H:%M:%S'),
|
||||
'dispose_time': item.dispose_time,
|
||||
'dispose_func': item.dispose_func,
|
||||
}
|
||||
tool_warning_list.append(val)
|
||||
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("没有注册功能刀具预警信息")
|
||||
@@ -251,8 +278,9 @@ class StockMoveLine(models.Model):
|
||||
for item in objs_all:
|
||||
val = {
|
||||
'id': item.id,
|
||||
'name': item.functional_tool_name_id.name,
|
||||
'name': item.functional_tool_name,
|
||||
'code': item.code,
|
||||
'rfid': item.rfid,
|
||||
'tool_groups_name': item.tool_groups_id.name,
|
||||
'reference': item.reference,
|
||||
'barcode': item.lot_id.name,
|
||||
@@ -269,9 +297,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("没有注册功能刀具出入库记录信息")
|
||||
@@ -309,7 +335,7 @@ class RealTimeDistributionFunctionalTools(models.Model):
|
||||
'id': item.id,
|
||||
'name': item.name,
|
||||
'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,
|
||||
@@ -322,17 +348,20 @@ class RealTimeDistributionFunctionalTools(models.Model):
|
||||
'unit': item.unit,
|
||||
'image': '' if not item.image else base64.b64encode(item.image).decode('utf-8'),
|
||||
'functional_tool_codes': str(functional_tool_codes),
|
||||
'whether_standard_knife': item.whether_standard_knife,
|
||||
'coarse_middle_thin': item.coarse_middle_thin,
|
||||
'whether_standard_knife': item.whether_standard_knife,
|
||||
'suitable_machining_method_names': get_suitable_machining_method_names(item),
|
||||
'blade_tip_characteristics_name': item.blade_tip_characteristics_id.name,
|
||||
'handle_type_name': item.handle_type_id.name,
|
||||
'cutting_direction_names': get_cutting_direction_names(item),
|
||||
'suitable_coolant_names': get_suitable_coolant_names(item),
|
||||
'active': item.active
|
||||
}
|
||||
tool_distribution_list.append(val)
|
||||
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("没有注册功能刀具出入库记录信息")
|
||||
@@ -341,11 +370,6 @@ class RealTimeDistributionFunctionalTools(models.Model):
|
||||
def create(self, vals_list):
|
||||
records = super(RealTimeDistributionFunctionalTools, self).create(vals_list)
|
||||
for record in records:
|
||||
if record.functional_tool_name_id:
|
||||
record.enroll_functional_tool_move()
|
||||
if record:
|
||||
record.enroll_functional_tool_real_time_distribution()
|
||||
return records
|
||||
|
||||
def write(self, vals):
|
||||
res = super().write(vals)
|
||||
self.enroll_functional_tool_move()
|
||||
return res
|
||||
|
||||
@@ -98,7 +98,7 @@ class StockLot(models.Model):
|
||||
|
||||
tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索')
|
||||
tool_material_status = fields.Selection([('可用', '可用'), ('在用', '在用'), ('报废', '报废')], string='状态',
|
||||
compute='_compute_tool_material_status')
|
||||
compute='_compute_tool_material_status', store=True)
|
||||
|
||||
@api.depends('quant_ids')
|
||||
def _compute_tool_material_status(self):
|
||||
@@ -110,6 +110,13 @@ class StockLot(models.Model):
|
||||
else:
|
||||
record.tool_material_status = '可用'
|
||||
|
||||
@api.onchange('tool_material_status')
|
||||
def _onchange_tool_material_status(self):
|
||||
for obj in self:
|
||||
if obj:
|
||||
# 注册刀具物料状态到cloud平台
|
||||
obj.enroll_tool_material_stock()
|
||||
|
||||
@api.model
|
||||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||||
# 调用父类的name_search方法
|
||||
@@ -137,9 +144,7 @@ class StockLot(models.Model):
|
||||
for record in records:
|
||||
if record.product_id.categ_id.name == '刀具':
|
||||
tool_material_search = self.env['sf.tool.material.search'].sudo().search(
|
||||
[('cutting_tool_material_id', '=', record.product_id.cutting_tool_material_id.id),
|
||||
('cutting_tool_standard_library_id', '=', record.product_id.cutting_tool_model_id.id),
|
||||
('specification_id', '=', record.product_id.specification_id.id)])
|
||||
[('id', '=', record.product_id.tool_material_id)])
|
||||
if tool_material_search:
|
||||
record.tool_material_search_id = tool_material_search
|
||||
return records
|
||||
@@ -148,12 +153,15 @@ class StockLot(models.Model):
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
tool_material_id = fields.Char('刀具物料搜索模型ID')
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(ProductProduct, self).create(vals_list)
|
||||
for record in records:
|
||||
if record.categ_id.name == '刀具':
|
||||
self.env['sf.tool.material.search'].sudo().create({
|
||||
tool_material = self.env['sf.tool.material.search'].sudo().create({
|
||||
'product_id': record.id
|
||||
})
|
||||
record.tool_material_id = tool_material.id
|
||||
return records
|
||||
|
||||
@@ -311,7 +311,7 @@ class ToolMaterial(models.Model):
|
||||
product_id = fields.Many2one('product.product', string='刀具物料产品')
|
||||
|
||||
name = fields.Char('名称', related='product_id.name')
|
||||
code = fields.Char('编码', store=True)
|
||||
code = fields.Char('编码')
|
||||
cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料',
|
||||
related='product_id.cutting_tool_material_id',
|
||||
store=True,
|
||||
@@ -331,14 +331,6 @@ class ToolMaterial(models.Model):
|
||||
|
||||
active = fields.Boolean(string='已归档', default=True)
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_code(self):
|
||||
for record in self:
|
||||
if record:
|
||||
code = '%s_%s' % (record.cutting_tool_standard_library_id.code, record.specification_id.name)
|
||||
obj = self.search([('code', 'like', code)], limit=1, order="id desc")
|
||||
record.code = '%s_%03d' % (code, 1 if obj else int(obj.code[-3:]) + 1)
|
||||
|
||||
@api.depends('barcode_ids')
|
||||
def _compute_number(self):
|
||||
for record in self:
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
<field name="arch" type="xml">
|
||||
<form create="0" edit="0" delete="0">
|
||||
<header>
|
||||
<button name="enroll_functional_tool_entity" string="功能刀具注册" type="object"
|
||||
class="btn-primary"/>
|
||||
<!-- <button name="enroll_functional_tool_entity" string="功能刀具注册" type="object"-->
|
||||
<!-- class="btn-primary"/>-->
|
||||
<field name="functional_tool_status" widget="statusbar" statusbar_visible="正常,报警,已拆除"/>
|
||||
</header>
|
||||
<sheet>
|
||||
@@ -245,8 +245,8 @@
|
||||
<field name="dispose_user"/>
|
||||
<field name="dispose_time"/>
|
||||
<field name="dispose_func"/>
|
||||
<button name="enroll_functional_tool_warning" string="刀具预警注册" type="object"
|
||||
class="btn-primary"/>
|
||||
<!-- <button name="enroll_functional_tool_warning" string="刀具预警注册" type="object"-->
|
||||
<!-- class="btn-primary"/>-->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
@@ -322,10 +322,10 @@
|
||||
<field name="model">sf.real.time.distribution.of.functional.tools</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<header>
|
||||
<button name="enroll_functional_tool_real_time_distribution" string="安全库存注册" type="object"
|
||||
class="btn-primary"/>
|
||||
</header>
|
||||
<!-- <header>-->
|
||||
<!-- <button name="enroll_functional_tool_real_time_distribution" string="安全库存注册" type="object"-->
|
||||
<!-- class="btn-primary"/>-->
|
||||
<!-- </header>-->
|
||||
<sheet>
|
||||
<div class="oe_title">
|
||||
<h1>
|
||||
@@ -462,7 +462,7 @@
|
||||
<field name="date"/>
|
||||
<field name="qty_done" string="数量"/>
|
||||
<field name="functional_tool_type_id" invisible="True"/>
|
||||
<button name="enroll_functional_tool_move" string="安全库存注册" type="object" class="btn-primary"/>
|
||||
<!-- <button name="enroll_functional_tool_move" string="安全库存注册" type="object" class="btn-primary"/>-->
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -62,6 +62,7 @@
|
||||
<tree>
|
||||
<field name="name"/>
|
||||
<field name="tool_material_status"/>
|
||||
<button name="enroll_tool_material_stock" string="序列号注册" type="object" class="btn-primary"/>
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
|
||||
@@ -481,9 +481,9 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
|
||||
# 创建组装入库单
|
||||
# 创建功能刀具批次/序列号记录
|
||||
stock_lot = product_id.create_assemble_warehouse_receipt(self.id, functional_tool_assembly)
|
||||
stock_lot = product_id.create_assemble_warehouse_receipt(self.id, functional_tool_assembly, self)
|
||||
# 创建刀具组装入库单
|
||||
self.env['stock.picking'].create_stocking_picking(stock_lot, functional_tool_assembly)
|
||||
self.env['stock.picking'].create_stocking_picking(stock_lot, functional_tool_assembly, self)
|
||||
# 刀具物料出库
|
||||
if self.integral_code_id:
|
||||
product_id.tool_material_stock_moves(self.integral_code_id)
|
||||
@@ -583,6 +583,7 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
return {
|
||||
'barcode_id': stock_lot.id,
|
||||
'code': self.tool_code,
|
||||
'name': self.after_assembly_functional_tool_name,
|
||||
'rfid': self.rfid,
|
||||
'tool_groups_id': self.tool_groups_id.id,
|
||||
'functional_tool_name_id': functional_tool_assembly_id.id,
|
||||
@@ -618,7 +619,7 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
class StockPicking(models.Model):
|
||||
_inherit = 'stock.picking'
|
||||
|
||||
def create_stocking_picking(self, stock_lot, functional_tool_assembly):
|
||||
def create_stocking_picking(self, stock_lot, functional_tool_assembly, obj):
|
||||
"""
|
||||
创建刀具组装入库单
|
||||
"""
|
||||
@@ -639,7 +640,14 @@ class StockPicking(models.Model):
|
||||
'location_dest_id': picking_id.location_dest_id.id,
|
||||
'lot_id': stock_lot.id,
|
||||
'qty_done': 1,
|
||||
'functional_tool_name_id': functional_tool_assembly.id
|
||||
'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.tool_code,
|
||||
'rfid': obj.rfid,
|
||||
'functional_tool_name': obj.after_assembly_functional_tool_name,
|
||||
'tool_groups_id': obj.tool_groups_id.id
|
||||
})
|
||||
# 将刀具组装入库单的状态更改为就绪
|
||||
picking_id.action_confirm()
|
||||
@@ -664,7 +672,7 @@ class StockPicking(models.Model):
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
def create_assemble_warehouse_receipt(self, tool_assembly_order_id, functional_tool_assembly):
|
||||
def create_assemble_warehouse_receipt(self, tool_assembly_order_id, functional_tool_assembly, obj):
|
||||
"""
|
||||
创建功能刀具批次/序列号记录
|
||||
"""
|
||||
@@ -680,7 +688,7 @@ class ProductProduct(models.Model):
|
||||
stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
|
||||
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
||||
stock_lot.create_stock_quant(location_inventory_id, stock_location_id, functional_tool_assembly.id,
|
||||
'功能刀具组装')
|
||||
'功能刀具组装', obj)
|
||||
|
||||
return stock_lot
|
||||
|
||||
@@ -714,13 +722,13 @@ class ProductProduct(models.Model):
|
||||
location_inventory_id = tool_material.quant_ids.location_id[-1]
|
||||
stock_location_id = self.env['stock.location'].search([('name', '=', '刀具组装位置')])
|
||||
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
||||
tool_material.create_stock_quant(location_inventory_id, stock_location_id, None, '功能刀具组装')
|
||||
tool_material.create_stock_quant(location_inventory_id, stock_location_id, None, '功能刀具组装', False)
|
||||
|
||||
|
||||
class StockLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
|
||||
def create_stock_quant(self, location_inventory_id, stock_location_id, functional_tool_assembly_id, name):
|
||||
def create_stock_quant(self, location_inventory_id, stock_location_id, functional_tool_assembly_id, name, obj):
|
||||
"""
|
||||
对功能刀具组装过程的功能刀具和刀具物料进行库存移动,以及创建移动历史
|
||||
"""
|
||||
@@ -743,6 +751,25 @@ class StockLot(models.Model):
|
||||
'move_id': stock_move_id.id,
|
||||
'install_tool_time': fields.Datetime.now(),
|
||||
'qty_done': 1.0,
|
||||
'state': 'done'
|
||||
'state': 'done',
|
||||
'functional_tool_type_id': False if not obj else obj.functional_tool_type_id.id,
|
||||
'diameter': None if not obj else obj.after_assembly_functional_tool_diameter,
|
||||
'knife_tip_r_angle': None if not obj else obj.after_assembly_knife_tip_r_angle,
|
||||
'code': '' if not obj else obj.tool_code,
|
||||
'rfid': '' if not obj else obj.rfid,
|
||||
'functional_tool_name': '' if not obj else obj.after_assembly_functional_tool_name,
|
||||
'tool_groups_id': False if not obj else obj.tool_groups_id.id
|
||||
})
|
||||
return stock_move_id, stock_move_line_id
|
||||
|
||||
|
||||
class StockQuant(models.Model):
|
||||
_inherit = 'stock.quant'
|
||||
|
||||
@api.model_create_multi
|
||||
def create(self, vals_list):
|
||||
records = super(StockQuant, self).create(vals_list)
|
||||
for record in records:
|
||||
if record.lot_id.product_id.categ_id.name == '刀具':
|
||||
record.lot_id.enroll_tool_material_stock()
|
||||
return records
|
||||
|
||||
Reference in New Issue
Block a user