Skip to content

Commit f682d46

Browse files
committed
OM-127 Changed floats to decimals in bill_create service method
1 parent fe54f41 commit f682d46

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

invoice/services/bill.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import decimal
12
from typing import Union, List
23

34
from invoice.models import Bill, BillItem
@@ -9,7 +10,6 @@
910

1011

1112
class BillService(BaseService):
12-
1313
OBJECT_TYPE = Bill
1414

1515
def __init__(self, user, validation_class: BillModelValidation = BillModelValidation):
@@ -55,17 +55,19 @@ def bill_create(cls, **kwargs):
5555
if result_bill["success"] is True:
5656
bill_update = {
5757
"id": result_bill["data"]["id"],
58-
"amount_net": 0,
59-
"amount_total": 0,
60-
"amount_discount": 0
58+
"amount_net": decimal.Decimal(0),
59+
"amount_total": decimal.Decimal(0),
60+
"amount_discount": decimal.Decimal(0),
6161
}
6262
for bill_line_item in bill_line_items:
6363
bill_line_item["bill_id"] = result_bill["data"]["id"]
6464
result_bill_line = bill_line_item_service.create(bill_line_item)
6565
if result_bill_line["success"] is True:
66-
bill_update["amount_net"] += float(result_bill_line["data"]["amount_net"])
67-
bill_update["amount_total"] += float(result_bill_line["data"]["amount_total"])
68-
bill_update["amount_discount"] += 0 if result_bill_line["data"]["discount"] else result_bill_line["data"]["discount"]
66+
bill_update["amount_net"] += decimal.Decimal(result_bill_line["data"]["amount_net"])
67+
bill_update["amount_total"] += decimal.Decimal(result_bill_line["data"]["amount_total"])
68+
bill_update["amount_discount"] += decimal.Decimal(0) \
69+
if not result_bill_line["data"]["discount"] \
70+
else decimal.Decimal(result_bill_line["data"]["discount"])
6971
generated_bill = bill_service.update(bill_update)
7072
return generated_bill
7173

0 commit comments

Comments
 (0)