Source code for ferrosoft.apps.ferrobase.views.material
# Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
from ferrosoft.apps.ferrobase.filter import MaterialFilterSet
from ferrosoft.apps.ferrobase.forms.copy import copy_form_factory
from ferrosoft.apps.ferrobase.models import Material
from ferrosoft.apps.ferrobase.views import generic
[docs]
class MaterialCreateView(generic.CreateView):
"""Create a material record (``code`` + ``name``)."""
fields = ["code", "name"]
help_topic = "materials"
model = Material
[docs]
class MaterialListView(generic.FilterView):
"""Filterable list of materials ordered by code."""
filterset_class = MaterialFilterSet
help_topic = "materials"
model = Material
ordering = "code"
[docs]
class MaterialUpdateView(generic.UpdateView):
"""Update a material; surfaces a Copy button via ``add_copy_action``."""
add_copy_action = True
fields = ["code", "name"]
help_topic = "materials"
model = Material
[docs]
class MaterialDeleteView(generic.DeleteView):
"""Delete a material, blocked when referenced by other records."""
help_topic = "materials"
model = Material
[docs]
class MaterialCopyView(generic.CopyView):
"""Create a new material seeded from an existing one's ``code`` + ``name``."""
form_class = copy_form_factory(
Material,
fields=["code", "name"],
)
model = Material
material_urls = generic.model_crud_routes(
Material,
create_view=MaterialCreateView,
read_view=MaterialListView,
update_view=MaterialUpdateView,
delete_view=MaterialDeleteView,
copy_view=MaterialCopyView,
)