Skip to content

Commit

Permalink
fix: unit price sent to financial manager
Browse files Browse the repository at this point in the history
The unit price fields should not multiply with its quantity.

fccn/nau-technical#212
  • Loading branch information
igobranco committed Jul 18, 2024
1 parent dc913a3 commit 185f7e7
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 2 deletions.
4 changes: 2 additions & 2 deletions nau_extensions/financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ def _convert_order_lines(order):
course_key = CourseKey.from_string(course.id) if course else None
organization_code = course_key.org if course else None
product_code = course_key.course if course else None
unit_price_excl_tax = line.quantity * line.unit_price_excl_tax
unit_price_incl_tax = line.quantity * line.unit_price_incl_tax
unit_price_excl_tax = line.unit_price_excl_tax
unit_price_incl_tax = line.unit_price_incl_tax
vat_tax = unit_price_incl_tax - unit_price_excl_tax
result.append(
{
Expand Down
101 changes: 101 additions & 0 deletions nau_extensions/tests/test_financial_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,107 @@ def test_financial_manager_sync_data_basic(self):

owner = UserFactory(email="ecommerce@example.com", full_name="Jon Snow")

# create an empty basket so we know what it's inside
basket = create_basket(owner=owner, empty=True)
basket.add_product(verified_product, quantity=3)
basket.add_product(honor_product, quantity=2)

# creating an order will mark the card submitted
create_order(basket=basket)

bti = BasketTransactionIntegration.create(basket)

basket.save()
bti.save()

country = CountryFactory(iso_3166_1_a2="PT", printable_name="Portugal")
country.save()

bbi = BasketBillingInformation()
bbi.first_name = "Fundação"
bbi.last_name = "Ciência Tecnologia"
bbi.line1 = "Av. do Brasil n.º 101"
bbi.line2 = "AA"
bbi.line3 = "BB CC"
bbi.line4 = "Lisboa"
bbi.state = "Lisboa"
bbi.postcode = "1700-066"
bbi.country = country
bbi.basket = basket
bbi.vatin = "123456789"
bbi.save()

sync_request_data(bti)

self.assertDictEqual(
bti.request,
{
"transaction_id": basket.order_number,
"transaction_type": "credit",
"client_name": "Fundação Ciência Tecnologia",
"email": "ecommerce@example.com",
"address_line_1": "Av. do Brasil n.º 101",
"address_line_2": "AA, BB CC",
"city": "Lisboa",
"postal_code": "1700-066",
"state": "Lisboa",
"country_code": "PT",
"vat_identification_number": "123456789",
"vat_identification_country": "PT",
"total_amount_exclude_vat": Decimal("30.00"),
"total_amount_include_vat": Decimal("30.00"),
"total_discount_excl_tax": Decimal('0.00'),
"total_discount_incl_tax": Decimal('0.00'),
"currency": "EUR",
"payment_type": None,
"items": [
# verified
{
"unit_price_excl_vat": Decimal("10.00"),
"unit_price_incl_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",
"quantity": 3,
"vat_tax": Decimal("0.00"),
},
# honor
{
"unit_price_excl_vat": Decimal("0.00"),
"unit_price_incl_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",
"quantity": 2,
"vat_tax": Decimal("0.00"),
},
],
},
)

@override_settings(OSCAR_DEFAULT_CURRENCY="EUR")
def test_financial_manager_sync_data_with_quantity(self):
"""
Test the synchronization of data between the models and the `BasketTransactionIntegration`
model.
"""
partner = PartnerFactory(short_code="edX")
course = CourseFactory(
id="course-v1:edX+DemoX+Demo_Course",
name="edX Demonstration Course",
partner=partner,
)
honor_product = course.create_or_update_seat("honor", False, 0)
verified_product = course.create_or_update_seat("verified", True, 10)

owner = UserFactory(email="ecommerce@example.com", full_name="Jon Snow")

# create an empty basket so we know what it's inside
basket = create_basket(owner=owner, empty=True)
basket.add_product(verified_product)
Expand Down

0 comments on commit 185f7e7

Please sign in to comment.