summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
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
commitc737d107405e79aa0d014400231bf3470bb15f71 (patch)
tree3fd84934542204953eae3124ae23400e770474e9
parentdb88ec5f327837d25aa142da13faa5e3c9b212da (diff)
downloadIshtar-c737d107405e79aa0d014400231bf3470bb15f71.tar.bz2
Ishtar-c737d107405e79aa0d014400231bf3470bb15f71.zip
Container: weight on form - fix weight display on sheet
-rw-r--r--archaeological_warehouse/forms.py3
-rw-r--r--archaeological_warehouse/models.py8
-rw-r--r--archaeological_warehouse/templates/ishtar/sheet_container.html15
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> &nbsp;
- {% 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>