diff --git a/sf_tool_management/models/functional_cutting_tool_model.py b/sf_tool_management/models/functional_cutting_tool_model.py index 9b5a5002..db04b762 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='刀具物料类型') \ 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 5272d4f0..627a8892 100644 --- a/sf_tool_management/models/jikimo_bom.py +++ b/sf_tool_management/models/jikimo_bom.py @@ -2,6 +2,7 @@ from xml import etree from odoo import models, fields, api, Command +from odoo.exceptions import UserError from odoo.http import request @@ -26,26 +27,28 @@ class jikimo_bom(models.Model): for bom in self: result.append((bom.id, '功能刀具物料清单')) return result + def bom_product_domains(self, assembly_options): self.options = assembly_options cutting_tool_materials = self.env['sf.cutting.tool.material'].search( [('name', 'in', assembly_options.split('+'))]) domains = [] for index, option in enumerate(cutting_tool_materials): - domain = ['&',('cutting_tool_material_id', '=', option.id), + domain = ['&', ('cutting_tool_material_id', '=', option.id), ("cutting_tool_type_id", "in", self.tool_inventory_id.functional_cutting_tool_model_id.cutting_tool_type_ids.ids)] if option.name == '刀柄': - domain = ['&']+domain+[ ("cutting_tool_taper_shank_model", "=", self.tool_inventory_id.knife_handle_model)] + domain = ['&'] + domain + [ + ("cutting_tool_taper_shank_model", "=", self.tool_inventory_id.knife_handle_model)] if option.name == '整体式刀具': - domain=['&']+domain+[ - '|', - # 刀具直径 - ('cutting_tool_blade_diameter', '=', self.tool_inventory_id.diameter), + domain = ['&'] + domain + [ + '|', + # 刀具直径 + ('cutting_tool_blade_diameter', '=', self.tool_inventory_id.diameter), - # r角 - ('cutting_tool_blade_tip_working_size', '=', self.tool_inventory_id.angle)] + # r角 + ('cutting_tool_blade_tip_working_size', '=', self.tool_inventory_id.angle)] if option.name == '刀杆': domain = ['&'] + domain + [ ("cutting_tool_cutter_arbor_diameter", "=", self.tool_inventory_id.diameter)] @@ -55,7 +58,7 @@ class jikimo_bom(models.Model): if option.name == '刀盘': domain = ['&'] + domain + [ ("cutting_tool_cutter_head_diameter", "=", self.tool_inventory_id.diameter)] - domains=domains+domain + domains = domains + domain if index != 0: domains = ['|'] + domains # wqwqwe = self.env['product.product'].search(ddd) @@ -65,7 +68,7 @@ class jikimo_bom(models.Model): return domains def generate_bill_materials(self, assembly_options): - domains=self.bom_product_domains(assembly_options) + domains = self.bom_product_domains(assembly_options) products = self.env['product.product'].search(domains) if products: self.product_ids = [Command.set(products.ids)] @@ -91,6 +94,9 @@ class ProductProduct(models.Model): # 例如,添加额外的搜索条件 if self.env.context.get('jikimo_bom_product'): bom_id = self.env['jikimo.bom'].browse(request.session.get('jikimo_bom_product').get('bom_id')) + + if not bom_id.options: + raise UserError('请先选择组装方式') domains = bom_id.bom_product_domains(bom_id.options) - args=args+domains + args = args + domains return super(ProductProduct, self).search(args, offset=offset, limit=limit, order=order, count=count) diff --git a/sf_tool_management/views/jikimo_bom.xml b/sf_tool_management/views/jikimo_bom.xml index bb1454df..90e3232e 100644 --- a/sf_tool_management/views/jikimo_bom.xml +++ b/sf_tool_management/views/jikimo_bom.xml @@ -33,7 +33,8 @@ - + +