mirror of https://gitlab.federez.net/re2o/re2o
Browse Source
changes: Article: remove COTISATION_TYPE, duration(_days), type_cotisation add duration(_days)_connection, duration(_days)_membership Vente: remove COTISATION_TYPE, duration(_days), type_cotisation add duration(_days)_connection, duration(_days)_membership add method `test_membership_or_connection()` to replace `bool(type_cotisation)` Cotisation: remove COTISATION_TYPE, date_start, date_end, type_cotisation add date_start_con, date_end_con, date_start_memb, date_end_memb create_cotis(date_start=False) -> create_cotis(date_start_con=False, date_start_memb=False) + migration + changes to use the new models in the remaining of the codearticle-diff-connexion-adhesion^2
11 changed files with 641 additions and 174 deletions
@ -0,0 +1,117 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.11.29 on 2020-09-20 17:19 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
import django.core.validators |
||||
|
from django.db import migrations, models |
||||
|
import django.utils.timezone |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('cotisations', '0042_auto_20191120_0159'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='duration', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='duration_days', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='date_end', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='date_start', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='duration', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='duration_days', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
migrations.AddField( |
||||
|
model_name='article', |
||||
|
name='duration_connection', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the connection (in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='article', |
||||
|
name='duration_days_connection', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the connection (in days, will be added to duration in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='article', |
||||
|
name='duration_days_membership', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the membership (in days, will be added to duration in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='article', |
||||
|
name='duration_membership', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the membership (in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='cotisation', |
||||
|
name='date_end_con', |
||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='end date for the connection'), |
||||
|
preserve_default=False, |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='cotisation', |
||||
|
name='date_end_memb', |
||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='end date for the membership'), |
||||
|
preserve_default=False, |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='cotisation', |
||||
|
name='date_start_con', |
||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='start date for the connection'), |
||||
|
preserve_default=False, |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='cotisation', |
||||
|
name='date_start_memb', |
||||
|
field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='start date for the membership'), |
||||
|
preserve_default=False, |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='vente', |
||||
|
name='duration_connection', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='duration of the connection (in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='vente', |
||||
|
name='duration_days_connection', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the connection (in days, will be added to duration in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='vente', |
||||
|
name='duration_days_membership', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the membership (in days, will be added to duration in months)'), |
||||
|
), |
||||
|
migrations.AddField( |
||||
|
model_name='vente', |
||||
|
name='duration_membership', |
||||
|
field=models.PositiveIntegerField(blank=True, null=True, verbose_name='duration of the membership (in months)'), |
||||
|
), |
||||
|
] |
||||
@ -0,0 +1,140 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.11.29 on 2020-09-20 17:19 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
import django.core.validators |
||||
|
from django.db import migrations, models |
||||
|
import django.utils.timezone |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('cotisations', '0043_separation_membership_connection_p1'), |
||||
|
] |
||||
|
|
||||
|
def split_dates(apps, schema_editor): |
||||
|
db_alias = schema_editor.connection.alias |
||||
|
cotisation = apps.get_model("cotisations", "Cotisation") |
||||
|
cotisations = cotisation.objects.using(db_alias).all() |
||||
|
for cotis in cotisations: |
||||
|
cotis.date_start_con = cotis.date_start |
||||
|
cotis.date_start_memb = cotis.date_start |
||||
|
cotis.date_end_con = cotis.date_end |
||||
|
cotis.date_end_memb = cotis.date_end |
||||
|
if cotis.type_cotisation == 'Connexion': |
||||
|
cotis.date_end_memb = cotis.date_start |
||||
|
if cotis.type_cotisation == 'Adhesion': |
||||
|
cotis.date_end_con = cotis.date_start |
||||
|
cotis.save() |
||||
|
|
||||
|
|
||||
|
|
||||
|
def split_duration_articles_and_ventes(apps, schema_editor): |
||||
|
def split_duration(e): |
||||
|
e.duration_membership = e.duration |
||||
|
e.duration_connection = e.duration |
||||
|
e.duration_days_membership = e.duration_days |
||||
|
e.duration_days_connection = e.duration_days |
||||
|
if e.type_cotisation == 'Connexion': |
||||
|
e.duration_membership = 0 |
||||
|
e.duration_days_membership = 0 |
||||
|
if e.type_cotisation == 'Adhesion': |
||||
|
e.duration_connection = 0 |
||||
|
e.duration_days_connection = 0 |
||||
|
e.save() |
||||
|
db_alias = schema_editor.connection.alias |
||||
|
article = apps.get_model("cotisations", "Article") |
||||
|
vente = apps.get_model("cotisations", "Vente") |
||||
|
for a in article.objects.using(db_alias).all(): |
||||
|
split_duration(a) |
||||
|
for v in vente.objects.using(db_alias).all(): |
||||
|
split_duration(v) |
||||
|
|
||||
|
def unsplit_dates(apps, schema_editor): |
||||
|
db_alias = schema_editor.connection.alias |
||||
|
cotisation = apps.get_model("cotisations", "Cotisation") |
||||
|
cotisations = cotisation.objects.using(db_alias).all() |
||||
|
for cotis in cotisations: |
||||
|
connection = cotis.date_start_con != cotis.date_end_con |
||||
|
adhesion = cotis.date_start_memb != cotis.date_end_memb |
||||
|
cotis.date_start = cotis.date_start_con |
||||
|
cotis.date_end = max(cotis.date_end_con, cotis.date_end_memb) |
||||
|
if connection: |
||||
|
cotis.type_cotisation = 'Connexion' |
||||
|
if adhesion: |
||||
|
cotis.type_cotisation = 'Adhesion' |
||||
|
if connection and adhesion: |
||||
|
cotis.type_cotisation = 'All' |
||||
|
if not (connection or adhesion): |
||||
|
cotis.type_cotisation = None |
||||
|
cotis.save() |
||||
|
|
||||
|
|
||||
|
|
||||
|
def unsplit_duration_articles_and_ventes(apps, schema_editor): |
||||
|
def unsplit_duration(e): |
||||
|
e.duration = max(e.duration_membership, e.duration_connection) |
||||
|
e.duration_days = max(e.duration_days_membership, e.duration_days_connection) |
||||
|
connection = not (((e.duration_connection == 0) or (e.duration_connection__isnull)) and \ |
||||
|
((e.duration_days_connection == 0) or (e.duration_days_connection__isnull))) |
||||
|
membership = not (((e.duration_membership == 0) or (e.duration_membership__isnull)) and \ |
||||
|
((e.duration_days_membership == 0) or (e.duration_days_membership__isnull))) |
||||
|
if connection: |
||||
|
e.type_cotisation = 'Connection' |
||||
|
if membership: |
||||
|
e.type_cotisation = 'Adhesion' |
||||
|
if connection and membership: |
||||
|
e.type_cotisation = 'All' |
||||
|
if not (connection or membership): |
||||
|
e.type_cotisation = None |
||||
|
e.save() |
||||
|
db_alias = schema_editor.connection.alias |
||||
|
article = apps.get_model("cotisations", "Article") |
||||
|
vente = apps.get_model("cotisations", "Vente") |
||||
|
for a in article.objects.using(db_alias).all(): |
||||
|
unsplit_duration(a) |
||||
|
for v in vente.objects.using(db_alias).all(): |
||||
|
unsplit_duration(v) |
||||
|
|
||||
|
|
||||
|
operations = [ |
||||
|
migrations.RunPython(split_dates, unsplit_dates), |
||||
|
migrations.RunPython(split_duration_articles_and_ventes, unsplit_duration_articles_and_ventes), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='duration', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='duration_days', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='article', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='date_end', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='date_start', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='cotisation', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='duration', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='duration_days', |
||||
|
# ), |
||||
|
# migrations.RemoveField( |
||||
|
# model_name='vente', |
||||
|
# name='type_cotisation', |
||||
|
# ), |
||||
|
] |
||||
@ -0,0 +1,53 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Generated by Django 1.11.29 on 2020-09-20 17:19 |
||||
|
from __future__ import unicode_literals |
||||
|
|
||||
|
import django.core.validators |
||||
|
from django.db import migrations, models |
||||
|
import django.utils.timezone |
||||
|
|
||||
|
|
||||
|
class Migration(migrations.Migration): |
||||
|
|
||||
|
dependencies = [ |
||||
|
('cotisations', '0044_separation_membership_connection_p2'), |
||||
|
] |
||||
|
|
||||
|
operations = [ |
||||
|
migrations.RemoveField( |
||||
|
model_name='article', |
||||
|
name='duration', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='article', |
||||
|
name='duration_days', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='article', |
||||
|
name='type_cotisation', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='cotisation', |
||||
|
name='date_end', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='cotisation', |
||||
|
name='date_start', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='cotisation', |
||||
|
name='type_cotisation', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='vente', |
||||
|
name='duration', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='vente', |
||||
|
name='duration_days', |
||||
|
), |
||||
|
migrations.RemoveField( |
||||
|
model_name='vente', |
||||
|
name='type_cotisation', |
||||
|
), |
||||
|
] |
||||
Loading…
Reference in new issue