mirror of https://github.com/zulip/zulip.git
analytics: Get customer discount for support views.
This commit is contained in:
parent
6621de6f07
commit
8d992405a6
|
@ -59,7 +59,7 @@ if settings.BILLING_ENABLED:
|
|||
SupportViewRequest,
|
||||
get_latest_seat_count,
|
||||
)
|
||||
from corporate.lib.support import get_discount_for_realm
|
||||
from corporate.lib.support import get_customer_discount_for_support_view
|
||||
from corporate.models import (
|
||||
Customer,
|
||||
CustomerPlan,
|
||||
|
@ -378,7 +378,7 @@ def support(
|
|||
|
||||
context["get_realm_owner_emails_as_string"] = get_realm_owner_emails_as_string
|
||||
context["get_realm_admin_emails_as_string"] = get_realm_admin_emails_as_string
|
||||
context["get_discount_for_realm"] = get_discount_for_realm
|
||||
context["get_discount"] = get_customer_discount_for_support_view
|
||||
context["get_org_type_display_name"] = get_org_type_display_name
|
||||
context["realm_icon_url"] = realm_icon_url
|
||||
context["Confirmation"] = Confirmation
|
||||
|
|
|
@ -5,7 +5,7 @@ from urllib.parse import urlencode, urljoin, urlunsplit
|
|||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from corporate.models import get_customer_by_realm
|
||||
from corporate.models import Customer
|
||||
from zerver.models import Realm, get_realm
|
||||
|
||||
|
||||
|
@ -18,8 +18,9 @@ def get_support_url(realm: Realm) -> str:
|
|||
return support_url
|
||||
|
||||
|
||||
def get_discount_for_realm(realm: Realm) -> Optional[Decimal]:
|
||||
customer = get_customer_by_realm(realm)
|
||||
if customer is not None:
|
||||
return customer.default_discount
|
||||
return None
|
||||
def get_customer_discount_for_support_view(
|
||||
customer: Optional[Customer] = None,
|
||||
) -> Optional[Decimal]:
|
||||
if customer is None:
|
||||
return None
|
||||
return customer.default_discount
|
||||
|
|
|
@ -76,7 +76,6 @@ from corporate.lib.stripe import (
|
|||
update_license_ledger_for_manual_plan,
|
||||
update_license_ledger_if_needed,
|
||||
)
|
||||
from corporate.lib.support import get_discount_for_realm
|
||||
from corporate.models import (
|
||||
Customer,
|
||||
CustomerPlan,
|
||||
|
@ -5120,15 +5119,6 @@ class TestRemoteServerBillingSession(StripeTestCase):
|
|||
|
||||
|
||||
class TestSupportBillingHelpers(StripeTestCase):
|
||||
def test_get_discount_for_realm(self) -> None:
|
||||
support_admin = self.example_user("iago")
|
||||
user = self.example_user("hamlet")
|
||||
self.assertEqual(get_discount_for_realm(user.realm), None)
|
||||
|
||||
billing_session = RealmBillingSession(support_admin, realm=user.realm, support_session=True)
|
||||
billing_session.attach_discount_to_customer(Decimal(85))
|
||||
self.assertEqual(get_discount_for_realm(user.realm), 85)
|
||||
|
||||
@mock_stripe()
|
||||
def test_attach_discount_to_realm(self, *mocks: Mock) -> None:
|
||||
# Attach discount before Stripe customer exists
|
||||
|
|
|
@ -101,10 +101,10 @@
|
|||
{{ csrf_input }}
|
||||
<input type="hidden" name="realm_id" value="{{ realm.id }}" />
|
||||
{% if plan_data[realm.id].current_plan and plan_data[realm.id].current_plan.fixed_price %}
|
||||
<input type="number" name="discount" value="{{ get_discount_for_realm(realm) }}" disabled />
|
||||
<input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" disabled />
|
||||
<button type="submit" class="btn btn-default support-submit-button" disabled>Update</button>
|
||||
{% else %}
|
||||
<input type="number" name="discount" value="{{ get_discount_for_realm(realm) }}" required />
|
||||
<input type="number" name="discount" value="{{ get_discount(plan_data[realm.id].customer) }}" required />
|
||||
<button type="submit" class="btn btn-default support-submit-button">Update</button>
|
||||
{% endif %}
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue