250 lines
9.9 KiB
Python
250 lines
9.9 KiB
Python
from odoo import fields, models, api
|
||
|
||
|
||
class SuitableMachiningMethod(models.Model):
|
||
_name = 'sf.suitable.machining.method'
|
||
_description = '适合加工方式'
|
||
|
||
name = fields.Char('名称')
|
||
image = fields.Image('图片')
|
||
|
||
@api.model
|
||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||
# 调用父类的name_search方法,获取原始的结果列表
|
||
res = super().name_search(name, args, operator, limit)
|
||
# 定义一个空字典用来存储id和name的映射关系
|
||
name_dict = {}
|
||
# 遍历结果列表,将id和name存入字典中
|
||
for item in res:
|
||
id = item[0]
|
||
name = item[1]
|
||
name_dict[id] = name
|
||
# 根据id列表搜索符合条件的记录
|
||
records = self.browse(name_dict.keys())
|
||
# 定义一个新的结果列表用来存储修改后的结果
|
||
new_res = []
|
||
# 遍历每条记录
|
||
for record in records:
|
||
# 获取记录的id,name和image属性
|
||
id = record.id
|
||
name = name_dict[id]
|
||
image = record.image
|
||
# 如果image不为空,将其转换为data URI scheme
|
||
if image:
|
||
data_uri = f"data:image/png;base64,{image.decode('utf-8')}"
|
||
else:
|
||
data_uri = ""
|
||
# 将这三个属性组成一个数组,并添加到结果列表中 result.append([id, name, data_uri]) # 返回结果列表 return result
|
||
new_res.append([id, name, data_uri])
|
||
# 返回新的结果列表
|
||
return new_res
|
||
|
||
|
||
class BladeTipCharacteristics(models.Model):
|
||
_name = 'sf.blade.tip.characteristics'
|
||
_description = '刀尖特征'
|
||
|
||
name = fields.Char('名称')
|
||
image = fields.Image('图片')
|
||
|
||
@api.model
|
||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||
# 调用父类的name_search方法,获取原始的结果列表
|
||
res = super().name_search(name, args, operator, limit)
|
||
# 定义一个空字典用来存储id和name的映射关系
|
||
name_dict = {}
|
||
# 遍历结果列表,将id和name存入字典中
|
||
for item in res:
|
||
id = item[0]
|
||
name = item[1]
|
||
name_dict[id] = name
|
||
# 根据id列表搜索符合条件的记录
|
||
records = self.browse(name_dict.keys())
|
||
# 定义一个新的结果列表用来存储修改后的结果
|
||
new_res = []
|
||
# 遍历每条记录
|
||
for record in records:
|
||
# 获取记录的id,name和image属性
|
||
id = record.id
|
||
name = name_dict[id]
|
||
image = record.image
|
||
# 如果image不为空,将其转换为data URI scheme
|
||
if image:
|
||
data_uri = f"data:image/png;base64,{image.decode('utf-8')}"
|
||
else:
|
||
data_uri = ""
|
||
# 将这三个属性组成一个数组,并添加到结果列表中 result.append([id, name, data_uri]) # 返回结果列表 return result
|
||
new_res.append([id, name, data_uri])
|
||
# 返回新的结果列表
|
||
return new_res
|
||
|
||
|
||
class HandleType(models.Model):
|
||
_name = 'sf.handle.type'
|
||
_description = '柄部类型'
|
||
|
||
name = fields.Char('名称')
|
||
image = fields.Image('图片')
|
||
|
||
@api.model
|
||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||
# 调用父类的name_search方法,获取原始的结果列表
|
||
res = super().name_search(name, args, operator, limit)
|
||
# 定义一个空字典用来存储id和name的映射关系
|
||
name_dict = {}
|
||
# 遍历结果列表,将id和name存入字典中
|
||
for item in res:
|
||
id = item[0]
|
||
name = item[1]
|
||
name_dict[id] = name
|
||
# 根据id列表搜索符合条件的记录
|
||
records = self.browse(name_dict.keys())
|
||
# 定义一个新的结果列表用来存储修改后的结果
|
||
new_res = []
|
||
# 遍历每条记录
|
||
for record in records:
|
||
# 获取记录的id,name和image属性
|
||
id = record.id
|
||
name = name_dict[id]
|
||
image = record.image
|
||
# 如果image不为空,将其转换为data URI scheme
|
||
if image:
|
||
data_uri = f"data:image/png;base64,{image.decode('utf-8')}"
|
||
else:
|
||
data_uri = ""
|
||
# 将这三个属性组成一个数组,并添加到结果列表中 result.append([id, name, data_uri]) # 返回结果列表 return result
|
||
new_res.append([id, name, data_uri])
|
||
# 返回新的结果列表
|
||
return new_res
|
||
|
||
|
||
class CuttingDirection(models.Model):
|
||
_name = 'sf.cutting.direction'
|
||
_description = '走刀方向'
|
||
|
||
name = fields.Char('名称')
|
||
image = fields.Image('图片')
|
||
|
||
@api.model
|
||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||
# 调用父类的name_search方法,获取原始的结果列表
|
||
res = super().name_search(name, args, operator, limit)
|
||
# 定义一个空字典用来存储id和name的映射关系
|
||
name_dict = {}
|
||
# 遍历结果列表,将id和name存入字典中
|
||
for item in res:
|
||
id = item[0]
|
||
name = item[1]
|
||
name_dict[id] = name
|
||
# 根据id列表搜索符合条件的记录
|
||
records = self.browse(name_dict.keys())
|
||
# 定义一个新的结果列表用来存储修改后的结果
|
||
new_res = []
|
||
# 遍历每条记录
|
||
for record in records:
|
||
# 获取记录的id,name和image属性
|
||
id = record.id
|
||
name = name_dict[id]
|
||
image = record.image
|
||
# 如果image不为空,将其转换为data URI scheme
|
||
if image:
|
||
data_uri = f"data:image/png;base64,{image.decode('utf-8')}"
|
||
else:
|
||
data_uri = ""
|
||
# 将这三个属性组成一个数组,并添加到结果列表中 result.append([id, name, data_uri]) # 返回结果列表 return result
|
||
new_res.append([id, name, data_uri])
|
||
# 返回新的结果列表
|
||
return new_res
|
||
|
||
|
||
class SuitableCoolant(models.Model):
|
||
_name = 'sf.suitable.coolant'
|
||
_description = '适合冷却液'
|
||
|
||
name = fields.Char('名称')
|
||
image = fields.Image('图片')
|
||
|
||
@api.model
|
||
def name_search(self, name='', args=None, operator='ilike', limit=100):
|
||
# 调用父类的name_search方法,获取原始的结果列表
|
||
res = super().name_search(name, args, operator, limit)
|
||
# 定义一个空字典用来存储id和name的映射关系
|
||
name_dict = {}
|
||
# 遍历结果列表,将id和name存入字典中
|
||
for item in res:
|
||
id = item[0]
|
||
name = item[1]
|
||
name_dict[id] = name
|
||
# 根据id列表搜索符合条件的记录
|
||
records = self.browse(name_dict.keys())
|
||
# 定义一个新的结果列表用来存储修改后的结果
|
||
new_res = []
|
||
# 遍历每条记录
|
||
for record in records:
|
||
# 获取记录的id,name和image属性
|
||
id = record.id
|
||
name = name_dict[id]
|
||
image = record.image
|
||
# 如果image不为空,将其转换为data URI scheme
|
||
if image:
|
||
data_uri = f"data:image/png;base64,{image.decode('utf-8')}"
|
||
else:
|
||
data_uri = ""
|
||
# 将这三个属性组成一个数组,并添加到结果列表中 result.append([id, name, data_uri]) # 返回结果列表 return result
|
||
new_res.append([id, name, data_uri])
|
||
# 返回新的结果列表
|
||
return new_res
|
||
|
||
|
||
class CuttingSpeed(models.Model):
|
||
_name = 'sf.cutting.speed'
|
||
_description = '切削速度Vc'
|
||
|
||
# def _get_order(self):
|
||
# last_tool = self.search([], order='id desc', limit=1)
|
||
# if last_tool:
|
||
# last_order = int(last_tool.order)
|
||
# new_order = last_order + 1
|
||
# else:
|
||
# new_order = '1'
|
||
# return new_order
|
||
#
|
||
# order = fields.Char('序', default=_get_order, readonly=True)
|
||
|
||
product_template_id = fields.Many2one('product.template', string='产品')
|
||
|
||
execution_standard_id = fields.Char('执行标准')
|
||
material_code = fields.Char('材料代号')
|
||
material_name = fields.Char('材料名称')
|
||
material_grade = fields.Char('材料牌号')
|
||
tensile_strength = fields.Float('拉伸强度 (N/mm²)')
|
||
hardness = fields.Float('硬度(HRC)')
|
||
|
||
cutting_speed_n1 = fields.Char('径向切宽 ae=100%D1 ap=1*D1 切削速度Vc')
|
||
cutting_speed_n2 = fields.Char('径向切宽 ae=50%D1 ap=1.5*D1 切削速度Vc')
|
||
cutting_speed_n3 = fields.Char('径向切宽 ae=25%D1 ap=L1max 切削速度Vc')
|
||
cutting_speed_n4 = fields.Char('径向切宽 ae=15%D1 ap=L1max 切削速度Vc')
|
||
cutting_speed_n5 = fields.Char('径向切宽 ae=5%D1 ap=L1max 切削速度Vc')
|
||
rough_machining = fields.Char('粗加工 Vc(m/min)')
|
||
precision_machining = fields.Char('精加工 Vc(m/min)')
|
||
application = fields.Selection([('主应用', '主应用'), ('次应用', '次应用')], '主/次应用')
|
||
|
||
|
||
class FeedPerTooth(models.Model):
|
||
_name = 'sf.feed.per.tooth'
|
||
_description = '每齿走刀量fz'
|
||
|
||
product_template_id = fields.Many2one('product.template', string='产品')
|
||
|
||
cutting_speed = fields.Char('径向切宽 ae(mm)')
|
||
machining_method = fields.Selection([('直铣', '直铣'), ('坡铣', '坡铣')], string='加工方式')
|
||
materials_type_id = fields.Many2one('sf.materials.model', string='材料型号')
|
||
blade_diameter = fields.Float('刃部直径D1(mm)', readonly=True, related='product_template_id.cutting_tool_blade_diameter')
|
||
feed_per_tooth = fields.Char('每齿走刀量 (mm/z)')
|
||
unit = fields.Char('单位', default='fz')
|
||
|
||
# @api.depends('product_template_id')
|
||
# def _compute_product_template_id(self):
|
||
# if self.product_template_id is not None:
|
||
# self.blade_diameter = self.product_template_id.cutting_tool_blade_diameter
|