bom清单问题修复

This commit is contained in:
liaodanlong
2024-09-19 13:42:52 +08:00
parent 78cb177ac5
commit 5e86d67316
2 changed files with 39 additions and 14 deletions

View File

@@ -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` 以调整搜索条件

View File

@@ -6,10 +6,32 @@
<field name="inherit_id" ref="sf_base.view_tool_inventory_tree"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='extension']" position="before">
<field name="knife_handle_model" />
<field name="knife_handle_model" class="o-sticky-header"/>
<button name="bom_mainfest" string="bom清单" type="object" class="btn-link"
icon="fa-refresh" />
icon="fa-refresh"/>
</xpath>
</field>
</record>
<record id="view_tool_inventory_inherit_search" model="ir.ui.view">
<field name="name">sf.tool.inventory.inherit.search</field>
<field name="model">sf.tool.inventory</field>
<field name="inherit_id" ref="sf_base.view_cutting_tool_material_search"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='extension']" position="after">
<searchpanel>
<field name="knife_handle_model" enable_counters="1"/>
<!-- <field name="job_id" enable_counters="1"/>-->
<!-- <field name="department_id" enable_counters="1"/>-->
<!-- <field name="company_id" enable_counters="1"/>-->
</searchpanel>
</xpath>
</field>
</record>
<!-- <searchpanel>-->
<!-- <field name="org_type_id_display" enable_counters="1"/>-->
<!-- &lt;!&ndash; <field name="job_id" enable_counters="1"/>&ndash;&gt;-->
<!-- <field name="department_id" enable_counters="1"/>-->
<!-- &lt;!&ndash; <field name="company_id" enable_counters="1"/>&ndash;&gt;-->
<!-- </searchpanel>-->
</odoo>