Skip to content
Snippets Groups Projects
Commit 3187e373 authored by Tom Teichler's avatar Tom Teichler :beers:
Browse files

Fixup models add create migration

parent 9dd077f4
No related branches found
No related tags found
No related merge requests found
Pipeline #58396 failed
# Generated by Django 3.2.12 on 2022-03-06 21:33
import aleksis.core.mixins
import django.contrib.sites.managers
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('sites', '0002_alter_domain_unique'),
('contenttypes', '0002_remove_content_type_name'),
]
operations = [
migrations.CreateModel(
name='Client',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extended_data', models.JSONField(default=dict, editable=False)),
('name', models.CharField(max_length=255, verbose_name='Name')),
('site', models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.site')),
],
managers=[
('objects', django.contrib.sites.managers.CurrentSiteManager()),
],
),
migrations.CreateModel(
name='InvoiceGroup',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('extended_data', models.JSONField(default=dict, editable=False)),
('name', models.CharField(max_length=255, verbose_name='Invoice group name')),
('template_name', models.CharField(blank=True, max_length=255, verbose_name='Template to render invoices with as PDF')),
('client', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoice_groups', to='tezor.client', verbose_name='Linked client')),
('site', models.ForeignKey(default=1, editable=False, on_delete=django.db.models.deletion.CASCADE, to='sites.site')),
],
managers=[
('objects', django.contrib.sites.managers.CurrentSiteManager()),
],
),
migrations.CreateModel(
name='Invoice',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('variant', models.CharField(max_length=255)),
('status', models.CharField(choices=[('waiting', 'Waiting for confirmation'), ('preauth', 'Pre-authorized'), ('confirmed', 'Confirmed'), ('rejected', 'Rejected'), ('refunded', 'Refunded'), ('error', 'Error'), ('input', 'Input')], default='waiting', max_length=10)),
('fraud_status', models.CharField(choices=[('unknown', 'Unknown'), ('accept', 'Passed'), ('reject', 'Rejected'), ('review', 'Review')], default='unknown', max_length=10, verbose_name='fraud check')),
('fraud_message', models.TextField(blank=True, default='')),
('created', models.DateTimeField(auto_now_add=True)),
('modified', models.DateTimeField(auto_now=True)),
('transaction_id', models.CharField(blank=True, max_length=255)),
('currency', models.CharField(max_length=10)),
('total', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('delivery', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('tax', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('description', models.TextField(blank=True, default='')),
('billing_first_name', models.CharField(blank=True, max_length=256)),
('billing_last_name', models.CharField(blank=True, max_length=256)),
('billing_address_1', models.CharField(blank=True, max_length=256)),
('billing_address_2', models.CharField(blank=True, max_length=256)),
('billing_city', models.CharField(blank=True, max_length=256)),
('billing_postcode', models.CharField(blank=True, max_length=256)),
('billing_country_code', models.CharField(blank=True, max_length=2)),
('billing_country_area', models.CharField(blank=True, max_length=256)),
('billing_email', models.EmailField(blank=True, max_length=254)),
('customer_ip_address', models.GenericIPAddressField(blank=True, null=True)),
('extra_data', models.TextField(blank=True, default='')),
('message', models.TextField(blank=True, default='')),
('token', models.CharField(blank=True, default='', max_length=36)),
('captured_amount', models.DecimalField(decimal_places=2, default='0.0', max_digits=9)),
('number', models.CharField(max_length=255, verbose_name='Invoice number')),
('for_object_id', models.PositiveIntegerField()),
('for_content_type', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to='contenttypes.contenttype')),
('group', models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='invoices', to='tezor.invoicegroup', verbose_name='Invoice group')),
],
bases=(models.Model, aleksis.core.mixins.PureDjangoModel),
),
migrations.AddConstraint(
model_name='invoicegroup',
constraint=models.UniqueConstraint(fields=('client', 'name'), name='group_uniq_per_client'),
),
migrations.AddConstraint(
model_name='invoice',
constraint=models.UniqueConstraint(fields=('transaction_id', 'group'), name='number_uniq_per_group'),
),
migrations.AddConstraint(
model_name='client',
constraint=models.UniqueConstraint(fields=('name', 'site'), name='uniq_client_per_site'),
),
]
......@@ -5,7 +5,7 @@ from aleksis.core.mixins import ExtensibleModel
class Client(ExtensibleModel):
name = models.CharField(verbose_name=_("Name"))
name = models.CharField(verbose_name=_("Name"), max_length=255)
class Meta:
constraints = [
......
......@@ -9,16 +9,16 @@ from payments.models import BasePayment
from aleksis.core.mixins import ExtensibleModel, PureDjangoModel
from .base import Client, Subject
from .base import Client
class InvoiceGroup(ExtensibleModel):
name = models.CharField(verbose_name=_("Invoice group name"), max_length=255)
client = models.ForeignKey(
Client, verbose_name=_("Linked client"), related_name="invoice_groups"
Client, verbose_name=_("Linked client"), related_name="invoice_groups", on_delete=models.SET_NULL, null=True
)
template_name = models.CharField(verbose_name=_("Template to render invoices with as PDF"), blank=True)
template_name = models.CharField(verbose_name=_("Template to render invoices with as PDF"), blank=True, max_length=255)
class Meta:
constraints = [
......@@ -28,12 +28,14 @@ class InvoiceGroup(ExtensibleModel):
class Invoice(BasePayment, PureDjangoModel):
group = models.ForeignKey(
InvoiceGroup, verbose_name=_("Invoice group"), related_name="invoices"
InvoiceGroup, verbose_name=_("Invoice group"), related_name="invoices", on_delete=models.SET_NULL, null=True
)
for_content_type = models.ForeignKey(ContetType, on_delete=models.SET_NULL)
number = models.CharField(verbose_name=_("Invoice number"), max_length=255)
for_content_type = models.ForeignKey(ContentType, on_delete=models.SET_NULL, null=True)
for_object_id = models.PositiveIntegerField()
for_object = GenericForeignKey("content_type", "object_id")
for_object = GenericForeignKey("for_content_type", "for_object_id")
def get_purchased_items(self):
return self.for_object.get_purchased_items()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment