完善采购审批流程、企业微信通知和采购专用章
This commit is contained in:
+7
-4
@@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""人民币金额转中文大写。"""
|
||||
from decimal import Decimal, InvalidOperation, ROUND_HALF_UP
|
||||
|
||||
|
||||
def amount_to_cn(amount):
|
||||
@@ -9,15 +10,17 @@ def amount_to_cn(amount):
|
||||
big_units = [u"", u"万", u"亿", u"兆"]
|
||||
|
||||
try:
|
||||
amount = round(float(amount) + 0.0, 2)
|
||||
except (TypeError, ValueError):
|
||||
amount = Decimal(str(amount)).quantize(Decimal('0.01'), rounding=ROUND_HALF_UP)
|
||||
if not amount.is_finite():
|
||||
raise ValueError('金额无效')
|
||||
except (InvalidOperation, TypeError, ValueError):
|
||||
return u"零元整"
|
||||
|
||||
negative = amount < 0
|
||||
amount = abs(amount)
|
||||
integer_part = int(amount)
|
||||
# 避免浮点误差:分位用字符串处理
|
||||
fen = int(round((amount - integer_part) * 100))
|
||||
fen = int((amount - integer_part) * 100)
|
||||
if fen == 100:
|
||||
integer_part += 1
|
||||
fen = 0
|
||||
@@ -60,7 +63,7 @@ def amount_to_cn(amount):
|
||||
if result and not result.endswith(digits[0]):
|
||||
result += digits[0]
|
||||
continue
|
||||
if result and idx < len(parts) - 1 and sections[idx] < 1000:
|
||||
if result and not result.endswith(digits[0]) and idx < len(parts) - 1 and sections[idx] < 1000:
|
||||
result += digits[0]
|
||||
result += p
|
||||
result = result.rstrip(digits[0]) or u"零"
|
||||
|
||||
Reference in New Issue
Block a user