From 5e86d6731617249138217607bb5bc9340ec80921 Mon Sep 17 00:00:00 2001 From: liaodanlong Date: Thu, 19 Sep 2024 13:42:52 +0800 Subject: [PATCH] =?UTF-8?q?bom=E6=B8=85=E5=8D=95=E9=97=AE=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_tool_management/models/jikimo_bom.py | 27 ++++++++++++--------- sf_tool_management/views/tool_inventory.xml | 26 ++++++++++++++++++-- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/sf_tool_management/models/jikimo_bom.py b/sf_tool_management/models/jikimo_bom.py index 8453eb48..62138d77 100644 --- a/sf_tool_management/models/jikimo_bom.py +++ b/sf_tool_management/models/jikimo_bom.py @@ -50,7 +50,7 @@ class jikimo_bom(models.Model): def write(self, vals): # 在更新模型时记录旧的 Many2many ID 列表 - if 'product_ids' in vals: + if 'product_ids' in vals and not self.env.context.get('is_assembly_options'): old_product_counter = Counter(self.product_ids.ids) super(jikimo_bom, self).write(vals) new_product_counter = Counter(self.product_ids.ids) @@ -102,7 +102,7 @@ class jikimo_bom(models.Model): domains = domains + domain if index != 0: domains = ['|'] + domains - domains = domains + [('stock_move_count', '>', 0)] + domains = domains + [('stock_move_ids', '!=',False)] return domains def generate_bill_materials(self, assembly_options): @@ -117,7 +117,10 @@ class jikimo_bom(models.Model): domains = self.bom_product_domains(assembly_options) products = self.env['product.product'].search(domains) if products: - self.product_ids = [Command.set(products.ids)] + new_context = dict(self.env.context) + new_context['is_assembly_options'] = True + self.with_context(new_context).write({'product_ids': [Command.set(products.ids)]}) + # self.product_ids = [Command.set(products.ids)] class jikimo_bom_line(models.Model): @@ -130,15 +133,15 @@ 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 + # stock_move_count = fields.Integer(string='stock_move count', compute='_compute_stock_move_count') + # + # @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/views/tool_inventory.xml b/sf_tool_management/views/tool_inventory.xml index 68efbca3..b08e5fce 100644 --- a/sf_tool_management/views/tool_inventory.xml +++ b/sf_tool_management/views/tool_inventory.xml @@ -6,10 +6,32 @@ - +