diff --git a/qgepqwat2ili/gui/gui_import.py b/qgepqwat2ili/gui/gui_import.py index 2c681451..edb16f7a 100644 --- a/qgepqwat2ili/gui/gui_import.py +++ b/qgepqwat2ili/gui/gui_import.py @@ -218,7 +218,7 @@ def commit_session(self): # session.begin_nested() and one additionnal self.session.commit() # add info in message bar - iface.messageBar().pushMessage("Please be patient!", "Importing data in qgep - working ...", level=Qgis.Warning) + iface.messageBar().pushMessage("Please be patient!", "Importing data in qgep - working ...", level=Qgis.Info) try: self.session.commit() diff --git a/qgepqwat2ili/qgepdss/import_.py b/qgepqwat2ili/qgepdss/import_.py index bb80eb4d..64d5e78b 100644 --- a/qgepqwat2ili/qgepdss/import_.py +++ b/qgepqwat2ili/qgepdss/import_.py @@ -130,6 +130,36 @@ def create_or_update_organisation(name): instance = obj break + # set instance with organisation.obj instead of organisation.name, as fk_dataowner / fk_provider could already be a obj_id instead of an identifier + if not instance: + instance = qgep_session.query(QGEP.organisation).filter(QGEP.organisation.obj_id == name).first() + + # also look for non-flushed objects in the session + if not instance: + for obj in qgep_session: + # for VSA-DSS look in subclasses instead of organisation + #if obj.__class__ is QGEP.organisation and obj.obj_id == name: + # instance = obj + # break + if obj.__class__ is QGEP.municipality and obj.obj_id == name: + instance = obj + break + if obj.__class__ is QGEP.administrative_office and obj.obj_id == name: + instance = obj + break + if obj.__class__ is QGEP.canton and obj.obj_id == name: + instance = obj + break + if obj.__class__ is QGEP.cooperative and obj.obj_id == name: + instance = obj + break + if obj.__class__ is QGEP.private and obj.obj_id == name: + instance = obj + break + if obj.__class__ is QGEP.waste_water_association and obj.obj_id == name: + instance = obj + break + # if still nothing, we create it if not instance: # 10.8.2022 extra logger info added