diff --git a/RIGS/migrations/0045_subhire.py b/RIGS/migrations/0045_subhire.py
new file mode 100644
index 00000000..327c4047
--- /dev/null
+++ b/RIGS/migrations/0045_subhire.py
@@ -0,0 +1,36 @@
+# Generated by Django 3.2.12 on 2022-10-15 19:36
+
+from django.db import migrations, models
+import django.db.models.deletion
+import versioning.versioning
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('RIGS', '0044_profile_is_supervisor'),
+ ]
+
+ operations = [
+ migrations.CreateModel(
+ name='Subhire',
+ fields=[
+ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
+ ('name', models.CharField(max_length=255)),
+ ('description', models.TextField(blank=True, default='')),
+ ('status', models.IntegerField(choices=[(0, 'Provisional'), (1, 'Confirmed'), (2, 'Booked'), (3, 'Cancelled')], default=0)),
+ ('start_date', models.DateField()),
+ ('start_time', models.TimeField(blank=True, null=True)),
+ ('end_date', models.DateField(blank=True, null=True)),
+ ('end_time', models.TimeField(blank=True, null=True)),
+ ('purchase_order', models.CharField(blank=True, default='', max_length=255, verbose_name='PO')),
+ ('insurance_value', models.DecimalField(decimal_places=2, max_digits=10)),
+ ('organisation', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.organisation')),
+ ('person', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='RIGS.person')),
+ ],
+ options={
+ 'abstract': False,
+ },
+ bases=(models.Model, versioning.versioning.RevisionMixin),
+ ),
+ ]
diff --git a/RIGS/models.py b/RIGS/models.py
index b1d290c6..9a4c620a 100644
--- a/RIGS/models.py
+++ b/RIGS/models.py
@@ -572,10 +572,16 @@ class EventAuthorisation(models.Model, RevisionMixin):
return f"{self.event.display_id} (requested by {self.sent_by.initials})"
+@reversion.register
class Subhire(BaseEvent):
insurance_value = models.DecimalField(max_digits=10, decimal_places=2) # TODO Validate if this is over notifiable threshold
# TODO Associated events
+ @property
+ def display_id(self):
+ return f"S{self.pk:05d}"
+
+
class InvoiceManager(models.Manager):
def outstanding_invoices(self):
# Manual query is the only way I have found to do this efficiently. Not ideal but needs must
diff --git a/RIGS/templates/event_detail.html b/RIGS/templates/event_detail.html
index b04089fb..3d83105b 100644
--- a/RIGS/templates/event_detail.html
+++ b/RIGS/templates/event_detail.html
@@ -25,12 +25,10 @@
{% include 'partials/hs_details.html' %}
{% endif %}
- {% if event.is_rig %}
- {% if event.is_rig and event.internal and perms.RIGS.view_event %}
-
- {% include 'partials/auth_details.html' %}
-
- {% endif %}
+ {% if event.is_rig and event.internal and perms.RIGS.view_event %}
+
+ {% include 'partials/auth_details.html' %}
+
{% endif %}
{% if not request.is_ajax and perms.RIGS.view_event %}
diff --git a/RIGS/templates/subhire_detail.html b/RIGS/templates/subhire_detail.html
new file mode 100644
index 00000000..a4309454
--- /dev/null
+++ b/RIGS/templates/subhire_detail.html
@@ -0,0 +1,27 @@
+{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
+
+{% load markdown_tags %}
+
+{% block content %}
+
+
+ {% include 'partials/contact_details.html' %}
+
+
+ {% include 'partials/event_details.html' %}
+
+ {% if not request.is_ajax and perms.RIGS.view_event %}
+
+ {% include 'partials/last_edited.html' with target="event_history" %}
+
+ {% endif %}
+
+{% endblock %}
+
+{% if request.is_ajax %}
+ {% block footer %}
+ {% if perms.RIGS.view_event %}
+ {% include 'partials/last_edited.html' with target="event_history" %}
+ {% endif %}
+ {% endblock %}
+{% endif %}
diff --git a/RIGS/urls.py b/RIGS/urls.py
index d51efb50..5dda94dd 100644
--- a/RIGS/urls.py
+++ b/RIGS/urls.py
@@ -70,9 +70,12 @@ urlpatterns = [
path('event/
/duplicate/', permission_required_with_403('RIGS.add_event')(views.EventDuplicate.as_view()),
name='event_duplicate'),
+ path('subhire//', views.SubhireDetail.as_view(),
+ name='subhire_detail'),
path('subhire/create/', permission_required_with_403('RIGS.add_event')(views.SubhireCreate.as_view()),
name='subhire_create'),
+
# Event H&S
path('event/hs/', permission_required_with_403('RIGS.view_riskassessment')(views.HSList.as_view()), name='hs_list'),
diff --git a/RIGS/views/rigboard.py b/RIGS/views/rigboard.py
index 20284d33..f0fa8757 100644
--- a/RIGS/views/rigboard.py
+++ b/RIGS/views/rigboard.py
@@ -61,10 +61,6 @@ class EventDetail(generic.DetailView, ModalURLMixin):
if self.object.dry_hire:
title += " Dry Hire"
context['page_title'] = title
- if is_ajax(self.request):
- context['override'] = "base_ajax.html"
- else:
- context['override'] = 'base_assets.html'
return context
@@ -100,20 +96,6 @@ class EventCreate(generic.CreateView):
return reverse_lazy('event_detail', kwargs={'pk': self.object.pk})
-class SubhireCreate(generic.CreateView):
- model = models.Subhire
- form_class = forms.SubhireForm
- template_name = 'subhire_form.html'
-
- def get_context_data(self, **kwargs):
- context = super().get_context_data(**kwargs)
- context['page_title'] = "New Subhire"
- context['edit'] = True
- form = context['form']
- get_related(form, context)
- return context
-
-
class EventUpdate(generic.UpdateView):
model = models.Event
form_class = forms.EventForm
@@ -391,3 +373,30 @@ class EventAuthoriseRequestEmailPreview(generic.DetailView):
context['to_name'] = self.request.GET.get('to_name', None)
context['target'] = 'event_authorise_form_preview'
return context
+
+
+class SubhireDetail(generic.DetailView, ModalURLMixin):
+ template_name = 'subhire_detail.html'
+ model = models.Subhire
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['page_title'] = f"{self.object.display_id} | {self.object.name}"
+ return context
+
+
+class SubhireCreate(generic.CreateView):
+ model = models.Subhire
+ form_class = forms.SubhireForm
+ template_name = 'subhire_form.html'
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ context['page_title'] = "New Subhire"
+ context['edit'] = True
+ form = context['form']
+ get_related(form, context)
+ return context
+
+ def get_success_url(self):
+ return reverse_lazy('subhire_detail', kwargs={'pk': self.object.pk})