add coop-assets-transaction reverse-entry to entity+table

This commit is contained in:
Michael Hoennig 2024-04-09 08:31:02 +02:00
parent 074187b499
commit 1e0583bab2
3 changed files with 41 additions and 10 deletions

View File

@ -50,6 +50,7 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO
.withProp(HsOfficeCoopAssetsTransactionEntity::getAssetValue)
.withProp(HsOfficeCoopAssetsTransactionEntity::getReference)
.withProp(HsOfficeCoopAssetsTransactionEntity::getComment)
.withProp(at -> ofNullable(at.getReverseEntry()).map(HsOfficeCoopAssetsTransactionEntity::toShortString).orElse(null))
.quotedValues(false);
@Id
@ -93,6 +94,13 @@ public class HsOfficeCoopAssetsTransactionEntity implements Stringifyable, RbacO
@Column(name = "comment")
private String comment;
/**
* Optionally, the corresponding transaction for an adjustment transaction,
* linked in both directions.
*/
@OneToOne
@JoinColumn(name = "reverseentryuuid")
private HsOfficeCoopAssetsTransactionEntity reverseEntry;
public String getTaggedMemberNumber() {
return ofNullable(membership).map(HsOfficeMembershipEntity::toShortString).orElse("M-?????");

View File

@ -17,14 +17,15 @@ CREATE CAST (character varying as HsOfficeCoopAssetsTransactionType) WITH INOUT
create table if not exists hs_office_coopassetstransaction
(
uuid uuid unique references RbacObject (uuid) initially deferred,
version int not null default 0,
membershipUuid uuid not null references hs_office_membership(uuid),
transactionType HsOfficeCoopAssetsTransactionType not null,
valueDate date not null,
assetValue money,
reference varchar(48),
comment varchar(512)
uuid uuid unique references RbacObject (uuid) initially deferred,
version int not null default 0,
membershipUuid uuid not null references hs_office_membership(uuid),
transactionType HsOfficeCoopAssetsTransactionType not null,
valueDate date not null,
assetValue money not null,
reference varchar(48) not null,
reverseEntryUuid uuid references hs_office_coopassetstransaction (uuid),
comment varchar(512)
);
--//

View File

@ -16,14 +16,36 @@ class HsOfficeCoopAssetsTransactionEntityUnitTest {
.valueDate(LocalDate.parse("2020-01-01"))
.transactionType(HsOfficeCoopAssetsTransactionType.DEPOSIT)
.assetValue(new BigDecimal("128.00"))
.comment("some comment")
.build();
final HsOfficeCoopAssetsTransactionEntity givenCoopAssetAdjustmentTransaction = HsOfficeCoopAssetsTransactionEntity.builder()
.membership(TEST_MEMBERSHIP)
.reference("some-ref")
.valueDate(LocalDate.parse("2020-01-15"))
.transactionType(HsOfficeCoopAssetsTransactionType.ADJUSTMENT)
.assetValue(new BigDecimal("-128.00"))
.comment("some comment")
.reverseEntry(givenCoopAssetTransaction)
.build();
final HsOfficeCoopAssetsTransactionEntity givenEmptyCoopAssetsTransaction = HsOfficeCoopAssetsTransactionEntity.builder().build();
@Test
void toStringContainsAlmostAllPropertiesAccount() {
void toStringContainsAllNonNullProperties() {
final var result = givenCoopAssetTransaction.toString();
assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref)");
assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment)");
}
@Test
void toStringWithReverseEntryContainsReverseEntry() {
givenCoopAssetTransaction.setReverseEntry(givenCoopAssetAdjustmentTransaction);
final var result = givenCoopAssetTransaction.toString();
assertThat(result).isEqualTo("CoopAssetsTransaction(M-1000101: 2020-01-01, DEPOSIT, 128.00, some-ref, some comment, M-1000101:-128.00)");
}
@Test