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


class UpdateLiabilityImport(SQLPacket, ChangeDTPPacket):
    """Update the liability template to remove all liability values before importing"""
    done_after_success = True
    run_on_startup = True
    category = PacketCategory.CATEGORY_MANDATORY
    wi_number = 12091

    FILENAME = 'wi12091_liability_import.sql'

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

    def fix(self, runner):
        record = self.get_record(dt_num=405, key_list=['009C68'], di_list=['python_module_subclass'])
        if not self.change_value(record=record, attribute='python_module_subclass',
                                 old_value='ppms.interface.MtsModule',
                                 new_value='ppms.interface.MtsLiabilityModule'):
            return self.fail('Could not update module customizing - was it individualized?')

        self.apply_dml_file(self.sql_planta_de_dbms, self.FILENAME)

        return self.success()