summaryrefslogtreecommitdiff
path: root/archaeological_files/models.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2021-07-29 19:02:32 +0200
committerÉtienne Loks <etienne.loks@iggdrasil.net>2021-07-29 19:02:32 +0200
commite180ed275c9b907a90ba98a0e60c2c746c264e48 (patch)
treeb001faf2afe326bd983065ea6f363faaad644e6c /archaeological_files/models.py
parent7e1b10f0645539698b3aad3512a5e865dd56522f (diff)
downloadIshtar-e180ed275c9b907a90ba98a0e60c2c746c264e48.tar.bz2
Ishtar-e180ed275c9b907a90ba98a0e60c2c746c264e48.zip
Preventive file: work on inlines - 3
Diffstat (limited to 'archaeological_files/models.py')
-rw-r--r--archaeological_files/models.py129
1 files changed, 94 insertions, 35 deletions
diff --git a/archaeological_files/models.py b/archaeological_files/models.py
index ab84be8cb..5129189cf 100644
--- a/archaeological_files/models.py
+++ b/archaeological_files/models.py
@@ -72,23 +72,60 @@ class Job(GeneralType):
ground_daily_cost = models.FloatField(_("Ground daily cost"), blank=True, null=True)
daily_cost = models.FloatField(_("Daily cost"), blank=True, null=True)
permanent_contract = models.NullBooleanField(
- _("Is a permanent contract"), blank=True, null=True)
+ _("Permanent contract"), blank=True, null=True
+ )
default_daily_need_on_ground = models.FloatField(
- _("Default daily number needed on the ground"), default=0)
- default_daily_need = models.FloatField(
- _("Default daily number needed"), default=0)
+ _("Def. daily number on ground"), default=0
+ )
+ default_daily_need = models.FloatField(_("Def. daily number"), default=0)
order = models.IntegerField(_("Order"), default=10)
- parents = models.ManyToManyField(
+ child = models.ForeignKey(
"self",
blank=True,
- verbose_name=_("Parents"),
- help_text=_("Auto-add this job when a parent is added")
+ null=True,
+ verbose_name=_("Child"),
+ help_text=_("Auto-add this job when a parent is added"),
+ related_name="parents",
)
class Meta:
verbose_name = _("Job")
verbose_name_plural = _("Jobs")
- ordering = ("order", "label",)
+ ordering = (
+ "order",
+ "-permanent_contract",
+ "label",
+ )
+
+ def __str__(self):
+ lbl = self.label
+ if not self.permanent_contract:
+ lbl += " ({})".format(_("fixed-term contract"))
+ return lbl
+
+ @classmethod
+ def get_choices(cls, current_value):
+ q = cls.objects.filter(
+ available=True,
+ parents__isnull=True,
+ )
+ permanent = [(j.pk, str(j)) for j in q.filter(permanent_contract=True).all()]
+ fixed_term = [(j.pk, str(j)) for j in q.filter(permanent_contract=False).all()]
+ if current_value:
+ if current_value.permanent_contract:
+ permanent.append((current_value.pk, str(current_value)))
+ else:
+ fixed_term.append((current_value.pk, str(current_value)))
+ return [("", "-" * 9)] + [
+ (
+ _("Permanent contract"),
+ permanent,
+ ),
+ (
+ _("Fixed-term contract"),
+ fixed_term,
+ ),
+ ]
class GenericEquipmentServiceType(GeneralType):
@@ -97,18 +134,25 @@ class GenericEquipmentServiceType(GeneralType):
class Meta:
verbose_name = _("Generic equipment type")
verbose_name_plural = _("Generic equipment types")
- ordering = ("order", "label",)
+ ordering = (
+ "order",
+ "label",
+ )
class EquipmentServiceType(GeneralType):
generic_equipment_type = models.ForeignKey(
- GenericEquipmentServiceType, verbose_name=_("Generic type"))
+ GenericEquipmentServiceType, verbose_name=_("Generic type")
+ )
order = models.IntegerField(_("Order"), default=10)
class Meta:
verbose_name = _("Equipment/service type")
verbose_name_plural = _("Equipment/service types")
- ordering = ("order", "label",)
+ ordering = (
+ "order",
+ "label",
+ )
ES_UNITS = (
@@ -118,10 +162,13 @@ ES_UNITS = (
("L", _("linear meter")),
)
+DCT_ES_UNITS = dict(ES_UNITS)
+
class EquipmentServiceCost(models.Model):
equipment_service_type = models.ForeignKey(
- EquipmentServiceType, verbose_name=_("Equipment/Service"))
+ EquipmentServiceType, verbose_name=_("Equipment/Service")
+ )
slug = models.SlugField(
_("Textual ID"),
unique=True,
@@ -133,13 +180,16 @@ class EquipmentServiceCost(models.Model):
),
)
service_provider = models.CharField(
- _("Service provider"), max_length=200, blank=True, default="")
+ _("Service provider"), max_length=200, blank=True, default=""
+ )
flat_rate = models.BooleanField(_("Flat rate"), default=False)
unitary_cost = models.FloatField(_("Unitary cost"), blank=True, null=True)
- unit = models.CharField(_("Unit"), max_length=1, choices=ES_UNITS,
- blank=True, null=True)
- specificity = models.CharField(_("Specificity"), blank=True,
- max_length=200, default="")
+ unit = models.CharField(
+ _("Unit"), max_length=1, choices=ES_UNITS, blank=True, null=True
+ )
+ specificity = models.CharField(
+ _("Specificity"), blank=True, max_length=200, default=""
+ )
order = models.IntegerField(_("Order"), default=10)
available = models.BooleanField(_("Available"), default=True)
parent = models.ForeignKey(
@@ -149,13 +199,16 @@ class EquipmentServiceCost(models.Model):
on_delete=models.CASCADE,
verbose_name=_("Parent"),
help_text=_("Auto-add this cost when a parent is added"),
- related_name="children"
+ related_name="children",
)
class Meta:
verbose_name = _("Equipment/service cost")
verbose_name_plural = _("Equipment/service costs")
- ordering = ("order", "equipment_service_type__label",)
+ ordering = (
+ "order",
+ "equipment_service_type__label",
+ )
def __str__(self):
lbl = ""
@@ -166,6 +219,10 @@ class EquipmentServiceCost(models.Model):
lbl += " - " + self.specificity
if self.service_provider:
lbl += f" ({self.service_provider})"
+ if self.flat_rate:
+ lbl += " - " + str(_("Flat rate"))
+ if self.unit and self.unit in DCT_ES_UNITS:
+ lbl += " - " + str(DCT_ES_UNITS[self.unit])
return lbl
@@ -544,14 +601,16 @@ class File(
# <-- research archaeology
# --> preventive detail
- study_period = models.CharField(_("Study period"), max_length=200,
- default="", blank=True)
+ study_period = models.CharField(
+ _("Study period"), max_length=200, default="", blank=True
+ )
start_date = models.DateField(_("Start date"), blank=True, null=True)
end_date = models.DateField(_("End date"), blank=True, null=True)
ground_start_date = models.DateField(_("Ground start date"), blank=True, null=True)
ground_end_date = models.DateField(_("Ground end date"), blank=True, null=True)
- execution_report_date = models.DateField(_("Execution report date"), blank=True,
- null=True)
+ execution_report_date = models.DateField(
+ _("Execution report date"), blank=True, null=True
+ )
linear_meter = models.IntegerField(_("Linear meter"), blank=True, null=True)
# <-- preventive detail
@@ -1178,13 +1237,13 @@ class FileDashboard:
class ManDays(models.Model):
man_by_day_planned = models.FloatField(
- _("Man by day - planned"), null=True, blank=True)
- days_planned = models.FloatField(
- _("Days - planned"), null=True, blank=True)
+ _("Man by day - planned"), null=True, blank=True
+ )
+ days_planned = models.FloatField(_("Days - planned"), null=True, blank=True)
man_by_day_worked = models.FloatField(
- _("Man by day - worked"), null=True, blank=True)
- days_worked = models.FloatField(
- _("Days - worked"), null=True, blank=True)
+ _("Man by day - worked"), null=True, blank=True
+ )
+ days_worked = models.FloatField(_("Days - worked"), null=True, blank=True)
class Meta:
abstract = True
@@ -1220,13 +1279,13 @@ class PreventiveFileJob(ManDays):
class TechDays(models.Model):
quantity_by_day_planned = models.FloatField(
- _("Quantity by day - planned"), null=True, blank=True)
- days_planned = models.FloatField(
- _("Days - planned"), null=True, blank=True)
+ _("Quantity by day - planned"), null=True, blank=True
+ )
+ days_planned = models.FloatField(_("Days - planned"), null=True, blank=True)
quantity_by_day_worked = models.FloatField(
- _("Quantity by day - worked"), null=True, blank=True)
- days_worked = models.FloatField(
- _("Days - worked"), null=True, blank=True)
+ _("Quantity by day - worked"), null=True, blank=True
+ )
+ days_worked = models.FloatField(_("Days - worked"), null=True, blank=True)
class Meta:
abstract = True