This commit is contained in:
Xuan Loi
2026-01-17 12:14:53 +07:00
parent 9c07a60576
commit 4079761962
2 changed files with 7 additions and 346 deletions

View File

@@ -11,6 +11,7 @@ from django.apps import apps
from num2words import num2words
from django.conf import settings
from app.models import Document_Configuration
from decimal import Decimal
# =============================================================================
# Constants
@@ -275,8 +276,12 @@ class DocumentGenerator:
fmt_type = fmt.get("type") if isinstance(fmt, dict) else fmt
if fmt_type == "currency":
try:
num_val = int(round(float(val), 0))
return "{:,}".format(num_val).replace(",", ".")
num_val = round(float(val), 2)
if Decimal(num_val) == Decimal(int(num_val)):
return "{:,}".format(int(num_val)).replace(",", ".")
else:
s = f"{num_val:,.2f}"
return s.replace(",", "X").replace(".", ",").replace("X", ".")
except Exception:
return str(val)
if fmt_type == "date":