From cb8285d0ca82c065c639e164262e77fa16bad566 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Sun, 18 Feb 2024 17:22:06 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E9=87=8D=E6=9E=84=E5=88=80=E5=85=B7?= =?UTF-8?q?=E7=89=A9=E6=96=99=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9E=8B=EF=BC=9B?= =?UTF-8?q?2=E3=80=81=E6=96=B0=E5=A2=9E=E4=BA=A7=E5=93=81=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=97=B6=E4=BA=A7=E5=93=81=E7=B1=BB=E5=88=AB=E4=B8=BA?= =?UTF-8?q?=E5=88=80=E5=85=B7=E6=97=B6=EF=BC=8C=E5=88=9B=E5=BB=BA=E5=88=80?= =?UTF-8?q?=E5=85=B7=E7=89=A9=E6=96=99=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9E=8B?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=EF=BC=9B3=E3=80=81=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8F=B7=E5=92=8C=E5=88=80=E5=85=B7=E7=89=A9?= =?UTF-8?q?=E6=96=99=E6=9F=A5=E8=AF=A2=E6=A8=A1=E5=9E=8B=E7=9A=84=E5=85=B3?= =?UTF-8?q?=E8=81=94=E5=AD=97=E6=AE=B5=EF=BC=8C=E6=96=B0=E5=A2=9E=E5=88=80?= =?UTF-8?q?=E5=85=B7=E7=89=A9=E6=96=99=E6=98=AF=E5=90=A6=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=AD=97=E6=AE=B5=EF=BC=9B=E5=B9=B6=E5=9C=A8?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BA=8F=E5=88=97=E5=8F=B7=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=A6=82=E6=9E=9C=E5=85=B3=E8=81=94=E7=9A=84?= =?UTF-8?q?=E4=BA=A7=E5=93=81=E7=9A=84=E4=BA=A7=E5=93=81=E7=B1=BB=E5=88=AB?= =?UTF-8?q?=E4=B8=BA=E5=88=80=E5=85=B7=E6=97=B6=EF=BC=8C=E5=AF=B9=E5=AF=B9?= =?UTF-8?q?=E5=BA=94=E5=88=80=E5=85=B7=E7=89=A9=E6=96=99=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E8=BF=9B=E8=A1=8C=E5=85=B3=E8=81=94=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/maintenance_equipment.py | 40 ++ .../models/tool_material_search.py | 54 ++- .../views/tool_material_search.xml | 349 ++---------------- 3 files changed, 128 insertions(+), 315 deletions(-) diff --git a/sf_tool_management/models/maintenance_equipment.py b/sf_tool_management/models/maintenance_equipment.py index f38f3a6c..4b5fe89e 100644 --- a/sf_tool_management/models/maintenance_equipment.py +++ b/sf_tool_management/models/maintenance_equipment.py @@ -32,6 +32,19 @@ class SfMaintenanceEquipmentTool(models.Model): class StockLot(models.Model): _inherit = 'stock.lot' + tool_material_search_id = fields.Many2one('sf.tool.material.search', string='刀具物料搜索') + tool_material_status = fields.Selection([('可用', '可用'), ('在用', '在用'), ('报废', '报废')], string='状态', + compute='_compute_tool_material_status') + + @api.depends('quant_ids') + def _compute_tool_material_status(self): + for record in self: + if record: + if record.quant_ids[-1].location_id.name == '刀具组装位置': + record.tool_material_status = '在用' + else: + record.tool_material_status = '可用' + @api.model def name_search(self, name='', args=None, operator='ilike', limit=100): # 调用父类的name_search方法 @@ -52,3 +65,30 @@ class StockLot(models.Model): if objs.product_id.categ_id.name == '刀具': raise ValidationError('这是【%s】物料,请扫入正确的【%s】物料!!!' % ( objs.product_id.cutting_tool_material_id.name, args[2][2])) + + @api.model_create_multi + def create(self, vals_list): + records = super(StockLot, self).create(vals_list) + for record in records: + if record.product_id.categ_id.name == '刀具': + tool_material_search = self.env['sf.tool.material.search'].sudo().search( + [('cutting_tool_material_id', '=', record.product_id.cutting_tool_material_id.id), + ('cutting_tool_standard_library_id', '=', record.product_id.cutting_tool_model_id.id), + ('specification_id', '=', record.product_id.specification_id.id)]) + if tool_material_search: + record.tool_material_search_id = tool_material_search + return records + + +class ProductProduct(models.Model): + _inherit = 'product.product' + + @api.model_create_multi + def create(self, vals_list): + records = super(ProductProduct, self).create(vals_list) + for record in records: + if record.categ_id.name == '刀具': + self.env['sf.tool.material.search'].sudo().create({ + 'product_id': record.id + }) + return records diff --git a/sf_tool_management/models/tool_material_search.py b/sf_tool_management/models/tool_material_search.py index 99ff6419..a5498c80 100644 --- a/sf_tool_management/models/tool_material_search.py +++ b/sf_tool_management/models/tool_material_search.py @@ -5,7 +5,7 @@ from odoo import fields, models, api, SUPERUSER_ID # from odoo.exceptions import ValidationError -# 刀具物料搜索 +# 刀具物料搜索(待删除) class SfToolMaterialSearch(models.Model): _name = 'sf.tool.material.search' _description = '刀具物料搜索' @@ -302,3 +302,55 @@ class SfToolMaterialSearch(models.Model): warehouse_area = fields.Char('库区') warehouse_location = fields.Char('库位') three_d_model = fields.Many2one('ir.attachment', '3D模型') + + +class ToolMaterial(models.Model): + _name = 'sf.tool.material.search' + _description = '刀具物料搜索' + + product_id = fields.Many2one('product.product', string='刀具物料产品') + + name = fields.Char('名称', related='product_id.name') + cutting_tool_material_id = fields.Many2one('sf.cutting.tool.material', '刀具物料', + related='product_id.cutting_tool_material_id', + store=True, + group_expand='_read_group_cutting_tool_material_id') + tool_material_name = fields.Char('物料名称', related='product_id.cutting_tool_material_id.name') + cutting_tool_standard_library_id = fields.Many2one('sf.cutting_tool.standard.library', '刀具型号', + related='product_id.cutting_tool_model_id') + specification_id = fields.Many2one('sf.tool.materials.basic.parameters', '规格', + related='product_id.specification_id') + image = fields.Binary('图片', related='product_id.image_1920') + number = fields.Integer('总数量', readonly=True, compute='_compute_number') + usable_num = fields.Integer('可用数量', readonly=True) + have_been_used_num = fields.Integer('在用数量', readonly=True) + scrap_num = fields.Integer('报废数量', readonly=True) + + barcode_ids = fields.One2many('stock.lot', 'tool_material_search_id', string='序列号', readonly=True) + + @api.depends('barcode_ids') + def _compute_number(self): + usable_num = 0 + have_been_used_num = 0 + scrap_num = 0 + for record in self: + if record.barcode_ids: + record.number = len(record.barcode_ids) + for barcode_id in record.barcode_ids: + if barcode_id.quant_ids[-1].location_id.name == '刀具组装位置': + have_been_used_num = have_been_used_num + 1 + else: + usable_num = usable_num + 1 + record.usable_num = usable_num + record.have_been_used_num = have_been_used_num + record.scrap_num = scrap_num + else: + record.number = 0 + record.usable_num = 0 + record.have_been_used_num = 0 + record.scrap_num = 0 + + @api.model + def _read_group_cutting_tool_material_id(self, categories, domain, order): + cutting_tool_material_id = categories._search([], order=order, access_rights_uid=SUPERUSER_ID) + return categories.browse(cutting_tool_material_id) diff --git a/sf_tool_management/views/tool_material_search.xml b/sf_tool_management/views/tool_material_search.xml index 92369fa8..158e83b9 100644 --- a/sf_tool_management/views/tool_material_search.xml +++ b/sf_tool_management/views/tool_material_search.xml @@ -6,116 +6,13 @@ sf.tool.material.search - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + @@ -128,221 +25,44 @@

- +

- - - - - - - - + + + + + - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + - - - -
@@ -356,9 +76,10 @@ - + + - +