处理订单行参数说明的精度问题
This commit is contained in:
@@ -130,7 +130,10 @@ class ReSaleOrder(models.Model):
|
||||
'order_id': self.id,
|
||||
'product_id': product.id,
|
||||
'name': '%s/%s/%s/%s/%s/%s' % (
|
||||
product.model_long, product.model_width, product.model_height, product.model_volume,
|
||||
self.format_float(product.model_long),
|
||||
self.format_float(product.model_width),
|
||||
self.format_float(product.model_height),
|
||||
self.format_float(product.model_volume),
|
||||
machining_accuracy_name,
|
||||
product.materials_id.name),
|
||||
'price_unit': product.list_price,
|
||||
@@ -143,6 +146,20 @@ class ReSaleOrder(models.Model):
|
||||
}
|
||||
return self.env['sale.order.line'].with_context(skip_procurement=True).create(vals)
|
||||
|
||||
def format_float(self, value):
|
||||
# 将浮点数转换为字符串
|
||||
value_str = str(value)
|
||||
# 检查小数点的位置
|
||||
if '.' in value_str:
|
||||
# 获取小数部分
|
||||
decimal_part = value_str.split('.')[1]
|
||||
# 判断小数位数是否超过2位
|
||||
if len(decimal_part) > 2:
|
||||
# 超过2位则保留2位小数
|
||||
return "{:.2f}".format(value)
|
||||
# 否则保持原来的位数
|
||||
return float(value_str)
|
||||
|
||||
@api.constrains('order_line')
|
||||
def check_order_line(self):
|
||||
for item in self:
|
||||
|
||||
Reference in New Issue
Block a user