From 5be5e8b3ec3fd69fe0200eabca40c5547f906e1b Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Mon, 1 Jul 2024 17:11:44 +0800
Subject: [PATCH 1/2] =?UTF-8?q?1=E3=80=81=E5=8A=9F=E8=83=BD=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E7=BB=84=E8=A3=85=E5=AE=8C=E6=88=90=E6=97=B6=EF=BC=8C?=
=?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90=E5=86=85=E9=83=A8=E8=B0=83?=
=?UTF-8?q?=E6=8B=A8=E5=8D=95=E4=BB=A5=E5=8F=8A=E6=89=80=E6=9C=89=E7=9A=84?=
=?UTF-8?q?=E5=88=80=E5=85=B7=E7=89=A9=E6=96=99=E7=9A=84=E5=BA=93=E5=AD=98?=
=?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=92=8C=E7=A7=BB=E5=8A=A8=E5=8E=86=E5=8F=B2?=
=?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=B9=B6=E8=87=AA=E5=8A=A8=E5=AE=8C?=
=?UTF-8?q?=E6=88=90=E8=AF=A5=E8=B0=83=E6=8B=A8=E5=8D=95=EF=BC=9B=E4=BC=98?=
=?UTF-8?q?=E5=8C=96=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E7=9A=84=E5=88=80?=
=?UTF-8?q?=E5=85=B7=E7=BB=84=E8=A3=85=E5=85=A5=E5=BA=93=E5=8D=95=E7=9A=84?=
=?UTF-8?q?=E7=94=9F=E6=88=90=EF=BC=8C=E7=AE=80=E5=8C=96=E5=85=A5=E5=BA=93?=
=?UTF-8?q?=E6=AD=A5=E9=AA=A4=E3=80=82?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../views/functional_tool_views.xml | 2 +-
sf_tool_management/wizard/wizard.py | 153 +++++++++++-------
2 files changed, 95 insertions(+), 60 deletions(-)
diff --git a/sf_tool_management/views/functional_tool_views.xml b/sf_tool_management/views/functional_tool_views.xml
index 6fde82a0..7211548c 100644
--- a/sf_tool_management/views/functional_tool_views.xml
+++ b/sf_tool_management/views/functional_tool_views.xml
@@ -174,7 +174,7 @@
-
+
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index af772016..005d8f84 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -621,26 +621,10 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
desc_1 = self.get_desc_1(stock_lot)
# 封装功能刀具数据,用于创建功能刀具记录
desc_2 = self.get_desc_2(stock_lot, functional_tool_assembly)
- # 创建刀具组装入库单
+ # 创建功能刀具组装入库单
self.env['stock.picking'].create_stocking_picking(stock_lot, functional_tool_assembly, self)
- # 刀具物料出库
- if self.handle_code_id:
- product_id.tool_material_stock_moves(self.handle_code_id, self.assembly_order_code)
- if self.integral_product_id:
- self.integral_product_id.material_stock_moves(self.integral_freight_barcode_id,
- self.integral_freight_lot_id, self.assembly_order_code)
- if self.blade_product_id:
- self.blade_product_id.material_stock_moves(self.blade_freight_barcode_id,
- self.blade_freight_lot_id, self.assembly_order_code)
- if self.bar_product_id:
- self.bar_product_id.material_stock_moves(self.bar_freight_barcode_id,
- self.bar_freight_lot_id, self.assembly_order_code)
- if self.pad_product_id:
- self.pad_product_id.material_stock_moves(self.pad_freight_barcode_id,
- self.pad_freight_lot_id, self.assembly_order_code)
- if self.chuck_product_id:
- self.chuck_product_id.material_stock_moves(self.chuck_freight_barcode_id,
- self.chuck_freight_lot_id, self.assembly_order_code)
+ # 创建刀具物料出库单
+ self.env['stock.picking'].create_stocking_picking1(self)
# ============================创建功能刀具列表、安全库存记录===============================
# 创建功能刀具列表记录
@@ -788,7 +772,7 @@ class StockPicking(models.Model):
def create_stocking_picking(self, stock_lot, functional_tool_assembly, obj):
"""
- 创建刀具组装入库单
+ 创建功能刀具组装入库单
"""
# 获取名称为刀具组装入库的作业类型
picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '刀具组装入库')])
@@ -807,6 +791,7 @@ class StockPicking(models.Model):
'location_id': picking_id.location_id.id,
'location_dest_id': picking_id.location_dest_id.id,
'lot_id': stock_lot.id,
+ 'install_tool_time': fields.Datetime.now(),
'qty_done': 1,
'functional_tool_name_id': functional_tool_assembly.id,
'functional_tool_type_id': obj.functional_tool_type_id.id,
@@ -836,6 +821,65 @@ class StockPicking(models.Model):
num = "%03d" % m
return name + str(num)
+ def create_stocking_picking1(self, obj):
+ """
+ 创建刀具物料出库单
+ """
+ # 获取名称为内部调拨的作业类型
+ picking_type_id = self.env['stock.picking.type'].sudo().search([('name', '=', '内部调拨')])
+ # 创建刀具物料出库单
+ picking_id = self.env['stock.picking'].create({
+ 'name': self._get_name_stock1(picking_type_id),
+ 'picking_type_id': picking_type_id.id,
+ 'location_id': self.env['stock.location'].search([('name', '=', '刀具房')]).id,
+ 'location_dest_id': self.env['stock.location'].search([('name', '=', '刀具组装位置')]).id,
+ 'origin': obj.assembly_order_code
+ })
+ # =============刀具物料出库===================
+ product_id = self.env['product.product']
+ datas = {'data': [], 'picking_id': picking_id}
+ if obj.handle_code_id:
+ datas['data'].append(
+ {'current_location_id': self.env['sf.shelf.location'], 'lot_id': obj.handle_code_id})
+ if obj.integral_product_id:
+ datas['data'].append(
+ {'current_location_id': obj.integral_freight_barcode_id, 'lot_id': obj.integral_freight_lot_id.lot_id})
+ if obj.blade_product_id:
+ datas['data'].append(
+ {'current_location_id': obj.blade_freight_barcode_id, 'lot_id': obj.blade_freight_lot_id.lot_id})
+ if obj.bar_product_id:
+ datas['data'].append(
+ {'current_location_id': obj.bar_freight_barcode_id, 'lot_id': obj.bar_freight_lot_id.lot_id})
+ if obj.pad_product_id:
+ datas['data'].append(
+ {'current_location_id': obj.pad_freight_barcode_id, 'lot_id': obj.pad_freight_lot_id.lot_id})
+ if obj.chuck_product_id:
+ datas['data'].append(
+ {'current_location_id': obj.chuck_freight_barcode_id, 'lot_id': obj.chuck_freight_lot_id.lot_id})
+ # 创建刀具物料出库库存移动记录
+ product_id.create_tool_material_stock_moves(datas)
+ # 将刀具物料出库库单的状态更改为就绪
+ picking_id.action_confirm()
+ # 修改刀具物料出库移动历史记录
+ product_id.write_tool_material_stock_move_lines(datas)
+ # 设置数量,并验证完成
+ picking_id.action_set_quantities_to_reservation()
+ picking_id.button_validate()
+
+ def _get_name_stock1(self, picking_type_id):
+ name = picking_type_id.sequence_id.prefix
+ stock_id = self.env['stock.picking'].sudo().search(
+ [('name', 'like', name), ('picking_type_id', '=', picking_type_id.id)],
+ limit=1,
+ order="id desc"
+ )
+ if not stock_id:
+ num = "%03d" % 1
+ else:
+ m = int(stock_id.name[-3:]) + 1
+ num = "%03d" % m
+ return name + str(num)
+
class ProductProduct(models.Model):
_inherit = 'product.product'
@@ -853,13 +897,6 @@ class ProductProduct(models.Model):
'product_id': product_id[0].id,
'company_id': self.env.company.id
})
- # 获取位置对象
- location_inventory_ids = self.env['stock.location'].search([('name', 'in', ('Production', '生产'))])
- stock_location_id = self.env['stock.location'].search([('name', '=', '组装后')])
- # 创建功能刀具该批次/序列号 库存移动和移动历史
- stock_lot.create_stock_quant(location_inventory_ids[-1], stock_location_id, functional_tool_assembly.id,
- obj.assembly_order_code, obj, obj.after_tool_groups_id)
-
return stock_lot
def get_stock_lot_name(self, obj):
@@ -878,39 +915,37 @@ class ProductProduct(models.Model):
num = "%03d" % m
return '%s-%s' % (code, num)
- def tool_material_stock_moves(self, tool_material, assembly_order_code):
- """
- 对刀具物料进行库存移动到 刀具组装位置
- """
- # 获取位置对象
- 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, assembly_order_code, False,
- False)
+ def create_tool_material_stock_moves(self, datas):
+ picking_id = datas['picking_id']
+ data = datas['data']
+ stock_move_ids = []
+ for res in data:
+ if res:
+ # 创建库存移动记录
+ stock_move_id = self.env['stock.move'].sudo().create({
+ 'name': picking_id.name,
+ 'picking_id': picking_id.id,
+ 'product_id': res['lot_id'].product_id.id,
+ 'location_id': picking_id.location_id.id,
+ 'location_dest_id': picking_id.location_dest_id.id,
+ 'product_uom_qty': 1.00,
+ 'reserved_availability': 1.00
+ })
+ stock_move_ids.append(stock_move_id)
+ return stock_move_ids
- def material_stock_moves(self, shelf_location_barcode_id, lot_id, assembly_order_code):
- # 创建库存移动记录
- stock_move_id = self.env['stock.move'].sudo().create({
- 'name': assembly_order_code,
- 'product_id': self.id,
- 'location_id': self.env['stock.location'].search([('name', '=', '刀具房')]).id,
- 'location_dest_id': self.env['stock.location'].search([('name', '=', '刀具组装位置')]).id,
- 'product_uom_qty': 1.00,
- 'state': 'done'
- })
-
- # 创建移动历史记录
- stock_move_line_id = self.env['stock.move.line'].sudo().create({
- 'product_id': self.id,
- 'move_id': stock_move_id.id,
- 'lot_id': lot_id.lot_id.id,
- 'current_location_id': shelf_location_barcode_id.id,
- 'install_tool_time': fields.Datetime.now(),
- 'qty_done': 1.0,
- 'state': 'done',
- })
- return stock_move_id, stock_move_line_id
+ def write_tool_material_stock_move_lines(self, datas):
+ picking_id = datas['picking_id']
+ data = datas['data']
+ move_line_ids = picking_id.move_line_ids
+ for move_line_id in move_line_ids:
+ for res in data:
+ if move_line_id.lot_id.product_id == res['lot_id'].product_id:
+ move_line_id.write({
+ 'current_location_id': res.get('current_location_id').id,
+ 'lot_id': res.get('lot_id').id
+ })
+ return True
class StockLot(models.Model):
From 0b267cc88a84e9014e05689b0848518375c9c30e Mon Sep 17 00:00:00 2001
From: yuxianghui <3437689193@qq.com>
Date: Tue, 2 Jul 2024 09:32:50 +0800
Subject: [PATCH 2/2] 1
---
sf_tool_management/models/base.py | 9 +++-
sf_tool_management/wizard/wizard.py | 74 +++++++++++++++--------------
2 files changed, 46 insertions(+), 37 deletions(-)
diff --git a/sf_tool_management/models/base.py b/sf_tool_management/models/base.py
index 182141cf..20c1e45d 100644
--- a/sf_tool_management/models/base.py
+++ b/sf_tool_management/models/base.py
@@ -776,7 +776,7 @@ class FunctionalToolDismantle(models.Model):
dismantle_person = fields.Char('拆解人', readonly=True)
image = fields.Binary('图片', readonly=True)
- scrap_id = fields.Char('报废单号', readonly=True)
+ scrap_ids = fields.One2many('stock.scrap', 'functional_tool_dismantle_id', string='报废单号', readonly=True)
grinding_id = fields.Char('磨削单号', readonly=True)
state = fields.Selection([('待拆解', '待拆解'), ('已拆解', '已拆解')], default='待拆解', tracking=True)
@@ -941,7 +941,6 @@ class FunctionalToolDismantle(models.Model):
lot = self.env['stock.lot'].sudo().search([('rfid', '=', self.handle_rfid)])
if not lot:
raise ValidationError('Rfid为【%s】的功能刀具序列号不存在!' % self.handle_rfid)
- functional_tool_assembly = self.functional_tool_id.functional_tool_name_id
if self.scrap_boolean:
# 刀柄报废 入库到Scrap
lot.create_stock_quant(location, location_dest_scrap_ids[-1], False, code, False, False)
@@ -1043,3 +1042,9 @@ class ProductProduct(models.Model):
})
return stock_move_id, stock_move_line_id
+
+
+class CustomStockScrap(models.Model):
+ _inherit = 'stock.scrap'
+
+ functional_tool_dismantle_id = fields.Many2one('sf.functional.tool.dismantle', string="功能刀具拆解单")
diff --git a/sf_tool_management/wizard/wizard.py b/sf_tool_management/wizard/wizard.py
index 005d8f84..111211c2 100644
--- a/sf_tool_management/wizard/wizard.py
+++ b/sf_tool_management/wizard/wizard.py
@@ -836,7 +836,7 @@ class StockPicking(models.Model):
'origin': obj.assembly_order_code
})
# =============刀具物料出库===================
- product_id = self.env['product.product']
+ stock_move_id = self.env['stock.move']
datas = {'data': [], 'picking_id': picking_id}
if obj.handle_code_id:
datas['data'].append(
@@ -857,11 +857,11 @@ class StockPicking(models.Model):
datas['data'].append(
{'current_location_id': obj.chuck_freight_barcode_id, 'lot_id': obj.chuck_freight_lot_id.lot_id})
# 创建刀具物料出库库存移动记录
- product_id.create_tool_material_stock_moves(datas)
+ stock_move_id.create_tool_material_stock_moves(datas)
# 将刀具物料出库库单的状态更改为就绪
picking_id.action_confirm()
# 修改刀具物料出库移动历史记录
- product_id.write_tool_material_stock_move_lines(datas)
+ stock_move_id.write_tool_material_stock_move_lines(datas)
# 设置数量,并验证完成
picking_id.action_set_quantities_to_reservation()
picking_id.button_validate()
@@ -881,6 +881,42 @@ class StockPicking(models.Model):
return name + str(num)
+class StockMove(models.Model):
+ _inherit = 'stock.move'
+
+ def create_tool_material_stock_moves(self, datas):
+ picking_id = datas['picking_id']
+ data = datas['data']
+ stock_move_ids = []
+ for res in data:
+ if res:
+ # 创建库存移动记录
+ stock_move_id = self.env['stock.move'].sudo().create({
+ 'name': picking_id.name,
+ 'picking_id': picking_id.id,
+ 'product_id': res['lot_id'].product_id.id,
+ 'location_id': picking_id.location_id.id,
+ 'location_dest_id': picking_id.location_dest_id.id,
+ 'product_uom_qty': 1.00,
+ 'reserved_availability': 1.00
+ })
+ stock_move_ids.append(stock_move_id)
+ return stock_move_ids
+
+ def write_tool_material_stock_move_lines(self, datas):
+ picking_id = datas['picking_id']
+ data = datas['data']
+ move_line_ids = picking_id.move_line_ids
+ for move_line_id in move_line_ids:
+ for res in data:
+ if move_line_id.lot_id.product_id == res['lot_id'].product_id:
+ move_line_id.write({
+ 'current_location_id': res.get('current_location_id').id,
+ 'lot_id': res.get('lot_id').id
+ })
+ return True
+
+
class ProductProduct(models.Model):
_inherit = 'product.product'
@@ -915,38 +951,6 @@ class ProductProduct(models.Model):
num = "%03d" % m
return '%s-%s' % (code, num)
- def create_tool_material_stock_moves(self, datas):
- picking_id = datas['picking_id']
- data = datas['data']
- stock_move_ids = []
- for res in data:
- if res:
- # 创建库存移动记录
- stock_move_id = self.env['stock.move'].sudo().create({
- 'name': picking_id.name,
- 'picking_id': picking_id.id,
- 'product_id': res['lot_id'].product_id.id,
- 'location_id': picking_id.location_id.id,
- 'location_dest_id': picking_id.location_dest_id.id,
- 'product_uom_qty': 1.00,
- 'reserved_availability': 1.00
- })
- stock_move_ids.append(stock_move_id)
- return stock_move_ids
-
- def write_tool_material_stock_move_lines(self, datas):
- picking_id = datas['picking_id']
- data = datas['data']
- move_line_ids = picking_id.move_line_ids
- for move_line_id in move_line_ids:
- for res in data:
- if move_line_id.lot_id.product_id == res['lot_id'].product_id:
- move_line_id.write({
- 'current_location_id': res.get('current_location_id').id,
- 'lot_id': res.get('lot_id').id
- })
- return True
-
class StockLot(models.Model):
_inherit = 'stock.lot'