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


class FixCostCalculationQuery(SQLPacket):
    """Fix cost aggregation from DT472 into year slices (DT861)"""
    version = 1
    run_on_startup = True
    done_after_success = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 13128

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

    sql_file_1 = "wi13128_p_verdichte_pr_akt.sql"
    sql_file_2 = "wi13128_P_UPD_KOST_AUFW_ERL_AKT.sql"

    def fix(self, runner):
        if self.DBMS == DBMS_MSSQL:
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_file_1)
            self.apply_fix_ddl_file(self.sql_planta_de_dbms, self.sql_file_2)
            return self.success()
        else:
            return self.success()