Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions api/migrations/0116_employeepayment_over_time_earnings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.8 on 2021-11-24 20:15

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0115_payrollperiod_total_employees'),
]

operations = [
migrations.AddField(
model_name='employeepayment',
name='over_time_earnings',
field=models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='overtime earnings'),
),
]
18 changes: 18 additions & 0 deletions api/migrations/0117_employeepayment_hourly_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.8 on 2021-11-24 20:29

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0116_employeepayment_over_time_earnings'),
]

operations = [
migrations.AddField(
model_name='employeepayment',
name='hourly_rate',
field=models.DecimalField(blank=True, decimal_places=2, default=0, max_digits=10),
),
]
22 changes: 22 additions & 0 deletions api/migrations/0118_auto_20211124_2114.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 2.2.8 on 2021-11-24 21:14

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0117_employeepayment_hourly_rate'),
]

operations = [
migrations.RemoveField(
model_name='employeepayment',
name='hourly_rate',
),
migrations.AddField(
model_name='employeepayment',
name='regular_hours_earnings',
field=models.DecimalField(decimal_places=2, default=0, max_digits=10, verbose_name='regular hours earnings'),
),
]
18 changes: 18 additions & 0 deletions api/migrations/0119_auto_20220221_2005.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.8 on 2022-02-21 20:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0118_auto_20211124_2114'),
]

operations = [
migrations.AlterField(
model_name='profile',
name='resume',
field=models.URLField(blank=True, default=True, null=True),
),
]
35 changes: 35 additions & 0 deletions api/migrations/0120_order_payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 3.2.12 on 2022-03-08 00:38

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('api', '0119_auto_20220221_2005'),
]

operations = [
migrations.CreateModel(
name='Payment',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_charge_id', models.CharField(max_length=50)),
('amount', models.FloatField()),
('timestamp', models.DateTimeField(auto_now_add=True)),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
migrations.CreateModel(
name='Order',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('ref_code', models.CharField(blank=True, max_length=20, null=True)),
('payment', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='api.payment')),
('user', models.OneToOneField(blank=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
24 changes: 24 additions & 0 deletions api/migrations/0121_userprofile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.2.12 on 2022-03-08 16:41

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('api', '0120_order_payment'),
]

operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('stripe_customer_id', models.CharField(blank=True, max_length=50, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
18 changes: 18 additions & 0 deletions api/migrations/0122_userprofile_stripe_sub_id.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.12 on 2022-03-17 20:27

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0121_userprofile'),
]

operations = [
migrations.AddField(
model_name='userprofile',
name='stripe_sub_id',
field=models.CharField(blank=True, max_length=100),
),
]
16 changes: 16 additions & 0 deletions api/migrations/0123_delete_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.2.12 on 2022-03-18 15:17

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('api', '0122_userprofile_stripe_sub_id'),
]

operations = [
migrations.DeleteModel(
name='Order',
),
]
36 changes: 29 additions & 7 deletions api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def __str__(self):
(APPROVED, 'Approved'),
)


class SubscriptionPlan(models.Model):
unique_name = models.CharField(max_length=25, unique=True)
visible_to_users = models.BooleanField(default=True)
Expand Down Expand Up @@ -100,7 +101,7 @@ class Employer(models.Model):
total_ratings = models.IntegerField(blank=True, default=0) # in minutes
badges = models.ManyToManyField(Badge, blank=True)
status = models.CharField(max_length=25, choices=EMPLOYER_STATUS, default=APPROVED, blank=True)

# talents on employer's favlist's will be automatically accepted
automatically_accept_from_favlists = models.BooleanField(default=True)

Expand Down Expand Up @@ -194,6 +195,7 @@ class EmployerSubscription(models.Model):
status = models.CharField(max_length=25, choices=SUBSCRIPTION_STATUS, default=ACTIVE, blank=True)
payment_mode = models.CharField(max_length=9,choices=SUBSCRIPTION_MODE,default=MONTHLY,blank=True)
stripe_sub = models.CharField(max_length=100, blank=True)
# stripe_sub_status = models.CharField(max_length=25, blank=True)
stripe_cus = models.CharField(max_length=100, blank=True)
due_at = models.DateTimeField()

Expand Down Expand Up @@ -303,7 +305,7 @@ def calculate_tax_amount(self, period_wage, period_quantity):
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, blank=True)
picture = models.URLField(blank=True)
resume = models.URLField(blank=True)
resume = models.URLField(blank=True, null=True, default=True)
bio = models.TextField(max_length=250, blank=True)
show_tutorial = models.BooleanField(default=True)

Expand Down Expand Up @@ -807,6 +809,8 @@ class EmployeePayment(models.Model):
over_time = models.DecimalField(max_digits=10, decimal_places=2, blank=True, default=0)
legal_over_time = models.DecimalField(max_digits=10, decimal_places=2, blank=True, default=0) # plus 40 hours/week
breaktime_minutes = models.IntegerField(blank=True, default=0)
regular_hours_earnings = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='regular hours earnings', default=0)
over_time_earnings = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='overtime earnings', default=0)
earnings = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='gross earnings')
amount = models.DecimalField(max_digits=10, decimal_places=2, blank=True, default=0, verbose_name='net earnings')
deductions = models.DecimalField(max_digits=10, decimal_places=2, blank=True, default=0)
Expand Down Expand Up @@ -1054,11 +1058,29 @@ class W4Form(models.Model):
updated_at = models.DateTimeField(auto_now=True, editable=False)
status = models.CharField(max_length=8, choices=W4_FORM_STATUS, default=PENDING)

