From 9d2bad977ce0e9a79f38e08b791013002936e9e2 Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Mon, 4 Mar 2024 17:10:41 +0800
Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E4=BA=A7=E5=93=81=E6=A8=A1?=
=?UTF-8?q?=E5=9E=8B=E7=9A=84=E4=BA=A7=E5=93=81=E7=B1=BB=E5=88=AB=E5=AD=97?=
=?UTF-8?q?=E6=AE=B5=E6=B7=BB=E5=8A=A0=E5=BF=85=E5=A1=AB=E6=A0=87=E8=AE=B0?=
=?UTF-8?q?=EF=BC=9B2=E3=80=81=E5=88=B6=E9=80=A0=E8=AE=A2=E5=8D=95?=
=?UTF-8?q?=E7=9A=84=E5=B7=A5=E5=8D=95=E6=B7=BB=E5=8A=A0RFID=E7=A0=81(?=
=?UTF-8?q?=E5=B7=B2=E8=A7=A3=E9=99=A4)=E5=AD=97=E6=AE=B5=EF=BC=8C?=
=?UTF-8?q?=E5=BD=93=E5=B7=A5=E5=8D=95=E8=A7=A3=E9=99=A4=E8=A3=85=E5=A4=B9?=
=?UTF-8?q?=E6=97=B6=E4=BF=9D=E5=AD=98RFID=E7=A0=81=E5=88=B0RFID=E7=A0=81(?=
=?UTF-8?q?=E5=B7=B2=E8=A7=A3=E9=99=A4)=E5=AD=97=E6=AE=B5=E8=BF=9B?=
=?UTF-8?q?=E8=A1=8C=E5=B1=95=E7=A4=BA=EF=BC=9B3=E3=80=81=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=88=80=E5=85=B7=E5=88=97=E8=A1=A8=E7=9A=84=E5=BD=93?=
=?UTF-8?q?=E5=89=8D=E4=BD=8D=E7=BD=AE=E5=AD=97=E6=AE=B5=E6=94=B9=E4=B8=BA?=
=?UTF-8?q?Selection=E7=B1=BB=E5=9E=8B=EF=BC=8C=E5=B9=B6=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E8=87=AA=E5=8A=A8=E8=AE=A1=E7=AE=97=E5=8A=9F=E8=83=BD=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E5=BD=93=E5=89=8D=E4=BD=8D=E7=BD=AE=E7=9A=84=E6=96=B9?=
=?UTF-8?q?=E6=B3=95=EF=BC=9B4=E3=80=81=E8=8E=B7=E5=8F=96=E6=9C=BA?=
=?UTF-8?q?=E5=BA=8A=E5=88=80=E5=BA=93=E4=BF=A1=E6=81=AF=E6=97=B6=EF=BC=8C?=
=?UTF-8?q?=E5=AF=B9=E6=96=B0=E8=A3=85=E5=88=80=E7=9A=84=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E5=88=80=E5=85=B7=E8=BF=9B=E8=A1=8C=E5=BA=93=E5=AD=98=E4=BD=8D?=
=?UTF-8?q?=E7=A7=BB=E5=88=80=E5=88=B6=E9=80=A0=E5=89=8D(=E6=9C=BA?=
=?UTF-8?q?=E5=86=85=E5=88=80=E5=BA=93)=EF=BC=9B5=E3=80=81=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E7=BB=84=E8=A3=85?=
=?UTF-8?q?=E6=97=B6=E6=89=AB=E7=A0=81=E8=87=AA=E5=8A=A8=E5=BD=95=E5=85=A5?=
=?UTF-8?q?RFID=E7=A0=81=E5=8A=9F=E8=83=BD=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../product_template_management_view.xml | 2 +-
sf_manufacturing/models/mrp_workorder.py | 2 +
sf_manufacturing/views/mrp_workorder_view.xml | 4 +-
sf_tool_management/models/base.py | 87 +++++++++++--------
.../models/maintenance_equipment.py | 3 +
sf_tool_management/views/tool_base_views.xml | 6 +-
6 files changed, 64 insertions(+), 40 deletions(-)
diff --git a/sf_dlm_management/views/product_template_management_view.xml b/sf_dlm_management/views/product_template_management_view.xml
index 1e761cc8..249decdb 100644
--- a/sf_dlm_management/views/product_template_management_view.xml
+++ b/sf_dlm_management/views/product_template_management_view.xml
@@ -7,7 +7,7 @@
-
+
-
+
+
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index 22cb1b42..649c757e 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -39,24 +39,29 @@ class FunctionalCuttingToolEntity(models.Model):
functional_tool_status = fields.Selection([('正常', '正常'), ('报警', '报警'), ('已拆除', '已拆除')],
string='状态', store=True, default='正常')
current_location_id = fields.Many2one('stock.location', string='当前位置', readonly=True)
- current_location = fields.Char('位置', compute='_compute_current_location_id')
+ current_location = fields.Selection(
+ [('组装后', '组装后'), ('刀具房', '刀具房'), ('线边刀库', '线边刀库'), ('机内刀库', '机内刀库')],
+ string='位置', compute='_compute_current_location_id', store=True)
image = fields.Binary('图片', readonly=True)
active = fields.Boolean(string='已归档', default=True)
- @api.depends('barcode_id')
+ @api.depends('barcode_id.quant_ids')
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.sudo().current_location_id = quant_id.location_id
- record.sudo().current_location = quant_id.location_id.name
+ 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.sudo().current_location_id = False
- record.sudo().current_location = False
+ record.current_location_id = False
+ record.current_location = False
def get_location_num(self):
"""
@@ -64,15 +69,15 @@ class FunctionalCuttingToolEntity(models.Model):
"""
for obj in self:
if obj.current_location_id:
- if obj.current_location_id.name in ['刀具房']:
+ 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_id.name:
+ 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_id.name:
+ elif "机内刀库" in obj.current_location:
obj.tool_room_num = 0
obj.line_edge_knife_library_num = 0
obj.machine_knife_library_num = 1
@@ -180,33 +185,45 @@ class FunctionalCuttingToolEntity(models.Model):
('coarse_middle_thin', '=', self.coarse_middle_thin)]
return result
- # ==========刀具组接口==========
- # 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 tool_inventory_displacement_out(self):
+ """
+ 机床当前刀库实时信息接口,功能刀具出库
+ """
+ # 获取位置对象
+ 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, '机床装刀')
- # @api.model_create_multi
- # def create(self, vals):
- # obj = super(FunctionalCuttingToolEntity, self).create(vals)
- # # 调用刀具组接口
- # self._register_functional_tool_groups(obj)
- # return obj
+
+# ==========刀具组接口==========
+# 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):
diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py
index 9f3cefba..467989b7 100644
--- a/sf_tool_management/models/maintenance_equipment.py
+++ b/sf_tool_management/models/maintenance_equipment.py
@@ -79,6 +79,9 @@ class SfMaintenanceEquipment(models.Model):
'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'],
diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml
index 239845a4..bf5fe0fb 100644
--- a/sf_tool_management/views/tool_base_views.xml
+++ b/sf_tool_management/views/tool_base_views.xml
@@ -152,8 +152,8 @@
-
-
+
+
@@ -203,7 +203,7 @@
-
+
From d85b05f9998889808a6fe2aecb117a4a014efaac Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Mon, 4 Mar 2024 17:11:18 +0800
Subject: [PATCH 2/2] 1
---
sf_tool_management/wizard/wizard.py | 62 +++++++++++++++--------------
1 file changed, 33 insertions(+), 29 deletions(-)
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index 3b2649a2..322cf096 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -300,29 +300,32 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
智能工厂组装单处扫码绑定刀具物料')
"""
for record in self:
- records = record.env['stock.lot'].search([('name', '=', barcode)])
- if not records:
- raise ValidationError('扫描的条形码数据不存在,请重新扫描!')
- for record_stock_lot in records:
- if record_stock_lot.quant_ids[-1].location_id.name == '刀具组装位置':
- raise ValidationError('该刀具物料已使用,请重新选择!!!')
- elif record_stock_lot.quant_ids[-1].location_id.name not in '刀具房':
- raise ValidationError('该刀具物料未入库,请重新选择!!!')
- 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('扫描的刀具物料不存在,请重新扫描!')
+ if 'DJWL' in barcode:
+ records = record.env['stock.lot'].search([('name', '=', barcode)])
+ if not records:
+ raise ValidationError('扫描的条形码数据不存在,请重新扫描!')
+ for record_stock_lot in records:
+ if record_stock_lot.quant_ids[-1].location_id.name == '刀具组装位置':
+ raise ValidationError('该刀具物料已使用,请重新选择!!!')
+ elif record_stock_lot.quant_ids[-1].location_id.name not in '刀具房':
+ raise ValidationError('该刀具物料未入库,请重新选择!!!')
+ 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('扫描的刀具物料不存在,请重新扫描!')
+ else:
+ record.rfid = barcode
# 组装功能刀具参数信息
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号')
@@ -676,7 +679,8 @@ class ProductProduct(models.Model):
location_inventory_id = self.env['stock.location'].search([('name', '=', 'Production')])
stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
# 创建功能刀具该批次/序列号 库存移动和移动历史
- stock_lot.create_stock_quant(location_inventory_id, stock_location_id, functional_tool_assembly.id)
+ stock_lot.create_stock_quant(location_inventory_id, stock_location_id, functional_tool_assembly.id,
+ '功能刀具组装')
return stock_lot
@@ -710,20 +714,20 @@ 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, '功能刀具组装')
class StockLot(models.Model):
_inherit = 'stock.lot'
- def create_stock_quant(self, location_inventory_id, stock_location_id, functional_tool_assembly_id):
+ def create_stock_quant(self, location_inventory_id, stock_location_id, functional_tool_assembly_id, name):
"""
对功能刀具组装过程的功能刀具和刀具物料进行库存移动,以及创建移动历史
"""
# 创建库存移动记录
- stock_move_id = self.env['stock.move'].create({
- 'name': '功能刀具组装',
+ stock_move_id = self.env['stock.move'].sudo().create({
+ 'name': name,
'product_id': self.product_id.id,
'location_id': location_inventory_id.id,
'location_dest_id': stock_location_id.id,
@@ -732,7 +736,7 @@ class StockLot(models.Model):
})
# 创建移动历史记录
- stock_move_line_id = self.env['stock.move.line'].create({
+ stock_move_line_id = self.env['stock.move.line'].sudo().create({
'product_id': self.product_id.id,
'functional_tool_name_id': functional_tool_assembly_id,
'lot_id': self.id,