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

View File

@@ -223,7 +223,6 @@ class ProductionLot(models.Model):
_inherit = ['stock.lot', 'printing.utils'] _inherit = ['stock.lot', 'printing.utils']
rfid = fields.Char('Rfid', readonly=True) 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) product_specification = fields.Char('规格', compute='_compute_product_specification', store=True)
@api.depends('product_id') @api.depends('product_id')

View File

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

View File

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

View File

@@ -1,4 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import re
import datetime import datetime
import logging import logging
import base64 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)
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): def action_revert_inventory(self):
# 检查用户是否有执行操作的权限 # 检查用户是否有执行操作的权限
@@ -746,7 +748,8 @@ class SfStockPicking(models.Model):
line.current_location_id.location_status = '空闲' line.current_location_id.location_status = '空闲'
for move in self.move_ids: 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: for item in move.move_line_nosuggest_ids:
if item.location_dest_id.name == '进货': if item.location_dest_id.name == '进货':
if not item.rfid: if not item.rfid:
@@ -950,16 +953,22 @@ class CustomStockMove(models.Model):
""" """
for record in self: for record in self:
if record: 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: for move_line_nosuggest_id in record.move_line_nosuggest_ids:
if move_line_nosuggest_id.rfid: if move_line_nosuggest_id.rfid:
if move_line_nosuggest_id.rfid == barcode: 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: 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 break
else: else:
raise ValidationError('该产品不是刀柄') raise ValidationError('该产品不需要录入Rfid')
def action_assign_serial_show_details(self): def action_assign_serial_show_details(self):
# 首先执行原有逻辑 # 首先执行原有逻辑