# -*- coding: utf-8 -*-

from ppms.migration.packet import *

AFTER_HASH = 'fd4e5d1f081ea0e8af42df99cdaabb21'
BEFORE_HASH = '93f8ad09c81688eb26271598d9acd977'

FIX_FUNC = '''
def computeOutput(di):
    rec = di.get_dtp_record()

    if rec.object_type.get_value() in (192,193):
        active_process_phase=ppms.search_record(461, [rec.object_id.get_value()], [59017], True).active_process_phase.get_value()
        if active_process_phase == rec.phase.get_value():
            return 1
        else:
            return 0
    else:
        return 0

computeOutput.deps = ('DI057817','DI057819', 'DI041152', 'DI058211')'''

class ChangeValueRangeAktivePhase(MigratePythonPacket):
    '''Change VR in di059076 for fixing the Process model'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 9402

            
    def fix(self, runner):
        error = 0
        
        fixfunc = lambda _: FIX_FUNC
        if not self.migrate_python(BEFORE_HASH, AFTER_HASH,self.CU_TYPE_DATAITEM, '059076', fixfunc):
            error += 1
        
        if error:
            return self.fail()

        return self.success()
