去除无用代码添加描述信息
This commit is contained in:
@@ -30,9 +30,23 @@ class jikimo_bom(models.Model):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def check_types_in_list(self):
|
def check_types_in_list(self):
|
||||||
# 统计每个元素的类型
|
"""
|
||||||
|
检查产品列表中的元素是否包含了所有指定的类型,并且每种类型至少出现一次。
|
||||||
|
:return: 如果条件满足返回True,否则返回False
|
||||||
|
"""
|
||||||
|
if not self.product_ids:
|
||||||
|
return False
|
||||||
|
try:
|
||||||
|
# 统计每个类型的出现次数
|
||||||
type_counts = Counter(item.cutting_tool_material_id.name for item in self.product_ids)
|
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('+')
|
|
||||||
|
# 检查是否每种类型的出现次数都大于0,并且类型的数量与选项字符串中的数量相等
|
||||||
|
return all(count > 0 for count in type_counts.values()) and len(type_counts) == len(self.options.split('+'))
|
||||||
|
except AttributeError:
|
||||||
|
# 如果出现属性错误,说明产品列表中的元素可能缺少必要的属性
|
||||||
|
return False
|
||||||
|
# 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):
|
def write(self, vals):
|
||||||
# 在更新模型时记录旧的 Many2many ID 列表
|
# 在更新模型时记录旧的 Many2many ID 列表
|
||||||
@@ -51,6 +65,11 @@ class jikimo_bom(models.Model):
|
|||||||
return super(jikimo_bom, self).write(vals)
|
return super(jikimo_bom, self).write(vals)
|
||||||
|
|
||||||
def bom_product_domains(self, assembly_options):
|
def bom_product_domains(self, assembly_options):
|
||||||
|
"""
|
||||||
|
根据装配选项生成产品域列表
|
||||||
|
:param assembly_options: 装配选项字符串,各选项以'+'分隔
|
||||||
|
:return: 动态生成的产品搜索条件
|
||||||
|
"""
|
||||||
self.options = assembly_options
|
self.options = assembly_options
|
||||||
cutting_tool_materials = self.env['sf.cutting.tool.material'].search(
|
cutting_tool_materials = self.env['sf.cutting.tool.material'].search(
|
||||||
[('name', 'in', assembly_options.split('+'))])
|
[('name', 'in', assembly_options.split('+'))])
|
||||||
@@ -83,23 +102,22 @@ class jikimo_bom(models.Model):
|
|||||||
domains = domains + domain
|
domains = domains + domain
|
||||||
if index != 0:
|
if index != 0:
|
||||||
domains = ['|'] + domains
|
domains = ['|'] + domains
|
||||||
# wqwqwe = self.env['product.product'].search(ddd)
|
|
||||||
# product = self.env['product.product'].search(domain)
|
|
||||||
# if product:
|
|
||||||
# products = products + product
|
|
||||||
domains = domains + [('stock_move_count', '>', 0)]
|
domains = domains + [('stock_move_count', '>', 0)]
|
||||||
return domains
|
return domains
|
||||||
|
|
||||||
def generate_bill_materials(self, assembly_options):
|
def generate_bill_materials(self, assembly_options):
|
||||||
|
"""
|
||||||
|
生成物料清单
|
||||||
|
|
||||||
|
根据装配选项生成物料清单,首先获取产品领域,然后搜索相关产品,并设置产品ID。
|
||||||
|
|
||||||
|
:param assembly_options: 组装方式
|
||||||
|
:type assembly_options: 装配选项字符串,各选项以'+'分隔
|
||||||
|
"""
|
||||||
domains = self.bom_product_domains(assembly_options)
|
domains = self.bom_product_domains(assembly_options)
|
||||||
products = self.env['product.product'].search(domains)
|
products = self.env['product.product'].search(domains)
|
||||||
if products:
|
if products:
|
||||||
self.product_ids = [Command.set(products.ids)]
|
self.product_ids = [Command.set(products.ids)]
|
||||||
# if option.name == '刀盘':
|
|
||||||
# hilt = self.env['product.product'].search(
|
|
||||||
# [('cutting_tool_blade_diameter', '=', self.tool_inventory_id.diameter),
|
|
||||||
# ('cutting_tool_material_id', '=', option.id)])
|
|
||||||
# self.product_ids = [Command.set(hilt.ids)]k
|
|
||||||
|
|
||||||
|
|
||||||
class jikimo_bom_line(models.Model):
|
class jikimo_bom_line(models.Model):
|
||||||
|
|||||||
@@ -14,10 +14,7 @@ class ToolInventory(models.Model):
|
|||||||
self._bom_mainfest()
|
self._bom_mainfest()
|
||||||
return self.bom_mainfest()
|
return self.bom_mainfest()
|
||||||
request.session['jikimo_bom_product'] = {'bom_id': int(self.jikimo_bom_ids)}
|
request.session['jikimo_bom_product'] = {'bom_id': int(self.jikimo_bom_ids)}
|
||||||
# context = dict(self.env.context)
|
|
||||||
# context.update({'jikimo_bom_product': self.jikimo_bom_ids.options})
|
|
||||||
# if self.functional_cutting_tool_model_id.cutting_tool_type_ids:
|
|
||||||
# context.update({'jikimo_bom_product_cutting_tool_type': self.functional_cutting_tool_model_id.cutting_tool_type_ids.ids})
|
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.act_window',
|
'type': 'ir.actions.act_window',
|
||||||
'name': '刀具组装清单',
|
'name': '刀具组装清单',
|
||||||
@@ -26,7 +23,6 @@ class ToolInventory(models.Model):
|
|||||||
'view_id': self.env.ref('sf_tool_management.view_jikimo_bom_form').id,
|
'view_id': self.env.ref('sf_tool_management.view_jikimo_bom_form').id,
|
||||||
'res_id': int(self.jikimo_bom_ids),
|
'res_id': int(self.jikimo_bom_ids),
|
||||||
'target': 'current', # Use 'new' to open in a new window/tab
|
'target': 'current', # Use 'new' to open in a new window/tab
|
||||||
# {'jikimo_bom_product': self.jikimo_bom_ids.options}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# 创建bom单
|
# 创建bom单
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class JikimoBomWizard(models.TransientModel):
|
|||||||
('刀柄+刀杆+刀片', '刀柄+刀杆+刀片'),
|
('刀柄+刀杆+刀片', '刀柄+刀杆+刀片'),
|
||||||
('刀柄+刀盘+刀片', '刀柄+刀盘+刀片')
|
('刀柄+刀盘+刀片', '刀柄+刀盘+刀片')
|
||||||
], string='组装方式', required=True)
|
], string='组装方式', required=True)
|
||||||
# assembly_options_ids = fields.Many2many('sf.cutting.tool.material', string="组装方式")
|
|
||||||
is_ok = fields.Boolean('确认上述信息正确无误。')
|
is_ok = fields.Boolean('确认上述信息正确无误。')
|
||||||
|
|
||||||
def submit(self):
|
def submit(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user