From 4b1dc37a7f046cd8644aa490567b9846f82a3d61 Mon Sep 17 00:00:00 2001 From: FreneticScribbler Date: Thu, 26 May 2022 10:29:53 +0100 Subject: [PATCH] Rename 'salvage value' to 'replacement cost' This more accurately reflects historical use of the field, and what the insurers actually want. Ref #439 --- ...ame_salvage_value_asset_replacement_cost.py | 18 ++++++++++++++++++ assets/models.py | 15 +++++++-------- .../partials/purchasedetails_form.html | 10 +++++----- 3 files changed, 30 insertions(+), 13 deletions(-) create mode 100644 assets/migrations/0025_rename_salvage_value_asset_replacement_cost.py 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 @@
- {% if object.purchased_from %} {% endif %} @@ -39,10 +39,10 @@
- +
£
- {% render_field form.salvage_value|add_class:'form-control' value=object.salvage_value %} + {% render_field form.replacement_cost|add_class:'form-control' value=object.replacement_cost %}
@@ -70,8 +70,8 @@
{% if object.purchased_from %}{{ object.purchased_from }}{%else%}-{%endif%}
Purchase Price
£{{ object.purchase_price|default_if_none:'-' }}
-
Salvage Value
-
£{{ object.salvage_value|default_if_none:'-' }}
+
Replacement Cost
+
£{{ object.replacement_cost|default_if_none:'-' }}
Date Acquired
{{ object.date_acquired|default_if_none:'-' }}
{% if object.date_sold %}