8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-23 23:43:47 +00:00
This commit is contained in:
Hugo Levy-Falk 2019-10-02 23:42:54 +02:00 committed by chirac
parent c260d3889e
commit c76f32cf26
4 changed files with 48 additions and 4 deletions

View file

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.23 on 2019-10-02 21:35
from __future__ import unicode_literals
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('cotisations', '0039_freepayment'),
]
operations = [
migrations.AddField(
model_name='article',
name='duration_days',
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration (in days, will be added to duration in months)'),
),
migrations.AddField(
model_name='vente',
name='duration_days',
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration (in days, will be added to duration in months)'),
),
]

View file

@ -460,6 +460,12 @@ class Vente(RevMixin, AclMixin, models.Model):
null=True,
verbose_name=_("duration (in months)")
)
duration_days = models.PositiveIntegerField(
blank=True,
null=True,
validators=[MinValueValidator(0)],
verbose_name=_("duration (in days, will be added to duration in months)")
)
# TODO : this field is not needed if you use Article ForeignKey
type_cotisation = models.CharField(
choices=COTISATION_TYPE,
@ -492,7 +498,9 @@ class Vente(RevMixin, AclMixin, models.Model):
if hasattr(self, 'cotisation'):
cotisation = self.cotisation
cotisation.date_end = cotisation.date_start + relativedelta(
months=self.duration*self.number)
months=(self.duration or 0)*self.number,
days=(self.duration_days or 0)*self.number,
)
return
def create_cotis(self, date_start=False):
@ -529,7 +537,8 @@ class Vente(RevMixin, AclMixin, models.Model):
date_max = max(end_cotisation, date_start)
cotisation.date_start = date_max
cotisation.date_end = cotisation.date_start + relativedelta(
months=self.duration*self.number
months=(self.duration or 0)*self.number,
days=(self.duration_days or 0)*self.number,
)
return
@ -540,7 +549,7 @@ class Vente(RevMixin, AclMixin, models.Model):
effect on the user's cotisation
"""
# Checking that if a cotisation is specified, there is also a duration
if self.type_cotisation and not self.duration:
if self.type_cotisation and not (self.duration or self.duration_days):
raise ValidationError(
_("Duration must be specified for a subscription.")
)
@ -695,6 +704,12 @@ class Article(RevMixin, AclMixin, models.Model):
validators=[MinValueValidator(0)],
verbose_name=_("duration (in months)")
)
duration_days = models.PositiveIntegerField(
blank=True,
null=True,
validators=[MinValueValidator(0)],
verbose_name=_("duration (in days, will be added to duration in months)")
)
type_user = models.CharField(
choices=USER_TYPES,
default='All',
@ -729,7 +744,7 @@ class Article(RevMixin, AclMixin, models.Model):
raise ValidationError(
_("Balance is a reserved article name.")
)
if self.type_cotisation and not self.duration:
if self.type_cotisation and not (self.duration or self.duration_days):
raise ValidationError(
_("Duration must be specified for a subscription.")
)

View file

@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<th>{% trans "Price" %}</th>
<th>{% trans "Subscription type" %}</th>
<th>{% trans "Duration (in months)" %}</th>
<th>{% trans "Duration (in days)" %}</th>
<th>{% trans "Concerned users" %}</th>
<th>{% trans "Available for everyone" %}</th>
<th></th>
@ -45,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
<td>{{ article.prix }}</td>
<td>{{ article.type_cotisation }}</td>
<td>{{ article.duration }}</td>
<td>{{ article.duration_days }}</td>
<td>{{ article.type_user }}</td>
<td>{{ article.available_for_everyone | tick }}</td>
<td class="text-right">

View file

@ -139,6 +139,7 @@ def new_facture(request, user, userid):
prix=article.prix,
type_cotisation=article.type_cotisation,
duration=article.duration,
duration_days=article.duration_days,
number=quantity
)
purchases.append(new_purchase)