Skip to content

Commit

Permalink
add product prijs & frequentie
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Jan 24, 2025
1 parent 7988492 commit 2b5c6fd
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.2.17 on 2025-01-24 16:16

from decimal import Decimal
import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("producten", "0002_alter_product_eind_datum_alter_product_start_datum"),
]

operations = [
migrations.AddField(
model_name="product",
name="frequentie",
field=models.CharField(
choices=[
("eenmalig", "Eenmalig"),
("maandelijks", "Maandelijks"),
("jaarlijks", "Jaarlijks"),
],
default="eenmalig",
help_text="Prijs frequentie.",
max_length=30,
verbose_name="Prijs frequentie",
),
preserve_default=False,
),
migrations.AddField(
model_name="product",
name="prijs",
field=models.DecimalField(
decimal_places=2,
default="1",
help_text="Het bedrag van de prijs optie.",
max_digits=8,
validators=[django.core.validators.MinValueValidator(Decimal("0.01"))],
verbose_name="bedrag",
),
preserve_default=False,
),
]
31 changes: 30 additions & 1 deletion src/open_producten/producten/models/product.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from django.core.validators import MinLengthValidator, RegexValidator, ValidationError
from decimal import Decimal

from django.core.validators import (
MinLengthValidator,
MinValueValidator,
RegexValidator,
ValidationError,
)
from django.db import models
from django.utils.translation import gettext_lazy as _

Expand All @@ -8,6 +15,13 @@
from .validators import validate_bsn


class PrijsFrequentieChoices(models.TextChoices):

EENMALIG = "eenmalig", _("Eenmalig")
MAANDELIJKS = "maandelijks", _("Maandelijks")
JAARLIJKS = "jaarlijks", _("Jaarlijks")


class Product(BasePublishableModel):
product_type = models.ForeignKey(
ProductType,
Expand Down Expand Up @@ -49,6 +63,21 @@ class Product(BasePublishableModel):
blank=True,
)

prijs = models.DecimalField(
verbose_name=_("bedrag"),
decimal_places=2,
max_digits=8,
validators=[MinValueValidator(Decimal("0.01"))],
help_text=_("Het bedrag van de prijs optie."),
)

frequentie = models.CharField(
_("Prijs frequentie"),
max_length=30,
choices=PrijsFrequentieChoices.choices,
help_text=_("Prijs frequentie."),
)

class Meta:
verbose_name = _("Product")
verbose_name_plural = _("Producten")
Expand Down
16 changes: 16 additions & 0 deletions src/open_producten/producten/tests/api/test_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def setUp(self):
"bsn": "111222333",
"start_datum": datetime.date(2024, 1, 2),
"eind_datum": datetime.date(2024, 12, 31),
"prijs": "20.20",
"frequentie": "eenmalig",
"data": [],
}
self.path = reverse("product-list")
Expand All @@ -46,6 +48,12 @@ def test_required_fields(self):
"product_type_id": [
ErrorDetail(string=_("This field is required."), code="required")
],
"prijs": [
ErrorDetail(string=_("This field is required."), code="required")
],
"frequentie": [
ErrorDetail(string=_("This field is required."), code="required")
],
},
)

