#132 WIP Migrate recording accounts
* adds recording state of ecoaccounts
This commit is contained in:
parent
d19a563491
commit
6ce2dd8509
@ -169,8 +169,8 @@ class BaseMigrater:
|
||||
action.save()
|
||||
instance.log.add(action)
|
||||
|
||||
first_entry = instance.log.order_by("-timestamp").first()
|
||||
last_entry = instance.log.order_by("timestamp").first()
|
||||
first_entry = instance.log.order_by("timestamp").first()
|
||||
last_entry = instance.log.order_by("-timestamp").first()
|
||||
|
||||
if first_entry is not None:
|
||||
instance.created = UserActionLogEntry.get_created_action(first_entry.user)
|
||||
|
@ -9,6 +9,7 @@ from django.utils import timezone
|
||||
from codelist.models import KonovaCode
|
||||
from codelist.settings import CODELIST_CONSERVATION_OFFICE_ID, CODELIST_COMPENSATION_HANDLER_ID
|
||||
from compensation.models import EcoAccount, EcoAccountDocument, EcoAccountDeduction
|
||||
from compensation.utils.quality import EcoAccountQualityChecker
|
||||
from intervention.models import Responsibility, Handler, Intervention, Legal
|
||||
from konova.management.commands.kspMigrater.compensation_migrater import CompensationMigrater
|
||||
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_actions(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_documents(eco_account, EcoAccountDocument, oek)
|
||||
eco_account.save()
|
||||
@ -334,3 +336,37 @@ class EcoAccountMigrater(CompensationMigrater):
|
||||
create_action.timestamp = timezone.make_aware(create_ts)
|
||||
create_action.save()
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user