From b525a451073f00746a9b258eb2220dd8fba0116e Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Sun, 4 Feb 2024 17:30:26 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=88=80=E5=85=B7=E7=BB=84=E8=A3=85=E7=9A=84=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E9=AA=8C=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/maintenance_equipment.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py index 1f42430c..e43cb767 100644 --- a/sf_tool_management/models/maintenance_equipment.py +++ b/sf_tool_management/models/maintenance_equipment.py @@ -1,4 +1,5 @@ from odoo import models, api, fields +from odoo.exceptions import ValidationError class SfMaintenanceEquipmentTool(models.Model): @@ -26,3 +27,25 @@ class SfMaintenanceEquipmentTool(models.Model): 'cutter_spacing_code_id': tool.id }) return tools + + +class StockLot(models.Model): + _inherit = 'stock.lot' + + @api.model + def name_search(self, name='', args=None, operator='ilike', limit=100): + # 调用父类的name_search方法 + records = super(StockLot, self).name_search(name=name, args=args, operator=operator, limit=limit) + + if records: + return records + else: + # 在调用父类方法之后执行自定义逻辑 + if 5 >= len(args) > 3: + if args[2][2] in ['整体式刀具', '刀片', '刀杆', '刀盘', '刀柄', '夹头']: + objs = self.search([('name', '=', name), ('quant_ids.location_id.name', 'in', ['刀具房']), + ('quant_ids.quantity', '>', 0)]) + if objs.product_id.categ_id.name == '刀具': + raise ValidationError('这是【%s】物料,请扫入正确的【%s】物料!!!' % ( + objs.product_id.cutting_tool_material_id.name, args[2][2])) + return records From b88e4af4e2c228837605501ac6ee18acd85b1761 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Mon, 5 Feb 2024 14:09:06 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E6=89=AB=E7=A0=81=E5=BD=95=E5=85=A5=E9=AA=8C?= =?UTF-8?q?=E8=AF=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/maintenance_equipment.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py index e43cb767..f38f3a6c 100644 --- a/sf_tool_management/models/maintenance_equipment.py +++ b/sf_tool_management/models/maintenance_equipment.py @@ -36,16 +36,19 @@ class StockLot(models.Model): def name_search(self, name='', args=None, operator='ilike', limit=100): # 调用父类的name_search方法 records = super(StockLot, self).name_search(name=name, args=args, operator=operator, limit=limit) - if records: return records else: # 在调用父类方法之后执行自定义逻辑 - if 5 >= len(args) > 3: - if args[2][2] in ['整体式刀具', '刀片', '刀杆', '刀盘', '刀柄', '夹头']: - objs = self.search([('name', '=', name), ('quant_ids.location_id.name', 'in', ['刀具房']), - ('quant_ids.quantity', '>', 0)]) - if objs.product_id.categ_id.name == '刀具': - raise ValidationError('这是【%s】物料,请扫入正确的【%s】物料!!!' % ( - objs.product_id.cutting_tool_material_id.name, args[2][2])) + self.tool_verify(args, name) return records + + def tool_verify(self, args, name): + # 刀具物料验证 + if 5 >= len(args) > 3: + objs = self.search([('name', '=', name), ('quant_ids.location_id.name', 'in', ['刀具房']), + ('quant_ids.quantity', '>', 0)]) + if args[2][2] in ['整体式刀具', '刀片', '刀杆', '刀盘', '刀柄', '夹头']: + if objs.product_id.categ_id.name == '刀具': + raise ValidationError('这是【%s】物料,请扫入正确的【%s】物料!!!' % ( + objs.product_id.cutting_tool_material_id.name, args[2][2]))