Skip to content

Commit

Permalink
ADR-1286: Make payment due date optional on return submission response (
Browse files Browse the repository at this point in the history
#23)

* ADR-1286: Make payment due date optional on return submission response

* ADR-1286: fix logging
  • Loading branch information
yasaracar authored Aug 20, 2024
1 parent 5a87ac1 commit a856521
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class ReturnsConnector @Inject() (
Left(ErrorResponse.EntityNotFound)
case Left(errorResponse) =>
logger.warn(
s"Received unexpected response from returns API (appaId ${returnId.appaId}, periodKey ${returnId.periodKey}): ${errorResponse.statusCode} ${errorResponse.message}"
s"Received unexpected response from returns API (appaId ${returnId.appaId}, " +
s"periodKey ${returnId.periodKey}): ${errorResponse.statusCode} ${errorResponse.message}"
)
Left(ErrorResponse.UnexpectedResponse)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ case class AdrReturnCreatedDetails(
processingDate: Instant,
amount: BigDecimal,
chargeReference: Option[String],
paymentDueDate: LocalDate
paymentDueDate: Option[LocalDate]
)

object AdrReturnCreatedDetails {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ object AlcoholProducts {
def fromAdrDutyDeclared(adrDutyDeclared: AdrDutyDeclared): AlcoholProducts =
AlcoholProducts(
alcoholProductsProducedFilled = adrDutyDeclared.declared,
regularReturn =
if (adrDutyDeclared.dutyDeclaredItems.nonEmpty)
Some(adrDutyDeclared.dutyDeclaredItems.map(RegularReturnDetails.fromAdrDutyDeclaredItem))
else None
regularReturn = if (adrDutyDeclared.dutyDeclaredItems.nonEmpty) {
Some(adrDutyDeclared.dutyDeclaredItems.map(RegularReturnDetails.fromAdrDutyDeclaredItem))
} else {
None
}
)
}

Expand Down Expand Up @@ -332,10 +333,11 @@ object NetDutySuspension {
def fromAdrDutySuspended(adrDutySuspended: AdrDutySuspended): NetDutySuspension =
NetDutySuspension(
netDutySuspensionFilled = adrDutySuspended.declared,
netDutySuspensionProducts =
if (adrDutySuspended.dutySuspendedProducts.nonEmpty)
Some(NetDutySuspensionProducts.fromAdrDutySuspendedProducts(adrDutySuspended.dutySuspendedProducts))
else None
netDutySuspensionProducts = if (adrDutySuspended.dutySuspendedProducts.nonEmpty) {
Some(NetDutySuspensionProducts.fromAdrDutySuspendedProducts(adrDutySuspended.dutySuspendedProducts))
} else {
None
}
)
}

Expand Down Expand Up @@ -603,7 +605,7 @@ case class ReturnCreatedDetails(
adReference: String,
amount: BigDecimal,
chargeReference: Option[String],
paymentDueDate: LocalDate,
paymentDueDate: Option[LocalDate],
submissionID: String
)

Expand Down

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions test-utils/helpers/TestData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ trait TestData extends ModelGenerators {
adReference = appaId,
amount = total,
chargeReference = if (total != 0) Some(chargeReference) else None,
paymentDueDate = PeriodKey.toYearMonth(periodKey).plusMonths(1).atDay(dueDate),
paymentDueDate = if (total != 0) Some(PeriodKey.toYearMonth(periodKey).plusMonths(1).atDay(dueDate)) else None,
submissionID = submissionId
)
)
Expand All @@ -1103,7 +1103,7 @@ trait TestData extends ModelGenerators {
processingDate = now,
amount = total,
chargeReference = if (total != 0) Some(chargeReference) else None,
paymentDueDate = PeriodKey.toYearMonth(periodKey).plusMonths(1).atDay(dueDate)
paymentDueDate = if (total != 0) Some(PeriodKey.toYearMonth(periodKey).plusMonths(1).atDay(dueDate)) else None
)

val calculateDutyDueByTaxTypeRequest: CalculateDutyDueByTaxTypeRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,43 @@ class AdrReturnSubmissionSpec extends SpecBase {
Json.toJson(adrReturnCreatedDetails).toString() shouldBe adrReturnCreatedDetailsJson
}

"serialise to json with minimal payload" in new SetUp {
Json.toJson(adrReturnCreatedDetailsMinimal).toString() shouldBe adrReturnCreatedDetailsMinimalJson
}

"convert from ReturnCreatedDetails to AdrReturnCreatedDetails" in new SetUp {
AdrReturnCreatedDetails.fromReturnCreatedDetails(returnCreatedDetails) shouldBe adrReturnCreatedDetails
}

"convert from ReturnCreatedDetails to AdrReturnCreatedDetails with minimal payload" in new SetUp {
AdrReturnCreatedDetails.fromReturnCreatedDetails(
returnCreatedDetailsMinimal
) shouldBe adrReturnCreatedDetailsMinimal
}
}

class SetUp {
val periodKey = "24AC"
val total = BigDecimal("12345.67")
val totalZero = BigDecimal("0")
val now = Instant.now(clock)

val adrReturnSubmissionJson =
"""{"dutyDeclared":{"declared":true,"dutyDeclaredItems":[{"quantityDeclared":{"litres":1000.1,"lpa":100.101},"dutyDue":{"taxCode":"331","dutyRate":1.27,"dutyDue":127.12}},{"quantityDeclared":{"litres":2000.21,"lpa":200.2022},"dutyDue":{"taxCode":"332","dutyRate":1.57,"dutyDue":314.31}}]},"adjustments":{"overDeclarationDeclared":true,"reasonForOverDeclaration":"Submitted too much","overDeclarationProducts":[{"returnPeriod":"24AD","adjustmentQuantity":{"litres":400.04,"lpa":40.0404},"dutyDue":{"taxCode":"352","dutyRate":1.32,"dutyDue":-52.85}}],"underDeclarationDeclared":true,"reasonForUnderDeclaration":"Submitted too little","underDeclarationProducts":[{"returnPeriod":"24AC","adjustmentQuantity":{"litres":300.03,"lpa":30.0303},"dutyDue":{"taxCode":"351","dutyRate":2.32,"dutyDue":69.67}}],"spoiltProductDeclared":true,"spoiltProducts":[{"returnPeriod":"24AE","adjustmentQuantity":{"litres":500.05,"lpa":50.0505},"dutyDue":{"taxCode":"353","dutyRate":1.82,"dutyDue":-91.09}}],"drawbackDeclared":true,"drawbackProducts":[{"returnPeriod":"24AF","adjustmentQuantity":{"litres":600.06,"lpa":60.0606},"dutyDue":{"taxCode":"361","dutyRate":2.21,"dutyDue":-132.73}}],"repackagedDraughtDeclared":true,"repackagedDraughtProducts":[{"returnPeriod":"24AG","originalTaxCode":"371","originalDutyRate":0.27,"newTaxCode":"331","newDutyRate":1.27,"repackagedQuantity":{"litres":700.07,"lpa":70.0707},"dutyAdjustment":70.07}]},"dutySuspended":{"declared":true,"dutySuspendedProducts":[{"regime":"Beer","suspendedQuantity":{"litres":101.1,"lpa":1010.1011}},{"regime":"Wine","suspendedQuantity":{"litres":202.2,"lpa":2020.2022}},{"regime":"Cider","suspendedQuantity":{"litres":303.3,"lpa":3030.3033}},{"regime":"Spirits","suspendedQuantity":{"litres":404.4,"lpa":4040.4044}},{"regime":"OtherFermentedProduct","suspendedQuantity":{"litres":505.5,"lpa":5050.5055}}]},"spirits":{"spiritsDeclared":true,"spiritsProduced":{"spiritsVolumes":{"totalSpirits":123.45,"scotchWhiskey":234.56,"irishWhisky":345.67},"typesOfSpirit":["Malt","Beer","Other"],"otherSpiritTypeName":"MaltyBeer","hasOtherMaltedGrain":true,"grainsQuantities":{"maltedBarley":10,"otherMaltedGrain":11.11,"wheat":22.22,"maize":33.33,"rye":44.44,"unmaltedGrain":55.55},"otherMaltedGrainType":"Smarties","ingredientsVolumes":{"ethylene":10.1,"molasses":20.2,"beer":30.3,"wine":40.4,"madeWine":50.5,"ciderOrPerry":60.6},"otherIngredient":{"quantity":70.7,"unitOfMeasure":"Tonnes","ingredientName":"Coco Pops"}}},"totals":{"declaredDutyDue":441.53,"overDeclaration":-52.85,"underDeclaration":69.67,"spoiltProduct":-91.09,"drawback":-132.73,"repackagedDraught":70.07,"totalDutyDue":304.6}}"""
val adrReturnCreatedDetailsJson =
s"""{"processingDate":"2024-06-11T15:07:47.838Z","amount":$total,"chargeReference":"$chargeReference","paymentDueDate":"2024-04-25"}"""

val adrReturnSubmission = exampleReturnSubmissionRequest
val returnCreatedDetails =
val adrReturnCreatedDetailsMinimalJson =
s"""{"processingDate":"2024-06-11T15:07:47.838Z","amount":$totalZero}"""

val adrReturnSubmission = exampleReturnSubmissionRequest
val returnCreatedDetails =
exampleReturnCreatedSuccessfulResponse(periodKey, total, now, chargeReference, submissionId).success
val adrReturnCreatedDetails = exampleReturnCreatedDetails(periodKey, total, now, chargeReference)

val returnCreatedDetailsMinimal =
exampleReturnCreatedSuccessfulResponse(periodKey, totalZero, now, chargeReference, submissionId).success

val adrReturnCreatedDetails = exampleReturnCreatedDetails(periodKey, total, now, chargeReference)
val adrReturnCreatedDetailsMinimal = exampleReturnCreatedDetails(periodKey, totalZero, now, chargeReference)
}
}

0 comments on commit a856521

Please sign in to comment.