1、新增装夹预调工单扫拖盘Rfid绑定托盘;2、删除工单的Rfid字段的customRFID样式;3、修改序列号模型的Rfid字段的隐藏条件;4、优化刀柄、托盘物料采购时绑定Rfid的判断条件

This commit is contained in:
yuxianghui
2024-04-03 16:52:16 +08:00
parent aac5195b4d
commit 02e5972272
5 changed files with 89 additions and 61 deletions

View File

@@ -1,3 +1,5 @@
import re
import logging
import base64
import urllib.parse
@@ -819,57 +821,77 @@ class SfWorkOrderBarcodes(models.Model):
workorder = self.env['mrp.workorder'].browse(self.ids)
# workorder = self.env['mrp.workorder'].search(
# [('routing_type', '=', '装夹预调'), ('production_id', '=', self.production_id.id)])
workorder_old = self.env['mrp.workorder'].search([('rfid_code', '=', barcode)])
if workorder_old:
raise UserError('该托盘已绑定工件,请先解除绑定!!!')
if workorder:
if workorder.routing_type == '装夹预调':
stock_move_line = self.env['stock.move.line'].search([('lot_name', '=', barcode)])
if stock_move_line.product_id.categ_type == '夹具':
workorder.write({
'tray_serial_number': stock_move_line.lot_name,
'tray_product_id': stock_move_line.product_id.id,
'tray_brand_id': stock_move_line.product_id.brand_id.id,
'tray_type_id': stock_move_line.product_id.fixture_material_id.id,
'tray_model_id': stock_move_line.product_id.fixture_model_id.id
})
workorder.button_start()
# return {
# 'type': 'ir.actions.act_window',
# 'res_model': 'mrp.workorder',
# 'view_mode': 'form',
# 'domain': [('id', 'in', workorder.id)],
# 'target': 'current'
# }
else:
embryo_stock_lot = self.env['stock.lot'].search([('name', '=', barcode)])
if embryo_stock_lot:
embryo_stock_move_line = self.env['stock.move.line'].search(
[('product_id', '=', embryo_stock_lot.product_id.id),
('reference', '=', workorder.production_id.name),
('lot_id', '=', embryo_stock_lot.id),
('product_category_name', '=', '坯料')])
if embryo_stock_move_line:
bom_production = self.env['mrp.production'].search(
[('product_id', '=', embryo_stock_lot.product_id.id),
('origin', '=', workorder.production_id.name)], limit=1, order='id asc')
workpiece_delivery = self.env['sf.workpiece.delivery'].search(
[('workorder_id', '=', workorder.id)], limit=1, order='id asc')
if workpiece_delivery:
embryo_workpiece_code = workpiece_delivery.workpiece_code
if bom_production:
if workpiece_delivery.workpiece_code and bom_production.name not in \
workpiece_delivery.workpiece_code:
embryo_workpiece_code = workpiece_delivery.workpiece_code + ',' + \
bom_production.name
if not workpiece_delivery.workpiece_code:
embryo_workpiece_code = bom_production.name
workpiece_delivery.write({'workpiece_code': embryo_workpiece_code})
else:
raise UserError('工件生产线不一致,请重新确认')
else:
workorder_rfid = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id)])
if workorder_rfid:
for item in workorder_rfid:
item.write({'rfid_code': barcode})
lots = self.env['stock.lot'].sudo().search([('rfid', '=', barcode)])
if lots:
for lot in lots:
if lot.product_id.categ_type == '夹具':
workorder.write({
'tray_serial_number': lot.name,
'tray_product_id': lot.product_id.id,
'tray_brand_id': lot.product_id.brand_id.id,
'tray_type_id': lot.product_id.fixture_material_id.id,
'tray_model_id': lot.product_id.fixture_model_id.id
})
workorder_rfid = self.env['mrp.workorder'].search(
[('production_id', '=', workorder.production_id.id)])
if workorder_rfid:
for item in workorder_rfid:
item.write({'rfid_code': barcode})
workorder.env.cr.commit()
# stock_move_line = self.env['stock.move.line'].search([('lot_name', '=', barcode)])
# if stock_move_line.product_id.categ_type == '夹具':
# workorder.write({
# 'tray_serial_number': stock_move_line.lot_name,
# 'tray_product_id': stock_move_line.product_id.id,
# 'tray_brand_id': stock_move_line.product_id.brand_id.id,
# 'tray_type_id': stock_move_line.product_id.fixture_material_id.id,
# 'tray_model_id': stock_move_line.product_id.fixture_model_id.id
# })
# workorder.button_start()
# # return {
# # 'type': 'ir.actions.act_window',
# # 'res_model': 'mrp.workorder',
# # 'view_mode': 'form',
# # 'domain': [('id', 'in', workorder.id)],
# # 'target': 'current'
# # }
# else:
# embryo_stock_lot = self.env['stock.lot'].search([('name', '=', barcode)])
# if embryo_stock_lot:
# embryo_stock_move_line = self.env['stock.move.line'].search(
# [('product_id', '=', embryo_stock_lot.product_id.id),
# ('reference', '=', workorder.production_id.name),
# ('lot_id', '=', embryo_stock_lot.id),
# ('product_category_name', '=', '坯料')])
# if embryo_stock_move_line:
# bom_production = self.env['mrp.production'].search(
# [('product_id', '=', embryo_stock_lot.product_id.id),
# ('origin', '=', workorder.production_id.name)], limit=1, order='id asc')
# workpiece_delivery = self.env['sf.workpiece.delivery'].search(
# [('workorder_id', '=', workorder.id)], limit=1, order='id asc')
# if workpiece_delivery:
# embryo_workpiece_code = workpiece_delivery.workpiece_code
# if bom_production:
# if workpiece_delivery.workpiece_code and bom_production.name not in \
# workpiece_delivery.workpiece_code:
# embryo_workpiece_code = workpiece_delivery.workpiece_code + ',' + \
# bom_production.name
# if not workpiece_delivery.workpiece_code:
# embryo_workpiece_code = bom_production.name
# workpiece_delivery.write({'workpiece_code': embryo_workpiece_code})
# else:
# raise UserError('工件生产线不一致,请重新确认')
# else:
# workorder_rfid = self.env['mrp.workorder'].search(
# [('production_id', '=', workorder.production_id.id)])
# if workorder_rfid:
# for item in workorder_rfid:
# item.write({'rfid_code': barcode})
class WorkPieceDelivery(models.Model):

