Skip to content

Commit

Permalink
add order status
Browse files Browse the repository at this point in the history
  • Loading branch information
nicokant committed Jun 19, 2024
1 parent 37d7e32 commit 50e0264
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Generated by Django 5.0.6 on 2024-06-19 15:07

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("genlab_bestilling", "0005_alter_project_species"),
]

operations = [
migrations.AddField(
model_name="order",
name="status",
field=models.CharField(
choices=[("draft", "Draft"), ("confirmed", "Confirmed")],
default="draft",
),
),
migrations.AlterField(
model_name="order",
name="project",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
to="genlab_bestilling.project",
),
),
migrations.AlterField(
model_name="sample",
name="order",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="samples",
to="genlab_bestilling.analysisorder",
),
),
]
28 changes: 28 additions & 0 deletions src/genlab_bestilling/migrations/0007_alter_order_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 5.0.6 on 2024-06-19 15:11

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"genlab_bestilling",
"0006_order_status_alter_order_project_alter_sample_order",
),
]

operations = [
migrations.AlterField(
model_name="order",
name="status",
field=models.CharField(
choices=[
("draft", "Draft"),
("confirmed", "Confirmed"),
("processing", "Processing"),
("completed", "Completed"),
],
default="draft",
),
),
]
7 changes: 7 additions & 0 deletions src/genlab_bestilling/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,20 @@ def get_absolute_url(self):


class Order(PolymorphicModel):
class OrderStatus(models.TextChoices):
DRAFT = "draft", _("Draft")
CONFIRMED = "confirmed", _("Confirmed")
PROCESSING = "processing", _("Processing")
COMPLETED = "completed", _("Completed")

name = models.CharField(null=True, blank=True)
project = models.ForeignKey(
"Project", on_delete=models.CASCADE, related_name="orders"
)
species = models.ManyToManyField("Species")
sample_types = models.ManyToManyField("SampleType")
notes = models.TextField(blank=True, null=True)
status = models.CharField(default=OrderStatus.DRAFT, choices=OrderStatus)

tags = TaggableManager(blank=True)

Expand Down
26 changes: 24 additions & 2 deletions src/genlab_bestilling/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@ class ProjectCreateView(FormsetCreateView):


class ProjectNestedMixin(LoginRequiredMixin):
"""
Provide a Mixin to simplify views that operates under /projects/<id>/
By default loads the project from the database,
filter the current queryset using the project
and adds it to the render context.
"""

project_id_accessor = "project_id"

def get_project(self):
Expand Down Expand Up @@ -129,6 +137,9 @@ class EquipmentOrderEditView(
model = EquipmentOrder
form_class = EquipmentOrderForm

def get_queryset(self) -> QuerySet[Any]:
return super().get_queryset().filter(status=Order.OrderStatus.DRAFT)

def get_success_url(self):
return reverse(
"project-order-detail",
Expand Down Expand Up @@ -157,6 +168,9 @@ class AnalysisOrderEditView(
model = AnalysisOrder
form_class = AnalysisOrderForm

def get_queryset(self) -> QuerySet[Any]:
return super().get_queryset().filter(status=Order.OrderStatus.DRAFT)

def get_success_url(self):
return reverse(
"project-analysis-detail",
Expand Down Expand Up @@ -185,7 +199,11 @@ class EquipmentOrderQuantityUpdateView(ProjectNestedMixin, BulkEditCollectionVie
project_id_accessor = "order__project_id"

def get_queryset(self) -> QuerySet[Any]:
return super().get_queryset().filter(order_id=self.kwargs["pk"])
return (
super()
.get_queryset()
.filter(order_id=self.kwargs["pk"], status=Order.OrderStatus.DRAFT)
)

def get_collection_kwargs(self):
kwargs = super().get_collection_kwargs()
Expand Down Expand Up @@ -214,7 +232,11 @@ class SamplesUpdateView(ProjectNestedMixin, BulkEditCollectionView):
project_id_accessor = "order__project_id"

def get_queryset(self) -> QuerySet[Any]:
return super().get_queryset().filter(order_id=self.kwargs["pk"])
return (
super()
.get_queryset()
.filter(order_id=self.kwargs["pk"], status=Order.OrderStatus.DRAFT)
)

def get_collection_kwargs(self):
kwargs = super().get_collection_kwargs()
Expand Down

0 comments on commit 50e0264

Please sign in to comment.