2023-12-04 16:12:39 +00:00
|
|
|
from django.db import models
|
2023-12-07 17:10:04 +00:00
|
|
|
from django.urls import reverse_lazy
|
|
|
|
from django.utils.translation import gettext_lazy as _
|
|
|
|
from oidc4vp.models import Authorization
|
2023-12-04 16:12:39 +00:00
|
|
|
|
2023-12-07 17:10:04 +00:00
|
|
|
|
|
|
|
class Promotion(models.Model):
|
|
|
|
class Types(models.IntegerChoices):
|
|
|
|
VULNERABLE = 1, _("Financial vulnerability")
|
|
|
|
|
|
|
|
name = models.CharField(max_length=250)
|
|
|
|
discount = models.PositiveSmallIntegerField(
|
|
|
|
choices=Types.choices,
|
|
|
|
)
|
|
|
|
authorize = models.ForeignKey(
|
|
|
|
Authorization,
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
related_name='promotions',
|
|
|
|
null=True,
|
|
|
|
)
|
|
|
|
|
|
|
|
def get_url(self, code):
|
|
|
|
url = "{}?code={}".format(
|
2023-12-11 11:11:18 +00:00
|
|
|
reverse_lazy("promotion:contract"),
|
2023-12-07 17:10:04 +00:00
|
|
|
code
|
2023-12-11 11:11:18 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
def get_discount(self, price):
|
2023-12-11 13:07:59 +00:00
|
|
|
return price - price*0.25
|
|
|
|
|