template dummies

This commit is contained in:
Rene Kaßeböhmer
2025-05-05 16:21:03 +02:00
parent 4ca8cc06c7
commit d338f04bc6
7 changed files with 57 additions and 18 deletions

4
.gitignore vendored
View File

@ -25,4 +25,6 @@ mapping.csv
SCInstalledBaseRole__c.csv
SCPriceList__c.csv
SCPriceListItem__c.csv
SCResourceAssignment__c.csv
SCResourceAssignment__c.csv
ContractTemplates.csv
ServiceContract.csv

View File

@ -1,10 +0,0 @@
{
"allOrNone": true,
"excludeIdsFromCSVFiles": true,
"objects": [
{
"query": "SELECT Business_Type__c, IsStandard, IsActive, Name, Brand__c, Country__c FROM Pricebook2",
"operation": "Insert"
}
]
}

View File

@ -0,0 +1,4 @@
ObjectName,FieldName,RawValue,Value
ServiceContract,Status,Active,Active
ServiceContract,Status,Cancelled,Inactive
ServiceContract,Status,Created,Active
1 ObjectName FieldName RawValue Value
2 ServiceContract Status Active Active
3 ServiceContract Status Cancelled Inactive
4 ServiceContract Status Created Active

View File

@ -0,0 +1,16 @@
{
"allOrNone": true,
"excludeIdsFromCSVFiles": true,
"objects": [
{
"query": "SELECT Name FROM Pricebook2",
"operation": "Readonly",
"master": false,
"externalId": "Name"
},{
"query": "SELECT PKey__c,Name,Status,BillingCountryCode,Term,Pricebook2.Name,IsTemplate__c,TemplateCountry__c,FSL_Sold_by__c FROM ServiceContract",
"operation": "Upsert",
"useValuesMapping": true
}
]
}

View File

@ -33,6 +33,9 @@
},{
"sobject": "SCResourceAssignment__c",
"query": "SELECT Id, ValidTo__c, ValidFrom__c, Country__c, City__c, PostalCode__c, District__c, Street__c, HouseNo__c, Extension__c, FlatNo__c, Floor__c, GeoY__c, GeoX__c, Resource__c, Resource__r.Employee__r.Name, Stock__c, Stock__r.ID2__c FROM SCResourceAssignment__c WHERE Country__c = '{country}' AND ValidTo__c >= TODAY"
},{
"sobject": "ContractTemplates",
"query": "SELECT id, name, TemplateName__c, status__c, Brand__r.Name, Country__c, Runtime__c FROM sccontract__c WHERE Template__c = null AND Country__c = '{country}'"
}
]
}

View File

@ -34,6 +34,7 @@ read_df_pricelistitem = pd.read_csv('../1_extract_data/results/SCPriceListItem__
read_df_resourceassignment = pd.read_csv('../1_extract_data/results/SCResourceAssignment__c.csv', header=0, keep_default_na=False, dtype=str)
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)
# 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']
@ -45,6 +46,7 @@ reindex_columns_pricelistitem = ['Id', 'Article__r.Name', 'Article__r.EANCode__c
reindex_columns_resourceassignment = ['Id', 'ValidTo__c', 'ValidFrom__c', 'Country__c', 'City__c', 'PostalCode__c', 'District__c', 'Street__c', 'HouseNo__c', 'Extension__c', 'FlatNo__c', 'Floor__c', 'GeoY__c', 'GeoX__c', 'Resource__c', 'Resource__r.Employee__r.Name', 'Stock__c', 'Stock__r.ID2__c']
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 the columns to match the desired format
df = read_df.reindex(reindex_columns, axis=1)
@ -56,6 +58,7 @@ df_pricelistitem = read_df_pricelistitem.reindex(reindex_columns_pricelistitem,
df_resourceassignment = read_df_resourceassignment.reindex(reindex_columns_resourceassignment, axis=1)
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)
##--------------------------------------------------------------------------##
## Update for IoT Addresses and Locations
@ -112,7 +115,8 @@ merged_df_ib = pd.merge(df_ib,
print(merged_df_ib.columns)
# If there are missing values (no match found), you can fill them with a placeholder
merged_df_ib['PKey__c'].fillna('Not Found', inplace=True)
#merged_df_ib['PKey__c'].fillna('Not Found', inplace=True)
#merged_df_ib = merged_df_ib['PKey__c'].fillna('Not Found')
merged_df_ib['PKey__c'] = (
merged_df_ib['PKey__c'].astype(str) + ';' +
@ -241,9 +245,6 @@ merged_df_ib = merged_df_ib.replace({'Kind_of_Energy__c': {'4': '3', '5': '3'}})
## 5. SCInstalledBaseRole__c.csv
print(df_ibr)
print(child_df)
df_ibr = pd.merge(df_ibr,
child_df[['Id', 'PKey__c']],
left_on='InstalledBaseLocation__c',
@ -256,8 +257,6 @@ df_ibr = df_ibr.drop('Id_x', axis=1)
df_ibr = df_ibr.drop('Id_y', axis=1)
df_ibr = df_ibr.drop('InstalledBaseLocation__c', axis=1)
print(df_ibr)
df_ibr.columns = ['Type', 'ActiveFrom', 'ActiveTo', 'ParentRecordId', 'Location.PKey__c']
#remove kind_of_energy__c and kind_of_installation if field dependency to main product group is not correct
@ -427,6 +426,31 @@ van_parenlocation_df['LocationType'] = 'Site'
new_parent_locations = van_parenlocation_df[~van_parenlocation_df['Name'].isin(parent_df['Name'])]
parent_df = pd.concat([parent_df, new_parent_locations], ignore_index=True)
##--------------------------------------------------------------------------##
## Service Contract Templates (Dummies)
##--------------------------------------------------------------------------##
df_servicecontracttemplates['Pricebook2.Name'] = (
df_servicecontracttemplates['Country__c'].astype(str).fillna('').str.upper() + ' ' +
df_servicecontracttemplates['Brand__r.Name'].astype(str).fillna('').str.upper() + ' ' +
"SERVICE"
)
df_servicecontracttemplates = df_servicecontracttemplates.drop('Name', axis=1)
df_servicecontracttemplates = df_servicecontracttemplates.drop('Brand__r.Name', axis=1)
df_servicecontracttemplates.columns = ['PKey__c', 'Name', 'Status', 'BillingCountryCode', 'Term', 'Pricebook2.Name']
df_servicecontracttemplates['Name'] = df_servicecontracttemplates['Name'].replace('', 'No Name')
df_servicecontracttemplates['IsTemplate__c'] = 'true'
df_servicecontracttemplates['TemplateCountry__c'] = df_servicecontracttemplates['BillingCountryCode']
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)
# Write each DataFrame to a separate CSV file
address_df.to_csv('../4_upsert_address_and_parent_location/Address.csv', index=False)
parent_df.to_csv('../4_upsert_address_and_parent_location/Location.csv', index=False)
@ -436,7 +460,7 @@ df_ibr.to_csv('../11_upsert_associated_location/AssociatedLocation_beforetransfo
df_pricelist.to_csv('../12_insert_pricebook2_and_pricebookentries/Pricebook2.csv', index=False)
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)
## end mapping
print('Data has been successfully transformed and saved to CSV files.')