mirror of
https://github.com/daniviga/django-ram.git
synced 2025-08-04 21:27:49 +02:00
Improve docs management and add invoices repo (#51)
* Create a repository app for documents, first step * Step two (broken) * Complete the implementation of document repository and add invoices * Add support for invoices * Update submodules
This commit is contained in:
0
ram/repository/__init__.py
Normal file
0
ram/repository/__init__.py
Normal file
248
ram/repository/admin.py
Normal file
248
ram/repository/admin.py
Normal file
@@ -0,0 +1,248 @@
|
||||
from django.contrib import admin
|
||||
|
||||
from ram.admin import publish, unpublish
|
||||
from repository.models import (
|
||||
GenericDocument,
|
||||
InvoiceDocument,
|
||||
BookDocument,
|
||||
CatalogDocument,
|
||||
DecoderDocument,
|
||||
RollingStockDocument
|
||||
)
|
||||
|
||||
|
||||
@admin.register(GenericDocument)
|
||||
class GenericDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size", "creation_time", "updated_time")
|
||||
list_display = (
|
||||
"__str__",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
"tags",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Notes",
|
||||
{"classes": ("collapse",), "fields": ("notes",)},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
||||
|
||||
@admin.register(InvoiceDocument)
|
||||
class InvoiceDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size", "creation_time", "updated_time")
|
||||
list_display = (
|
||||
"__str__",
|
||||
"description",
|
||||
"date",
|
||||
"shop",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"rolling_stock__manufacturer__name",
|
||||
"rolling_stock__item_number",
|
||||
"book__title",
|
||||
"catalog__manufacturer__name",
|
||||
"shop__name",
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("rolling_stock", "book", "catalog", "shop")
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"rolling_stock",
|
||||
"book",
|
||||
"catalog",
|
||||
"description",
|
||||
"date",
|
||||
"shop",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
(
|
||||
"Notes",
|
||||
{"classes": ("collapse",), "fields": ("notes",)},
|
||||
),
|
||||
(
|
||||
"Audit",
|
||||
{
|
||||
"classes": ("collapse",),
|
||||
"fields": (
|
||||
"creation_time",
|
||||
"updated_time",
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@admin.register(BookDocument)
|
||||
class BookDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
list_display = (
|
||||
"__str__",
|
||||
"book",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"book__title",
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("book",)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"book",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
||||
|
||||
@admin.register(CatalogDocument)
|
||||
class CatalogDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
list_display = (
|
||||
"__str__",
|
||||
"catalog",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"catalog__title",
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("catalog",)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"catalog",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
||||
|
||||
@admin.register(DecoderDocument)
|
||||
class DecoderDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
list_display = (
|
||||
"__str__",
|
||||
"decoder",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"decoder__name",
|
||||
"decoder__manufacturer__name",
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("decoder",)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"decoder",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
||||
|
||||
|
||||
@admin.register(RollingStockDocument)
|
||||
class RollingStockDocumentAdmin(admin.ModelAdmin):
|
||||
readonly_fields = ("size",)
|
||||
list_display = (
|
||||
"__str__",
|
||||
"rolling_stock",
|
||||
"description",
|
||||
"private",
|
||||
"size",
|
||||
"download",
|
||||
)
|
||||
search_fields = (
|
||||
"rolling_stock__rolling_class__identifier",
|
||||
"rolling_stock__item_number",
|
||||
"description",
|
||||
"file",
|
||||
)
|
||||
autocomplete_fields = ("rolling_stock",)
|
||||
fieldsets = (
|
||||
(
|
||||
None,
|
||||
{
|
||||
"fields": (
|
||||
"private",
|
||||
"rolling_stock",
|
||||
"description",
|
||||
"file",
|
||||
"size",
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
actions = [publish, unpublish]
|
6
ram/repository/apps.py
Normal file
6
ram/repository/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class RepositoryConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "repository"
|
361
ram/repository/migrations/0001_initial.py
Normal file
361
ram/repository/migrations/0001_initial.py
Normal file
@@ -0,0 +1,361 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-09 13:04
|
||||
|
||||
import django.db.models.deletion
|
||||
import ram.utils
|
||||
import tinymce.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def migrate_document(apps, schema_editor):
|
||||
document = apps.get_model("metadata", "GenericDocument")
|
||||
document_new = apps.get_model("repository", "GenericDocument")
|
||||
for d in document.objects.all():
|
||||
n = document_new.objects.create(
|
||||
notes=d.notes,
|
||||
description=d.description,
|
||||
file=d.file,
|
||||
private=d.private,
|
||||
creation_time=d.creation_time,
|
||||
updated_time=d.updated_time,
|
||||
)
|
||||
for t in d.tags.all():
|
||||
n.tags.add(t)
|
||||
|
||||
|
||||
def migrate_decoder(apps, schema_editor):
|
||||
dcc_document = apps.get_model("metadata", "DecoderDocument")
|
||||
dcc_document_new = apps.get_model("repository", "DecoderDocument")
|
||||
for d in dcc_document.objects.all():
|
||||
dcc_document_new.objects.create(
|
||||
decoder=d.decoder,
|
||||
description=d.description,
|
||||
file=d.file,
|
||||
private=d.private,
|
||||
creation_time=d.creation_time,
|
||||
updated_time=d.updated_time,
|
||||
)
|
||||
|
||||
|
||||
def migrate_rollingstock(apps, schema_editor):
|
||||
rs_document = apps.get_model("roster", "RollingStockDocument")
|
||||
rs_document_new = apps.get_model("repository", "RollingStockDocument")
|
||||
for d in rs_document.objects.all():
|
||||
rs_document_new.objects.create(
|
||||
rolling_stock=d.rolling_stock,
|
||||
description=d.description,
|
||||
file=d.file,
|
||||
private=d.private,
|
||||
creation_time=d.creation_time,
|
||||
updated_time=d.updated_time,
|
||||
)
|
||||
|
||||
|
||||
def migrate_book(apps, schema_editor):
|
||||
book_document = apps.get_model("bookshelf", "BaseBookDocument")
|
||||
book_document_new = apps.get_model("repository", "BaseBookDocument")
|
||||
catalog_document_new = apps.get_model("repository", "CatalogDocument")
|
||||
for d in book_document.objects.all():
|
||||
if hasattr(d.book, "book"):
|
||||
book_document_new.objects.create(
|
||||
book=d.book.book,
|
||||
description=d.description,
|
||||
file=d.file,
|
||||
private=d.private,
|
||||
creation_time=d.creation_time,
|
||||
updated_time=d.updated_time,
|
||||
)
|
||||
else:
|
||||
catalog_document_new.objects.create(
|
||||
catalog=d.book.catalog,
|
||||
description=d.description,
|
||||
file=d.file,
|
||||
private=d.private,
|
||||
creation_time=d.creation_time,
|
||||
updated_time=d.updated_time,
|
||||
)
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0022_basebook_shop"),
|
||||
("metadata", "0023_shop"),
|
||||
("roster", "0035_alter_rollingstock_shop"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="BaseBookDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"book",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="new_document",
|
||||
to="bookshelf.basebook",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Documents",
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="BookDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
(
|
||||
"book",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="document",
|
||||
to="bookshelf.book",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Book documents",
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
fields=("book", "file"), name="unique_book_file"
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="CatalogDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
(
|
||||
"catalog",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="document",
|
||||
to="bookshelf.catalog",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Catalog documents",
|
||||
"constraints": [
|
||||
models.UniqueConstraint(
|
||||
fields=("catalog", "file"), name="unique_catalog_file"
|
||||
)
|
||||
],
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="GenericDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
("notes", tinymce.models.HTMLField(blank=True)),
|
||||
(
|
||||
"tags",
|
||||
models.ManyToManyField(
|
||||
blank=True, related_name="new_document", to="metadata.tag"
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Generic Documents",
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="RollingStockDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"rolling_stock",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="new_document",
|
||||
to="roster.rollingstock",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Documents",
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name="DecoderDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
(
|
||||
"file",
|
||||
models.FileField(
|
||||
storage=ram.utils.DeduplicatedStorage(), upload_to="files/"
|
||||
),
|
||||
),
|
||||
(
|
||||
"private",
|
||||
models.BooleanField(
|
||||
default=False,
|
||||
help_text="Document will be visible only to logged users",
|
||||
),
|
||||
),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
(
|
||||
"decoder",
|
||||
models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="new_document",
|
||||
to="metadata.decoder",
|
||||
),
|
||||
),
|
||||
],
|
||||
options={
|
||||
"verbose_name_plural": "Documents",
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_document,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_decoder,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_rollingstock,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
migrations.RunPython(
|
||||
migrate_book,
|
||||
reverse_code=migrations.RunPython.noop
|
||||
),
|
||||
]
|
@@ -0,0 +1,157 @@
|
||||
# Generated by Django 5.1.4 on 2025-02-09 23:10
|
||||
|
||||
import django.db.models.deletion
|
||||
import tinymce.models
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookshelf", "0023_delete_basebookdocument"),
|
||||
(
|
||||
"metadata",
|
||||
"0024_remove_genericdocument_tags_delete_decoderdocument_and_more",
|
||||
),
|
||||
("repository", "0001_initial"),
|
||||
("roster", "0036_delete_rollingstockdocument"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name="InvoiceDocument",
|
||||
fields=[
|
||||
(
|
||||
"id",
|
||||
models.BigAutoField(
|
||||
auto_created=True,
|
||||
primary_key=True,
|
||||
serialize=False,
|
||||
verbose_name="ID",
|
||||
),
|
||||
),
|
||||
("description", models.CharField(blank=True, max_length=128)),
|
||||
("creation_time", models.DateTimeField(auto_now_add=True)),
|
||||
("updated_time", models.DateTimeField(auto_now=True)),
|
||||
("private", models.BooleanField(default=True, editable=False)),
|
||||
("date", models.DateField()),
|
||||
("file", models.FileField(upload_to="files/invoices/")),
|
||||
("notes", tinymce.models.HTMLField(blank=True)),
|
||||
],
|
||||
options={
|
||||
"abstract": False,
|
||||
},
|
||||
),
|
||||
migrations.RemoveField(
|
||||
model_name="basebookdocument",
|
||||
name="book",
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="decoderdocument",
|
||||
options={},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="genericdocument",
|
||||
options={"verbose_name_plural": "Generic documents"},
|
||||
),
|
||||
migrations.AlterModelOptions(
|
||||
name="rollingstockdocument",
|
||||
options={},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="bookdocument",
|
||||
name="file",
|
||||
field=models.FileField(upload_to="files/"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="catalogdocument",
|
||||
name="file",
|
||||
field=models.FileField(upload_to="files/"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="decoderdocument",
|
||||
name="decoder",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="document",
|
||||
to="metadata.decoder",
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="decoderdocument",
|
||||
name="file",
|
||||
field=models.FileField(upload_to="files/"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="genericdocument",
|
||||
name="file",
|
||||
field=models.FileField(upload_to="files/"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="genericdocument",
|
||||
name="tags",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="document", to="metadata.tag"
|
||||
),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockdocument",
|
||||
name="file",
|
||||
field=models.FileField(upload_to="files/"),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name="rollingstockdocument",
|
||||
name="rolling_stock",
|
||||
field=models.ForeignKey(
|
||||
on_delete=django.db.models.deletion.CASCADE,
|
||||
related_name="document",
|
||||
to="roster.rollingstock",
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="decoderdocument",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("decoder", "file"), name="unique_decoder_file"
|
||||
),
|
||||
),
|
||||
migrations.AddConstraint(
|
||||
model_name="rollingstockdocument",
|
||||
constraint=models.UniqueConstraint(
|
||||
fields=("rolling_stock", "file"), name="unique_stock_file"
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="invoicedocument",
|
||||
name="book",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="bookshelf.book"
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="invoicedocument",
|
||||
name="catalog",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="bookshelf.catalog"
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="invoicedocument",
|
||||
name="rolling_stock",
|
||||
field=models.ManyToManyField(
|
||||
blank=True, related_name="invoice", to="roster.rollingstock"
|
||||
),
|
||||
),
|
||||
migrations.AddField(
|
||||
model_name="invoicedocument",
|
||||
name="shop",
|
||||
field=models.ForeignKey(
|
||||
blank=True,
|
||||
null=True,
|
||||
on_delete=django.db.models.deletion.SET_NULL,
|
||||
to="metadata.shop",
|
||||
),
|
||||
),
|
||||
migrations.DeleteModel(
|
||||
name="BaseBookDocument",
|
||||
),
|
||||
]
|
0
ram/repository/migrations/__init__.py
Normal file
0
ram/repository/migrations/__init__.py
Normal file
90
ram/repository/models.py
Normal file
90
ram/repository/models.py
Normal file
@@ -0,0 +1,90 @@
|
||||
from django.db import models
|
||||
from django.core.exceptions import ValidationError
|
||||
|
||||
from tinymce import models as tinymce
|
||||
|
||||
from ram.models import PrivateDocument
|
||||
from metadata.models import Decoder, Shop, Tag
|
||||
from roster.models import RollingStock
|
||||
from bookshelf.models import Book, Catalog
|
||||
|
||||
|
||||
class GenericDocument(PrivateDocument):
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
tags = models.ManyToManyField(Tag, blank=True, related_name="document")
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Generic documents"
|
||||
|
||||
|
||||
class InvoiceDocument(PrivateDocument):
|
||||
private = models.BooleanField(default=True, editable=False)
|
||||
rolling_stock = models.ManyToManyField(
|
||||
RollingStock, related_name="invoice", blank=True
|
||||
)
|
||||
book = models.ManyToManyField(Book, related_name="invoice", blank=True)
|
||||
catalog = models.ManyToManyField(
|
||||
Catalog, related_name="invoice", blank=True
|
||||
)
|
||||
date = models.DateField()
|
||||
shop = models.ForeignKey(
|
||||
Shop, on_delete=models.SET_NULL, null=True, blank=True
|
||||
)
|
||||
file = models.FileField(
|
||||
upload_to="files/invoices/",
|
||||
)
|
||||
notes = tinymce.HTMLField(blank=True)
|
||||
|
||||
|
||||
class DecoderDocument(PrivateDocument):
|
||||
decoder = models.ForeignKey(
|
||||
Decoder, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["decoder", "file"], name="unique_decoder_file"
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class BookDocument(PrivateDocument):
|
||||
book = models.ForeignKey(
|
||||
Book, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Book documents"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["book", "file"], name="unique_book_file"
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class CatalogDocument(PrivateDocument):
|
||||
catalog = models.ForeignKey(
|
||||
Catalog, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Catalog documents"
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["catalog", "file"], name="unique_catalog_file"
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
class RollingStockDocument(PrivateDocument):
|
||||
rolling_stock = models.ForeignKey(
|
||||
RollingStock, on_delete=models.CASCADE, related_name="document"
|
||||
)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["rolling_stock", "file"], name="unique_stock_file"
|
||||
)
|
||||
]
|
3
ram/repository/tests.py
Normal file
3
ram/repository/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
3
ram/repository/views.py
Normal file
3
ram/repository/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
Reference in New Issue
Block a user