From 9eee8557c2c4271dafa904de8d0899ebf2e12545 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Wed, 11 Sep 2024 10:23:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=80=E5=85=B7=E6=B8=85?= =?UTF-8?q?=E5=8D=95=20bom=E6=B7=BB=E5=8A=A0=E6=9F=A5=E8=AF=A2=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E4=B8=8E=E6=B8=85=E5=8D=95=E6=98=8E=E7=BB=86=E8=A1=8C?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/__init__.py | 3 +- .../models/functional_cutting_tool_model.py | 2 +- sf_tool_management/models/jikimo_bom.py | 34 ++++++++++++++++++- sf_tool_management/models/tool_inventory.py | 4 +-- sf_tool_management/views/jikimo_bom.xml | 3 +- 5 files changed, 40 insertions(+), 6 deletions(-) diff --git a/sf_tool_management/models/__init__.py b/sf_tool_management/models/__init__.py index e4f2a622..c39b6763 100644 --- a/sf_tool_management/models/__init__.py +++ b/sf_tool_management/models/__init__.py @@ -10,4 +10,5 @@ from . import temporary_data_processing_methods from . import stock from . import jikimo_bom from . import tool_inventory -from . import functional_cutting_tool_model \ No newline at end of file +from . import functional_cutting_tool_model +# from . import product_product \ No newline at end of file diff --git a/sf_tool_management/models/functional_cutting_tool_model.py b/sf_tool_management/models/functional_cutting_tool_model.py index db04b762..fe2c68c5 100644 --- a/sf_tool_management/models/functional_cutting_tool_model.py +++ b/sf_tool_management/models/functional_cutting_tool_model.py @@ -3,4 +3,4 @@ from odoo import models, fields class SyncFunctionalCuttingToolModel(models.Model): _inherit = 'sf.functional.cutting.tool.model' - cutting_tool_type_ids = fields.Many2many('sf.cutting.tool.type', string='刀具物料类型') \ No newline at end of file + cutting_tool_type_ids = fields.Many2many('sf.cutting.tool.type', string='适用刀具物料类型', required=True) \ No newline at end of file diff --git a/sf_tool_management/models/jikimo_bom.py b/sf_tool_management/models/jikimo_bom.py index 627a8892..29ef1605 100644 --- a/sf_tool_management/models/jikimo_bom.py +++ b/sf_tool_management/models/jikimo_bom.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- +from collections import Counter from xml import etree from odoo import models, fields, api, Command -from odoo.exceptions import UserError +from odoo.exceptions import UserError, AccessError from odoo.http import request @@ -28,6 +29,26 @@ class jikimo_bom(models.Model): result.append((bom.id, '功能刀具物料清单')) return result + def check_types_in_list(self): + # 统计每个元素的类型 + type_counts = Counter(item.cutting_tool_material_id.name for item in self.product_ids) + return all(count > 0 for count in type_counts.values()) and len(type_counts) == self.options.split('+') + + def write(self, vals): + # 在更新模型时记录旧的 Many2many ID 列表 + if 'product_ids' in vals: + old_product_counter = Counter(self.product_ids.ids) + super(jikimo_bom, self).write(vals) + new_product_counter = Counter(self.product_ids.ids) + delete_product_counter = old_product_counter - new_product_counter + if delete_product_counter: + # 删除操作 + if self.check_types_in_list(): + return True + else: + raise UserError('每种物料最少要有一个') + return super(jikimo_bom, self).write(vals) + def bom_product_domains(self, assembly_options): self.options = assembly_options cutting_tool_materials = self.env['sf.cutting.tool.material'].search( @@ -65,6 +86,7 @@ class jikimo_bom(models.Model): # product = self.env['product.product'].search(domain) # if product: # products = products + product + domains = domains + [('stock_move_count', '>', 0)] return domains def generate_bill_materials(self, assembly_options): @@ -88,6 +110,16 @@ class jikimo_bom_line(models.Model): class ProductProduct(models.Model): _inherit = 'product.product' + _order = 'cutting_tool_material_id, cutting_tool_type_id' + stock_move_count = fields.Integer(string='stock_move count', compute='_compute_stock_move_count', store=True) + + @api.depends('stock_move_ids') + def _compute_stock_move_count(self): + for record in self: + if record.stock_move_ids: + record.stock_move_count = len(record.stock_move_ids) + else: + record.stock_move_count = 0 def search(self, args, offset=0, limit=None, order=None, count=False): # 你可以在这里修改 `args` 以调整搜索条件 diff --git a/sf_tool_management/models/tool_inventory.py b/sf_tool_management/models/tool_inventory.py index db15834a..5b27c9aa 100644 --- a/sf_tool_management/models/tool_inventory.py +++ b/sf_tool_management/models/tool_inventory.py @@ -5,10 +5,10 @@ from odoo.http import request class ToolInventory(models.Model): _inherit = 'sf.tool.inventory' _description = '功能刀具清单' - knife_handle_model = fields.Selection([('BT30', 'BT30'), ('BT40', 'BT40'), ('BT50', 'BT50'), ('GSK30', 'GSK30'), ('GSK40', 'GSK40'), ('GSK50', 'GSK50')], string='使用刀柄型号') + knife_handle_model = fields.Selection([('BT30', 'BT30'), ('BT40', 'BT40'), ('BT50', 'BT50'), ('GSK30', 'GSK30'), ('GSK40', 'GSK40'), ('GSK50', 'GSK50')], string='使用刀柄型号', required=True) jikimo_bom_ids = fields.One2many('jikimo.bom','tool_inventory_id', 'bom单') + blade_length = fields.Float('刃长(mm)') def bom_mainfest(self): - jikimo_bom_ids = self.mapped('jikimo_bom_ids') if not jikimo_bom_ids: self._bom_mainfest() diff --git a/sf_tool_management/views/jikimo_bom.xml b/sf_tool_management/views/jikimo_bom.xml index 90e3232e..c42af591 100644 --- a/sf_tool_management/views/jikimo_bom.xml +++ b/sf_tool_management/views/jikimo_bom.xml @@ -35,11 +35,12 @@ + + -