2018-07-21 22:16:05 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# Generated by Django 1.10.7 on 2018-07-21 20:01
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.db import migrations, models
|
|
|
|
import django.db.models.deletion
|
2018-07-26 08:11:53 +00:00
|
|
|
from django.contrib.auth.management import create_permissions
|
2018-07-21 22:16:05 +00:00
|
|
|
import re2o.field_permissions
|
|
|
|
import re2o.mixins
|
|
|
|
|
|
|
|
|
|
|
|
def reattribute_ids(apps, schema_editor):
|
2019-11-04 16:55:03 +00:00
|
|
|
Facture = apps.get_model("cotisations", "Facture")
|
|
|
|
BaseInvoice = apps.get_model("cotisations", "BaseInvoice")
|
2018-07-21 22:16:05 +00:00
|
|
|
|
|
|
|
for f in Facture.objects.all():
|
2018-08-25 09:10:18 +00:00
|
|
|
base = BaseInvoice.objects.create(id=f.pk)
|
|
|
|
base.date = f.date
|
|
|
|
base.save()
|
2018-07-21 22:16:05 +00:00
|
|
|
f.baseinvoice_ptr = base
|
|
|
|
f.save()
|
|
|
|
|
2018-07-26 08:11:53 +00:00
|
|
|
|
|
|
|
def update_rights(apps, schema_editor):
|
2019-11-04 16:55:03 +00:00
|
|
|
Permission = apps.get_model("auth", "Permission")
|
2018-07-26 08:11:53 +00:00
|
|
|
|
|
|
|
# creates needed permissions
|
2019-11-04 16:55:03 +00:00
|
|
|
app = apps.get_app_config("cotisations")
|
2018-07-26 08:11:53 +00:00
|
|
|
app.models_module = True
|
|
|
|
create_permissions(app)
|
|
|
|
app.models_module = False
|
|
|
|
|
2018-09-19 08:06:09 +00:00
|
|
|
ContentType = apps.get_model("contenttypes", "ContentType")
|
|
|
|
content_type = ContentType.objects.get_for_model(Permission)
|
2019-11-04 16:55:03 +00:00
|
|
|
former, created = Permission.objects.get_or_create(
|
|
|
|
codename="change_facture_pdf", content_type=content_type
|
|
|
|
)
|
|
|
|
new_1 = Permission.objects.get(codename="add_custominvoice")
|
|
|
|
new_2 = Permission.objects.get(codename="change_custominvoice")
|
|
|
|
new_3 = Permission.objects.get(codename="view_custominvoice")
|
|
|
|
new_4 = Permission.objects.get(codename="delete_custominvoice")
|
2018-07-26 08:11:53 +00:00
|
|
|
for group in former.group_set.all():
|
|
|
|
group.permissions.remove(former)
|
|
|
|
group.permissions.add(new_1)
|
|
|
|
group.permissions.add(new_2)
|
|
|
|
group.permissions.add(new_3)
|
|
|
|
group.permissions.add(new_4)
|
|
|
|
group.save()
|
|
|
|
|
|
|
|
|
2018-07-21 22:16:05 +00:00
|
|
|
class Migration(migrations.Migration):
|
|
|
|
|
2019-11-04 16:55:03 +00:00
|
|
|
dependencies = [("cotisations", "0031_comnpaypayment_production")]
|
2018-07-21 22:16:05 +00:00
|
|
|
|
|
|
|
operations = [
|
|
|
|
migrations.CreateModel(
|
2019-11-04 16:55:03 +00:00
|
|
|
name="BaseInvoice",
|
2018-07-21 22:16:05 +00:00
|
|
|
fields=[
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
"id",
|
|
|
|
models.AutoField(
|
|
|
|
auto_created=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
verbose_name="ID",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
("date", models.DateTimeField(auto_now_add=True, verbose_name="Date")),
|
2018-07-21 22:16:05 +00:00
|
|
|
],
|
2019-11-04 16:55:03 +00:00
|
|
|
bases=(
|
|
|
|
re2o.mixins.RevMixin,
|
|
|
|
re2o.mixins.AclMixin,
|
|
|
|
re2o.field_permissions.FieldPermissionModelMixin,
|
|
|
|
models.Model,
|
|
|
|
),
|
2018-07-21 22:16:05 +00:00
|
|
|
),
|
|
|
|
migrations.CreateModel(
|
2019-11-04 16:55:03 +00:00
|
|
|
name="CustomInvoice",
|
2018-07-21 22:16:05 +00:00
|
|
|
fields=[
|
2019-11-04 16:55:03 +00:00
|
|
|
(
|
|
|
|
"baseinvoice_ptr",
|
|
|
|
models.OneToOneField(
|
|
|
|
auto_created=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
parent_link=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
to="cotisations.BaseInvoice",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"recipient",
|
|
|
|
models.CharField(max_length=255, verbose_name="Recipient"),
|
|
|
|
),
|
|
|
|
(
|
|
|
|
"payment",
|
|
|
|
models.CharField(max_length=255, verbose_name="Payment type"),
|
|
|
|
),
|
|
|
|
("address", models.CharField(max_length=255, verbose_name="Address")),
|
|
|
|
("paid", models.BooleanField(verbose_name="Paid")),
|
2018-07-21 22:16:05 +00:00
|
|
|
],
|
2019-11-04 16:55:03 +00:00
|
|
|
bases=("cotisations.baseinvoice",),
|
|
|
|
options={
|
|
|
|
"permissions": (("view_custominvoice", "Can view a custom invoice"),)
|
|
|
|
},
|
2018-07-21 22:16:05 +00:00
|
|
|
),
|
|
|
|
migrations.AddField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="facture",
|
|
|
|
name="baseinvoice_ptr",
|
|
|
|
field=models.OneToOneField(
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
to="cotisations.BaseInvoice",
|
|
|
|
null=True,
|
|
|
|
),
|
2018-07-21 22:16:05 +00:00
|
|
|
preserve_default=False,
|
|
|
|
),
|
|
|
|
migrations.RunPython(reattribute_ids),
|
|
|
|
migrations.AlterField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="vente",
|
|
|
|
name="facture",
|
|
|
|
field=models.ForeignKey(
|
|
|
|
on_delete=models.CASCADE,
|
|
|
|
verbose_name="Invoice",
|
|
|
|
to="cotisations.BaseInvoice",
|
|
|
|
),
|
2018-07-21 22:16:05 +00:00
|
|
|
),
|
2019-11-04 16:55:03 +00:00
|
|
|
migrations.RemoveField(model_name="facture", name="id"),
|
|
|
|
migrations.RemoveField(model_name="facture", name="date"),
|
2018-07-21 22:16:05 +00:00
|
|
|
migrations.AlterField(
|
2019-11-04 16:55:03 +00:00
|
|
|
model_name="facture",
|
|
|
|
name="baseinvoice_ptr",
|
|
|
|
field=models.OneToOneField(
|
|
|
|
auto_created=True,
|
|
|
|
on_delete=django.db.models.deletion.CASCADE,
|
|
|
|
parent_link=True,
|
|
|
|
primary_key=True,
|
|
|
|
serialize=False,
|
|
|
|
to="cotisations.BaseInvoice",
|
|
|
|
),
|
2018-07-26 08:11:53 +00:00
|
|
|
),
|
|
|
|
migrations.RunPython(update_rights),
|
|
|
|
migrations.AlterModelOptions(
|
2019-11-04 16:55:03 +00:00
|
|
|
name="facture",
|
|
|
|
options={
|
|
|
|
"permissions": (
|
|
|
|
("change_facture_control", 'Can change the "controlled" state'),
|
|
|
|
("view_facture", "Can see an invoice's details"),
|
|
|
|
("change_all_facture", "Can edit all the previous invoices"),
|
|
|
|
),
|
|
|
|
"verbose_name": "Invoice",
|
|
|
|
"verbose_name_plural": "Invoices",
|
|
|
|
},
|
2018-07-26 08:11:53 +00:00
|
|
|
),
|
2018-07-21 22:16:05 +00:00
|
|
|
]
|