Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model changes #100

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
308 changes: 142 additions & 166 deletions code/db/data-model.cds
Original file line number Diff line number Diff line change
@@ -1,175 +1,151 @@
using {
managed,
cuid,
Currency,
Country,
Language
managed,
cuid,
Currency,
Country,
Language
} from '@sap/cds/common';
using from '@sap/cds-common-content';
using {Percentage} from './data-types';
using {Percentage} from './data-types';

context susaas.db {
// Define reusable aspects for common patterns
aspect ManagedCuid : cuid, managed;

entity Projects : cuid, managed {
description : String;
validFrom : Date;
validTo : Date;

// compositions
assessments : Association to many Assessments
on assessments.project = $self;
members : Composition of many Members
on members.project = $self;
};


@assert.unique: {membersUserProject: [
user,
project
]}
entity Members : cuid, managed {
// associations
user : Association to Users;
project : Association to Projects;
}

@assert.unique: {usersEmail: [email]}
entity Users : cuid, managed {
@Core.Computed: true
fullName : String;
firstName : String;
lastName : String;
email : String;
shadowId : UUID;
iasLocation : String;
// associations
role : Association to Roles;
}

// Start of Assessments entity and associated Child Entities
entity Assessments : cuid, managed {
description : String;
eolProductDesign : Percentage;
// association
product : Association to Products;
project : Association to Projects;

// compositions
salesSplits : Composition of many SalesSplits
on salesSplits.assessment = $self;
materialSplits : Composition of many MaterialSplits
on materialSplits.assessment = $self;
circularityMetrics : Composition of many CircularityMetrics
on circularityMetrics.assessment = $self;
}

entity MaterialSplits : cuid {
materialCode : String;
materialType : String;
weightShare : Percentage;
shareRecycled : Percentage;
// association
assessment : Association to Assessments;
}

entity CircularityMetrics : cuid {
eoLRecyclability : Percentage;
countryRecyclability : Country;
// association
assessment : Association to Assessments;
}

entity SalesSplits : cuid {
totalRevenue : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
traditionalProductSales : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
repairServicesSales : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
reSellSales : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
currency : Currency;
country : Country;
// association
assessment : Association to Assessments;
}


entity Roles : managed {
key ID : String;
description : String;
}


// ##############################
// Uploaded data
// ##############################

entity SalesOrders {
key so : String(100);
key soItemPos : String(10);
lifecycleStatus : String(1);
billingStatus : String(1);
deliveryStatus : String(1);
grossAmount : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
taxAmount : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
netAmount : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
quantity : Decimal(15, 2);
quantityUnit : String(3);
deliveryDate : Timestamp;
product : Association to Products;
category : String(40);
bpRole : String(3);
bpId : String(10);
companyName : String(80);
text : String(255);
itemAtpStatus : String(1);
firstName : String(40);
lastName : String(40);
overallStatus : String(1);
currency : Currency;
country : Country;
language : Language;
}

entity Products {
key ID : String(10);
typeCode : String(2);
category : String(40);
supplierId : String(10);
taxTarifCode : Integer;
measureUnit : String(3);
weightMeasure : Decimal(15, 3) @Measures.ISOCurrency: weightUnit;
weightUnit : String(3);
price : Decimal(10, 3) @Measures.ISOCurrency: currency_code;
text : String(255);
language : Language;
currency : Currency;
eolProductDesign : Percentage;
traditionalSalesShare : Percentage;
repairSalesShare : Percentage;
resellSalesShare : Percentage;
recyclingCountries : Composition of many RecyclingCountries
on recyclingCountries.product = $self;
recyclingMaterials : Composition of many RecyclingMaterials
on recyclingMaterials.product = $self;
}

entity RecyclingCountries {
key product : Association to Products;
key country : Country;
eolRecyclability : Percentage;

}

entity RecyclingMaterials {
key product : Association to Products;
key material : String;
materialName : String;
weightShare : Percentage;
recycleShare : Percentage;
}
context susaas.db {
entity Projects : ManagedCuid {
description : String;
validFrom : Date;
validTo : Date;

// compositions
assessments : Association to many Assessments on assessments.project = $self;
members : Composition of many Members on members.project = $self;
};

@assert.unique.membersUserProject: [user, project]
entity Members : ManagedCuid {
user : Association to Users;
project : Association to Projects;
}

@assert.unique.usersEmail: [email]
entity Users : ManagedCuid {
@Core.Computed: 'firstName || \' \' || lastName'
fullName : String virtual;
firstName : String;
lastName : String;
@Core.IsEmail
email : String(255);
shadowId : UUID;
iasLocation : String;
role : Association to Roles;
}

entity Assessments : ManagedCuid {
description : String;
eolProductDesign : Percentage;
product : Association to Products;
project : Association to Projects;

salesSplits : Composition of many SalesSplits on salesSplits.assessment = $self;
materialSplits : Composition of many MaterialSplits on materialSplits.assessment = $self;
circularityMetrics : Composition of many CircularityMetrics on circularityMetrics.assessment = $self;
}

entity MaterialSplits : cuid {
materialCode : String;
materialType : String;
weightShare : Percentage;
shareRecycled : Percentage;
assessment : Association to Assessments;
}

entity CircularityMetrics : cuid {
eoLRecyclability : Percentage;
countryRecyclability : Country;
assessment : Association to Assessments;
}

entity SalesSplits : cuid {
totalRevenue : Decimal(15,3) @Measures.ISOCurrency: currency;
traditionalProductSales : Decimal(15,3) @Measures.ISOCurrency: currency;
repairServicesSales : Decimal(15,3) @Measures.ISOCurrency: currency;
reSellSales : Decimal(15,3) @Measures.ISOCurrency: currency;
currency : Currency;
country : Country;
assessment : Association to Assessments;
}

entity Roles : managed {
key ID : String(10);
description : String(255);
}

entity SalesOrders {
key so : String(100);
key soItemPos : String(10);
lifecycleStatus : String(1);
billingStatus : String(1);
deliveryStatus : String(1);
grossAmount : Decimal(15,3) @Measures.ISOCurrency: currency;
taxAmount : Decimal(15,3) @Measures.ISOCurrency: currency;
netAmount : Decimal(15,3) @Measures.ISOCurrency: currency;
quantity : Decimal(15,2);
quantityUnit : String(3);
deliveryDate : Date;
product : Association to Products;
category : String(40);
bpRole : String(3);
bpId : String(10);
companyName : String(80);
text : String(255);
itemAtpStatus : String(1);
overallStatus : String(1);
currency : Currency;
country : Country;
language : Language;
}

entity Products {
key ID : String(10);
typeCode : String(2);
category : String(40);
supplierId : String(10);
taxTarifCode : Integer;
measureUnit : String(3);
weightMeasure : Decimal(15,3) @Measures.Unit: weightUnit;
weightUnit : String(3);
price : Decimal(15,3) @Measures.ISOCurrency: currency;
text : String(255);
language : Language;
currency : Currency;
eolProductDesign : Percentage;
traditionalSalesShare : Percentage;
repairSalesShare : Percentage;
resellSalesShare : Percentage;
recyclingCountries : Composition of many RecyclingCountries on recyclingCountries.product = $self;
recyclingMaterials : Composition of many RecyclingMaterials on recyclingMaterials.product = $self;
}


entity RecyclingCountries {
key product : Association to Products;
key country : Country;
eolRecyclability : Percentage;
}

entity RecyclingMaterials {
key product : Association to Products;
key material : String(10);
materialName : String(50);
weightShare : Percentage;
recycleShare : Percentage;
}
}

context susaas.common {
@cds.persistence.exists
entity Shared : cuid {
value : String;
};
@cds.persistence.exists
entity Shared : cuid {
value : String(255);
};
}
Loading