diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-09 12:07:20 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-09 12:07:20 +0100 |
commit | 7333b2ea0d040d739015371b0a3d5f64f52b4ae9 (patch) | |
tree | 3fd84934542204953eae3124ae23400e770474e9 | |
parent | 3c956ab09941a77b04cf0aa4c1fd5368353533fe (diff) | |
download | Ishtar-7333b2ea0d040d739015371b0a3d5f64f52b4ae9.tar.bz2 Ishtar-7333b2ea0d040d739015371b0a3d5f64f52b4ae9.zip |
Container: weight on form - fix weight display on sheet
-rw-r--r-- | archaeological_warehouse/forms.py | 3 | ||||
-rw-r--r-- | archaeological_warehouse/models.py | 8 | ||||
-rw-r--r-- | archaeological_warehouse/templates/ishtar/sheet_container.html | 15 |
3 files changed, 15 insertions, 11 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 06a3ca493..83f045349 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -294,6 +294,9 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): "filled."), required=False ) + weight = forms.FloatField( + label=_("Measured weight (g)"), + widget=widgets.GramKilogramWidget, required=False) comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) TYPES = [ diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 089a021af..fc0184990 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -962,7 +962,7 @@ class Container(DocumentItem, Merge, LightHistorizedItem, related_name="children", blank=True, null=True) index = models.IntegerField(_("Container ID"), blank=True, null=True, db_index=True) - weight = models.FloatField(_("Weight (g)"), blank=True, null=True) + weight = models.FloatField(_("Measured weight (g)"), blank=True, null=True) calculated_weight = models.FloatField( _("Calculated weight (g)"), blank=True, null=True) cached_weight = models.FloatField( @@ -1102,9 +1102,9 @@ class Container(DocumentItem, Merge, LightHistorizedItem, @property def get_calculated_weight_percent(self): if not self.calculated_weight or not self.weight: - return (self.calculated_weight - - self.weight) / self.calculated_weight * 100 - return 0 + return 0 + return (self.calculated_weight + - self.weight) / self.calculated_weight * 100 @property def get_cached_division(self): diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index 686bd08ff..737be11f6 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -109,22 +109,23 @@ {% if item.responsibility != item.location %} {% field_flex_detail "Responsibility" item.responsibility %} {% endif %} - {% include "ishtar/blocks/sheet_creation_section.html" %} {% field_flex "Old reference" item.old_reference %} - {% if item.get_calculated_weight_percent > 5 %} - <div class="alert alert-warning" role="alert"> + {% with calculated_weight_percent=item.get_calculated_weight_percent%} + {% if calculated_weight_percent > 10 or calculated_weight_percent < -10 %} + <div class="alert alert-warning col-12" role="alert"> <i class="fa fa-exclamation-triangle" aria-hidden="true"></i> - {% trans "Calculated weight is bigger than entered weight (over 5%)." %} + {% trans "Calculated weight and measured weight are too different (over 10%)." %} </div> - {% field_flex "Weight (g)" item.weight %} + {% field_flex "Measured weight (g)" item.weight %} {% field_flex "Calculated weight (g)" item.calculated_weight %} {% else %} {% if item.weight %} - {% field_flex "Weight (g)" item.weight %} + {% field_flex "Measured weight (g)" item.weight %} {% elif item.calculated_weight %} {% field_flex "Calculated weight (g)" item.calculated_weight %} {% endif %} - {% endif %} + {% endif %}{% endwith %} + {% include "ishtar/blocks/sheet_creation_section.html" %} {% field_flex_full "Comment" item.comment "<pre>" "</pre>" %} {% include "ishtar/blocks/sheet_json.html" %} </div> |