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 @@ + + -