diff --git a/assets/migrations/0025_rename_salvage_value_asset_replacement_cost.py b/assets/migrations/0025_rename_salvage_value_asset_replacement_cost.py new file mode 100644 index 00000000..540d7577 --- /dev/null +++ b/assets/migrations/0025_rename_salvage_value_asset_replacement_cost.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.12 on 2022-05-26 09:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('assets', '0024_alter_asset_salvage_value'), + ] + + operations = [ + migrations.RenameField( + model_name='asset', + old_name='salvage_value', + new_name='replacement_cost', + ), + ] diff --git a/assets/models.py b/assets/models.py index 2ee3c724..365fd5d6 100644 --- a/assets/models.py +++ b/assets/models.py @@ -105,6 +105,11 @@ def get_available_asset_id(wanted_prefix=""): return 9000 if last_asset is None else wanted_prefix + str(last_asset.asset_id_number + 1) +def validate_positive(value): + if value < 0: + raise ValidationError("A price cannot be negative") + + @reversion.register class Asset(models.Model, RevisionMixin): parent = models.ForeignKey(to='self', related_name='asset_parent', @@ -117,8 +122,8 @@ class Asset(models.Model, RevisionMixin): purchased_from = models.ForeignKey(to=Supplier, on_delete=models.SET_NULL, blank=True, null=True, related_name="assets") date_acquired = models.DateField() date_sold = models.DateField(blank=True, null=True) - purchase_price = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=10) - salvage_value = models.DecimalField(null=True, decimal_places=2, max_digits=10) + purchase_price = models.DecimalField(blank=True, null=True, decimal_places=2, max_digits=10, validators=[validate_positive]) + replacement_cost = models.DecimalField(null=True, decimal_places=2, max_digits=10, validators=[validate_positive]) comments = models.TextField(blank=True) # Audit @@ -165,12 +170,6 @@ class Asset(models.Model, RevisionMixin): errdict["asset_id"] = [ "An Asset ID can only consist of letters and numbers, with a final number"] - if self.purchase_price and self.purchase_price < 0: - errdict["purchase_price"] = ["A price cannot be negative"] - - if self.salvage_value and self.salvage_value < 0: - errdict["salvage_value"] = ["A price cannot be negative"] - if self.is_cable: if not self.length or self.length <= 0: errdict["length"] = ["The length of a cable must be more than 0"] diff --git a/assets/templates/partials/purchasedetails_form.html b/assets/templates/partials/purchasedetails_form.html index d55f2ae8..9fa226b9 100644 --- a/assets/templates/partials/purchasedetails_form.html +++ b/assets/templates/partials/purchasedetails_form.html @@ -10,7 +10,7 @@