Browse Source

小数问题

flower 1 day ago
parent
commit
57c11fa0d4
2 changed files with 12 additions and 2 deletions
  1. 9 1
      bound/views.py
  2. 3 1
      erp/views.py

+ 9 - 1
bound/views.py

@@ -835,7 +835,15 @@ class OutBoundBatchViewSet(viewsets.ModelViewSet):
         data['openid'] = self.request.auth.openid
         data.setdefault('is_delete', False)
         data['goods_total_weight'] = data['goods_weight']*data['goods_out_qty']
-        data['goods_qty'] = batch_obj.goods_qty -batch_obj.goods_reserve_qty - data['goods_out_qty']
+        from decimal import Decimal
+
+        # 假设 data['goods_out_qty'] 是一个 float 类型的数值
+        data['goods_out_qty'] = Decimal(str(data['goods_out_qty']))
+
+        # 现在所有数值都是 Decimal 类型,可以安全地进行减法运算
+        data['goods_qty'] = batch_obj.goods_qty - batch_obj.goods_reserve_qty - data['goods_out_qty']
+
+        # data['goods_qty'] = batch_obj.goods_qty -batch_obj.goods_reserve_qty - data['goods_out_qty']
 
         data['status'] = 0  #现在处于出库申请状态
    

+ 3 - 1
erp/views.py

@@ -780,7 +780,9 @@ class GenerateOutbound(APIView):
             # 计算重量 - 使用入库单件的重量进行计算
             unit_weight = batch_obj.goods_weight or 1  # 避免除零错误
             out_qty = material.goods_out_qty
-            total_weight = unit_weight * out_qty
+            from decimal import Decimal
+
+            total_weight = Decimal(unit_weight) * Decimal(out_qty)
 
             # 创建出库批次记录
             batch = OutBatchModel(