Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created subscription accordingly to payment
close #3763
- Loading branch information
renzon
committed
Jun 5, 2021
1 parent
989c47a
commit 0c8fd1a
Showing
6 changed files
with
111 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
from typing import List | ||
|
||
from pythonpro.memberkit import api | ||
from pythonpro.memberkit.models import SubscriptionType | ||
from pythonpro.memberkit.models import SubscriptionType, Subscription | ||
|
||
|
||
def synchronize_subscription_types() -> List[SubscriptionType]: | ||
return [ | ||
SubscriptionType.objects.update_or_create(id=dct['id'], name=dct['name'])[0] | ||
for dct in api.list_membership_levels() | ||
] | ||
|
||
|
||
def create_new_subscription(payment: 'django_pagarme.models.PagarmePayment', observation: str = '') -> Subscription: | ||
subscription_types = [item.subscription_type_relation.subscription_type for item in payment.items.all()] | ||
if len(subscription_types) == 0: | ||
raise ValueError(f"Payment {payment} doesn't have subscription types") | ||
|
||
subscription = Subscription.objects.create( | ||
status=Subscription.Status.INACTIVE, | ||
payment=payment, | ||
subscriber=payment.user, | ||
observation=observation | ||
) | ||
subscription.subscription_types.set(subscription_types) | ||
return subscription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 3.2.4 on 2021-06-05 20:15 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('django_pagarme', '0004_pagarme_item_config_available_until'), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('memberkit', '0002_create_relationship_with_payment_config_item'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Subscription', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('status', models.CharField(choices=[('A', 'Ativo'), ('I', 'Inativo')], max_length=1)), | ||
('created_at', models.DateTimeField(auto_now_add=True)), | ||
('updated_at', models.DateTimeField(auto_now=True)), | ||
('observation', models.TextField(blank=True, default='', verbose_name='Observação')), | ||
('payment', models.OneToOneField(null=True, on_delete=django.db.models.deletion.DO_NOTHING, to='django_pagarme.pagarmepayment')), | ||
('responsible', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='created_subscriptions', to=settings.AUTH_USER_MODEL)), | ||
('subscriber', models.ForeignKey(null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='subscriptions', to=settings.AUTH_USER_MODEL)), | ||
('subscription_types', models.ManyToManyField(related_name='subscriptions', to='memberkit.SubscriptionType')), | ||
], | ||
options={ | ||
'verbose_name': 'Assinatura', | ||
'verbose_name_plural': 'Assinaturas', | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters