Skip to content

Commit

Permalink
Merge b419e16 into b17ba87
Browse files Browse the repository at this point in the history
  • Loading branch information
BarbosaJackson committed Dec 9, 2021
2 parents b17ba87 + b419e16 commit 7c008a4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
4 changes: 4 additions & 0 deletions connect/api/v1/organization/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Meta:
"payment_warnings",
"problem_capture_invoice",
"currenty_invoice",
"contract_on",
]
ref_name = None

Expand All @@ -54,6 +55,7 @@ class Meta:
BillingPlan.PLAN_CHOICES, label=_("plan"), default=BillingPlan.PLAN_FREE
)
is_active = serializers.BooleanField()
contract_on = serializers.DateField()
final_card_number = serializers.CharField(
read_only=True,
allow_null=True,
Expand Down Expand Up @@ -96,6 +98,7 @@ class Meta:
"authorization",
"created_at",
"is_suspended",
"extra_integration",
]
ref_name = None

Expand All @@ -118,6 +121,7 @@ class Meta:
required=False,
help_text=_("Whether this organization is currently suspended."),
)
extra_integration = serializers.IntegerField(read_only=True)

def create(self, validated_data):
task = tasks.create_organization.delay( # pragma: no cover
Expand Down
6 changes: 4 additions & 2 deletions connect/api/v1/organization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,9 @@ def remove_card_setup(
self.check_object_permissions(self.request, organization)

if organization.organization_billing.remove_credit_card:

organization.is_suspended = True
organization.organization_billing.is_active = False
organization.organization_billing.save(update_fields=["is_active"])
organization.save(update_fields=["is_suspended"])

return JsonResponse(data={"status": True}, status=status.HTTP_200_OK)
Expand Down Expand Up @@ -274,12 +275,12 @@ def closing_plan(self, request, organization_uuid): # pragma: no cover
permission_classes=[AllowAny],
)
def reactivate_plan(self, request, organization_uuid): # pragma: no cover
result = {}

organization = get_object_or_404(Organization, uuid=organization_uuid)
org_billing = organization.organization_billing
org_billing.termination_date = None
org_billing.is_active = True
org_billing.contract_on = timezone.now().date()
org_billing.save()

for project in organization.project.all():
Expand All @@ -294,6 +295,7 @@ def reactivate_plan(self, request, organization_uuid): # pragma: no cover
"plan": org_billing.plan,
"is_active": org_billing.is_active,
"termination_date": org_billing.termination_date,
"contract_on": org_billing.contract_on,
}
return JsonResponse(data=result, status=status.HTTP_200_OK)

Expand Down
21 changes: 21 additions & 0 deletions connect/common/migrations/0031_billingplan_contract_on.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Generated by Django 3.2.9 on 2021-12-09 12:42

import datetime
from django.db import migrations, models
from django.utils.timezone import utc


class Migration(migrations.Migration):

dependencies = [
('common', '0030_project_extra_active_integration'),
]

operations = [
migrations.AddField(
model_name='billingplan',
name='contract_on',
field=models.DateField(auto_now_add=True, default=datetime.datetime(2021, 12, 9, 12, 42, 40, 540676, tzinfo=utc), verbose_name='date of contract plan'),
preserve_default=False,
),
]
9 changes: 4 additions & 5 deletions connect/common/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,7 @@ class Meta:
)
fixed_discount = models.FloatField(_("fixed discount"), default=0)
plan = models.CharField(_("plan"), max_length=10, choices=PLAN_CHOICES)
contract_on = models.DateField(_("date of contract plan"), auto_now_add=True)
is_active = models.BooleanField(_("active plan"), default=True)
stripe_customer = models.CharField(
verbose_name=_("Stripe Customer"),
Expand Down Expand Up @@ -646,15 +647,14 @@ def currenty_invoice(self):

return {
"total_contact": contact_count,
"amount_currenty": Decimal(
"amount_currenty": 0 if self.plan == BillingPlan.PLAN_FREE
else Decimal(
float(
float(
self.organization.organization_billing.calculate_amount(
contact_count=0 if contact_count is None else contact_count
)
)
+ settings.BILLING_COST_PER_WHATSAPP
* self.organization.extra_integration
) + (settings.BILLING_COST_PER_WHATSAPP * self.organization.extra_integration)
)
* float(1 - self.fixed_discount / 100)
).quantize(Decimal(".01"), decimal.ROUND_HALF_UP),
Expand All @@ -673,7 +673,6 @@ def change_plan(self, plan):

def add_additional_information(self, data: dict):
count = 0
print(type(data['extra_integration']))
if data['additional_info']:
self.additional_billing_information = data['additional_info']
count += 1
Expand Down
2 changes: 1 addition & 1 deletion connect/common/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def generate_project_invoice():
is_suspended=False,
):
invoice = org.organization_billing_invoice.create(
due_date=timezone.now() + timedelta(days=10),
due_date=timezone.now() + timedelta(days=30),
invoice_random_id=1
if org.organization_billing_invoice.last() is None else org.organization_billing_invoice.last().invoice_random_id + 1,
discount=org.organization_billing.fixed_discount,
Expand Down

0 comments on commit 7c008a4

Please sign in to comment.