# -*- coding: utf-8 -*-
from ppms.migration import SQLPacket, PacketCategory, \
    VersionType, MinVersionDependency, MaxVersionDependency

FILE = 'WI15227_target_contribution.sql'


class AddCostsLastReportPerYear(SQLPacket):
    """Creates the column DT823.DI040214 'Statusbericht: Kosten Gesamt' which
    has been virtual before. Then recalculates it's value from the current
    approved report per project. Needed for Portfolioauswertung/Scoring"""

    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 15227

    def get_dependencies(self):
        return(MinVersionDependency(version='39.5', version_type=VersionType.CUSTOMIZING),
               MaxVersionDependency(version='39.5.6', version_type=VersionType.CUSTOMIZING))

    def fix(self, packet_runner):
        self.apply_fix_ddl_file(self.sql_planta_de_dbms, FILE, split=True)
        return self.success()