feat: add Nepali currency support, number-to-words conversion, and REST API enhancements
- Implement NepaliCurrencyField for model-level currency handling.
- Add format_nepali_currency utility with Lakhs/Crores comma formatting and decimal support.
- Implement number_to_nepali_words and english_to_nepali_unicode helper functions.
- Add nepali_currency, nepali_words, and nepali_unicode template filters.
- Enhance REST API (DRF) support:
- Added NepaliCurrencySerializerField for formatted currency output.
- Added NepaliLocalizedSerializerMixin for automatic Devanagari field generation.
- Added flexible NepaliCurrencyRangeFilter and NepaliDateRangeFilter.
- Integrated automatic currency formatting into NepaliModelAdmin.
- Expanded the example demo app with a Transaction model and updated filters.
- Added comprehensive unit tests for formatting, models, and API components.
- Updated documentation (README.md and todo.md) to reflect new features.
This commit is contained in:
10 files changed
+295
-13
No files matched your search
@@ -89,12 +89,14 @@ def get_municipalities_by_district(district_name, ne=False, en=True):
|
||||
return _get_location_children(districts, district_name, "municipalities", ne=ne)
|
||||
|
||||
|
||||
def format_nepali_currency(number: Any, currency_symbol: str = "Rs.") -> str:
|
||||
def format_nepali_currency(
|
||||
number: Any, currency_symbol: str = "Rs.", ne: bool = False
|
||||
) -> str:
|
||||
"""
|
||||
Formats a number with Nepali-style commas and optional currency symbol.
|
||||
Eg. 1234567 -> Rs. 12,34,567
|
||||
"""
|
||||
from nepali.number import add_comma
|
||||
from nepali.number import add_comma, english_to_nepali
|
||||
|
||||
if number is None:
|
||||
return ""
|
||||
@@ -115,6 +117,9 @@ def format_nepali_currency(number: Any, currency_symbol: str = "Rs.") -> str:
|
||||
if decimal_part:
|
||||
res = f"{res}.{decimal_part}"
|
||||
|
||||
if ne:
|
||||
res = english_to_nepali(res)
|
||||
|
||||
if currency_symbol:
|
||||
return f"{currency_symbol} {res}"
|
||||
return res
|
||||
|
||||
Reference in new issue
Block a user