Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate tests for Shared Revenue #106 #169

Merged
merged 7 commits into from
Nov 13, 2023
10 changes: 6 additions & 4 deletions apps/billing/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Meta:
payment_type = factory.fuzzy.FuzzyChoice(PAYMENT_TYPE)
transaction_type = factory.Faker("random_element", elements=[t[0] for t in TRANSACTION_TYPE])
transaction_date = factory.Faker(
"date_time_between", start_date="-1d", end_date="-5d", tzinfo=timezone.get_current_timezone()
"date_time_between", start_date="-5d", end_date="-1d", tzinfo=timezone.get_current_timezone()
)
document_id = factory.Faker("pystr_format", string_format="DCI-######{{random_int}}")

Expand All @@ -48,15 +48,17 @@ class Meta:
description = factory.Faker("sentence")
quantity = factory.Faker("pyint", min_value=1, max_value=10)
vat_tax = factory.Faker("pydecimal", min_value=1, max_value=100, left_digits=3, right_digits=2)
amount_exclude_vat = factory.Faker("pydecimal", min_value=1, max_value=100, left_digits=5, right_digits=2)
organization_code = factory.LazyAttribute(lambda obj: slugify(obj.description))
product_code = "".join([random.choice(string.ascii_uppercase) for _ in range(5)])

@factory.lazy_attribute
def product_id(self):
return f"course-v1:{self.organization_code}+{self.product_code}+2023_T3"

# Assuming 20% VAT
@factory.lazy_attribute
def amount_exclude_vat(self):
return self.transaction.total_amount_exclude_vat

@factory.lazy_attribute
def amount_include_vat(self):
return round(self.amount_exclude_vat * Decimal("1.20"), 2)
return round(self.transaction.total_amount_exclude_vat * Decimal("1.20"), 2)
8 changes: 3 additions & 5 deletions apps/shared_revenue/factories.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import random
import string

import factory
from django.utils import timezone
from factory.django import DjangoModelFactory
Expand All @@ -14,8 +11,9 @@ class Meta:

organization = None
partner_percentage = 0.70
product_id = (
f"course-v1:UPorto+CBN{random.choice(string.ascii_uppercase)}{random.choice(string.ascii_uppercase)}F+2023_T3"
product_id = factory.Faker(
"pystr_format",
string_format="course-v%:?????+CBN???F+2023_T3",
)
start_date = factory.Faker(
"date_time_between", start_date="-10d", end_date="+30d", tzinfo=timezone.get_current_timezone()
Expand Down
5 changes: 1 addition & 4 deletions apps/shared_revenue/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,7 @@ def has_concurrent_revenue_configuration(self) -> bool:
def _check_partner_percentage(self) -> None:
try:
same_configurations: list[RevenueConfiguration] = RevenueConfiguration.objects.filter(
**{
"organization": self.organization,
"product_id": self.product_id,
}
product_id=self.product_id
)

percentages = self.partner_percentage
Expand Down
Empty file.
Loading
Loading