Skip to content

Commit

Permalink
feat: add discounts data to financial manager
Browse files Browse the repository at this point in the history
Add discount related fields:
To transaction
- total_discount_incl_tax
- total_discount_excl_tax
To line:
 - discount_excl_tax
 - discount_incl_tax
#3
  • Loading branch information
igobranco committed Mar 5, 2024
1 parent 4ad7d73 commit 3ff546a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 9 additions & 5 deletions nau_extensions/financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ def sync_request_data(bti: BasketTransactionIntegration) -> dict:
"country_code": country_code,
"vat_identification_number": vat_identification_number,
"vat_identification_country": vat_identification_country,
"total_amount_exclude_vat": basket.total_excl_tax,
"total_amount_include_vat": basket.total_incl_tax,
"currency": basket.currency,
"total_amount_exclude_vat": order.total_excl_tax,
"total_amount_include_vat": order.total_incl_tax,
"total_discount_incl_tax": order.total_discount_incl_tax,
"total_discount_excl_tax": order.total_discount_excl_tax,
"currency": order.currency,
"payment_type": _get_payment_type(order),
"items": _convert_order_lines(order),
}
Expand All @@ -108,8 +110,6 @@ def _convert_order_lines(order):
"""
result = []
for line in order.lines.all():
# line.discount_incl_tax
# line.discount_excl_tax
course = line.product.course
course_id = course.id if course else line.product.title
course_key = CourseKey.from_string(course.id) if course else None
Expand All @@ -128,6 +128,8 @@ def _convert_order_lines(order):
"organization_code": organization_code,
"product_code": product_code,
"product_id": course_id,
"discount_excl_tax": line.discount_excl_tax,
"discount_incl_tax": line.discount_incl_tax,
}
)
return result
Expand Down Expand Up @@ -163,7 +165,9 @@ def send_to_financial_manager_if_enabled(
try:
response_json = response.json()
except Exception as e: # pylint: disable=broad-except
response_json = None
logger.exception("Error can't parse send to financial manager response as json [%s]", e)

basket_transaction_integration.response = response_json
basket_transaction_integration.save()
return basket_transaction_integration
18 changes: 18 additions & 0 deletions nau_extensions/tests/test_financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ def test_financial_manager_sync_data_basic(self):
"vat_identification_country": "PT",
"total_amount_exclude_vat": Decimal("10.00"),
"total_amount_include_vat": Decimal("10.00"),
"total_discount_excl_tax": Decimal('0.00'),
"total_discount_incl_tax": Decimal('0.00'),
"currency": "EUR",
"payment_type": None,
"items": [
Expand All @@ -99,6 +101,8 @@ def test_financial_manager_sync_data_basic(self):
"amount_exclude_vat": Decimal("10.00"),
"amount_include_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand All @@ -110,6 +114,8 @@ def test_financial_manager_sync_data_basic(self):
"amount_exclude_vat": Decimal("0.00"),
"amount_include_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand Down Expand Up @@ -187,6 +193,8 @@ def test_financial_manager_sync_data_with_tax_rate(self):
"vat_identification_country": "PT",
"total_amount_exclude_vat": Decimal("10.00"),
"total_amount_include_vat": Decimal("12.99"),
"total_discount_excl_tax": Decimal('0.00'),
"total_discount_incl_tax": Decimal('0.00'),
"currency": "EUR",
"payment_type": None,
"items": [
Expand All @@ -195,6 +203,8 @@ def test_financial_manager_sync_data_with_tax_rate(self):
"amount_exclude_vat": Decimal("10.00"),
"amount_include_vat": Decimal("12.99"),
"description": "Seat in edX Demonstration Course with verified certificate",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand All @@ -206,6 +216,8 @@ def test_financial_manager_sync_data_with_tax_rate(self):
"amount_exclude_vat": Decimal("0.00"),
"amount_include_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
'discount_excl_tax': Decimal('0.00'),
'discount_incl_tax': Decimal('0.00'),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand Down Expand Up @@ -268,6 +280,8 @@ def test_financial_manager_sync_data_without_bbi(self):
"vat_identification_country": None,
"total_amount_exclude_vat": Decimal("10.00"),
"total_amount_include_vat": Decimal("10.00"),
"total_discount_excl_tax": Decimal("0.00"),
"total_discount_incl_tax": Decimal("0.00"),
"currency": "EUR",
"payment_type": None,
"items": [
Expand All @@ -276,6 +290,8 @@ def test_financial_manager_sync_data_without_bbi(self):
"amount_exclude_vat": Decimal("10.00"),
"amount_include_vat": Decimal("10.00"),
"description": "Seat in edX Demonstration Course with verified certificate",
"discount_excl_tax": Decimal("0.00"),
"discount_incl_tax": Decimal("0.00"),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand All @@ -287,6 +303,8 @@ def test_financial_manager_sync_data_without_bbi(self):
"amount_exclude_vat": Decimal("0.00"),
"amount_include_vat": Decimal("0.00"),
"description": "Seat in edX Demonstration Course with honor certificate",
"discount_excl_tax": Decimal("0.00"),
"discount_incl_tax": Decimal("0.00"),
"organization_code": "edX",
"product_code": "DemoX",
"product_id": "course-v1:edX+DemoX+Demo_Course",
Expand Down

0 comments on commit 3ff546a

Please sign in to comment.