示例#1
0
class SaleItems(models.Model):
    product = models.ForeignKey('Product', null=True)
    sale = models.ForeignKey('Sales', null=True)
    quantity_purchased = models.IntegerField(null=True, blank=False)
    sale_price = models.DecimalField(max_digits=6, decimal_places=2)
    tax = models.DecimalField(max_digits=6, decimal_places=2)
    shipping_cost = models.DecimalField(max_digits=6, decimal_places=2)

    @staticmethod
    def calc_subtotal():
        cartItems = ShoppingCartItems.objects.all()

        subtotal = 0
        for s in cartItems:
            subtotal += s.extended_amount

        return subtotal

    @staticmethod
    def calc_tax():
        tax = round(SaleItems.calc_subtotal() * Decimal(0.0725), 2)
        return tax

    @staticmethod
    def calc_total():
        total = (SaleItems.calc_subtotal() + SaleItems.calc_tax() + 10)
        return total

    @staticmethod
    def clear_cart(user):
        product = ShoppingCartItems.objects.filter(user=user)
        for p in product:
            p.delete()
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('saldo',
                 models.DecimalField(
                     decimal_places=2,
                     max_digits=10,
                     validators=[
                         django.core.validators.MinValueValidator(0.0)
                     ])),
                ('accountNumber',
                 models.CharField(
                     default=account.models.Account.accountGenerator,
                     max_length=12,
                     unique=True)),
                ('owner',
                 models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                   to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
示例#3
0
class ShoppingCartItems(models.Model):
    product = models.ForeignKey('Product', null=True)
    user = models.ForeignKey('account.FomoUser', null=True)
    quantity = models.IntegerField(default=0, null=True)
    extended_amount = models.DecimalField(max_digits=6,
                                          decimal_places=2,
                                          null=True)
示例#4
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0011_update_proxy_permissions'),
    ]

    operations = [
        migrations.CreateModel(
            name='BaseAccount',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
                ('username', models.CharField(error_messages={'unique': 'A user with that username already exists.'}, help_text='Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only.', max_length=150, unique=True, validators=[django.contrib.auth.validators.UnicodeUsernameValidator()], verbose_name='username')),
                ('first_name', models.CharField(blank=True, max_length=30, verbose_name='first name')),
                ('last_name', models.CharField(blank=True, max_length=150, verbose_name='last name')),
                ('is_staff', models.BooleanField(default=False, help_text='Designates whether the user can log into this admin site.', verbose_name='staff status')),
                ('is_active', models.BooleanField(default=True, help_text='Designates whether this user should be treated as active. Unselect this instead of deleting accounts.', verbose_name='active')),
                ('date_joined', models.DateTimeField(default=django.utils.timezone.now, verbose_name='date joined')),
                ('email', models.EmailField(max_length=254, unique=True)),
                ('check_staff', models.BooleanField(default=False)),
                ('staff_id', models.CharField(blank=True, max_length=15, null=True, unique=True)),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
                ('user_permissions', models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'user',
                'verbose_name_plural': 'users',
                'abstract': False,
            },
            managers=[
                ('objects', django.contrib.auth.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='UserProfile',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('dp', models.ImageField(blank=True, null=True, upload_to=account.models.get_uplaod_file_name, verbose_name='Display picture')),
                ('first_name', models.CharField(blank=True, max_length=25, null=True)),
                ('last_name', models.CharField(blank=True, max_length=25, null=True)),
                ('balance', models.DecimalField(decimal_places=2, default=0.0, max_digits=8)),
                ('delivery_address', models.CharField(blank=True, max_length=1055, null=True)),
                ('contact_no', models.CharField(blank=True, max_length=11, null=True)),
                ('user_created', models.DateTimeField(auto_now_add=True)),
                ('last_updated', models.DateTimeField(auto_now=True)),
                ('base', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
示例#5
0
class Product(PolymorphicModel):
    #id
    price = models.DecimalField(max_digits=8,
                                decimal_places=2,
                                blank=True,
                                null=True)  #999,999.99
    name = models.TextField(blank=True, null=True)
    brand = models.TextField(blank=True, null=True)
    category = models.ForeignKey('Category')
    create_date = models.DateTimeField(auto_now_add=True)
    modified_date = models.DateTimeField(auto_now=True)
    path = models.TextField(blank=True, null=True)
    desc = models.TextField(blank=True, null=True)
示例#6
0
class Sales(models.Model):
    user = models.ForeignKey('account.FomoUser', null=True)
    date = models.DateTimeField(auto_now=True, null=True)
    shipping_address = models.TextField(blank=False, null=False)
    total_cost = models.DecimalField(max_digits=6, decimal_places=2)

    @staticmethod
    def record_sale(user, cart_items, address, stripe_token, sale_id):

        sale = Sales()
        sale.user = user
        sale.shipping_address = address

        sale.total_cost = SaleItems.calc_total()

        sale.save()

        saleItem = SaleItems()
        for s in cart_items:
            saleItem.product = s.product
            saleItem.sale = sale
            saleItem.quantity_purchased = s.quantity
            saleItem.sale_price = s.product.price
            saleItem.tax = round(s.product.price * Decimal(.075), 2)
            saleItem.shipping_cost = 10

            saleItem.save()

        payment = Payment()
        payment.sale = sale
        payment.stripe_token = stripe_token
        payment.amount = sale.total_cost
        payment.save()

        for s in cart_items:
            product = Product.objects.get(id=s.product.id)
            if hasattr(s.product, 'quantity'):
                product.quantity -= s.quantity
            elif hasattr(s.product, 'active'):
                product.active = False

            product.save()

        sale_id['value'] = sale.id
示例#7
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('product', '0001_initial'),
        ('auth', '0011_update_proxy_permissions'),
    ]

    operations = [
        migrations.CreateModel(
            name='User',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('password',
                 models.CharField(max_length=128, verbose_name='password')),
                ('last_login',
                 models.DateTimeField(blank=True,
                                      null=True,
                                      verbose_name='last login')),
                ('is_superuser',
                 models.BooleanField(
                     default=False,
                     help_text=
                     'Designates that this user has all permissions without explicitly assigning them.',
                     verbose_name='superuser status')),
                ('first_name',
                 models.CharField(blank=True,
                                  max_length=30,
                                  verbose_name='first name')),
                ('last_name',
                 models.CharField(blank=True,
                                  max_length=150,
                                  verbose_name='last name')),
                ('is_staff',
                 models.BooleanField(
                     default=False,
                     help_text=
                     'Designates whether the user can log into this admin site.',
                     verbose_name='staff status')),
                ('is_active',
                 models.BooleanField(
                     default=True,
                     help_text=
                     'Designates whether this user should be treated as active. Unselect this instead of deleting accounts.',
                     verbose_name='active')),
                ('date_joined',
                 models.DateTimeField(default=django.utils.timezone.now,
                                      verbose_name='date joined')),
                ('email',
                 models.EmailField(max_length=255,
                                   unique=True,
                                   verbose_name='email address')),
                ('phone',
                 models.DecimalField(decimal_places=0,
                                     max_digits=10,
                                     unique=True)),
                ('cart', models.ManyToManyField(to='product.Product')),
                ('groups',
                 models.ManyToManyField(
                     blank=True,
                     help_text=
                     'The groups this user belongs to. A user will get all permissions granted to each of their groups.',
                     related_name='user_set',
                     related_query_name='user',
                     to='auth.Group',
                     verbose_name='groups')),
                ('user_permissions',
                 models.ManyToManyField(
                     blank=True,
                     help_text='Specific permissions for this user.',
                     related_name='user_set',
                     related_query_name='user',
                     to='auth.Permission',
                     verbose_name='user permissions')),
            ],
            options={
                'verbose_name': 'User',
                'verbose_name_plural': 'Users',
            },
            managers=[
                ('objects', account.models.UserManager()),
            ],
        ),
    ]
示例#8
0
class Migration(migrations.Migration):

    dependencies = [
        ('socle', '0006_auto_20211006_2229'),
        ('account', '0017_auto_20220328_0857'),
    ]

    operations = [
        migrations.RemoveField(
            model_name='adhesion',
            name='children',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='chrono',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='date_end',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='date_start',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='file',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='levels',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='students',
        ),
        migrations.RemoveField(
            model_name='adhesion',
            name='user',
        ),
        migrations.AddField(
            model_name='adhesion',
            name='level',
            field=models.ForeignKey(
                blank=True,
                editable=False,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name='adhesions',
                to='socle.Level'),
        ),
        migrations.AddField(
            model_name='adhesion',
            name='start',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.AddField(
            model_name='adhesion',
            name='stop',
            field=models.DateTimeField(blank=True, editable=False, null=True),
        ),
        migrations.AddField(
            model_name='adhesion',
            name='student',
            field=models.ForeignKey(
                blank=True,
                editable=False,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name='adhesions',
                to='account.Student'),
        ),
        migrations.AlterField(
            model_name='adhesion',
            name='amount',
            field=models.DecimalField(decimal_places=2,
                                      editable=False,
                                      max_digits=6,
                                      verbose_name='Montant'),
        ),
        migrations.CreateModel(
            name='Facture',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('chrono',
                 models.CharField(editable=False,
                                  max_length=50,
                                  verbose_name='Chrono')),
                ('file',
                 models.FileField(blank=True,
                                  default='',
                                  editable=False,
                                  null=True,
                                  upload_to=account.models.file_directory_path,
                                  verbose_name='fichier')),
                ('chro',
                 models.CharField(blank=True,
                                  editable=False,
                                  max_length=50,
                                  null=True,
                                  verbose_name='Chrono')),
                ('adhesions',
                 models.ManyToManyField(blank=True,
                                        editable=False,
                                        related_name='factures',
                                        to='account.Adhesion')),
                ('user',
                 models.ForeignKey(blank=True,
                                   editable=False,
                                   null=True,
                                   on_delete=django.db.models.deletion.CASCADE,
                                   related_name='factures',
                                   to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
示例#9
0
class Payment(models.Model):
    sale = models.ForeignKey('Sales', null=True)
    stripe_token = models.TextField(blank=True, null=True)
    date = models.DateTimeField(auto_now=True, null=True)
    amount = models.DecimalField(max_digits=6, decimal_places=2)
示例#10
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Category',
            fields=[
                ('title', models.CharField(max_length=255, unique=True)),
                ('slug',
                 models.SlugField(max_length=255,
                                  primary_key=True,
                                  serialize=False)),
                ('parent',
                 models.ForeignKey(blank=True,
                                   null=True,
                                   on_delete=django.db.models.deletion.CASCADE,
                                   related_name='children',
                                   to='main.category')),
            ],
        ),
        migrations.CreateModel(
            name='Master',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('name', models.CharField(max_length=255, unique=True)),
                ('surname', models.CharField(max_length=255)),
            ],
        ),
        migrations.CreateModel(
            name='Place',
            fields=[
                ('title', models.CharField(max_length=255)),
                ('slug',
                 models.SlugField(max_length=255,
                                  primary_key=True,
                                  serialize=False)),
                ('price', models.DecimalField(decimal_places=2, max_digits=5)),
                ('categories', models.ManyToManyField(to='main.Category')),
                ('parent',
                 models.ForeignKey(blank=True,
                                   null=True,
                                   on_delete=django.db.models.deletion.CASCADE,
                                   related_name='children',
                                   to='main.place')),
            ],
        ),
        migrations.CreateModel(
            name='MasterImage',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('image',
                 models.ImageField(blank=True, null=True,
                                   upload_to='masters')),
                ('master',
                 models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                   related_name='images',
                                   to='main.master')),
            ],
        ),
        migrations.AddField(
            model_name='master',
            name='places',
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE, to='main.place'),
        ),
        migrations.CreateModel(
            name='Comment',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('text', models.CharField(max_length=100)),
                ('author',
                 models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                   to=settings.AUTH_USER_MODEL)),
                ('master',
                 models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                   to='main.master')),
            ],
        ),
        migrations.CreateModel(
            name='Application',
            fields=[
                ('id',
                 models.AutoField(auto_created=True,
                                  primary_key=True,
                                  serialize=False,
                                  verbose_name='ID')),
                ('time', models.DateTimeField()),
                ('master',
                 models.ForeignKey(on_delete=django.db.models.deletion.CASCADE,
                                   to='main.master')),
                ('user',
                 models.ForeignKey(default=account.models.User,
                                   on_delete=django.db.models.deletion.CASCADE,
                                   to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]
示例#11
0
class Migration(migrations.Migration):

    initial = True

    dependencies = [
        ('auth', '0009_alter_user_last_name_max_length'),
    ]

    operations = [
        migrations.CreateModel(
            name='Account',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('password', models.CharField(max_length=128, verbose_name='password')),
                ('last_login', models.DateTimeField(blank=True, null=True, verbose_name='last login')),
                ('uid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('datetime_updated', models.DateTimeField(null=True)),
                ('datetime_deleted', models.DateTimeField(null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('email', models.EmailField(max_length=150, unique=True)),
                ('name', models.CharField(max_length=150)),
                ('phone_number', models.CharField(blank=True, max_length=50, null=True)),
                ('is_superuser', models.BooleanField(default=False)),
                ('is_staff', models.BooleanField(default=False)),
                ('is_admin', models.BooleanField(default=False)),
                ('groups', models.ManyToManyField(blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', related_name='user_set', related_query_name='user', to='auth.Group', verbose_name='groups')),
            ],
            options={
                'verbose_name': 'account',
                'verbose_name_plural': 'accounts',
                'ordering': ['email'],
            },
            managers=[
                ('objects', account.models.UserManager()),
            ],
        ),
        migrations.CreateModel(
            name='Organization',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('datetime_updated', models.DateTimeField(null=True)),
                ('datetime_deleted', models.DateTimeField(null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('name', models.CharField(max_length=150)),
                ('short_name', models.CharField(max_length=20, unique=True)),
                ('timezone', models.CharField(default='Africa/Kigali', max_length=50)),
                ('logo_object_key', models.CharField(max_length=255, null=True)),
            ],
            options={
                'ordering': ['name'],
            },
        ),
        migrations.CreateModel(
            name='RealTimeAccount',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('datetime_updated', models.DateTimeField(null=True)),
                ('datetime_deleted', models.DateTimeField(null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('status', models.CharField(choices=[('healthy', 'healthy'), ('unhealthy', 'unhealthy'), ('pending', 'pending')], default='pending', max_length=50)),
                ('title', models.CharField(blank=True, max_length=100, null=True)),
                ('source', models.CharField(choices=[('collar', 'collar')], max_length=50)),
                ('provider', models.CharField(choices=[('orbcomm', 'orbcomm'), ('savannah_tracking', 'savannah_tracking')], max_length=100)),
                ('type', models.CharField(max_length=100)),
                ('device_indexes', models.TextField(blank=True, null=True)),
                ('organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rt_accounts', to='account.Organization')),
            ],
            options={
                'ordering': ['-datetime_created'],
            },
        ),
        migrations.CreateModel(
            name='RealTimeIndividual',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('datetime_updated', models.DateTimeField(null=True)),
                ('datetime_deleted', models.DateTimeField(null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('device_id', models.CharField(max_length=100)),
                ('status', models.CharField(choices=[('active', 'active'), ('broken', 'broken'), ('inactive', 'inactive')], default='active', max_length=50)),
                ('name', models.CharField(blank=True, max_length=100, null=True)),
                ('subtype', models.CharField(blank=True, max_length=100, null=True)),
                ('sex', models.CharField(blank=True, choices=[('male', 'male'), ('female', 'female')], max_length=100, null=True)),
                ('blood_type', models.CharField(blank=True, choices=[('', '')], max_length=100, null=True)),
                ('call_sign', models.CharField(blank=True, max_length=100, null=True)),
                ('monthly_paths', models.TextField(blank=True, null=True)),
                ('last_position', django.contrib.gis.db.models.fields.PointField(null=True, srid=4326)),
                ('datetime_last_position', models.DateTimeField(null=True)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rt_individuals', to='account.RealTimeAccount')),
            ],
        ),
        migrations.CreateModel(
            name='RealTimePosition',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('uid', models.UUIDField(default=uuid.uuid4, editable=False, unique=True)),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('datetime_updated', models.DateTimeField(null=True)),
                ('datetime_deleted', models.DateTimeField(null=True)),
                ('is_active', models.BooleanField(default=True)),
                ('position', django.contrib.gis.db.models.fields.PointField(srid=4326)),
                ('datetime_recorded', models.DateTimeField(null=True)),
                ('temp_celcius', models.DecimalField(decimal_places=1, max_digits=5, null=True)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rt_positions', to='account.RealTimeAccount')),
                ('individual', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rt_positions', to='account.RealTimeIndividual')),
            ],
        ),
        migrations.CreateModel(
            name='RealTimePositionHash',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('datetime_created', models.DateTimeField(default=django.utils.timezone.now)),
                ('hash', models.CharField(max_length=255, unique=True)),
                ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='rt_hash_positions', to='account.RealTimeAccount')),
            ],
        ),
        migrations.AddField(
            model_name='account',
            name='organization',
            field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='accounts', to='account.Organization'),
        ),
        migrations.AddField(
            model_name='account',
            name='user_permissions',
            field=models.ManyToManyField(blank=True, help_text='Specific permissions for this user.', related_name='user_set', related_query_name='user', to='auth.Permission', verbose_name='user permissions'),
        ),
        migrations.AlterUniqueTogether(
            name='realtimeposition',
            unique_together={('individual', 'position', 'datetime_recorded')},
        ),
        migrations.AlterUniqueTogether(
            name='realtimeindividual',
            unique_together={('account', 'device_id')},
        ),
        migrations.AlterUniqueTogether(
            name='realtimeaccount',
            unique_together={('organization', 'source', 'provider', 'type')},
        ),
    ]