Expand All @@ -63,6 +71,8 @@ def test_create_product(self):
"gepubliceerd": False,
"start_datum": str(product.start_datum),
"eind_datum": str(product.eind_datum),
"prijs": str(product.prijs),
"frequentie": product.frequentie,
"aanmaak_datum": product.aanmaak_datum.astimezone().isoformat(),
"update_datum": product.update_datum.astimezone().isoformat(),
"product_type": {
Expand Down Expand Up @@ -160,6 +170,8 @@ def test_read_producten(self):
"gepubliceerd": False,
"start_datum": None,
"eind_datum": None,
"prijs": str(product1.prijs),
"frequentie": product1.frequentie,
"aanmaak_datum": product1.aanmaak_datum.astimezone().isoformat(),
"update_datum": product1.update_datum.astimezone().isoformat(),
"product_type": {
Expand All @@ -181,6 +193,8 @@ def test_read_producten(self):
"gepubliceerd": False,
"start_datum": None,
"eind_datum": None,
"prijs": str(product2.prijs),
"frequentie": product2.frequentie,
"aanmaak_datum": product2.aanmaak_datum.astimezone().isoformat(),
"update_datum": product2.update_datum.astimezone().isoformat(),
"product_type": {
Expand Down Expand Up @@ -213,6 +227,8 @@ def test_read_product(self):
"gepubliceerd": False,
"start_datum": None,
"eind_datum": None,
"prijs": str(product.prijs),
"frequentie": product.frequentie,
"aanmaak_datum": "2025-12-31T01:00:00+01:00",
"update_datum": "2025-12-31T01:00:00+01:00",
"product_type": {
Expand Down
5 changes: 5 additions & 0 deletions src/open_producten/producten/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@

from ...producttypen.tests.factories import ProductTypeFactory
from ..models import Product
from ..models.product import PrijsFrequentieChoices


class ProductFactory(factory.django.DjangoModelFactory):
product_type = factory.SubFactory(ProductTypeFactory)
prijs = factory.fuzzy.FuzzyDecimal(1, 10)
frequentie = factory.fuzzy.FuzzyChoice(
[x[0] for x in PrijsFrequentieChoices.choices]
)

class Meta:
model = Product
4 changes: 3 additions & 1 deletion src/open_producten/producten/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
"product_type_id": "95792000-d57f-4d3a-b14c-c4c7aa964907",
"gepubliceerd": False,
"bsn": "111222333",
"prijs": "20.20",
"frequentie": "eenmalig"
},
request_only=True,
)
Expand All @@ -43,4 +45,4 @@ class ProductViewSet(OrderedModelViewSet):
lookup_url_field = "id"
serializer_class = ProductSerializer
filter_backends = [DjangoFilterBackend]
filterset_fields = ["gepubliceerd"]
filterset_fields = ["gepubliceerd", "frequentie"]
79 changes: 79 additions & 0 deletions src/producten-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ paths:
description: Deze lijst kan gefilterd wordt met query-string parameters.
summary: Alle PRODUCTEN opvragen.
parameters:
- in: query
name: frequentie
schema:
type: string
title: Prijs frequentie
enum:
- eenmalig
- jaarlijks
- maandelijks
description: |-
Prijs frequentie.
* `eenmalig` - Eenmalig
* `maandelijks` - Maandelijks
* `jaarlijks` - Jaarlijks
- in: query
name: gepubliceerd
schema:
Expand Down Expand Up @@ -85,6 +100,8 @@ paths:
product_type_id: 95792000-d57f-4d3a-b14c-c4c7aa964907
gepubliceerd: false
bsn: '111222333'
prijs: '20.20'
frequentie: eenmalig
summary: Create product
required: true
security:
Expand Down Expand Up @@ -325,6 +342,16 @@ components:
required:
- veld_a
- veld_b
FrequentieEnum:
enum:
- eenmalig
- maandelijks
- jaarlijks
type: string
description: |-
* `eenmalig` - Eenmalig
* `maandelijks` - Maandelijks
* `jaarlijks` - Jaarlijks
NestedProductType:
type: object
properties:
Expand Down Expand Up @@ -468,6 +495,22 @@ components:
pattern: ^[0-9]*$
maxLength: 8
minLength: 8
prijs:
type: string
format: decimal
pattern: ^-?\d{0,6}(?:\.\d{0,2})?$
title: Bedrag
description: Het bedrag van de prijs optie.
frequentie:
allOf:
- $ref: '#/components/schemas/FrequentieEnum'
title: Prijs frequentie
description: |-
Prijs frequentie.
* `eenmalig` - Eenmalig
* `maandelijks` - Maandelijks
* `jaarlijks` - Jaarlijks
Product:
type: object
properties:
Expand Down Expand Up @@ -517,9 +560,27 @@ components:
pattern: ^[0-9]*$
maxLength: 8
minLength: 8
prijs:
type: string
format: decimal
pattern: ^-?\d{0,6}(?:\.\d{0,2})?$
title: Bedrag
description: Het bedrag van de prijs optie.
frequentie:
allOf:
- $ref: '#/components/schemas/FrequentieEnum'
title: Prijs frequentie
description: |-
Prijs frequentie.
* `eenmalig` - Eenmalig
* `maandelijks` - Maandelijks
* `jaarlijks` - Jaarlijks
required:
- aanmaak_datum
- frequentie
- id
- prijs
- product_type
- update_datum
ProductRequest:
Expand Down Expand Up @@ -555,7 +616,25 @@ components:
pattern: ^[0-9]*$
maxLength: 8
minLength: 8
prijs:
type: string
format: decimal
pattern: ^-?\d{0,6}(?:\.\d{0,2})?$
title: Bedrag
description: Het bedrag van de prijs optie.
frequentie:
allOf:
- $ref: '#/components/schemas/FrequentieEnum'
title: Prijs frequentie
description: |-
Prijs frequentie.
* `eenmalig` - Eenmalig
* `maandelijks` - Maandelijks
* `jaarlijks` - Jaarlijks
required:
- frequentie
- prijs
- product_type_id
securitySchemes:
tokenAuth:
Expand Down

0 comments on commit 2b5c6fd

Please sign in to comment.