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

class FixProgramTrafficLights(SQLPacket):
    '''Fixes the traffic lights in modules status and status report for programs.
    Recalculates existing data of total effort and effort budget for status
    reports (DI008610 and DI008615) as sum of their underlying cost type group
    per report data (DT284)'''
    
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 14362

    fix_report_data =  'WI14362_fix_effort_program_reports.sql'
    
    def get_dependencies(self):
        return (MinVersionDependency(version='39.5.3', 
                                     version_type=VersionType.CUSTOMIZING),
                MaxVersionDependency(version='39.5.6', 
                                     version_type=VersionType.CUSTOMIZING))

    def fix(self, runner):       
        # Fix existing report data
        self.apply_dml_file(self.sql_planta_de_dbms, self.fix_report_data)
        
        return self.success()