Skip to content

Commit

Permalink
Merge pull request #33433 from dimagi/jc/remove-free-50-sms
Browse files Browse the repository at this point in the history
Migration to remove free 50 sms
  • Loading branch information
jingcheng16 authored Sep 7, 2023
2 parents 40dae32 + 8371750 commit 9864606
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from decimal import Decimal

from corehq.apps.accounting.models import FeatureType, SoftwarePlanEdition

BOOTSTRAP_CONFIG = {
(SoftwarePlanEdition.STANDARD, False, False): {
'role': 'standard_plan_v1',
'product_rate_monthly_fee': Decimal('300.00'),
'feature_rates': {
FeatureType.USER: dict(monthly_limit=125, per_excess_fee=Decimal('2.00')),
FeatureType.SMS: dict(monthly_limit=0),
},
},
(SoftwarePlanEdition.PRO, False, False): {
'role': 'pro_plan_v1',
'product_rate_monthly_fee': Decimal('600.00'),
'feature_rates': {
FeatureType.USER: dict(monthly_limit=250, per_excess_fee=Decimal('2.00')),
FeatureType.SMS: dict(monthly_limit=0),
},
},
(SoftwarePlanEdition.ADVANCED, False, False): {
'role': 'advanced_plan_v0',
'product_rate_monthly_fee': Decimal('1200.00'),
'feature_rates': {
FeatureType.USER: dict(monthly_limit=500, per_excess_fee=Decimal('2.00')),
FeatureType.SMS: dict(monthly_limit=0),
}
},
}
6 changes: 1 addition & 5 deletions corehq/apps/accounting/bootstrap/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
log_accounting_info,
)

FEATURE_TYPES = [
FeatureType.USER,
FeatureType.SMS,
FeatureType.WEB_USER,
]
FEATURE_TYPES = list(dict(FeatureType.CHOICES))


def ensure_plans(config, verbose, apps):
Expand Down
21 changes: 21 additions & 0 deletions corehq/apps/accounting/migrations/0085_remove_free_50_sms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django.db import migrations

from corehq.apps.accounting.bootstrap.config.remove_free_50_sms_sep_2023 import (
BOOTSTRAP_CONFIG,
)
from corehq.apps.accounting.bootstrap.utils import ensure_plans


def _bootstrap_new_standard_pricing(apps, schema_editor):
ensure_plans(BOOTSTRAP_CONFIG, verbose=True, apps=apps)


class Migration(migrations.Migration):

dependencies = [
('accounting', '0084_copy_cases_priv'),
]

operations = [
migrations.RunPython(_bootstrap_new_standard_pricing),
]
9 changes: 8 additions & 1 deletion corehq/apps/accounting/tests/test_invoicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ def num_users():


class TestSmsLineItem(BaseInvoiceTestCase):
is_using_test_plans = True

@classmethod
def setUpClass(cls):
Expand Down Expand Up @@ -654,7 +655,13 @@ def test_multipart_under_limit(self):
self.assertEqual(sms_line_item.subtotal, Decimal('0.0000'))
self.assertEqual(sms_line_item.total, Decimal('0.0000'))

def test_multipart_over_limit(self):
def test_multipart_over_limit_and_part_of_the_billable_is_under_limit(self):
"""
In this test, we particularly test the scenario that
half of the billable is within the limit, the remaining half exceeds the limit.
So it's crucial to use test plan in this test instead of default plan whose limit is 0.
"""

def _set_billable_date_sent_day(sms_billable, day):
sms_billable.date_sent = datetime.date(
sms_billable.date_sent.year,
Expand Down
1 change: 1 addition & 0 deletions migrations.lock
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ accounting
0082_application_error_report_priv
0083_data_dictionary_priv
0084_copy_cases_priv
0085_remove_free_50_sms
admin
0001_initial
0002_logentry_remove_auto_add
Expand Down

0 comments on commit 9864606

Please sign in to comment.