invoicing: Invoice models (#71528)
This commit is contained in:
parent
452093fd50
commit
ecb8c5adf3
|
@ -0,0 +1,124 @@
|
|||
import django.contrib.postgres.fields.jsonb
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('invoicing', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Invoice',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
('label', models.CharField(max_length=300, verbose_name='Label')),
|
||||
('total_amount', models.DecimalField(decimal_places=2, max_digits=9, default=0)),
|
||||
('date_issue', models.DateField(verbose_name='Issue date')),
|
||||
('payer', models.CharField(max_length=300, verbose_name='Payer')),
|
||||
(
|
||||
'regie',
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to='invoicing.Regie',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='InvoiceLine',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
('slug', models.SlugField(max_length=250)),
|
||||
('label', models.CharField(max_length=260)),
|
||||
('quantity', models.FloatField()),
|
||||
('unit_amount', models.DecimalField(decimal_places=2, max_digits=9)),
|
||||
('total_amount', models.DecimalField(decimal_places=2, max_digits=9)),
|
||||
('user_external_id', models.CharField(max_length=250)),
|
||||
('payer_external_id', models.CharField(max_length=250)),
|
||||
('event', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
|
||||
('pricing_data', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
|
||||
(
|
||||
'status',
|
||||
models.CharField(choices=[('success', 'Success'), ('error', 'Error')], max_length=10),
|
||||
),
|
||||
(
|
||||
'invoice',
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to='invoicing.Invoice',
|
||||
related_name='lines',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DraftInvoice',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
('label', models.CharField(max_length=300, verbose_name='Label')),
|
||||
('total_amount', models.DecimalField(decimal_places=2, max_digits=9, default=0)),
|
||||
('date_issue', models.DateField(verbose_name='Issue date')),
|
||||
('payer', models.CharField(max_length=300, verbose_name='Payer')),
|
||||
(
|
||||
'regie',
|
||||
models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='invoicing.Regie'),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='DraftInvoiceLine',
|
||||
fields=[
|
||||
(
|
||||
'id',
|
||||
models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
|
||||
),
|
||||
('slug', models.SlugField(max_length=250)),
|
||||
('label', models.CharField(max_length=260)),
|
||||
('quantity', models.FloatField()),
|
||||
('unit_amount', models.DecimalField(decimal_places=2, max_digits=9)),
|
||||
('total_amount', models.DecimalField(decimal_places=2, max_digits=9)),
|
||||
('user_external_id', models.CharField(max_length=250)),
|
||||
('payer_external_id', models.CharField(max_length=250)),
|
||||
('event', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
|
||||
('pricing_data', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
|
||||
(
|
||||
'status',
|
||||
models.CharField(choices=[('success', 'Success'), ('error', 'Error')], max_length=10),
|
||||
),
|
||||
(
|
||||
'invoice',
|
||||
models.ForeignKey(
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.PROTECT,
|
||||
to='invoicing.DraftInvoice',
|
||||
related_name='lines',
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
'abstract': False,
|
||||
},
|
||||
),
|
||||
]
|
|
@ -17,6 +17,7 @@
|
|||
import copy
|
||||
|
||||
from django.contrib.auth.models import Group
|
||||
from django.contrib.postgres.fields import JSONField
|
||||
from django.db import models
|
||||
from django.utils.text import slugify
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
@ -84,3 +85,55 @@ class Regie(models.Model):
|
|||
|
||||
regie, created = cls.objects.update_or_create(slug=data['slug'], defaults=data)
|
||||
return created, regie
|
||||
|
||||
|
||||
class AbstractInvoice(models.Model):
|
||||
label = models.CharField(_('Label'), max_length=300)
|
||||
total_amount = models.DecimalField(
|
||||
max_digits=9, decimal_places=2, default=0
|
||||
) # XXX PG trigger to maintain this ?
|
||||
date_issue = models.DateField(_('Issue date'))
|
||||
regie = models.ForeignKey(Regie, on_delete=models.PROTECT)
|
||||
payer = models.CharField(_('Payer'), max_length=300)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class DraftInvoice(AbstractInvoice):
|
||||
pass
|
||||
|
||||
|
||||
class Invoice(AbstractInvoice):
|
||||
pass
|
||||
|
||||
|
||||
class AbstractInvoiceLine(models.Model):
|
||||
slug = models.SlugField(max_length=250)
|
||||
label = models.CharField(max_length=260)
|
||||
quantity = models.FloatField()
|
||||
unit_amount = models.DecimalField(max_digits=9, decimal_places=2)
|
||||
total_amount = models.DecimalField(max_digits=9, decimal_places=2)
|
||||
|
||||
user_external_id = models.CharField(max_length=250)
|
||||
payer_external_id = models.CharField(max_length=250)
|
||||
event = JSONField(default=dict)
|
||||
pricing_data = JSONField(default=dict)
|
||||
status = models.CharField(
|
||||
max_length=10,
|
||||
choices=[
|
||||
('success', _('Success')),
|
||||
('error', _('Error')),
|
||||
],
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class DraftInvoiceLine(AbstractInvoiceLine):
|
||||
invoice = models.ForeignKey(DraftInvoice, on_delete=models.PROTECT, null=True, related_name='lines')
|
||||
|
||||
|
||||
class InvoiceLine(AbstractInvoiceLine):
|
||||
invoice = models.ForeignKey(Invoice, on_delete=models.PROTECT, null=True, related_name='lines')
|
||||
|
|
Loading…
Reference in New Issue