Skip to content

Commit

Permalink
Merge pull request #6 from hmrc/MTDSA-1158
Browse files Browse the repository at this point in the history
[MTDSA-1158] Change validation of net vat due to accept non-negative values
  • Loading branch information
sudoku007 authored Oct 30, 2017
2 parents 60eaf98 + 13fa669 commit 4709902
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 3 additions & 3 deletions app/uk/gov/hmrc/vatapi/models/VatReturn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object VatReturn {
(__ \ "vatDueAcquisitions").read[Amount](vatAmountValidator) and
(__ \ "totalVatDue").read[Amount](vatAmountValidator) and
(__ \ "vatReclaimedCurrPeriod").read[Amount](vatAmountValidator) and
(__ \ "netVatDue").read[Amount](vatAmountValidator) and
(__ \ "netVatDue").read[Amount](vatNonNegativeAmountValidator) and
(__ \ "totalValueSalesExVAT").read[Amount](vatWholeAmountValidator) and
(__ \ "totalValuePurchasesExVAT")
.read[Amount](vatWholeAmountValidator) and
Expand All @@ -67,9 +67,9 @@ object VatReturn {
Validation[VatReturn](
JsPath \ "netVatDue",
vatReturn =>
vatReturn.netVatDue == vatReturn.totalVatDue - vatReturn.vatReclaimedCurrPeriod,
vatReturn.netVatDue == (vatReturn.totalVatDue - vatReturn.vatReclaimedCurrPeriod).abs,
JsonValidationError(
"netVatDue should be equal to totalVatDue - vatReclaimedCurrPeriod",
"netVatDue should be the difference between the largest and the smallest values among totalVatDue and vatReclaimedCurrPeriod",
ErrorCode.VAT_NET_VALUE)
)
)
Expand Down
9 changes: 9 additions & 0 deletions public/api/conf/1.0/application.raml
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,12 @@ traits:
description: Invalid request
value:
code: INVALID_REQUEST
invalidTotalValue:
description: totalVatDue should be equal to the sum of vatDueSales and vatDueAcquisitions
value:
code: VAT_TOTAL_VALUE
invalidNetValue:
description: netVatDue should be the difference between the largest and the smallest values among totalVatDue and vatReclaimedCurrPeriod
value:
code: VAT_NET_VALUE

19 changes: 19 additions & 0 deletions test/uk/gov/hmrc/vatapi/models/VatReturnSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,25 @@ class VatReturnSpec extends UnitSpec with JsonSpec {
)
}

"reject VAT returns with negative amounts where non-negative amounts are expected" in {
assertValidationErrorWithCode(
VatReturn(
periodKey = "#001",
vatDueSales = 10.00,
vatDueAcquisitions = 100.30,
totalVatDue = BigDecimal(10.00) + BigDecimal(100.30),
vatReclaimedCurrPeriod = 450.00,
netVatDue = BigDecimal(10.00) + BigDecimal(100.30) - BigDecimal(450.00),
totalValueSalesExVAT = 1000,
totalValuePurchasesExVAT = 200.00,
totalValueGoodsSuppliedExVAT = 100.00,
totalAcquisitionsExVAT = 540.00
),
"/netVatDue",
ErrorCode.INVALID_MONETARY_AMOUNT
)
}

"accept VAT returns with negative amounts where non" in {
assertValidationPasses(
VatReturn(
Expand Down

0 comments on commit 4709902

Please sign in to comment.