From 47c73ae66e83a64cdeba7182aa35fefd76fa0f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Fri, 17 Jan 2025 15:20:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E8=AE=A2=E5=8D=95=E8=A1=8C?= =?UTF-8?q?=E5=8F=82=E6=95=B0=E8=AF=B4=E6=98=8E=E7=9A=84=E7=B2=BE=E5=BA=A6?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_sale/models/sale_order.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sf_sale/models/sale_order.py b/sf_sale/models/sale_order.py index 73837271..31681932 100644 --- a/sf_sale/models/sale_order.py +++ b/sf_sale/models/sale_order.py @@ -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: