From 981872b0b11fbf0cd55411e786522f26fcecbaeb Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Wed, 6 Dec 2023 17:25:47 +0800
Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=A0=B9=E6=8D=AE=E6=9C=BA=E5=8F=B0?=
=?UTF-8?q?=E6=8D=A2=E5=88=80=E7=94=B3=E8=AF=B7=E7=9A=84=E7=8A=B6=E6=80=81?=
=?UTF-8?q?=EF=BC=8C=E5=A6=82=E6=9E=9C=E4=B8=BA=E6=8A=A5=E8=AD=A6=E7=8A=B6?=
=?UTF-8?q?=E6=80=81=E5=B0=B1=E8=87=AA=E5=8A=A8=E5=88=9B=E5=BB=BA=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=88=80=E5=85=B7=E9=A2=84=E8=AD=A6=E8=AE=B0=E5=BD=95?=
=?UTF-8?q?=EF=BC=9B2=E3=80=81=E8=87=AA=E5=8A=A8=E6=A3=80=E7=B4=A2?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E5=88=97=E8=A1=A8=E7=9A=84?=
=?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8F=B7=E6=89=80=E5=9C=A8=E4=BD=8D=E7=BD=AE?=
=?UTF-8?q?=EF=BC=8C=E8=AE=A1=E7=AE=97=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7?=
=?UTF-8?q?=E7=9A=84=E5=BD=93=E5=89=8D=E4=BD=8D=E7=BD=AE=E5=8F=8A=E6=95=B0?=
=?UTF-8?q?=E9=87=8F=EF=BC=9B3=E3=80=81=E5=8A=9F=E8=83=BD=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E5=AE=89=E5=85=A8=E5=BA=93=E5=AD=98=E6=A8=A1=E5=9E=8B?=
=?UTF-8?q?=EF=BC=8C=E6=A0=B9=E6=8D=AE=E5=BD=93=E5=89=8D=E8=AE=B0=E5=BD=95?=
=?UTF-8?q?=E7=9A=84=E5=8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=E6=90=9C?=
=?UTF-8?q?=E7=B4=A2=EF=BC=9B5=E3=80=81=E5=8A=9F=E8=83=BD=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E7=BB=84=E8=A3=85=E6=A8=A1=E5=9E=8B=E5=92=8C=E7=BB=84?=
=?UTF-8?q?=E8=A3=85=E5=8D=95=E6=A8=A1=E5=9E=8B=E6=96=B0=E5=A2=9E=E5=9B=BE?=
=?UTF-8?q?=E7=89=87=E5=AD=97=E6=AE=B5=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_tool_management/models/base.py | 128 +++++++++++++++----
sf_tool_management/views/tool_base_views.xml | 9 +-
sf_tool_management/wizard/wizard.py | 5 +-
sf_tool_management/wizard/wizard_view.xml | 3 +
4 files changed, 115 insertions(+), 30 deletions(-)
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index 92242197..fc58e6e0 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -34,20 +34,48 @@ 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')
image = fields.Binary('图片', readonly=True)
- # @api.depends('current_location_id')
- # def _compute_location_num(self):
- # """
- # 计算库存位置数量
- # """
- # for obj in self:
- # if obj.current_location_id:
- # if obj.current_location_id.name in ('组装后', '刀具房'):
- # obj.tool_room_num = 1
- # obj.line_edge_knife_library_num = 0
- # obj.machine_knife_library_num = 0
- #
+ @api.depends('barcode_id')
+ def _compute_current_location_id(self):
+ for record in self:
+ if record.barcode_id.quant_ids:
+ print(record.barcode_id.quant_ids)
+ for quant_id in record.barcode_id.quant_ids:
+ if quant_id.inventory_quantity_auto_apply > 0:
+ print(quant_id)
+ record.current_location_id = quant_id.location_id
+ record.current_location = quant_id.location_id.name
+ print(record.current_location_id)
+ if record.current_location_id:
+ record.get_location_num()
+ else:
+ record.current_location_id = False
+ record.current_location = False
+
+ def get_location_num(self):
+ """
+ 计算库存位置数量
+ """
+ for obj in self:
+ if obj.current_location_id:
+ if obj.current_location_id.name 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:
+ 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:
+ 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):
@@ -144,13 +172,13 @@ class FunctionalToolWarning(models.Model):
diameter = fields.Integer(string='刀具直径(mm)')
knife_tip_r_angle = fields.Float(string='刀尖R角(mm)')
# 其他信息
- install_tool_time = fields.Datetime("刀具组装时间")
+ 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.Char('报警时间')
+ alarm_time = fields.Datetime('报警时间')
dispose_user = fields.Char('处理人')
dispose_time = fields.Char('处理时间')
dispose_func = fields.Char('处理方法/措施', readonly=False)
@@ -160,6 +188,29 @@ class FunctionalToolWarning(models.Model):
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'
@@ -191,10 +242,10 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
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, compute='_compute_tool_stock_total')
+ tool_stock_total = fields.Integer(string='当前库存量', readonly=True)
min_stock_num = fields.Integer('最低库存量')
max_stock_num = fields.Integer('最高库存量')
- batch_replenishment_num = fields.Integer('批次补货量')
+ batch_replenishment_num = fields.Integer('批次补货量', readonly=True, compute='_compute_batch_replenishment_num')
unit = fields.Char('单位')
image = fields.Binary('图片')
@@ -228,29 +279,45 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
mrs_cutting_tool_type_ids = categories._search([], order=order, access_rights_uid=SUPERUSER_ID)
return categories.browse(mrs_cutting_tool_type_ids)
- @api.depends('tool_stock_num', 'side_shelf_num', 'on_tool_stock_num')
- def _compute_tool_stock_total(self):
- for record in self:
- if record:
- record.tool_stock_total = record.tool_stock_num + record.side_shelf_num + record.on_tool_stock_num
+ @api.depends('sf_functional_cutting_tool_entity_ids')
+ def _compute_batch_replenishment_num(self):
+ for tool in self:
+ if tool:
+ tool.get_stock_num(tool)
+ # 计算当前库存量
+ tool.tool_stock_total = tool.tool_stock_num + tool.side_shelf_num + tool.on_tool_stock_num
+ # 如果当前库存量小于最低库存量,计算批次补货量
+ if tool.tool_stock_total < tool.min_stock_num:
+ tool.batch_replenishment_num = tool.max_stock_num - tool.tool_stock_total
+ else:
+ tool.batch_replenishment_num = 0
- # @api.depends('tool_stock_total', 'min_stock_num', 'max_stock_num')
- # def _compute_batch_replenishment_num(self):
- # for record in self:
- # if record.tool_stock_total < record.min_stock_num:
- # record.batch_replenishment_num = record.max_stock_num - record.tool_stock_total
+ 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_cutting_tool_entity_ids:
+ for cutting_tool in tool.sf_functional_cutting_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
def create_or_edit_safety_stock(self, vals, sf_functional_cutting_tool_entity_ids):
"""
根据传入的信息新增或者更新功能刀具安全库存的信息
"""
- print(vals)
# 根据功能刀具名称、直径或尖刀R角、粗/中/精查询该功能刀具是否已经存在
record = self.env['sf.real.time.distribution.of.functional.tools'].search(
[('name', '=', vals['name']), ('sf_cutting_tool_type_id', '=', vals['sf_cutting_tool_type_id']),
('diameter', '=', vals['diameter']), ('knife_tip_r_angle', '=', vals['knife_tip_r_angle']),
('coarse_middle_thin', '=', vals['coarse_middle_thin'])])
- print(record)
if len(record) > 0:
for obj in record:
obj.write({'sf_functional_cutting_tool_entity_ids': [(4, sf_functional_cutting_tool_entity_ids.id)]})
@@ -357,6 +424,9 @@ class MachineTableToolChangingApply(models.Model):
('cutter_spacing_code_id', '=', self.cutter_spacing_code_id.id)
])
+ # 创建功能刀具预警记录
+ self.env['sf.functional.tool.warning'].create_tool_warning_record({'tool_changing_apply_id': self})
+
# 新建组装任务
sf_functional_tool_assembly = self.env['sf.functional.tool.assembly'].create({
'functional_tool_name': self.functional_tool_name,
@@ -538,6 +608,8 @@ class FunctionalToolAssembly(models.Model):
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
used_value = fields.Integer(string='已使用值(min)', readonly=True)
+ image = fields.Binary('图片', readonly=True)
+
@api.model
def _read_group_functional_tool_type_ids(self, categories, domain, order):
"""读取分组自定义以便在看板视图中显示所有的类别,即使它们为空"""
diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml
index a5e09fb8..9d4e4a64 100644
--- a/sf_tool_management/views/tool_base_views.xml
+++ b/sf_tool_management/views/tool_base_views.xml
@@ -26,6 +26,7 @@
+
@@ -147,6 +148,7 @@
+
@@ -213,7 +215,7 @@
sf.functional.tool.warning.tree
sf.functional.tool.warning
-
+
@@ -260,6 +262,8 @@
+
+
@@ -953,6 +957,9 @@
+
+
+
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index b072ec2c..d5445694 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -193,6 +193,8 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
alarm_value = fields.Integer(string='报警值(min)', readonly=True)
used_value = fields.Integer(string='已使用值(min)', readonly=True)
+ image = fields.Binary('图片')
+
# 功能刀具组装信息
# 整体式刀具型号
integral_code_id = fields.Many2one('stock.lot', string='整体式刀具序列号',
@@ -483,6 +485,7 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'hiding_length': self.hiding_length,
'assemble_status': '1',
'tool_loading_person': self.env.user.name,
+ 'image': self.image,
'tool_loading_time': fields.Datetime.now()
}
@@ -515,7 +518,7 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'cut_time': self.cut_time,
'cut_length': self.cut_length,
'cut_number': self.cut_number,
- 'current_location_id': stock_lot.quant_ids.location_id.ids[-1],
+ 'image': self.image,
}
diff --git a/sf_tool_management/wizard/wizard_view.xml b/sf_tool_management/wizard/wizard_view.xml
index 35db780f..96a9e090 100644
--- a/sf_tool_management/wizard/wizard_view.xml
+++ b/sf_tool_management/wizard/wizard_view.xml
@@ -169,6 +169,9 @@
+
+
+