Skip to content

Commit f5a4e39

Browse files
authored
Merge pull request #23 from kainotomo/bug/cost-not-working
2 parents c23060d + 57d450b commit f5a4e39

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

invoice2erpnext/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11

2-
__version__ = '2.0.0'
2+
__version__ = '2.0.1'
33

invoice2erpnext/utils.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def format_currency_value(value):
1111
value: The value to format (string or numeric)
1212
1313
Returns:
14-
str: Formatted value according to system number format
14+
str: Formatted value according to system number format and currency precision
1515
"""
1616
# First ensure we have a float value to work with
1717
if isinstance(value, str):
@@ -20,19 +20,33 @@ def format_currency_value(value):
2020
else:
2121
value_float = float(value)
2222

23+
# Get currency precision from Frappe
24+
try:
25+
currency_precision = frappe.get_precision("Currency", "amount")
26+
if currency_precision is None:
27+
currency_precision = 2 # Default to 2 decimal places
28+
except:
29+
currency_precision = 2 # Default to 2 decimal places if anything goes wrong
30+
31+
# Round the value to the specified precision
32+
value_float = round(value_float, currency_precision)
33+
34+
# Format with the exact number of decimal places
35+
value_str = f"{{:.{currency_precision}f}}".format(value_float)
36+
2337
# Get the number format from system settings
2438
number_format = frappe.get_system_settings('number_format')
2539

2640
# Format according to the system's number format
2741
if number_format == "#.###,##": # European format (1.234,56)
28-
formatted_value = str(value_float).replace(".", ",")
42+
formatted_value = value_str.replace(".", ",")
2943
elif number_format == "# ###.##": # Format with space (1 234.56)
30-
integer_part, decimal_part = str(value_float).split(".")
31-
formatted_value = " ".join([integer_part, decimal_part])
44+
integer_part, decimal_part = value_str.split(".")
45+
formatted_value = f"{integer_part} {decimal_part}"
3246
elif number_format == "#,###.##": # US format (1,234.56)
33-
formatted_value = str(value_float)
47+
formatted_value = value_str
3448
else:
3549
# Default format if none of the above
36-
formatted_value = str(value_float)
50+
formatted_value = value_str
3751

3852
return formatted_value

0 commit comments

Comments
 (0)