Skip to content

Commit

Permalink
Merge pull request #134 from hmrc/SASS-10648-Amend
Browse files Browse the repository at this point in the history
Sass 10648 amend Foreign Property Adjustments model
  • Loading branch information
tbg2003 authored Jan 23, 2025
2 parents 8a1f29d + 4b62224 commit 1115d3c
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 41 deletions.
9 changes: 5 additions & 4 deletions app/models/ForeignAdjustmentsStoreAnswers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ package models
import play.api.libs.json.{Json, OFormat}

case class ForeignAdjustmentsStoreAnswers(
balancingChargeYesNo: Boolean,
foreignUnusedResidentialFinanceCostYesNo: Boolean,
unusedLossesPreviousYearsYesNo: Boolean
)
balancingChargeYesNo: Boolean,
foreignUnusedResidentialFinanceCostYesNo: Option[Boolean],
unusedLossesPreviousYearsYesNo: Boolean,
whenYouReportedTheLoss: Option[String]
)

object ForeignAdjustmentsStoreAnswers {
implicit val expensesAnswersFormat: OFormat[ForeignAdjustmentsStoreAnswers] = Json.format[ForeignAdjustmentsStoreAnswers]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@

package models.request.foreign.adjustments

import models.Enumerable
import models.request.BalancingCharge
import models.request.foreign.WithName
import play.api.libs.json.{Format, Json}


case class ForeignPropertyAdjustmentsWithCountryCode(
countryCode: String,
privateUseAdjustment: BigDecimal,
balancingCharge: BalancingCharge,
residentialFinanceCost: BigDecimal,
unusedResidentialFinanceCost: ForeignUnusedResidentialFinanceCost,
unusedLossesPreviousYears: UnusedLossesPreviousYears
residentialFinanceCost: Option[BigDecimal],
unusedResidentialFinanceCost: Option[ForeignUnusedResidentialFinanceCost],
propertyIncomeAllowanceClaim: Option[BigDecimal],
unusedLossesPreviousYears: UnusedLossesPreviousYears,
whenYouReportedTheLoss: Option[ForeignWhenYouReportedTheLoss]
)


Expand All @@ -36,9 +40,9 @@ object ForeignPropertyAdjustmentsWithCountryCode {


final case class ForeignUnusedResidentialFinanceCost (
foreignUnusedResidentialFinanceCostYesNo: Boolean,
foreignUnusedResidentialFinanceCostAmount: Option[BigDecimal]
)
foreignUnusedResidentialFinanceCostYesNo: Boolean,
foreignUnusedResidentialFinanceCostAmount: Option[BigDecimal]
)
object ForeignUnusedResidentialFinanceCost {
implicit val format: Format[ForeignUnusedResidentialFinanceCost] = Json.format[ForeignUnusedResidentialFinanceCost]
}
Expand All @@ -51,4 +55,22 @@ final case class UnusedLossesPreviousYears(

object UnusedLossesPreviousYears {
implicit val format: Format[UnusedLossesPreviousYears] = Json.format
}

sealed trait ForeignWhenYouReportedTheLoss

object ForeignWhenYouReportedTheLoss extends Enumerable.Implicits {

case object y2018to2019 extends WithName("y2018to2019") with ForeignWhenYouReportedTheLoss
case object y2019to2020 extends WithName("y2019to2020") with ForeignWhenYouReportedTheLoss
case object y2020to2021 extends WithName("y2020to2021") with ForeignWhenYouReportedTheLoss
case object y2021to2022 extends WithName("y2021to2022") with ForeignWhenYouReportedTheLoss
case object y2022to2023 extends WithName("y2022to2023") with ForeignWhenYouReportedTheLoss

val values: Seq[ForeignWhenYouReportedTheLoss] = Seq(
y2018to2019, y2019to2020, y2020to2021, y2021to2022, y2022to2023
)

implicit val enumerable: Enumerable[ForeignWhenYouReportedTheLoss] =
Enumerable(values.map(v => v.toString -> v): _*)
}
5 changes: 3 additions & 2 deletions app/services/ForeignPropertyService.scala
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,9 @@ class ForeignPropertyService @Inject() (
journeyContext,
ForeignAdjustmentsStoreAnswers(
balancingChargeYesNo = foreignAdjustmentsWithCountryCode.balancingCharge.balancingChargeYesNo,
foreignUnusedResidentialFinanceCostYesNo = foreignAdjustmentsWithCountryCode.unusedResidentialFinanceCost.foreignUnusedResidentialFinanceCostYesNo,
unusedLossesPreviousYearsYesNo = foreignAdjustmentsWithCountryCode.unusedLossesPreviousYears.unusedLossesPreviousYearsYesNo
foreignUnusedResidentialFinanceCostYesNo = foreignAdjustmentsWithCountryCode.unusedResidentialFinanceCost.map(_.foreignUnusedResidentialFinanceCostYesNo),
unusedLossesPreviousYearsYesNo = foreignAdjustmentsWithCountryCode.unusedLossesPreviousYears.unusedLossesPreviousYearsYesNo,
whenYouReportedTheLoss = foreignAdjustmentsWithCountryCode.whenYouReportedTheLoss.map(_.toString)
),
foreignAdjustmentsWithCountryCode.countryCode
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import models.common._
import models.errors.{ApiServiceError, InvalidJsonFormatError, ServiceError}
import models.request.BalancingCharge
import models.request.foreign._
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, UnusedLossesPreviousYears}
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, ForeignWhenYouReportedTheLoss, UnusedLossesPreviousYears}
import models.request.foreign.allowances.ForeignPropertyAllowancesWithCountryCode
import models.request.foreign.expenses.ForeignPropertyExpensesWithCountryCode
import models.request.foreign.sba.{ForeignPropertySbaWithCountryCode, ForeignStructureBuildingAllowance, ForeignStructureBuildingAllowanceAddress}
Expand Down Expand Up @@ -406,7 +406,8 @@ class ForeignPropertyJourneyAnswersControllerSpec
| "unusedLossesPreviousYears": {
| "unusedLossesPreviousYearsYesNo": true,
| "unusedLossesPreviousYearsAmount": 80.80
| }
| },
| "whenYouReportedTheLoss": "y2018to2019"
|}
|""".stripMargin)

Expand Down Expand Up @@ -435,15 +436,17 @@ class ForeignPropertyJourneyAnswersControllerSpec
balancingChargeYesNo = true,
balancingChargeAmount = Some(108)
),
residentialFinanceCost = 490.58,
unusedResidentialFinanceCost = ForeignUnusedResidentialFinanceCost(
residentialFinanceCost = Some(490.58),
unusedResidentialFinanceCost = Some(ForeignUnusedResidentialFinanceCost(
foreignUnusedResidentialFinanceCostYesNo = true,
foreignUnusedResidentialFinanceCostAmount = Some(110.10)
),
)),
propertyIncomeAllowanceClaim = None,
unusedLossesPreviousYears = UnusedLossesPreviousYears(
unusedLossesPreviousYearsYesNo = true,
unusedLossesPreviousYearsAmount = Some(80.80)
)
),
whenYouReportedTheLoss = Some(ForeignWhenYouReportedTheLoss.y2018to2019)
)
result.header.status shouldBe NO_CONTENT
}
Expand Down
36 changes: 18 additions & 18 deletions test/models/ForeignPropertyAdjustmentsSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package models

import models.request.BalancingCharge
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, UnusedLossesPreviousYears}
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, ForeignWhenYouReportedTheLoss, UnusedLossesPreviousYears}
import org.scalatestplus.play.PlaySpec
import play.api.libs.json.{JsError, JsSuccess, Json}

Expand All @@ -32,15 +32,14 @@ class ForeignPropertyAdjustmentsSpec extends PlaySpec {
balancingCharge = BalancingCharge(
balancingChargeYesNo = true,
balancingChargeAmount = Some(108)),
residentialFinanceCost = 490.58,
unusedResidentialFinanceCost = ForeignUnusedResidentialFinanceCost(
foreignUnusedResidentialFinanceCostYesNo = true,
foreignUnusedResidentialFinanceCostAmount = Some(110.10)
),
residentialFinanceCost = None,
unusedResidentialFinanceCost = None,
propertyIncomeAllowanceClaim = Some(12.34),
unusedLossesPreviousYears = UnusedLossesPreviousYears(
unusedLossesPreviousYearsYesNo = true,
unusedLossesPreviousYearsAmount = Some(109.09)
),
whenYouReportedTheLoss = Some(ForeignWhenYouReportedTheLoss.y2018to2019)
)

val expectedJson = Json.parse(
Expand All @@ -52,15 +51,12 @@ class ForeignPropertyAdjustmentsSpec extends PlaySpec {
| "balancingChargeYesNo": true,
| "balancingChargeAmount": 108
| },
| "residentialFinanceCost": 490.58,
| "unusedResidentialFinanceCost": {
| "foreignUnusedResidentialFinanceCostYesNo": true,
| "foreignUnusedResidentialFinanceCostAmount": 110.10
| },
| "propertyIncomeAllowanceClaim": 12.34,
| "unusedLossesPreviousYears": {
| "unusedLossesPreviousYearsYesNo": true,
| "unusedLossesPreviousYearsAmount": 109.09
| }
| },
| "whenYouReportedTheLoss": "y2018to2019"
|}
|""".stripMargin
)
Expand Down Expand Up @@ -97,15 +93,17 @@ class ForeignPropertyAdjustmentsSpec extends PlaySpec {
balancingCharge = BalancingCharge(
balancingChargeYesNo = true,
balancingChargeAmount = Some(108)),
residentialFinanceCost = 300.00,
unusedResidentialFinanceCost = ForeignUnusedResidentialFinanceCost(
residentialFinanceCost = Some(300.00),
unusedResidentialFinanceCost = Some(ForeignUnusedResidentialFinanceCost(
foreignUnusedResidentialFinanceCostYesNo = true,
foreignUnusedResidentialFinanceCostAmount = Some(110.10)
),
)),
propertyIncomeAllowanceClaim = None,
unusedLossesPreviousYears = UnusedLossesPreviousYears(
unusedLossesPreviousYearsYesNo = true,
unusedLossesPreviousYearsAmount = Some(109.09)
),
whenYouReportedTheLoss = None
)

