savestate

This commit is contained in:
Rene Kaßeböhmer
2025-05-09 15:41:55 +02:00
parent 14bc0f6dca
commit 8af0ef8e78
17 changed files with 290 additions and 108 deletions

View File

@ -24,6 +24,10 @@ country_mapping = {
'RO': 'Romania'
}
##--------------------------------------------------------------------------##
## Loading Data
##--------------------------------------------------------------------------##
# Read the input CSV file, assuming the second row is the header
read_df = pd.read_csv('../1_extract_data/results/SCInstalledBaseLocation__c.csv', header=0, keep_default_na=False, dtype=str)
read_df_ib = pd.read_csv('../1_extract_data/results/SCInstalledBase__c.csv', header=0, keep_default_na=False, dtype=str)
@ -35,6 +39,7 @@ read_df_resourceassignment = pd.read_csv('../1_extract_data/results/SCResourceAs
read_df_address_iot = pd.read_csv('../1_extract_data/results/Address.csv', header=0, keep_default_na=False, dtype=str)
read_df_location_iot = pd.read_csv('../1_extract_data/results/ParentLocation.csv', header=0, keep_default_na=False, dtype=str)
read_df_servicecontracttemplates = pd.read_csv('../1_extract_data/results/ContractTemplates.csv', header=0, keep_default_na=False, dtype=str)
read_df_servicecontracts = pd.read_csv('../1_extract_data/results/SCContract__c.csv', header=0, keep_default_na=False, dtype=str)
# Columns for reindexing
reindex_columns = ['Id','City__c','Country__c','GeoY__c','GeoX__c','PostalCode__c','Street__c','Extension__c','HouseNo__c','FlatNo__c','Floor__c']
@ -47,6 +52,7 @@ reindex_columns_resourceassignment = ['Id', 'ValidTo__c', 'ValidFrom__c', 'Count
reindex_columns_address_iot = ['Id', 'Country', 'CountryCode', 'Street', 'City', 'ParentId', 'PostalCode']
reindex_columns_location_iot = ['Id', 'Name']
reindex_columns_servicecontracttemplates = ['Id', 'Name', 'TemplateName__c', 'Status__c', 'Brand__r.Name', 'Country__c', 'Runtime__c']
reindex_columns_servicecontracts = ['Id', 'Name', 'Template__c', 'Status__c', 'Brand__r.Name', 'Country__c', 'Runtime__c', 'EndDate__c', 'StartDate__c', 'Account__c', 'AccountOwner__c', 'IoT_Registration_Status__c']
# Reindex the columns to match the desired format
df = read_df.reindex(reindex_columns, axis=1)
@ -59,6 +65,7 @@ df_resourceassignment = read_df_resourceassignment.reindex(reindex_columns_resou
df_address_iot = read_df_address_iot.reindex(reindex_columns_address_iot, axis=1)
df_location_iot = read_df_location_iot.reindex(reindex_columns_location_iot, axis=1)
df_servicecontracttemplates = read_df_servicecontracttemplates.reindex(reindex_columns_servicecontracttemplates, axis=1)
df_servicecontract = read_df_servicecontracts.reindex(reindex_columns_servicecontracts, axis=1)
##--------------------------------------------------------------------------##
## Update for IoT Addresses and Locations
@ -449,7 +456,36 @@ df_servicecontracttemplates['FSL_Sold_by__c'] = 'Service'
# Convert Runtime__c (Term) to natural numbers
df_servicecontracttemplates['Term'] = pd.to_numeric(df_servicecontracttemplates['Term'].str.extract('(\d+)')[0], errors='coerce')
df_servicecontracttemplates['Term'] = df_servicecontracttemplates['Term'].fillna(12).astype(int)
df_servicecontracttemplates['Term'] = df_servicecontracttemplates['Term'].fillna(0).astype(int)
##--------------------------------------------------------------------------##
## Service Contract
##--------------------------------------------------------------------------##
df_servicecontract['Pricebook2.Name'] = (
df_servicecontract['Country__c'].astype(str).fillna('').str.upper() + ' ' +
df_servicecontract['Brand__r.Name'].astype(str).fillna('').str.upper() + ' ' +
"SERVICE"
)
df_servicecontract = df_servicecontract.drop('Name', axis=1)
df_servicecontract = df_servicecontract.drop('Brand__r.Name', axis=1)
df_servicecontract.columns = ['PKey__c', 'TemplateId__r.PKey__c', 'Status', 'BillingCountryCode', 'Term', 'EndDate', 'StartDate', 'AccountId', 'Service_Recipient__c', 'IoT_Registration_Status__c', 'Pricebook2.Name']
df_servicecontract['IoT_Registration_Status__c'] = df_servicecontract['IoT_Registration_Status__c'].replace('', 'Open')
df_servicecontract['Name'] = df_servicecontract['PKey__c']
df_servicecontract['TemplateCountry__c'] = df_servicecontract['BillingCountryCode']
#df_servicecontract = df_servicecontract.drop('TemplateId__r.PKey__c', axis=1)
# Convert Runtime__c (Term) to natural numbers
df_servicecontract['Term'] = pd.to_numeric(df_servicecontract['Term'].str.extract('(\d+)')[0], errors='coerce')
df_servicecontract['Term'] = df_servicecontract['Term'].fillna(0).astype(int)
##--------------------------------------------------------------------------##
## Saving to CSV
##--------------------------------------------------------------------------##
# Write each DataFrame to a separate CSV file
address_df.to_csv('../4_upsert_address_and_parent_location/Address.csv', index=False)
@ -461,6 +497,7 @@ df_pricelist.to_csv('../12_insert_pricebook2_and_pricebookentries/Pricebook2.csv
df_pricelistitem.to_csv('../12_insert_pricebook2_and_pricebookentries/PricebookEntry.csv', index=False)
merged_df_location_iot.to_csv('../3_update_address_and_location_data_for_migration/Location.csv', index=False)
df_servicecontracttemplates.to_csv('../13_insert_servicecontracttemplates_dummies/ServiceContract.csv', index=False)
df_servicecontract.to_csv('../15_insert_servicecontract/ServiceContract_beforetransform.csv', index=False)
## end mapping
print('Data has been successfully transformed and saved to CSV files.')