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

class AddMissingAuditDataitems(SQLPacket):
    '''In S18 the data items for audited functionality are missing, those are added here.'''
    version = 1
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 17073


    fname = "WI17073_add_audit_dataitems.sql"

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

    def fix(self, runner):
        di_exists = ppms.db_select("select count(*) from DT412 where DI000238='063233'")
        if int(di_exists[0][0]) == 1:
            self.log("The data items are already there - skipping package!")
            return self.success()

        self.apply_dml_file(self.sql_planta_de_dbms, self.fname)

        return self.success()