json.validate[ForeignPropertyAdjustmentsWithCountryCode] mustEqual JsSuccess(expectedAdjustments)
Expand Down Expand Up @@ -151,15 +149,17 @@ class ForeignPropertyAdjustmentsSpec extends PlaySpec {
balancingChargeYesNo = false,
balancingChargeAmount = None
),
residentialFinanceCost = 300.00,
unusedResidentialFinanceCost = ForeignUnusedResidentialFinanceCost(
residentialFinanceCost = Some(300.00),
unusedResidentialFinanceCost = Some(ForeignUnusedResidentialFinanceCost(
foreignUnusedResidentialFinanceCostYesNo = false,
foreignUnusedResidentialFinanceCostAmount = None
),
)),
propertyIncomeAllowanceClaim = None,
unusedLossesPreviousYears = UnusedLossesPreviousYears(
unusedLossesPreviousYearsYesNo = false,
unusedLossesPreviousYearsAmount = None
),
whenYouReportedTheLoss = None
)

jsonWithMissingFields.validate[ForeignPropertyAdjustmentsWithCountryCode] mustEqual JsSuccess(expectedAdjustments)
Expand Down
12 changes: 7 additions & 5 deletions test/services/ForeignPropertyServiceSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import models.common._
import models.errors.{ApiError, ApiServiceError, DataNotFoundError, SingleErrorBody}
import models.request._
import models.request.foreign._
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, UnusedLossesPreviousYears}
import models.request.foreign.adjustments.{ForeignPropertyAdjustmentsWithCountryCode, ForeignUnusedResidentialFinanceCost, ForeignWhenYouReportedTheLoss, UnusedLossesPreviousYears}
import models.request.foreign.allowances.ForeignPropertyAllowancesWithCountryCode
import models.request.foreign.expenses.{ConsolidatedExpenses, ForeignPropertyExpensesWithCountryCode}
import models.request.foreign.sba.{ForeignPropertySbaWithCountryCode, ForeignStructureBuildingAllowance, ForeignStructureBuildingAllowanceAddress}
Expand Down Expand Up @@ -952,15 +952,17 @@ class ForeignPropertyServiceSpec
countryCode = "AUS",
privateUseAdjustment = BigDecimal(25.25),
balancingCharge = BalancingCharge(balancingChargeYesNo = true, balancingChargeAmount = Some(BigDecimal(50.50))),
residentialFinanceCost = BigDecimal(75.75),
unusedResidentialFinanceCost = ForeignUnusedResidentialFinanceCost(
residentialFinanceCost = Some(BigDecimal(75.75)),
unusedResidentialFinanceCost = Some(ForeignUnusedResidentialFinanceCost(
foreignUnusedResidentialFinanceCostYesNo = true,
foreignUnusedResidentialFinanceCostAmount = Some(BigDecimal(101.01))
),
)),
propertyIncomeAllowanceClaim = None,
unusedLossesPreviousYears = UnusedLossesPreviousYears(
unusedLossesPreviousYearsYesNo = true,
unusedLossesPreviousYearsAmount = Some(BigDecimal(80.8))
)
),
whenYouReportedTheLoss = Some(ForeignWhenYouReportedTheLoss.y2018to2019)
)

"persist the foreign adjustments supporting answers into the backend mongo" in {
Expand Down

0 comments on commit 1115d3c

Please sign in to comment.