功能刀具组装点【更多】按钮弹窗的物料添加【BOM物料】默认筛选,根据BOM筛选出符合条件的物料信息;取消默认筛选后记录按满足BOM的和不满足BOM的顺序排序出现。

This commit is contained in:
yuxianghui
2025-06-13 10:19:11 +08:00
parent 012ff120b4
commit 6517d2bd12
4 changed files with 67 additions and 16 deletions

View File

@@ -833,8 +833,8 @@ class FunctionalToolAssembly(models.Model):
location_lots = self.env['sf.shelf.location.lot'].sudo().search([('lot_id', '=', lot_id.id)])
if location_lots:
return location_lots[0]
raise ValidationError(f'{lot_ids[0].product_id.cutting_tool_material_id.name}】物料在货位库存不足,请先进行盘点入库')
raise ValidationError(
f'{lot_ids[0].product_id.cutting_tool_material_id.name}】物料在货位库存不足,请先进行盘点入库')
def _get_inventory_bom(self, inventory_id):
"""获取BOM的刀具物料产品信息"""
@@ -894,25 +894,25 @@ class FunctionalToolAssembly(models.Model):
tool_material_ids = self._get_all_material_location_lot(tool_data.get('pad_ids'))
tool_material_tree_id = self.env.ref('sf_tool_management.view_shelf_location_lot_tree_4')
action = {
"type": "ir.actions.act_window",
"target": "new",
"domain": [('cutting_tool_type', '=', tool_type)],
"context": {'tool_id': self.id, 'search_default_bom_ids': 1, 'tool_material_ids': tool_material_ids.ids}
}
if tool_type == '刀柄':
return {
"type": "ir.actions.act_window",
action.update({
"res_model": "product.product",
"views": [[tool_material_tree_id.id, "tree"],
[self.env.ref('sf_tool_management.view_tool_product_search').id, "search"]],
"target": "new",
"domain": [('id', 'in', tool_material_ids.ids)],
"context": {'tool_id': self.id}
}
[self.env.ref('sf_tool_management.view_tool_product_search').id, "search"]]
})
elif tool_type in ['整体式刀具', '刀片', '刀杆', '刀盘']:
return {
"type": "ir.actions.act_window",
action.update({
"res_model": "sf.shelf.location.lot",
"views": [[tool_material_tree_id.id, "tree"]],
"target": "new",
"domain": [('id', 'in', tool_material_ids.ids)],
"context": {'tool_id': self.id}
}
"views": [[tool_material_tree_id.id, "tree"],
[self.env.ref('sf_tool_management.view_shelf_location_lot_search').id, 'search']]
})
return action
def _get_all_material_location_lot(self, material_ids):
""" 获取所有满足条件 """

View File

@@ -256,6 +256,22 @@ class ProductProduct(models.Model):
})
return stock_lot
def search(self, domain, offset=0, limit=None, order=None, count=False):
context = self.env.context
tool_material_ids = context.get('tool_material_ids')
if tool_material_ids:
if context.get('default_tool_bom_id'):
domain += [('id', 'in', tool_material_ids)]
return super(ProductProduct, self).search(domain, offset=0, limit=None, order=None, count=False)
else:
domain_1 = domain + [('id', 'in', tool_material_ids)]
domain_2 = domain + [('id', 'not in', tool_material_ids)]
res_1 = super(ProductProduct, self).search(domain_1, offset=0, limit=None, order=None, count=False)
res_2 = super(ProductProduct, self).search(domain_2, offset=0, limit=None, order=None, count=False)
return res_1 + res_2
else:
return super(ProductProduct, self).search(domain, offset=0, limit=None, order=None, count=False)
def get_stock_lot_name(self, obj):
"""
生成功能刀具序列号
@@ -317,6 +333,22 @@ class SfShelfLocationLot(models.Model):
fit_blade_shape_id = fields.Many2one('maintenance.equipment.image', '适配刀片形状',
related='product_id.fit_blade_shape_id')
def search(self, domain, offset=0, limit=None, order=None, count=False):
context = self.env.context
tool_material_ids = context.get('tool_material_ids')
if tool_material_ids:
if context.get('default_tool_bom_id'):
domain += [('id', 'in', tool_material_ids)]
return super(SfShelfLocationLot, self).search(domain, offset=0, limit=None, order=None, count=False)
else:
domain_1 = domain + [('id', 'in', tool_material_ids)]
domain_2 = domain + [('id', 'not in', tool_material_ids)]
res_1 = super(SfShelfLocationLot, self).search(domain_1, offset=0, limit=None, order=None, count=False)
res_2 = super(SfShelfLocationLot, self).search(domain_2, offset=0, limit=None, order=None, count=False)
return res_1 + res_2
else:
return super(SfShelfLocationLot, self).search(domain, offset=0, limit=None, order=None, count=False)
@api.depends('lot_id')
def _compute_product_id(self):
for item in self:

View File

@@ -187,6 +187,7 @@
<field name="current_location" string="当前位置"/>
<field name="current_shelf_location_id" string="当前货位"
attrs="{'invisible': [('current_shelf_location_id', '=', False)]}"/>
<field name="create_date" string="装刀时间"/>
</group>
</group>
</page>

View File

@@ -33,10 +33,15 @@
</record>
<record id="view_tool_product_search" model="ir.ui.view">
<field name="name">刀柄产品搜索视图</field>
<field name="model">product.product</field>
<field name="priority" eval="10"/>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="specification_id"/>
<field name="brand_id"/>
<filter string="bom物料" name="bom_ids" domain="[]" context="{'default_tool_bom_id': 1}"/>
</search>
</field>
</record>
@@ -141,4 +146,17 @@
</tree>
</field>
</record>
<record id="view_shelf_location_lot_search" model="ir.ui.view">
<field name="name">sf.shelf.location.lot.search</field>
<field name="model">sf.shelf.location.lot</field>
<field name="arch" type="xml">
<search>
<field name="product_id"/>
<field name="specification_id"/>
<field name="brand_id"/>
<filter string="bom物料" name="bom_ids" domain="[]" context="{'default_tool_bom_id': 1}"/>
</search>
</field>
</record>
</odoo>