summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-08-03 17:53:55 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-08-03 18:00:22 +0200
commitc328845dacc9f66fea624b26e06db20d764529be (patch)
treeff68e86facf98e4e278162d81af44189a715584a
parentb02f7994119b99a6a20cb2810f65f4e63b56082c (diff)
downloadIshtar-c328845dacc9f66fea624b26e06db20d764529be.tar.bz2
Ishtar-c328845dacc9f66fea624b26e06db20d764529be.zip
Preventive file: add fields - remove dynamic add (too buggy for now)
-rw-r--r--Makefile.example2
-rw-r--r--archaeological_files/admin.py2
-rw-r--r--archaeological_files/fixtures/initial_data-fr.json102
-rw-r--r--archaeological_files/forms.py13
-rw-r--r--archaeological_files/migrations/0106_auto_20210803_1730.py (renamed from archaeological_files/migrations/0106_auto_20210730_1749.py)57
-rw-r--r--archaeological_files/models.py42
-rw-r--r--archaeological_files/views.py3
7 files changed, 217 insertions, 4 deletions
diff --git a/Makefile.example b/Makefile.example
index f7f6b7b90..093ed7406 100644
--- a/Makefile.example
+++ b/Makefile.example
@@ -246,6 +246,8 @@ fixtures_files:
archaeological_files.genericequipmentservicetype \
archaeological_files.equipmentservicetype \
archaeological_files.equipmentservicecost \
+ archaeological_files.operationtypeforroyalties \
+ archaeological_files.agreementtype \
> '../archaeological_files/fixtures/initial_data-'$(default_data)'.json'
readme_md_to_rst:
diff --git a/archaeological_files/admin.py b/archaeological_files/admin.py
index a2834c498..433b521bc 100644
--- a/archaeological_files/admin.py
+++ b/archaeological_files/admin.py
@@ -74,6 +74,8 @@ general_models = [
models.FileType,
models.PermitType,
models.GenericEquipmentServiceType,
+ models.OperationTypeForRoyalties,
+ models.AgreementType
]
if settings.COUNTRY == "fr":
general_models.append(models.SaisineType)
diff --git a/archaeological_files/fixtures/initial_data-fr.json b/archaeological_files/fixtures/initial_data-fr.json
index 1bfd8d08c..4573e70ef 100644
--- a/archaeological_files/fixtures/initial_data-fr.json
+++ b/archaeological_files/fixtures/initial_data-fr.json
@@ -3000,5 +3000,107 @@
"cloture-mobile-de-chantier-par-panneaux-en-treilli"
]
}
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie simple > sup\u00e9rieure \u00e0 15 ha",
+ "txt_idx": "superieure-15-ha",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 1.0,
+ "increased_final_value": 0.36,
+ "category": 1
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie simple > comprise entre 3 et 15 ha",
+ "txt_idx": "comprise-entre-3-et-15-ha",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 1.5,
+ "increased_final_value": 0.54,
+ "category": 1
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie simple > inf\u00e9rieure \u00e0 3 ha",
+ "txt_idx": "inferieure-3-ha",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 2.7,
+ "increased_final_value": 0.97,
+ "category": 1
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie complexe > profondeur inf\u00e9rieure \u00e0 1,3 m",
+ "txt_idx": "profondeur-inferieure-13-m",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 2.7,
+ "increased_final_value": 0.97,
+ "category": 2
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie complexe > profondeur sup\u00e9rieure \u00e0 1,3 m",
+ "txt_idx": "profondeur-superieure-13-m",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 5.4,
+ "increased_final_value": 1.94,
+ "category": 3
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie complexe > occupations complexes Pal\u00e9o, N\u00e9o ou Proto",
+ "txt_idx": "occupations-complexes-paleo-neo-ou-proto",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 2.7,
+ "increased_final_value": 0.97,
+ "category": 4
+ }
+},
+{
+ "model": "archaeological_files.operationtypeforroyalties",
+ "fields": {
+ "label": "Stratigraphie complexe > \u00e9tude de b\u00e2ti",
+ "txt_idx": "etude-de-bati",
+ "comment": "",
+ "available": true,
+ "increase_coefficient": 2.7,
+ "increased_final_value": 0.97,
+ "category": 5
+ }
+},
+{
+ "model": "archaeological_files.agreementtype",
+ "fields": {
+ "label": "Demande anticip\u00e9e de r\u00e9alisation",
+ "txt_idx": "demande-anticipee-de-realisation",
+ "comment": "",
+ "available": true
+ }
+},
+{
+ "model": "archaeological_files.agreementtype",
+ "fields": {
+ "label": "Inscription normale du dossier",
+ "txt_idx": "inscription-normale-du-dossier",
+ "comment": "",
+ "available": true
+ }
}
]
diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py
index 77d19ce2f..46e0aae9c 100644
--- a/archaeological_files/forms.py
+++ b/archaeological_files/forms.py
@@ -518,6 +518,7 @@ class FileFormPreventiveDetail(forms.ModelForm, CustomForm, ManageOldType):
HEADERS = {
"start_date": FormHeader(_("Dates")),
"total_developed_surface": FormHeader(_("Surfaces")),
+ "type_of_agreement": FormHeader(_("Archaeological royalties")),
}
class Meta:
@@ -529,6 +530,8 @@ class FileFormPreventiveDetail(forms.ModelForm, CustomForm, ManageOldType):
"ground_end_date",
"study_period",
"execution_report_date",
+ "type_of_agreement",
+ "operation_type_for_royalties",
"total_developed_surface",
"total_surface",
"linear_meter",
@@ -594,6 +597,10 @@ class FileFormPreventiveDetail(forms.ModelForm, CustomForm, ManageOldType):
if kwargs.get("user", None):
self.user = kwargs.pop("user")
super(FileFormPreventiveDetail, self).__init__(*args, **kwargs)
+ if not models.AgreementType.objects.count():
+ self.fields.pop("type_of_agreement")
+ if not models.OperationTypeForRoyalties.objects.count():
+ self.fields.pop("operation_type_for_royalties")
class FileBaseFormset(forms.BaseModelFormSet):
@@ -704,7 +711,8 @@ PreventiveFileJobFormSet = formset_factory(
PreventiveFileJobFormSet.form_label = _("Post-excavation")
PreventiveFileJobFormSet.form_admin_name = _("Preventive file - 030 - Post-excavation")
PreventiveFileJobFormSet.form_slug = "preventive-030-post-excavation"
-PreventiveFileJobFormSet.dynamic_add = True
+PreventiveFileJobFormSet.extra = 2
+#PreventiveFileJobFormSet.dynamic_add = True
class PreventiveFileGroundJobForm(PreventiveFileGenJobForm):
@@ -723,13 +731,14 @@ PreventiveFileGroundJobFormSet = formset_factory(
PreventiveFileGroundJobForm,
formset=PreventiveFileGroundJobBaseFormSet,
can_delete=True,
+ extra=2
)
PreventiveFileGroundJobFormSet.form_label = _("Ground jobs")
PreventiveFileGroundJobFormSet.form_admin_name = _(
"Preventive file - 040 - Ground jobs"
)
PreventiveFileGroundJobFormSet.form_slug = "preventive-040-ground-jobs"
-PreventiveFileGroundJobFormSet.dynamic_add = True
+#PreventiveFileGroundJobFormSet.dynamic_add = True
COST_LABELS = {
"quantity_by_day_planned": _("Quantity"),
diff --git a/archaeological_files/migrations/0106_auto_20210730_1749.py b/archaeological_files/migrations/0106_auto_20210803_1730.py
index 8af41ba91..7f78e72fe 100644
--- a/archaeological_files/migrations/0106_auto_20210730_1749.py
+++ b/archaeological_files/migrations/0106_auto_20210803_1730.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
-# Generated by Django 1.11.28 on 2021-07-30 17:49
+# Generated by Django 1.11.28 on 2021-08-03 17:30
from __future__ import unicode_literals
import django.core.validators
@@ -17,6 +17,22 @@ class Migration(migrations.Migration):
operations = [
migrations.CreateModel(
+ name='AgreementType',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('label', models.TextField(verbose_name='Label')),
+ ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z', 32), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')),
+ ('comment', models.TextField(blank=True, default='', verbose_name='Comment')),
+ ('available', models.BooleanField(default=True, verbose_name='Available')),
+ ],
+ options={
+ 'verbose_name': 'Agreement type - France',
+ 'verbose_name_plural': 'Agreement types - France',
+ 'ordering': ('label',),
+ },
+ bases=(ishtar_common.models_common.Cached, models.Model),
+ ),
+ migrations.CreateModel(
name='EquipmentServiceCost',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
@@ -94,6 +110,25 @@ class Migration(migrations.Migration):
bases=(ishtar_common.models_common.Cached, models.Model),
),
migrations.CreateModel(
+ name='OperationTypeForRoyalties',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('label', models.TextField(verbose_name='Label')),
+ ('txt_idx', models.TextField(help_text='The slug is the standardized version of the name. It contains only lowercase letters, numbers and hyphens. Each slug must be unique.', unique=True, validators=[django.core.validators.RegexValidator(re.compile('^[-a-zA-Z0-9_]+\\Z', 32), "Enter a valid 'slug' consisting of letters, numbers, underscores or hyphens.", 'invalid')], verbose_name='Textual ID')),
+ ('comment', models.TextField(blank=True, default='', verbose_name='Comment')),
+ ('available', models.BooleanField(default=True, verbose_name='Available')),
+ ('increase_coefficient', models.FloatField(default=1, verbose_name='Increase coefficient')),
+ ('increased_final_value', models.FloatField(default=1, verbose_name='Increased final value')),
+ ('category', models.PositiveSmallIntegerField(default=1, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(5)], verbose_name='Category')),
+ ],
+ options={
+ 'verbose_name': 'Operation type for royalties - France',
+ 'verbose_name_plural': 'Operation types for royalties - France',
+ 'ordering': ('id',),
+ },
+ bases=(ishtar_common.models_common.Cached, models.Model),
+ ),
+ migrations.CreateModel(
name='PreventiveFileEquipmentServiceCost',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
@@ -243,4 +278,24 @@ class Migration(migrations.Migration):
name='parent',
field=models.ForeignKey(blank=True, help_text='Auto-add this cost when a parent is added', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='children', to='archaeological_files.EquipmentServiceType', verbose_name='Parent'),
),
+ migrations.AddField(
+ model_name='file',
+ name='operation_type_for_royalties',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_files.OperationTypeForRoyalties', verbose_name='Operation type for royalties'),
+ ),
+ migrations.AddField(
+ model_name='file',
+ name='type_of_agreement',
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to='archaeological_files.AgreementType', verbose_name='Type of agreement'),
+ ),
+ migrations.AddField(
+ model_name='historicalfile',
+ name='operation_type_for_royalties',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_files.OperationTypeForRoyalties', verbose_name='Operation type for royalties'),
+ ),
+ migrations.AddField(
+ model_name='historicalfile',
+ name='type_of_agreement',
+ field=models.ForeignKey(blank=True, db_constraint=False, null=True, on_delete=django.db.models.deletion.DO_NOTHING, related_name='+', to='archaeological_files.AgreementType', verbose_name='Type of agreement'),
+ ),
]
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index 51273a17e..79dabc84d 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -25,6 +25,7 @@ from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.postgres.indexes import GinIndex
from django.core.cache import cache
+from django.core.validators import MinValueValidator, MaxValueValidator
from django.db.models import Q, Count, Sum
from django.db.models.signals import post_save, m2m_changed, post_delete
from django.core.urlresolvers import reverse
@@ -57,6 +58,7 @@ from ishtar_common.models import (
SearchVectorConfig,
DocumentItem,
CompleteIdentifierItem,
+ HierarchicalType,
)
from ishtar_common.models_common import HistoricalRecords, Department
@@ -279,6 +281,36 @@ if settings.COUNTRY == "fr":
post_delete.connect(post_save_cache, sender=SaisineType)
+class AgreementType(GeneralType):
+ class Meta:
+ verbose_name = _("Agreement type - France")
+ verbose_name_plural = _("Agreement types - France")
+ ordering = ("label",)
+
+
+post_save.connect(post_save_cache, sender=AgreementType)
+post_delete.connect(post_save_cache, sender=AgreementType)
+
+
+class OperationTypeForRoyalties(GeneralType):
+ increase_coefficient = models.FloatField(
+ _("Increase coefficient"), default=1)
+ increased_final_value = models.FloatField(
+ _("Increased final value"), default=1)
+ category = models.PositiveSmallIntegerField(
+ _("Category"), default=1, validators=[MinValueValidator(1),
+ MaxValueValidator(5)])
+
+ class Meta:
+ verbose_name = _("Operation type for royalties - France")
+ verbose_name_plural = _("Operation types for royalties - France")
+ ordering = ("id",)
+
+
+post_save.connect(post_save_cache, sender=OperationTypeForRoyalties)
+post_delete.connect(post_save_cache, sender=OperationTypeForRoyalties)
+
+
class File(
ClosedItem,
DocumentItem,
@@ -620,6 +652,16 @@ class File(
_("Execution report date"), blank=True, null=True
)
linear_meter = models.IntegerField(_("Linear meter"), blank=True, null=True)
+ type_of_agreement = models.ForeignKey(
+ AgreementType, blank=True, null=True,
+ on_delete=models.SET_NULL,
+ verbose_name=_("Type of agreement"),
+ )
+ operation_type_for_royalties = models.ForeignKey(
+ OperationTypeForRoyalties, blank=True, null=True,
+ on_delete=models.SET_NULL,
+ verbose_name=_("Operation type for royalties"),
+ )
# <-- preventive detail
documents = models.ManyToManyField(
diff --git a/archaeological_files/views.py b/archaeological_files/views.py
index 9f45d5e08..5a7c6b1d9 100644
--- a/archaeological_files/views.py
+++ b/archaeological_files/views.py
@@ -445,8 +445,9 @@ class PreventiveEditView(IshtarMixin, LoginRequiredMixin, MixFormFormsetUpdateVi
)
formset.form_label = str(inline_type)
formset.form_slug = inline_type.txt_idx
- formset.dynamic_add = True
+ # formset.dynamic_add = True # todo fix
formset.type_filter = inline_type.txt_idx
+ formset.extra = 2
inlines.append(formset)
return inlines