1、优化功能刀具组装模型,重构刀具物料的组成结构;2、优化刀具物料查询模型,重构刀具物流库存统计方法;3、优化功能刀具组装流程,重构刀具物料出库方法;4、重构扫码录入刀具物料数据方法;5、优化功能刀具列表模型;
This commit is contained in:
@@ -224,9 +224,6 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
# 功能刀具组装信息
|
||||
# ===============整体式刀具型号=================
|
||||
integral_freight_barcode = fields.Char('整体式刀具货位')
|
||||
integral_code_id = fields.Many2one('stock.lot', string='整体式刀具序列号',
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '整体式刀具'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
integral_product_id = fields.Many2one('product.product', string='整体式刀具名称',
|
||||
compute='_compute_integral_product_id', store=True)
|
||||
cutting_tool_integral_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='整体式刀具型号',
|
||||
@@ -241,12 +238,11 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.integral_freight_barcode)])
|
||||
if location:
|
||||
self.integral_product_id = location.product_id.id
|
||||
else:
|
||||
self.integral_product_id = False
|
||||
|
||||
# ===============刀片型号====================
|
||||
blade_freight_barcode = fields.Char('刀片货位')
|
||||
blade_code_id = fields.Many2one('stock.lot', '刀片序列号',
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀片'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
blade_product_id = fields.Many2one('product.product', string='刀片名称', compute='_compute_blade_product_id',
|
||||
store=True)
|
||||
cutting_tool_blade_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀片型号',
|
||||
@@ -260,12 +256,11 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.blade_freight_barcode)])
|
||||
if location:
|
||||
self.blade_product_id = location.product_id.id
|
||||
else:
|
||||
self.blade_product_id = False
|
||||
|
||||
# ====================刀杆型号==================
|
||||
bar_freight_barcode = fields.Char('刀杆货位')
|
||||
bar_code_id = fields.Many2one('stock.lot', '刀杆序列号',
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀杆'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
bar_product_id = fields.Many2one('product.product', string='刀杆名称', compute='_compute_bar_product_id',
|
||||
store=True)
|
||||
cutting_tool_cutterbar_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀杆型号',
|
||||
@@ -279,12 +274,11 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.bar_freight_barcode)])
|
||||
if location:
|
||||
self.bar_product_id = location.product_id.id
|
||||
else:
|
||||
self.bar_product_id = False
|
||||
|
||||
# ===============刀盘型号===================
|
||||
pad_freight_barcode = fields.Char('刀盘货位')
|
||||
pad_code_id = fields.Many2one('stock.lot', '刀盘序列号',
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀盘'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
pad_product_id = fields.Many2one('product.product', string='刀盘名称', compute='_compute_pad_product_id',
|
||||
store=True)
|
||||
cutting_tool_cutterpad_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀盘型号',
|
||||
@@ -298,23 +292,31 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.pad_freight_barcode)])
|
||||
if location:
|
||||
self.pad_product_id = location.product_id.id
|
||||
else:
|
||||
self.pad_product_id = False
|
||||
|
||||
# ================刀柄型号===============
|
||||
handle_freight_barcode = fields.Char('刀柄货位', required=True)
|
||||
handle_code_id = fields.Many2one('stock.lot', '刀柄序列号', required=True,
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '刀柄'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
handle_product_id = fields.Many2one('product.product', string='刀柄名称', related='handle_code_id.product_id')
|
||||
handle_product_id = fields.Many2one('product.product', string='刀柄名称', compute='_compute_handle_product_id',
|
||||
store=True)
|
||||
cutting_tool_cutterhandle_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='刀柄型号',
|
||||
related='handle_code_id.product_id.cutting_tool_model_id')
|
||||
handle_specification_id = fields.Many2one('sf.tool.materials.basic.parameters', string='刀柄规格',
|
||||
related='handle_code_id.product_id.specification_id')
|
||||
sf_tool_brand_id_5 = fields.Many2one('sf.machine.brand', '刀柄品牌', related='handle_code_id.product_id.brand_id')
|
||||
|
||||
@api.depends('handle_code_id')
|
||||
def _compute_handle_product_id(self):
|
||||
if self.handle_code_id:
|
||||
self.handle_product_id = self.handle_code_id.product_id.id
|
||||
else:
|
||||
self.pad_product_id = False
|
||||
|
||||
# =================夹头型号==============
|
||||
chuck_freight_barcode = fields.Char('夹头货位', required=True)
|
||||
chuck_code_id = fields.Many2one('stock.lot', '夹头序列号',
|
||||
domain=[('product_id.cutting_tool_material_id.name', '=', '夹头'),
|
||||
('tool_material_status', '=', '可用')])
|
||||
chuck_product_id = fields.Many2one('product.product', string='夹头名称', compute='_compute_chuck_product_id',
|
||||
store=True)
|
||||
cutting_tool_cutterhead_model_id = fields.Many2one('sf.cutting_tool.standard.library', string='夹头型号',
|
||||
@@ -328,6 +330,8 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', self.chuck_freight_barcode)])
|
||||
if location:
|
||||
self.chuck_product_id = location.product_id.id
|
||||
else:
|
||||
self.chuck_product_id = False
|
||||
|
||||
# ========================================
|
||||
|
||||
@@ -341,6 +345,11 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
for lot_id in lot_ids:
|
||||
if lot_id.quant_ids[-1].location_id.name in '刀具房':
|
||||
record.handle_code_id = lot_id.id
|
||||
location = self.env['sf.shelf.location'].sudo().search(
|
||||
[('product_sn_id', '=', lot_id.id)])
|
||||
if not location:
|
||||
raise ValidationError('该刀柄未入库到库位,请先入库!!!')
|
||||
record.handle_freight_barcode = location.barcode
|
||||
elif lot_id.quant_ids[-1].location_id.name == '刀具组装位置':
|
||||
raise ValidationError('该刀柄已使用,请重新扫描!!!')
|
||||
else:
|
||||
@@ -349,16 +358,29 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
location = self.env['sf.shelf.location'].sudo().search([('barcode', '=', barcode)])
|
||||
if location:
|
||||
material_name = location.product_id.cutting_tool_material_id.name
|
||||
if material_name == '整体式刀具':
|
||||
if material_name == '夹头':
|
||||
record.chuck_freight_barcode = barcode
|
||||
elif material_name == '刀柄':
|
||||
record.handle_freight_barcode = barcode
|
||||
location = self.env['sf.shelf.location'].sudo().search(
|
||||
[('barcode', '=', barcode)])
|
||||
record.handle_code_id = location.product_sn_id.id
|
||||
elif material_name == '整体式刀具':
|
||||
record.integral_freight_barcode = barcode
|
||||
record.blade_freight_barcode = ''
|
||||
record.bar_freight_barcode = ''
|
||||
record.pad_freight_barcode = ''
|
||||
elif material_name == '刀片':
|
||||
record.blade_freight_barcode = barcode
|
||||
record.integral_freight_barcode = ''
|
||||
elif material_name == '刀杆':
|
||||
record.bar_freight_barcode = barcode
|
||||
record.integral_freight_barcode = ''
|
||||
record.pad_freight_barcode = ''
|
||||
elif material_name == '刀盘':
|
||||
record.pad_freight_barcode = barcode
|
||||
elif material_name == '夹头':
|
||||
record.chuck_freight_barcode = barcode
|
||||
record.integral_freight_barcode = ''
|
||||
record.bar_freight_barcode = ''
|
||||
else:
|
||||
raise ValidationError('扫描的刀具物料不存在,请重新扫描!')
|
||||
else:
|
||||
@@ -375,8 +397,8 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
# 组装功能刀具参数信息
|
||||
after_name_id = fields.Many2one('sf.tool.inventory', string='功能刀具名称', required=True)
|
||||
barcode_id = fields.Many2one('stock.lot', string='功能刀具序列号')
|
||||
rfid = fields.Char('Rfid', readonly=True, store=True, compute='_compute_rfid')
|
||||
tool_code = fields.Char(string='功能刀具编码', readonly=True, compute='_compute_tool_code')
|
||||
rfid = fields.Char('Rfid', compute='_compute_rfid')
|
||||
tool_code = fields.Char(string='功能刀具编码', compute='_compute_tool_code')
|
||||
after_assembly_functional_tool_name = fields.Char(string='组装后功能刀具名称', compute='_compute_name', store=True)
|
||||
after_assembly_functional_tool_type_id = fields.Many2one('sf.functional.cutting.tool.model',
|
||||
string='组装后功能刀具类型',
|
||||
@@ -409,27 +431,26 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
for obj in self:
|
||||
str_1 = 'GNDJ-%s' % obj.after_assembly_functional_tool_type_id.code
|
||||
str_2 = ''
|
||||
num = None
|
||||
if obj.handle_specification_id:
|
||||
if obj.integral_specification_id:
|
||||
str_2 = '%s-D%sL%sB%sH%s-' % (
|
||||
str_1, obj.integral_specification_id.blade_diameter, obj.after_assembly_tool_loading_length,
|
||||
obj.integral_specification_id.blade_length, obj.handle_specification_id.total_length)
|
||||
num = self._get_code(str_2)
|
||||
elif obj.bar_specification_id:
|
||||
str_2 = '%s-D%sL%sB%sH%s-' % (
|
||||
str_1, obj.bar_specification_id.cutter_arbor_diameter, obj.after_assembly_tool_loading_length,
|
||||
obj.bar_specification_id.blade_length, obj.handle_specification_id.total_length)
|
||||
num = self._get_code(str_2)
|
||||
elif obj.pad_specification_id:
|
||||
str_2 = '%s-D%sL%sB%sH%s-' % (
|
||||
str_1, obj.pad_specification_id.cutter_head_diameter, obj.after_assembly_tool_loading_length,
|
||||
obj.pad_specification_id.cut_depth_max, obj.handle_specification_id.total_length,
|
||||
)
|
||||
num = self._get_code(str_2)
|
||||
obj.tool_code = str_2 + str(num)
|
||||
else:
|
||||
obj.tool_code = str_2
|
||||
return True
|
||||
obj.tool_code = str_2 + str(self._get_code(str_2))
|
||||
else:
|
||||
obj.tool_code = ''
|
||||
obj.tool_code = str_2
|
||||
|
||||
def _get_code(self, str_2):
|
||||
functional_tool_assembly = self.env['sf.functional.tool.assembly'].sudo().search(
|
||||
@@ -455,16 +476,16 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
@api.onchange('integral_freight_barcode')
|
||||
def _onchange_after_assembly_functional_tool_diameter(self):
|
||||
for obj in self:
|
||||
if obj.integral_code_id:
|
||||
obj.after_assembly_functional_tool_diameter = obj.integral_code_id.product_id.cutting_tool_blade_diameter
|
||||
if obj.integral_product_id:
|
||||
obj.after_assembly_functional_tool_diameter = obj.integral_product_id.cutting_tool_blade_diameter
|
||||
else:
|
||||
obj.after_assembly_functional_tool_diameter = 0
|
||||
|
||||
@api.onchange('blade_code_id')
|
||||
@api.onchange('blade_freight_barcode')
|
||||
def _onchange_after_assembly_knife_tip_r_angle(self):
|
||||
for obj in self:
|
||||
if obj.blade_code_id:
|
||||
obj.after_assembly_knife_tip_r_angle = obj.blade_code_id.product_id.cutting_tool_blade_tip_circular_arc_radius
|
||||
if obj.blade_product_id:
|
||||
obj.after_assembly_knife_tip_r_angle = obj.blade_product_id.cutting_tool_blade_tip_circular_arc_radius
|
||||
else:
|
||||
obj.after_assembly_knife_tip_r_angle = 0
|
||||
|
||||
@@ -524,18 +545,18 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
# 创建刀具组装入库单
|
||||
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)
|
||||
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)
|
||||
if self.integral_product_id:
|
||||
self.integral_product_id.material_stock_moves()
|
||||
if self.blade_product_id:
|
||||
self.blade_product_id.material_stock_moves()
|
||||
if self.bar_product_id:
|
||||
self.bar_product_id.material_stock_moves()
|
||||
if self.pad_product_id:
|
||||
self.pad_product_id.material_stock_moves()
|
||||
if self.chuck_product_id:
|
||||
self.chuck_product_id.material_stock_moves()
|
||||
|
||||
# ============================创建功能刀具列表、安全库存记录===============================
|
||||
# 封装功能刀具数据
|
||||
@@ -575,25 +596,24 @@ class FunctionalToolAssemblyOrder(models.TransientModel):
|
||||
"""
|
||||
功能刀具组装物料必填判断
|
||||
"""
|
||||
if not self.integral_code_id and not self.blade_code_id:
|
||||
if not self.integral_product_id and not self.blade_product_id:
|
||||
raise ValidationError('【整体式刀具】和【刀片】必须填写一个!')
|
||||
if self.blade_code_id:
|
||||
if not self.bar_code_id and not self.pad_code_id:
|
||||
if self.blade_product_id:
|
||||
if not self.bar_product_id and not self.pad_product_id:
|
||||
raise ValidationError('【刀盘】和【刀杆】必须填写一个!')
|
||||
|
||||
def get_desc_1(self, stock_lot):
|
||||
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,
|
||||
'integral_product_id': self.integral_product_id.id,
|
||||
'blade_product_id': self.blade_product_id.id,
|
||||
'bar_product_id': self.bar_product_id.id,
|
||||
'pad_product_id': self.pad_product_id.id,
|
||||
'handle_code_id': self.handle_code_id.id,
|
||||
'chuck_product_id': self.chuck_product_id.id,
|
||||
'integral_freight_barcode': self.integral_freight_barcode,
|
||||
'blade_freight_barcode': self.blade_freight_barcode,
|
||||
'bar_freight_barcode': self.bar_freight_barcode,
|
||||
'pad_freight_barcode': self.pad_freight_barcode,
|
||||
'handle_freight_barcode': self.handle_freight_barcode,
|
||||
'chuck_freight_barcode': self.chuck_freight_barcode,
|
||||
|
||||
'after_assembly_functional_tool_name': self.after_assembly_functional_tool_name,
|
||||
'after_assembly_functional_tool_type_id': self.after_assembly_functional_tool_type_id.id,
|
||||
@@ -764,6 +784,28 @@ class ProductProduct(models.Model):
|
||||
# 创建功能刀具该批次/序列号 库存移动和移动历史
|
||||
tool_material.create_stock_quant(location_inventory_id, stock_location_id, None, '功能刀具组装', False)
|
||||
|
||||
def material_stock_moves(self):
|
||||
# 创建库存移动记录
|
||||
stock_move_id = self.env['stock.move'].sudo().create({
|
||||
'name': '功能刀具组装',
|
||||
'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,
|
||||
'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
|
||||
|
||||
|
||||
class StockLot(models.Model):
|
||||
_inherit = 'stock.lot'
|
||||
|
||||
@@ -289,9 +289,14 @@
|
||||
</div>
|
||||
<group>
|
||||
<group>
|
||||
<field name="handle_code_id" string="序列号" placeholder="请选择"
|
||||
class="custom_required"
|
||||
options="{'no_create': True, 'no_quick_create': True}"/>
|
||||
<group>
|
||||
<field name="handle_freight_barcode" string="货位"/>
|
||||
</group>
|
||||
<group>
|
||||
<field name="handle_code_id" string="序列号" placeholder="请选择"
|
||||
class="custom_required"
|
||||
options="{'no_create': True, 'no_quick_create': True}"/>
|
||||
</group>
|
||||
</group>
|
||||
</group>
|
||||
<group col="2">
|
||||
|
||||
Reference in New Issue
Block a user