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


CODE = """from ppms import ppms_cu
def computeOutput(di):
    mod_obj = ppms.get_macro_module()
    return ppms_cu.Access.get_text_constant(mod_obj,'001473')
computeOutput.deps = ("",)"""
BEFORE_HASH = 'd41d8cd98f00b204e9800998ecf8427e'
AFTER_HASH = '8bfd9eb1479457a00f9c39685e2fe28b'

class ChangeDBNameField(ChangeDTPPacket, MigratePythonPacket):
    '''Fix the datafield that shows the DB Name being empty in some cases'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 7282

    def fix(self, runner):
        record = self.get_record(412, ['025749'], [1990])
        if not self.change_value(record, 'wb_type', '', 'PY'):
            return self.fail()

        fix_func = lambda _: CODE
        if not self.migrate_python(BEFORE_HASH, AFTER_HASH,
                                   self.CU_TYPE_DATAITEM, '025749', fix_func):
            return self.fail()

        return self.success()
