diff options
Diffstat (limited to 'archaeological_files')
-rw-r--r-- | archaeological_files/admin.py | 6 | ||||
-rw-r--r-- | archaeological_files/forms.py | 51 | ||||
-rw-r--r-- | archaeological_files/ishtar_menu.py | 31 | ||||
-rw-r--r-- | archaeological_files/models.py | 4 | ||||
-rw-r--r-- | archaeological_files/tests.py | 79 |
5 files changed, 83 insertions, 88 deletions
diff --git a/archaeological_files/admin.py b/archaeological_files/admin.py index 4f3bc5333..6f73c1340 100644 --- a/archaeological_files/admin.py +++ b/archaeological_files/admin.py @@ -174,6 +174,12 @@ class CopyPriceAgreementAdmin(GeneralTypeAdmin): def copy_price_agreement(self, request): form = None + if not hasattr(request.user, "ishtaruser") or request.user.ishtaruser.has_right( + "change_priceagreement", session=request.session): + self.message_user( + request, str(_("Cannot change price agreement.")) + ) + return HttpResponseRedirect(reverse("admin:login")) if "apply" in request.POST: form = CopyPriceForm(request.POST) diff --git a/archaeological_files/forms.py b/archaeological_files/forms.py index eb366b927..a75e5bf34 100644 --- a/archaeological_files/forms.py +++ b/archaeological_files/forms.py @@ -64,7 +64,6 @@ from ishtar_common.forms_common import get_town_field from archaeological_operations.forms import ( AdministrativeActForm, AdministrativeActOpeFormSelection, - SLICING, AdministrativeActModifForm, ParcelForm, ParcelFormSet, @@ -195,56 +194,6 @@ class FileFormMultiSelection(LockForm, MultiSearchForm): ) -DATE_SOURCE = (("creation", _("Creation date")), ("reception", _("Reception date"))) - - -class DashboardForm(IshtarForm): - slicing = forms.ChoiceField(label=_("Slicing"), choices=SLICING, required=False) - department_detail = forms.BooleanField(label=_("Department detail"), required=False) - date_source = forms.ChoiceField( - label=_("Date get from"), choices=DATE_SOURCE, required=False - ) - file_type = forms.ChoiceField(label=_("File type"), choices=[], required=False) - saisine_type = forms.ChoiceField( - label=_("Saisine type"), choices=[], required=False - ) - after = forms.DateField(label=_("Date after"), widget=DatePicker, required=False) - before = forms.DateField(label=_("Date before"), widget=DatePicker, required=False) - - def __init__(self, *args, **kwargs): - if "prefix" not in kwargs: - kwargs["prefix"] = "files" - super(DashboardForm, self).__init__(*args, **kwargs) - self.fields["saisine_type"].choices = models.SaisineType.get_types() - self.fields["file_type"].choices = models.FileType.get_types() - - def get_show_detail(self): - return hasattr(self, "cleaned_data") and self.cleaned_data.get( - "department_detail" - ) - - def get_date_source(self): - date_source = "creation" - if hasattr(self, "cleaned_data") and self.cleaned_data.get("date_source"): - date_source = self.cleaned_data["date_source"] - return date_source - - def get_filter(self): - if not hasattr(self, "cleaned_data") or not self.cleaned_data: - return {} - date_source = self.get_date_source() - fltr = {} - if self.cleaned_data.get("saisine_type"): - fltr["saisine_type_id"] = self.cleaned_data["saisine_type"] - if self.cleaned_data.get("file_type"): - fltr["file_type_id"] = self.cleaned_data["file_type"] - if self.cleaned_data.get("after"): - fltr[date_source + "_date__gte"] = self.cleaned_data["after"] - if self.cleaned_data.get("before"): - fltr[date_source + "_date__lte"] = self.cleaned_data["before"] - return fltr - - class FileFormGeneral(ManageOldType): form_label = _("General") associated_models = { diff --git a/archaeological_files/ishtar_menu.py b/archaeological_files/ishtar_menu.py index 3d6b85466..517b0276d 100644 --- a/archaeological_files/ishtar_menu.py +++ b/archaeological_files/ishtar_menu.py @@ -100,34 +100,3 @@ MENU_SECTIONS = [ ), ), ] -""" - (100, - SectionItem( - 'dashboard', _("Dashboard"), - profile_restriction='files', - css='menu-file', - childs=[MenuItem('dashboard_main', _("General informations"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _("Archaeological files"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - ]), - ), - SectionItem('dashboard', _("Dashboard"), - childs=[ - MenuItem('dashboard_main', _("General informations"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - MenuItem('dashboard_file', _("Archaeological files"), - model=models.File, - access_controls=['change_file', 'change_own_file']), - #MenuItem('dashboard_treatment', _("Treatments"), - # model=models.Treatment, - # access_controls=['change_treatment',]), - #MenuItem('dashboard_warehouse', _("Warehouses"), - # model=models.Warehouse, - # access_controls=['change_warehouse',]), - ]), - ] -""" diff --git a/archaeological_files/models.py b/archaeological_files/models.py index 2cd42d5ba..bcc90ab4f 100644 --- a/archaeological_files/models.py +++ b/archaeological_files/models.py @@ -89,7 +89,7 @@ class PriceAgreement(GeneralType): class Job(GeneralType): price_agreement = models.ForeignKey( PriceAgreement, verbose_name=_("Price agreement"), blank=True, null=True, - on_delete=models.CASCADE + on_delete=models.CASCADE, related_name="jobs" ) ground_daily_cost = models.FloatField(_("Ground daily cost"), blank=True, null=True) daily_cost = models.FloatField(_("Daily cost"), blank=True, null=True) @@ -199,7 +199,7 @@ ES_UNITS_DAYS = { class EquipmentServiceCost(models.Model): price_agreement = models.ForeignKey( PriceAgreement, verbose_name=_("Price agreement"), blank=True, null=True, - on_delete=models.CASCADE + on_delete=models.CASCADE, related_name="equipment_service_costs" ) equipment_service_type = models.ForeignKey( EquipmentServiceType, verbose_name=_("Equipment/Service"), on_delete=models.CASCADE diff --git a/archaeological_files/tests.py b/archaeological_files/tests.py index 1d54584da..7145cb836 100644 --- a/archaeological_files/tests.py +++ b/archaeological_files/tests.py @@ -27,13 +27,15 @@ from django.urls import reverse from ishtar_common.tests import ( TestCase, - COMMON_FIXTURES, create_superuser, AutocompleteTestBase, AcItem, + FILE_TOWNS_FIXTURES, ) from ishtar_common.models import Town, IshtarSiteProfile +from ishtar_common.utils import ugettext_lazy as _ + from archaeological_files import models, views from archaeological_operations.models import ( Parcel, @@ -41,7 +43,6 @@ from archaeological_operations.models import ( ActType, AdministrativeAct, ) -from ishtar_common.tests import FILE_TOWNS_FIXTURES from archaeological_operations.tests import OperationInitTest, FileInit @@ -65,7 +66,7 @@ class FileTest(TestCase, FileInit): model = models.File def setUp(self): - IshtarSiteProfile.objects.create() + self.profile = IshtarSiteProfile.objects.create() self.create_file() def test_external_id(self): @@ -246,6 +247,77 @@ class FileTest(TestCase, FileInit): self.assertEqual(response.status_code, 200) self.assertIn('class="card sheet"', response.content.decode()) + def test_select_page(self): + url = "file_search" + # need auth + response = self.client.get(reverse(url)) + self.assertRedirects(response, "/", status_code=302) + # need file module + self.login_as_superuser() + response = self.client.get(reverse(url)) + self.assertRedirects(response, "/file_search/general-file_search", + status_code=302) + + +class FileCostTest(TestCase, FileInit): + fixtures = FILE_TOWNS_FIXTURES + model = models.File + + def setUp(self): + IshtarSiteProfile.objects.create() + self.create_file() + + def test_admin_copy_cost(self): + default = models.PriceAgreement.objects.all()[0] + new = models.PriceAgreement.objects.create(label="New") + ln_equipment_service_costs = default.equipment_service_costs.count() + self.assertNotEqual(ln_equipment_service_costs, 0) + self.assertEqual(new.equipment_service_costs.count(), 0) + ln_jobs = default.jobs.count() + self.assertNotEqual(ln_jobs, 0) + self.assertEqual(new.jobs.count(), 0) + url = "/admin/archaeological_files/priceagreement/copy-price-agreement/" + response = self.client.get(url) + self.assertRedirects( + response, + reverse("admin:login"), + status_code=302, + ) + self.login_as_superuser() + response = self.client.get(url) + self.assertEqual(response.status_code, 200) + response = self.client.post( + url, + {"source": default.pk, "destination": default.pk, + "action": "import_generic", "apply": "1"} + ) + # cannot copy on same price agreement (nonsense) + self.assertContains( + response, + str(_("Source and destination must be different.")) + ) + response = self.client.post( + url, + {"source": default.pk, "destination": new.pk, + "action": "import_generic", "apply": "1"} + ) + self.assertEqual(response.status_code, 302) + new = models.PriceAgreement.objects.get(pk=new.pk) + self.assertEqual(new.jobs.count(), ln_jobs) + self.assertEqual(new.equipment_service_costs.count(), + ln_equipment_service_costs) + # repost - verify no duplication + response = self.client.post( + url, + {"source": default.pk, "destination": new.pk, + "action": "import_generic", "apply": "1"} + ) + self.assertEqual(response.status_code, 302) + new = models.PriceAgreement.objects.get(pk=new.pk) + self.assertEqual(new.jobs.count(), ln_jobs) + self.assertEqual(new.equipment_service_costs.count(), + ln_equipment_service_costs) + def test_preventive_price_agreement(self): pk = self.item.pk self.login_as_superuser() @@ -303,7 +375,6 @@ class FileTest(TestCase, FileInit): self.assertEqual(q_equip.count(), 0) self.assertEqual(q_job.count(), 0) - def test_preventive(self): pk = self.item.pk self.item.price_agreement_id = models.PriceAgreement.objects.all()[0] |