View File

@@ -223,7 +223,6 @@ class ProductionLot(models.Model):
_inherit = ['stock.lot', 'printing.utils']
rfid = fields.Char('Rfid', readonly=True)
product_material_name = fields.Char('刀具产品物料名称', related='product_id.cutting_tool_material_id.name')
product_specification = fields.Char('规格', compute='_compute_product_specification', store=True)
@api.depends('product_id')

View File

@@ -184,10 +184,9 @@
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
<field name="functional_fixture_type_id"
attrs='{"invisible": [("routing_type","!=","装夹预调")]}'/>
<field name="rfid_code" force_save="1" readonly="1" class="customRFID"
<field name="rfid_code" force_save="1" readonly="1" cache="True"
attrs="{'invisible': [('rfid_code_old', '!=', False)]}"/>
<field name="rfid_code_old" readonly="1" attrs="{'invisible': [('rfid_code_old', '=', False)]}"/>
<script src="/sf_manufacturing/static/src/js/customRFID.js"></script>
</group>
<!-- <group>-->
<!-- <div>-->
@@ -242,6 +241,7 @@
<!-- </page>-->
<page string="工件装夹" attrs='{"invisible": [("routing_type","!=","装夹预调")]}'>
<group>
<field name="_barcode_scanned" widget="barcode_handler"/>
<group string="卡盘">
<field name="chuck_serial_number"/>
<field name="chuck_name"/>
@@ -250,7 +250,6 @@
<field name="chuck_model_id"/>
</group>
<group string="托盘">
<field name="_barcode_scanned" widget="barcode_handler"/>
<field name="tray_serial_number" readonly="1" string="序列号"/>
<field name="tray_product_id" readonly="1" string="名称"/>
<field name="tray_brand_id" readonly="1" string="品牌"/>

View File

@@ -14,8 +14,7 @@
</header>
</xpath>
<xpath expr="//field[@name='product_id']" position="before">
<field name="rfid" attrs="{'invisible': [('product_material_name', 'not in', '刀柄')]}"/>
<field name="product_material_name" invisible="1"/>
<field name="rfid" attrs="{'invisible': [('rfid', '=', False)]}"/>
</xpath>
<xpath expr="//field[@name='product_id']" position="after">
<field name="product_specification"/>

View File

@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*-
import re
import datetime
import logging
import base64
@@ -424,7 +426,7 @@ class Sf_stock_move_line(models.Model):
# lot_qr_code = fields.Binary(string='二维码', compute='_compute_lot_qr_code', store=True)
lot_qr_code = fields.Binary(string='二维码', compute='_compute_lot_qr_code', store=True)
rfid = fields.Char('Rfid')
rfid = fields.Char('Rfid', readonly=True)
def action_revert_inventory(self):
# 检查用户是否有执行操作的权限
@@ -746,7 +748,8 @@ class SfStockPicking(models.Model):
line.current_location_id.location_status = '空闲'
for move in self.move_ids:
if move and move.product_id.cutting_tool_material_id.name == '刀柄':
if move and move.product_id.cutting_tool_material_id.name == '刀柄' or '托盘' in (
move.product_id.fixture_material_id.name or ''):
for item in move.move_line_nosuggest_ids:
if item.location_dest_id.name == '进货':
if not item.rfid:
@@ -950,16 +953,22 @@ class CustomStockMove(models.Model):
"""
for record in self:
if record:
if '刀柄' in record.product_id.cutting_tool_material_id.name:
if '刀柄' in (record.product_id.cutting_tool_material_id.name or '') or '托盘' in (
record.product_id.fixture_material_id.name or ''):
for move_line_nosuggest_id in record.move_line_nosuggest_ids:
if move_line_nosuggest_id.rfid:
if move_line_nosuggest_id.rfid == barcode:
raise ValidationError('该刀柄的rfid已经录入请勿重复录入')
if record.product_id.cutting_tool_material_id.name:
raise ValidationError('该刀柄的Rfid已经录入请勿重复录入')
else:
raise ValidationError('该托盘的Rfid已经录入请勿重复录入')
else:
move_line_nosuggest_id.sudo().rfid = barcode
line_id = int(re.sub(r"\D", "", str(move_line_nosuggest_id.id)))
self.env['stock.move.line'].sudo().search([('id', '=', line_id)]).write({'rfid': barcode})
move_line_nosuggest_id.rfid = barcode
break
else:
raise ValidationError('该产品不是刀柄')
raise ValidationError('该产品不需要录入Rfid')
def action_assign_serial_show_details(self):
# 首先执行原有逻辑