#132 WIP Migrate recording accounts

* adds recording state of ecoaccounts
This commit is contained in:
mpeltriaux 2022-04-06 09:55:37 +02:00
parent d19a563491
commit 6ce2dd8509
2 changed files with 39 additions and 3 deletions

View File

@ -169,8 +169,8 @@ class BaseMigrater:
action.save() action.save()
instance.log.add(action) instance.log.add(action)
first_entry = instance.log.order_by("-timestamp").first() first_entry = instance.log.order_by("timestamp").first()
last_entry = instance.log.order_by("timestamp").first() last_entry = instance.log.order_by("-timestamp").first()
if first_entry is not None: if first_entry is not None:
instance.created = UserActionLogEntry.get_created_action(first_entry.user) instance.created = UserActionLogEntry.get_created_action(first_entry.user)

View File

@ -9,6 +9,7 @@ from django.utils import timezone
from codelist.models import KonovaCode from codelist.models import KonovaCode
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_COMPENSATION_HANDLER_ID from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_COMPENSATION_HANDLER_ID
from compensation.models import EcoAccount, EcoAccountDocument, EcoAccountDeduction from compensation.models import EcoAccount, EcoAccountDocument, EcoAccountDeduction
from compensation.utils.quality import EcoAccountQualityChecker
from intervention.models import Responsibility, Handler, Intervention, Legal from intervention.models import Responsibility, Handler, Intervention, Legal
from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater
from konova.models import Geometry from konova.models import Geometry
@ -69,6 +70,7 @@ class EcoAccountMigrater(CompensationMigrater):
eco_account = self._migrate_action_control_deadlines(eco_account, oek) eco_account = self._migrate_action_control_deadlines(eco_account, oek)
eco_account = self._migrate_actions(eco_account, oek) eco_account = self._migrate_actions(eco_account, oek)
eco_account = self._migrate_log(eco_account, oek) eco_account = self._migrate_log(eco_account, oek)
eco_account = self._migrate_recorded(eco_account, oek)
eco_account = self._migrate_deductions(eco_account, oek) eco_account = self._migrate_deductions(eco_account, oek)
eco_account = self._migrate_documents(eco_account, EcoAccountDocument, oek) eco_account = self._migrate_documents(eco_account, EcoAccountDocument, oek)
eco_account.save() eco_account.save()
@ -334,3 +336,37 @@ class EcoAccountMigrater(CompensationMigrater):
create_action.timestamp = timezone.make_aware(create_ts) create_action.timestamp = timezone.make_aware(create_ts)
create_action.save() create_action.save()
return create_action return create_action
def _migrate_recorded(self, instance, db_result):
quality_checker = EcoAccountQualityChecker(instance)
quality_checker.run_check()
if quality_checker.valid:
identifier = f"'{db_result[0]}'"
tmp_cursor = self.db_connection.cursor()
tmp_cursor.execute(
'select '
'lb.status_neu, '
'lb.erstelltvon, '
'lb.erstelltam '
'from "OBJ_MASTER" om '
'join logbuch lb on om."GISPADID"=lb.gispadid '
'where '
f'om."KENNUNG"={identifier} and '
'lb.status_neu=610 '
'order by lb.erstelltam desc '
'limit 1'
)
fetch_result = tmp_cursor.fetchone()
if fetch_result is not None:
recorded_by = fetch_result[1]
recorded_ts = timezone.make_aware(fetch_result[2])
user = self._get_migrate_user(recorded_by)
instance.recorded = instance.recorded or UserActionLogEntry.get_recorded_action(
user,
"Migriertes Verzeichnen"
)
instance.recorded.timestamp = recorded_ts
instance.recorded.save()
return instance