fix: 修复四舍五入计算问题

This commit is contained in:
han0
2025-05-19 18:12:03 +08:00
parent 7a9aa93a10
commit a10ab91a31

View File

@@ -1,4 +1,6 @@
import datetime
import decimal
from decimal import Decimal
from sqlalchemy import func
@@ -60,24 +62,25 @@ class Collector:
material_id, price, price_fuzhou, price_xiamen, price_putian, price_sanming, price_quanzhou, \
price_zhangzhou, price_nanpin, price_longyan, price_ningde, price_pintan, price_zhangzhoukfq = item
display_digit = self.digit_map.get(material_id, 1)
PricePublish(
year=self.year,
month=self.month,
material_id=material_id,
name=self.name_map.get(material_id, ''),
spec=self.spec_map.get(material_id, ''),
price=round(price, 2),
price_fuzhou=round(price_fuzhou or 0, 2),
price_xiamen=round(price_xiamen or 0, 2),
price_putian=round(price_putian or 0, 2),
price_sanming=round(price_sanming or 0, 2),
price_quanzhou=round(price_quanzhou or 0, 2),
price_zhangzhou=round(price_zhangzhou or 0, 2),
price_nanpin=round(price_nanpin or 0, 2),
price_longyan=round(price_longyan or 0, 2),
price_ningde=round(price_ningde or 0, 2),
price_pintan=round(price_pintan or 0, 2),
price_zhangzhoukfq=round(price_zhangzhoukfq or 0, 2),
price=price.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price else 0,
price_fuzhou=price_fuzhou.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_fuzhou else 0,
price_xiamen=price_xiamen.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_xiamen else 0,
price_putian=price_putian.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_putian else 0,
price_sanming=price_sanming.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_sanming else 0,
price_quanzhou=price_quanzhou.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_quanzhou else 0,
price_zhangzhou=price_zhangzhou.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_zhangzhou else 0,
price_nanpin=price_nanpin.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_nanpin else 0,
price_longyan=price_longyan.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_longyan else 0,
price_ningde=price_ningde.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_ningde else 0,
price_pintan=price_pintan.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_pintan else 0,
price_zhangzhoukfq=price_zhangzhoukfq.quantize(Decimal('0.00'), decimal.ROUND_HALF_UP) if price_zhangzhoukfq else 0,
tax=self.tax_map.get(material_id, 0), # 从材料表获取税率
type=2,
unit=self.unit_map.get(material_id, ''),