class Payment(models.Model):
stripe_charge_id = models.CharField(max_length=50)
user = models.ForeignKey(User, on_delete=models.SET_NULL, blank=True, null=True)
amount = models.FloatField()
timestamp = models.DateTimeField(auto_now_add=True)

def __str__(self):
return self.user.username

def serialize(self):
return {
'stripe_charge_id': self.stripe_charge_id,
'user': self.user,
'amount': self.amount,
'timestamp': self.timestamp
}

class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
# employer = models.ForeignKey(Employer, on_delete=models.CASCADE, blank=True, related_name="company_users_profile")
stripe_customer_id = models.CharField(max_length=50, blank=True, null=True)
stripe_sub_id = models.CharField(max_length=100, blank=True)






def __str__(self):
return self.user.username

11 changes: 7 additions & 4 deletions api/serializers/auth_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from random import randint
from django.db import transaction
from django.utils.translation import ugettext_lazy as _

import stripe
from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.serializers import JSONWebTokenSerializer
from rest_framework import serializers
Expand All @@ -16,7 +16,7 @@
from api.actions import employee_actions, auth_actions
from api.models import (
User, Employer, Employee, Profile,
JobCoreInvite, FCMDevice)
JobCoreInvite, FCMDevice, UserProfile)
from api.utils import notifier

jwt_payload_handler = api_settings.JWT_PAYLOAD_HANDLER
Expand All @@ -36,7 +36,6 @@ class Meta:
'token', 'employer', 'employee')
extra_kwargs = {"password": {"write_only": True}}


class CustomJWTSerializer(JSONWebTokenSerializer):
username_field = 'username_or_email'
user = UserLoginSerializer(required=False)
Expand Down Expand Up @@ -86,10 +85,13 @@ def validate(self, attrs):
FCMDevice.objects.filter(registration_id=device_id).delete()
device = FCMDevice(user=user, registration_id=device_id)
device.save()



return {
'token': jwt_encode_handler(payload),
'user': user
'user': user,

}
def get_active_subscription(self, employer):
_sub = employer.employersubscription_set.filter(status='ACTIVE').first()
Expand Down Expand Up @@ -181,6 +183,7 @@ def create(self, validated_data):
# @TODO: Use IP address to get the initial address,
# latitude and longitud.
user = User.objects.filter(email=validated_data["email"]).first()

if not user:
user = User.objects.create(**{**validated_data, "username": validated_data["email"]})

Expand Down
Loading