# -*- coding: utf-8 -*-
from ppms.migration.packet import *


class AbsenceAggregation(ChangeDTPPacket):
    '''Activates the structure aggregation parameter in the absence module'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 11161

    def fix(self, runner):
        failures = 0
        for da_id, df_id in (('046138', 46005), ('046138', 46006)):
            record = self.get_record(411, [da_id, df_id], [106])
            if not self.change_value(record, 'structure_summary', 0, 1):
                failures += 1
                
        if failures:
            return self.fail()
        
        return self.success()