Skip to content

Feat/add active field to costcenter #278

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

Open
wants to merge 3 commits into
base: release/1.1.0
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void testNoCostCenterConversionSuccess() {
@Test
void testCostCenterConversionSuccess() {
val txId = Transaction.id("1", "1");
when(organisationPublicApiIF.findCostCenter("1", "1")).thenReturn(Optional.of(new OrganisationCostCenter(new OrganisationCostCenter.Id("1", "1"), "Cost Center 1", "2", null, null)));
when(organisationPublicApiIF.findCostCenter("1", "1")).thenReturn(Optional.of(new OrganisationCostCenter(new OrganisationCostCenter.Id("1", "1"), "Cost Center 1", "2", null, null, true)));

val txItem1 = new TransactionItemEntity();
txItem1.setId(TransactionItem.id(txId, "0"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,13 @@ void testDocumentConversionWithMultipleViolations() {
}

@Test
public void testDocumentConversionWithNoCurrenciInDocument() {
val txId = "1";
val txInternalNumber = "txn123";
val organisationId = "org1";
val customerCurrencyCode = "UNKNOWN_CURRENCY";
val customerVatCode = "UNKNOWN_VAT";

val document = Document.builder()
void testDocumentConversionWithNoCurrencyInDocument() {
String txId = "1";
String txInternalNumber = "txn123";
String organisationId = "org1";
String customerVatCode = "UNKNOWN_VAT";

Document document = Document.builder()
.vat(Vat.builder()
.customerCode(customerVatCode)
.build())
Expand All @@ -235,13 +234,13 @@ public void testDocumentConversionWithNoCurrenciInDocument() {
.build())
.build();

val txItem = new TransactionItemEntity();
TransactionItemEntity txItem = new TransactionItemEntity();
txItem.setDocument(Optional.of(document));

val items = new LinkedHashSet<TransactionItemEntity>();
LinkedHashSet<TransactionItemEntity> items = new LinkedHashSet<TransactionItemEntity>();
items.add(txItem);

val transaction = new TransactionEntity();
TransactionEntity transaction = new TransactionEntity();
transaction.setId(txId);
transaction.setTransactionInternalNumber(txInternalNumber);
transaction.setOrganisation(Organisation.builder()
Expand Down
4 changes: 2 additions & 2 deletions docs/examples/cost_center_csv_example.csv
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
customer code,external customer code,name,parent customer code
12323,456,CostCenter,99
customer code,external customer code,name,parent customer code,active
12323,456,CostCenter,99,True
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ public class CostCenterUpdate {
private String name;
@CsvBindByName(column = "parent customer code")
private String parentCustomerCode;
@CsvBindByName(column = "active")
private boolean active = true;

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class OrganisationCostCenter extends CommonEntity implements Persistable<
@Column(name = "parent_customer_code")
private String parentCustomerCode;

@Column(name = "active")
@Builder.Default
private boolean active = true;

public Optional<OrganisationCostCenter> getParent() {
return Optional.ofNullable(parent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ public class OrganisationCostCenterView {

private OrganisationCostCenterView parentCustomerCode;

private boolean active;

private Problem error;

public static OrganisationCostCenterView fromEntity(OrganisationCostCenter costCenter) {
OrganisationCostCenterViewBuilder builder = OrganisationCostCenterView.builder()
.customerCode(costCenter.getId() == null ? null : costCenter.getId().getCustomerCode())
.externalCustomerCode(costCenter.getExternalCustomerCode())
.name(costCenter.getName());
.name(costCenter.getName())
.active(costCenter.isActive());
if (costCenter.getParent().isPresent()) {
builder.parentCustomerCode(OrganisationCostCenterView.fromEntity(costCenter.getParent().get()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public OrganisationCostCenterView updateCostCenter(String orgId, CostCenterUpdat
OrganisationCostCenter costCenter = costCenterFound.get();
costCenter.setExternalCustomerCode(costCenterUpdate.getExternalCustomerCode());
costCenter.setName(costCenterUpdate.getName());
costCenter.setActive(costCenterUpdate.isActive());
// check if parent exists
if (costCenterUpdate.getParentCustomerCode() != null) {
Optional<OrganisationCostCenter> project = getCostCenter(orgId, costCenterUpdate.getParentCustomerCode());
Expand Down Expand Up @@ -87,7 +88,8 @@ public OrganisationCostCenterView insertCostCenter(String orgId, CostCenterUpdat
OrganisationCostCenter.OrganisationCostCenterBuilder builder = OrganisationCostCenter.builder()
.id(new OrganisationCostCenter.Id(orgId, costCenterUpdate.getCustomerCode()))
.externalCustomerCode(costCenterUpdate.getExternalCustomerCode())
.name(costCenterUpdate.getName());
.name(costCenterUpdate.getName())
.active(costCenterUpdate.isActive());

// check if parent exists
if (costCenterUpdate.getParentCustomerCode() != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE organisation_cost_center
ADD COLUMN active BOOLEAN DEFAULT TRUE;
ALTER TABLE organisation_cost_center_aud
ADD COLUMN active BOOLEAN DEFAULT TRUE;
Loading