summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2024-11-28 17:09:34 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-02-19 14:45:56 +0100
commit85108e2ecf8fd38453e5ac0cb7a25d1c169cdb3b (patch)
treef508182f5ec001d868d8ad0ae55848ac8595aafb /archaeological_finds
parent80c491d145cad911099c88fb1bc10d1bd4b6db9b (diff)
downloadIshtar-85108e2ecf8fd38453e5ac0cb7a25d1c169cdb3b.tar.bz2
Ishtar-85108e2ecf8fd38453e5ac0cb7a25d1c169cdb3b.zip
✨ site profile: ability to set default localisation for treatments
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/forms_treatments.py18
-rw-r--r--archaeological_finds/wizards.py7
2 files changed, 20 insertions, 5 deletions
diff --git a/archaeological_finds/forms_treatments.py b/archaeological_finds/forms_treatments.py
index be1921568..d5e353a53 100644
--- a/archaeological_finds/forms_treatments.py
+++ b/archaeological_finds/forms_treatments.py
@@ -214,9 +214,22 @@ class BaseTreatmentForm(CustomForm, ManageOldType):
def __init__(self, *args, **kwargs):
user = kwargs.pop('user')
- super(BaseTreatmentForm, self).__init__(*args, **kwargs)
+ current_profile = get_current_profile()
+ has_default_location = kwargs.get("data", None) or (
+ "initial" in kwargs and
+ kwargs["initial"].get("location", None))
+ super().__init__(*args, **kwargs)
+
+ if not has_default_location and \
+ current_profile.default_location_for_treatment_id:
+ self.fields["location"].initial = \
+ current_profile.default_location_for_treatment_id
+ if current_profile.default_location_for_treatment.organization:
+ self.fields["organization"].initial = \
+ current_profile.default_location_for_treatment.organization_id
+
# set current currency
- currency = get_current_profile().currency
+ currency = current_profile.currency
for key in ('estimated_cost', 'quoted_cost', 'realized_cost',
'insurance_cost'):
self.fields[key].label = self.fields[key].label.format(
@@ -261,7 +274,6 @@ class BaseTreatmentForm(CustomForm, ManageOldType):
except models.TreatmentType.DoesNotExist:
raise forms.ValidationError(_("Unknow treatment type"))
-
change_current_location = [
str(tp) for tp in treatment_types
if tp.change_current_location
diff --git a/archaeological_finds/wizards.py b/archaeological_finds/wizards.py
index c70721eac..f1d4a2dc4 100644
--- a/archaeological_finds/wizards.py
+++ b/archaeological_finds/wizards.py
@@ -177,13 +177,16 @@ class TreatmentBase(Wizard):
finds = self.get_current_finds()
if not finds:
return initial
- locations = [find.container.location.pk for find in finds if find.container]
+ locations = [find.container.location for find in finds if find.container]
# no location or multiple locations
if not locations or len(set(locations)) != 1:
return initial
if not initial:
initial = {}
- initial["location"] = locations[0]
+ default_location = locations[0]
+ initial["location"] = default_location.id
+ if default_location.organization:
+ initial["organization"] = default_location.organization_id
return initial
def get_extra_model(self, dct, m2m, form_list):