#132 EMA finance volume migration
* adds migration of finance volumes into ema comment
This commit is contained in:
		
							parent
							
								
									4a06f8625a
								
							
						
					
					
						commit
						899a6240c1
					
				@ -1,5 +1,6 @@
 | 
			
		||||
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
from django.utils import formats
 | 
			
		||||
 | 
			
		||||
from codelist.models import KonovaCode
 | 
			
		||||
from codelist.settings import CODELIST_BIOTOPES_ID, CODELIST_BIOTOPES_EXTRA_CODES_ID, \
 | 
			
		||||
@ -551,6 +552,7 @@ class EmaMigrater(CompensationMigrater):
 | 
			
		||||
                ema_obj = self._migrate_deadlines(ema_obj, ema)
 | 
			
		||||
                ema_obj = self._migrate_action_control_deadlines(ema_obj, ema)
 | 
			
		||||
                ema_obj = self._migrate_actions(ema_obj, ema)
 | 
			
		||||
                ema_obj = self._migrate_finance_volume_to_comment(ema_obj, ema)
 | 
			
		||||
                ema_obj = self._migrate_documents(ema_obj, EmaDocument, ema)
 | 
			
		||||
                ema_obj.save()
 | 
			
		||||
 | 
			
		||||
@ -656,3 +658,31 @@ class EmaMigrater(CompensationMigrater):
 | 
			
		||||
 | 
			
		||||
        tmp_cursor.close()
 | 
			
		||||
        return ema_obj
 | 
			
		||||
 | 
			
		||||
    def _migrate_finance_volume_to_comment(self, ema_obj, ema_result):
 | 
			
		||||
        ema_identifier = f"'{ema_result[0]}'"
 | 
			
		||||
        tmp_cursor = self.db_connection.cursor()
 | 
			
		||||
        tmp_cursor.execute(
 | 
			
		||||
            'select '
 | 
			
		||||
                'b.datum, '
 | 
			
		||||
                'b.hoehe '
 | 
			
		||||
            'from "OBJ_MASTER" om '
 | 
			
		||||
                'left join bewilligung b on om."GISPADID"=b.gispadid '
 | 
			
		||||
            'where '
 | 
			
		||||
                f'om."KENNUNG"={ema_identifier} '
 | 
			
		||||
        )
 | 
			
		||||
        db_results = tmp_cursor.fetchall()
 | 
			
		||||
        for result in db_results:
 | 
			
		||||
            payment_date = result[0]
 | 
			
		||||
            payment_amount = result[1]
 | 
			
		||||
 | 
			
		||||
            comment_extra = f"\n\nFinanzierung bewilligt am {formats.localize(payment_date, use_l10n=True)} in Höhe von {formats.localize(payment_amount, use_l10n=True)} €"
 | 
			
		||||
            comment = ema_obj.comment or ""
 | 
			
		||||
            if comment_extra in comment:
 | 
			
		||||
                # skip
 | 
			
		||||
                continue
 | 
			
		||||
            comment += comment_extra
 | 
			
		||||
            ema_obj.comment = comment
 | 
			
		||||
 | 
			
		||||
        tmp_cursor.close()
 | 
			
		||||
        return ema_obj
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user