Merge branch 'master' into assets_audit

# Conflicts:
#	assets/models.py
This commit is contained in:
2020-04-13 15:59:02 +01:00
19 changed files with 350 additions and 92 deletions

View File

@@ -63,6 +63,21 @@ class Connector(models.Model):
return self.description
class CableType(models.Model):
class Meta:
ordering = ['plug', 'socket', '-circuits']
circuits = models.IntegerField(blank=True, null=True)
cores = models.IntegerField(blank=True, null=True)
plug = models.ForeignKey(Connector, on_delete=models.SET_NULL,
related_name='plug', blank=True, null=True)
socket = models.ForeignKey(Connector, on_delete=models.SET_NULL,
related_name='socket', blank=True, null=True)
def __str__(self):
return "%s%s" % (self.plug.description, self.socket.description)
@reversion.register
class Asset(models.Model, RevisionMixin):
class Meta:
@@ -93,16 +108,11 @@ class Asset(models.Model, RevisionMixin):
# Cable assets
is_cable = models.BooleanField(default=False)
plug = models.ForeignKey(Connector, on_delete=models.SET_NULL,
related_name='plug', blank=True, null=True)
socket = models.ForeignKey(Connector, on_delete=models.SET_NULL,
related_name='socket', blank=True, null=True)
cable_type = models.ForeignKey(to=CableType, blank=True, null=True, on_delete=models.SET_NULL)
length = models.DecimalField(decimal_places=1, max_digits=10,
blank=True, null=True, help_text='m')
csa = models.DecimalField(decimal_places=2, max_digits=10,
blank=True, null=True, help_text='mm²')
circuits = models.IntegerField(blank=True, null=True)
cores = models.IntegerField(blank=True, null=True)
# Hidden asset_id components
# For example, if asset_id was "C1001" then asset_id_prefix would be "C" and number "1001"
@@ -132,7 +142,7 @@ class Asset(models.Model, RevisionMixin):
def __str__(self):
out = str(self.asset_id) + ' - ' + self.description
if self.is_cable:
out += '{} - {}m - {}'.format(self.plug, self.length, self.socket)
out += '{} - {}m - {}'.format(self.cable_type.plug, self.length, self.cable_type.socket)
return out
def clean(self):
@@ -157,14 +167,16 @@ class Asset(models.Model, RevisionMixin):
errdict["length"] = ["The length of a cable must be more than 0"]
if not self.csa or self.csa <= 0:
errdict["csa"] = ["The CSA of a cable must be more than 0"]
if not self.circuits or self.circuits <= 0:
errdict["circuits"] = ["There must be at least one circuit in a cable"]
if not self.cores or self.cores <= 0:
errdict["cores"] = ["There must be at least one core in a cable"]
if self.socket is None:
errdict["socket"] = ["A cable must have a socket"]
if self.plug is None:
errdict["plug"] = ["A cable must have a plug"]
if not self.cable_type:
errdict["cable_type"] = ["A cable must have a type"]
# if not self.circuits or self.circuits <= 0:
# errdict["circuits"] = ["There must be at least one circuit in a cable"]
# if not self.cores or self.cores <= 0:
# errdict["cores"] = ["There must be at least one core in a cable"]
# if self.socket is None:
# errdict["socket"] = ["A cable must have a socket"]
# if self.plug is None:
# errdict["plug"] = ["A cable must have a plug"]
if errdict != {}: # If there was an error when validation
raise ValidationError(errdict)