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] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD=E5=88=80?= =?UTF-8?q?=E5=85=B7=E7=BB=84=E8=A3=85=E7=9A=84=E5=88=80=E5=85=B7=E7=89=A9?= =?UTF-8?q?=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