From 5926d71d2720dd505cfa2f19a35493385409c3cd Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Mon, 27 Nov 2023 17:27:55 +0800
Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E6=96=B0=E5=A2=9E=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=88=80=E5=85=B7=E5=88=97=E8=A1=A8=E6=A8=A1=E5=9E=8B?=
=?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=9C=A8=E5=88=80=E5=85=B7=E6=88=BF=E6=95=B0=E9=87=8F?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=EF=BC=9B2=E3=80=81=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E5=AE=89=E5=85=A8=E5=BA=93?=
=?UTF-8?q?=E5=AD=98=E6=A8=A1=E5=9E=8B=E7=9B=B8=E5=90=8C=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E5=88=80=E5=85=B7=E7=9A=84=E6=A3=80=E7=B4=A2=E6=9D=A1=E4=BB=B6?=
=?UTF-8?q?=EF=BC=9B3=E3=80=81=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD?=
=?UTF-8?q?=E5=88=80=E5=85=B7=E7=BB=84=E8=A3=85=E5=8D=95=E7=BB=84=E8=A3=85?=
=?UTF-8?q?=E7=9A=84=E5=88=9D=E5=A7=8B=E4=BD=8D=E7=BD=AE=E4=B8=BAProductio?=
=?UTF-8?q?n=EF=BC=8C=E4=BF=AE=E6=94=B9=E5=8A=9F=E8=83=BD=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E5=BA=8F=E5=88=97=E5=8F=B7=E7=9A=84=E7=94=9F=E6=88=90?=
=?UTF-8?q?=E8=A7=84=E5=88=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_manufacturing/models/model_type.py | 2 +-
sf_tool_management/__manifest__.py | 4 +-
sf_tool_management/models/base.py | 4 +-
.../models/tool_material_search.py | 2 +-
sf_tool_management/views/tool_base_views.xml | 1 +
sf_tool_management/wizard/wizard.py | 37 ++-----------------
6 files changed, 9 insertions(+), 41 deletions(-)
diff --git a/sf_manufacturing/models/model_type.py b/sf_manufacturing/models/model_type.py
index 48707939..29357d02 100644
--- a/sf_manufacturing/models/model_type.py
+++ b/sf_manufacturing/models/model_type.py
@@ -1,4 +1,4 @@
-from odoo import fields, models, api
+from odoo import fields, models
class ModelType(models.Model):
diff --git a/sf_tool_management/__manifest__.py b/sf_tool_management/__manifest__.py
index d59c6b34..66142708 100644
--- a/sf_tool_management/__manifest__.py
+++ b/sf_tool_management/__manifest__.py
@@ -10,12 +10,10 @@
""",
'category': 'sf',
'website': 'https://www.sf.jikimo.com',
- 'depends': ['sf_base', 'sf_manufacturing'],
+ 'depends': ['sf_manufacturing'],
'data': [
# 'security/group_security.xml',
'security/ir.model.access.csv',
- # 'views/tool_base_views.xml',
- # # 'views/menu_view.xml',
'wizard/wizard_view.xml',
'views/tool_base_views.xml',
'views/menu_view.xml',
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index 35949f47..99a7f3d9 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -25,7 +25,7 @@ class FunctionalCuttingToolEntity(models.Model):
tool_loading_length = fields.Float(string='装刀长(mm)', readonly=True)
functional_tool_length = fields.Float(string='伸出长(mm)', readonly=True)
effective_length = fields.Float(string='有效长(mm)', readonly=True)
- tool_room_num = fields.Integer(string='刀具房数量', readonly=True, )
+ tool_room_num = fields.Integer(string='刀具房数量', readonly=True, compute='_compute_location_num')
line_edge_knife_library_num = fields.Integer(string='线边刀库数量', readonly=True)
machine_knife_library_num = fields.Integer(string='机内刀库数量', readonly=True)
max_lifetime_value = fields.Integer(string='最大寿命值(min)', readonly=True)
@@ -241,7 +241,7 @@ class RealTimeDistributionOfFunctionalTools(models.Model):
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']),
- ('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:
diff --git a/sf_tool_management/models/tool_material_search.py b/sf_tool_management/models/tool_material_search.py
index b89b76cd..2453aafb 100644
--- a/sf_tool_management/models/tool_material_search.py
+++ b/sf_tool_management/models/tool_material_search.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
from odoo import fields, models, api, SUPERUSER_ID
-from odoo.exceptions import ValidationError
+# from odoo.exceptions import ValidationError
# 刀具物料搜索
diff --git a/sf_tool_management/views/tool_base_views.xml b/sf_tool_management/views/tool_base_views.xml
index a764b896..8ebb20d4 100644
--- a/sf_tool_management/views/tool_base_views.xml
+++ b/sf_tool_management/views/tool_base_views.xml
@@ -284,6 +284,7 @@
+
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index 16ae5259..e3d4cff7 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -438,45 +438,13 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
return stock_lot
- # def tool_material_out_of_store(self, tool_material_serial_id):
- # """
- # 刀具物料出库
- # """
- # # 获取位置
- # location_id = self.env['stock.location'].search([('name', '=', 'Stock')])
- # location_dest_id = self.env['stock.location'].search([('name', '=', '刀具组装位置')])
- # print("已运行2222")
- # # 创建库存移动
- # stock_move_id = self.env['stock.move'].create({
- # 'name': '刀具物料出库',
- # 'lot_id': tool_material_serial_id.id,
- # 'product_id': tool_material_serial_id.product_id.id,
- # 'location_id': location_id.id,
- # 'location_dest_id': location_dest_id.id,
- # 'product_uom_qty': 1.00,
- # 'state': 'done'
- # })
- # print("已运行3333")
- # print(stock_move_id)
- # # 创建移动历史
- # stock_move_line_id = self.env['stock.move.line'].create({
- # 'product_id': tool_material_serial_id.product_id.id,
- # 'lot_id': tool_material_serial_id.id,
- # 'move_id': stock_move_id.id,
- # 'install_tool_time': fields.Datetime.now(),
- # 'qty_done': 1.0,
- # 'state': 'done'
- # })
- #
- # return stock_move_id, stock_move_line_id
-
def create_stock_quant(self, product_id, stock_lot, functional_tool_assembly):
"""
创建功能刀具该批次/序列号 库存移动和移动历史
"""
# 获取位置对象
stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
- location_inventory_id = self.env['stock.location'].search([('name', '=', 'Inventory adjustment')])
+ location_inventory_id = self.env['stock.location'].search([('name', '=', 'Production')])
# 创建库存移动
stock_move_id = self.env['stock.move'].create({
@@ -504,7 +472,8 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
"""
生成功能刀具序列号
"""
- code = 'JKM-T-' + str(self.functional_tool_type_id.code) + '-' + str(self.functional_tool_diameter) + '-'
+ code = 'JKM-T-' + str(self.functional_tool_type_id.code) + '-' + str(
+ self.after_assembly_functional_tool_diameter) + '-'
new_time = fields.Date.today()
code += str(new_time) + '-'
stock_lot_id = self.env['stock.lot'].sudo().search(
From e403f2f8e6cb983427b0ca5a97dbc0b4c2b1a896 Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Tue, 28 Nov 2023 14:52:43 +0800
Subject: [PATCH 2/2] =?UTF-8?q?1=E3=80=81=E6=8C=89=E9=9D=A2=E5=90=91?=
=?UTF-8?q?=E5=AF=B9=E8=B1=A1=E7=9A=84=E6=80=9D=E6=83=B3=E4=BC=98=E5=8C=96?=
=?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E7=BB=84=E8=A3=85=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E7=9A=84=E6=95=B4=E4=B8=AA=E6=B5=81=E7=A8=8B=EF=BC=9B?=
=?UTF-8?q?2=E3=80=81=E6=96=B0=E5=A2=9E=E5=88=80=E5=85=B7=E7=BB=84?=
=?UTF-8?q?=E8=A3=85=E5=AE=8C=E6=88=90=E6=97=B6=E7=9A=84=E5=88=80=E5=85=B7?=
=?UTF-8?q?=E7=89=A9=E6=96=99=E5=87=BA=E5=BA=93=E5=88=B0=E5=88=80=E5=85=B7?=
=?UTF-8?q?=E7=BB=84=E8=A3=85=E4=BD=8D=E7=BD=AE=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
sf_tool_management/wizard/wizard.py | 182 ++++++++++++++++------------
1 file changed, 107 insertions(+), 75 deletions(-)
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index e3d4cff7..649d6b86 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -341,6 +341,7 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
功能刀具组装
:return:
"""
+ # 获取组装单对象
functional_tool_assembly = self.env['sf.functional.tool.assembly'].search([
('assembly_order_code', '=', self.assembly_order_code),
('machine_tool_name_id', '=', self.machine_tool_name_id.id),
@@ -349,20 +350,28 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
])
# 对物料做必填判断
self.materials_must_be_judged()
- # # 刀具物料出库
- # if self.integral_code_id:
- # print("已运行1111")
- # self.tool_material_out_of_store(self.integral_code_id)
+ product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
# 创建组装入库单
# 创建功能刀具批次/序列号记录
- stock_lot = self.create_assemble_warehouse_receipt(functional_tool_assembly)
+ stock_lot = product_id.create_assemble_warehouse_receipt(self.id, functional_tool_assembly)
# 创建刀具组装入库单
self.create_stocking_picking(stock_lot)
- # 封装功能刀具数据
- desc_1 = self.get_desc_1(stock_lot)
+ # 刀具物料出库
+ if self.integral_code_id:
+ product_id.tool_material_stock_moves(self.integral_code_id)
+ if self.blade_code_id:
+ product_id.tool_material_stock_moves(self.blade_code_id)
+ if self.bar_code_id:
+ product_id.tool_material_stock_moves(self.bar_code_id)
+ if self.pad_code_id:
+ product_id.tool_material_stock_moves(self.pad_code_id)
+ if self.handle_code_id:
+ product_id.tool_material_stock_moves(self.handle_code_id)
+ if self.chuck_code_id:
+ product_id.tool_material_stock_moves(self.chuck_code_id)
- # 创建功能刀具列表记录
+ # ============================创建功能刀具列表、安全库存记录===============================
# 封装功能刀具数据
desc_2 = self.get_desc_2(stock_lot, functional_tool_assembly)
# 创建功能刀具列表记录
@@ -376,9 +385,11 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'coarse_middle_thin': self.after_assembly_coarse_middle_thin,
}, record_1)
+ # =====================修改功能刀具组装单、机床换刀申请、CAM工单程序用刀计划的状态==============
+ # 封装功能刀具数据
+ desc_1 = self.get_desc_1(stock_lot)
# 修改功能刀具组装单信息
functional_tool_assembly.write(desc_1)
-
if functional_tool_assembly.sf_machine_table_tool_changing_apply_id:
# 修改机床换刀申请的状态
self.env['sf.machine.table.tool.changing.apply'].sudo().search([
@@ -422,72 +433,6 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
# 将刀具组装入库单的状态更改为就绪
picking_id.action_confirm()
- def create_assemble_warehouse_receipt(self, functional_tool_assembly):
- """
- 创建功能刀具批次/序列号记录
- """
- product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
-
- stock_lot = self.env['stock.lot'].create({
- 'name': self.get_stock_lot_name(),
- 'product_id': product_id.id,
- 'company_id': self.env.company.id
- })
- # 创建功能刀具该批次/序列号 库存移动和移动历史
- self.create_stock_quant(product_id, stock_lot, functional_tool_assembly)
-
- return stock_lot
-
- def create_stock_quant(self, product_id, stock_lot, functional_tool_assembly):
- """
- 创建功能刀具该批次/序列号 库存移动和移动历史
- """
- # 获取位置对象
- stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
- location_inventory_id = self.env['stock.location'].search([('name', '=', 'Production')])
-
- # 创建库存移动
- stock_move_id = self.env['stock.move'].create({
- 'name': '功能刀具组装出库',
- 'product_id': product_id.id,
- 'location_id': location_inventory_id.id,
- 'location_dest_id': stock_location_id.id,
- 'product_uom_qty': 1.00,
- 'state': 'done'
- })
-
- # 创建移动历史
- stock_move_line_id = self.env['stock.move.line'].create({
- 'product_id': product_id.id,
- 'functional_tool_name_id': functional_tool_assembly.id,
- 'lot_id': stock_lot.id,
- 'move_id': stock_move_id.id,
- 'install_tool_time': fields.Datetime.now(),
- 'qty_done': 1.0,
- 'state': 'done'
- })
- return stock_move_id, stock_move_line_id
-
- def get_stock_lot_name(self):
- """
- 生成功能刀具序列号
- """
- code = 'JKM-T-' + str(self.functional_tool_type_id.code) + '-' + str(
- self.after_assembly_functional_tool_diameter) + '-'
- new_time = fields.Date.today()
- code += str(new_time) + '-'
- stock_lot_id = self.env['stock.lot'].sudo().search(
- [('name', 'like', new_time), ('product_id.name', '=', '功能刀具')],
- limit=1,
- order="id desc"
- )
- if not stock_lot_id:
- num = "%03d" % 1
- else:
- m = int(stock_lot_id.name[-3:]) + 1
- num = "%03d" % m
- return code + str(num)
-
def get_desc_1(self, stock_lot):
return {
'barcode_id': stock_lot.id,
@@ -552,3 +497,90 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
'cut_number': self.cut_number,
'current_location_id': stock_lot.quant_ids.location_id.ids[-1],
}
+
+
+class ProductProduct(models.Model):
+ _inherit = 'product.product'
+
+ def create_assemble_warehouse_receipt(self, tool_assembly_order_id, functional_tool_assembly):
+ """
+ 创建功能刀具批次/序列号记录
+ """
+ product_id = self.env['product.product'].search([('name', '=', '功能刀具')])
+
+ stock_lot = self.env['stock.lot'].create({
+ 'name': self.get_stock_lot_name(tool_assembly_order_id),
+ 'product_id': product_id.id,
+ 'company_id': self.env.company.id
+ })
+ # 获取位置对象
+ 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)
+
+ return stock_lot
+
+ def get_stock_lot_name(self, tool_assembly_order_id):
+ """
+ 生成功能刀具序列号
+ """
+ tool_assembly_order = self.env['sf.functional.tool.assembly.order'].search(
+ [('id', '=', tool_assembly_order_id)])
+ code = 'JKM-T-' + str(tool_assembly_order.after_assembly_functional_tool_type_id.code) + '-' + str(
+ tool_assembly_order.after_assembly_functional_tool_diameter) + '-'
+ new_time = fields.Date.today()
+ code += str(new_time) + '-'
+ stock_lot_id = self.env['stock.lot'].sudo().search(
+ [('name', 'like', new_time), ('product_id.name', '=', '功能刀具')],
+ limit=1,
+ order="id desc"
+ )
+ if not stock_lot_id:
+ num = "%03d" % 1
+ else:
+ m = int(stock_lot_id.name[-3:]) + 1
+ num = "%03d" % m
+ return code + str(num)
+
+ def tool_material_stock_moves(self, tool_material):
+ """
+ 对刀具物料进行库存移动到 刀具组装位置
+ """
+ # 获取位置对象
+ location_inventory_id = tool_material.quant_ids.location_id[-1]
+ print(location_inventory_id)
+ stock_location_id = self.env['stock.location'].search([('name', '=', '刀具组装位置')])
+ # 创建功能刀具该批次/序列号 库存移动和移动历史
+ 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):
+ """
+ 对功能刀具组装过程的功能刀具和刀具物料进行库存移动,以及创建移动历史
+ """
+
+ # 创建库存移动记录
+ stock_move_id = self.env['stock.move'].create({
+ 'name': '功能刀具组装',
+ 'product_id': self.product_id.id,
+ 'location_id': location_inventory_id.id,
+ 'location_dest_id': stock_location_id.id,
+ 'product_uom_qty': 1.00,
+ 'state': 'done'
+ })
+
+ # 创建移动历史记录
+ stock_move_line_id = self.env['stock.move.line'].create({
+ 'product_id': self.product_id.id,
+ 'functional_tool_name_id': functional_tool_assembly_id,
+ 'lot_id': self.id,
+ 'move_id': stock_move_id.id,
+ 'install_tool_time': fields.Datetime.now(),
+ 'qty_done': 1.0,
+ 'state': 'done'
+ })
+ return stock_move_id, stock_move_line_id