Skip to content
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

[MODINVOICE-554]. Invoices app: Incorrect formula for calculating adjustments, that are included and pro-rated by amount #1563

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
@@ -0,0 +1,136 @@
# For MODINVOICE-554
Feature: Check invoice lines with VAT adjustments

Background:
* url baseUrl

* call login testAdmin
* def okapitokenAdmin = okapitoken

* call login testUser
* def okapitokenUser = okapitoken

* def headersUser = { 'Content-Type': 'application/json', 'x-okapi-token': '#(okapitokenUser)', 'Accept': 'application/json' }
* def headersAdmin = { 'Content-Type': 'application/json', 'x-okapi-token': '#(okapitokenAdmin)', 'Accept': 'application/json' }

* configure headers = headersUser

* callonce variables

@Positive
Scenario: Check invoice lines with VAT adjustments
# Check that each invoice line VAT calculation is unaffected by other invoice lines
# as other forms of adjustments typically involve every invoice line in its adjustment calculation
* def fundId = call uuid
* def budgetId = call uuid

* def adjustmentId = call uuid
* def invoiceId1 = call uuid
* def invoiceId2 = call uuid
* def invoiceLineId1 = call uuid
* def invoiceLineId2 = call uuid
* def invoiceLineId3 = call uuid
* def invoiceLineId4 = call uuid

### 1. Create fund and budgets
* configure headers = headersAdmin
* def v = call createFund { id: '#(fundId)', code: '#(fundId)' }
* def v = call createBudget { id: '#(budgetId)', fundId: '#(fundId)', allocated: 1000 }
* configure headers = headersUser

### 4. Create invoices
* def invoiceAdjustments =
"""
[{
"id": "#(adjustmentId)",
"value": 7.0,
"type": "Percentage",
"prorate": "By amount",
"description": "VAT",
"relationToTotal": "Included in",
"fundDistributions": [],
"exportToAccounting": false
}]
"""
* table invoices
| id | invoiceId | currency | adjustments |
| invoiceId1 | invoiceId1 | 'EUR' | invoiceAdjustments |
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two invoices used, first invoice is used to verify the logic for a simple single-line case, while the second invoice for cases with multiple invoice lines being added and/or removed. Both cases should not affect other invoice line adjustments.

| invoiceId2 | invoiceId2 | 'EUR' | invoiceAdjustments |
* def v = call createInvoice invoices

### 5. Add invoice lines
* table invoiceLines
| invoiceLineId | invoiceId | total | fundId |
| invoiceLineId1 | invoiceId1 | 30.0 | fundId |
| invoiceLineId2 | invoiceId2 | 30.0 | fundId |
| invoiceLineId3 | invoiceId2 | 30.0 | fundId |
| invoiceLineId4 | invoiceId2 | 30.0 | fundId |
* def v = call createInvoiceLine invoiceLines

### 6. Check invoices and invoice lines before approval
* table invoicesExpected
| id | invoiceTotal | invoiceLines | invoiceLineTotal | invoiceLineAdjustment | status |
| invoiceId1 | 28.04 | 1 | 28.04 | 1.96 | 'Open' |
| invoiceId2 | 84.12 | 3 | 28.04 | 1.96 | 'Open' |
* def v = call read('@CheckInvoices') invoicesExpected
* def v = call read('@CheckInvoiceLines') invoicesExpected

### 7. Remove a single invoice line from the second invoice
Given path 'invoice/invoice-lines', invoiceLineId4
When method DELETE
Then status 204

### 8. Recheck invoices and invoice lines to verify that the adjustment calculation was unaffected
* table invoicesExpected
| id | invoiceTotal | invoiceLines | invoiceLineTotal | invoiceLineAdjustment | status |
| invoiceId1 | 28.04 | 1 | 28.04 | 1.96 | 'Open' |
| invoiceId2 | 56.08 | 2 | 28.04 | 1.96 | 'Open' |
* def v = call read('@CheckInvoices') invoicesExpected
* def v = call read('@CheckInvoiceLines') invoicesExpected

### 9. Approve the invoices
* def v = call approveInvoice invoices

### 10. Check invoices and invoice lines after approval
* table invoicesExpected
| id | invoiceTotal | invoiceLines | invoiceLineTotal | invoiceLineAdjustment | status |
| invoiceId1 | 28.04 | 1 | 28.04 | 1.96 | 'Approved' |
| invoiceId2 | 56.08 | 2 | 28.04 | 1.96 | 'Approved' |
* def v = call read('@CheckInvoices') invoicesExpected
* def v = call read('@CheckInvoiceLines') invoicesExpected

@ignore @CheckInvoices
Scenario: Check invoices
Given path 'invoice/invoices', id
When method GET
Then status 200
And match response.currency == 'EUR'
And match response.status == status
And match response.adjustmentsTotal == 0.0
And match response.subTotal == invoiceTotal
And match response.total == invoiceTotal
And match each response.adjustments[*].id == adjustmentId
And match each response.adjustments[*].value == 7.0
And match each response.adjustments[*].type == 'Amount'
And match each response.adjustments[*].prorate == 'By amount'
And match each response.adjustments[*].description == 'VAT'
And match each response.adjustments[*].relationToTotal == 'Included in'

@ignore @CheckInvoiceLines
Scenario: Check invoice line
Given path 'invoice/invoice-lines'
And param query = 'invoiceId==' + id
When method GET
Then status 200
And match response.totalRecords == invoiceLines
And match each response.invoiceLines[*].quantity == 1
And match each response.invoiceLines[*].total == invoiceLineTotal
And match each response.invoiceLines[*].subTotal == invoiceLineTotal
And match each response.invoiceLines[*].adjustmentsTotal == 0.0
And match each response.invoiceLines[*].invoiceLineStatus == status
And match each response.invoiceLines[*].adjustments[*].adjustmentId == adjustmentId
And match each response.invoiceLines[*].adjustments[*].value == invoiceLineAdjustment
And match each response.invoiceLines[*].adjustments[*].type == 'Amount'
And match each response.invoiceLines[*].adjustments[*].prorate == 'Not prorated'
And match each response.invoiceLines[*].adjustments[*].description == 'VAT'
And match each response.invoiceLines[*].adjustments[*].relationToTotal == 'Included in'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Create invoice line
# parameters: invoiceLineId, invoiceId, poLineId?, fundId, encumbranceId?, total, expenseClassId?, releaseEncumbrance?
# parameters: invoiceLineId, invoiceId, poLineId?, fundId, encumbranceId?, total, expenseClassId?, releaseEncumbrance?, adjustments?

Background:
* url baseUrl
Expand All @@ -9,6 +9,7 @@ Feature: Create invoice line
* def encumbranceId = karate.get('encumbranceId', null)
* def expenseClassId = karate.get('expenseClassId', null)
* def releaseEncumbrance = karate.get('releaseEncumbrance', true)
* def adjustments = karate.get('adjustments', [])
* def invoiceLine = read('classpath:samples/mod-invoice/invoices/global/invoice-line-percentage.json')
* set invoiceLine.id = invoiceLineId
* set invoiceLine.invoiceId = invoiceId
Expand All @@ -19,6 +20,7 @@ Feature: Create invoice line
* set invoiceLine.subTotal = total
* set invoiceLine.fundDistributions[0].expenseClassId = expenseClassId
* set invoiceLine.releaseEncumbrance = releaseEncumbrance
* set invoiceLine.adjustments = adjustments
Given path 'invoice/invoice-lines'
And request invoiceLine
When method POST
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Feature: Create invoice
# parameters: id, acqUnitIds?
# parameters: id, fiscalYearId?, acqUnitIds?, currency?, adjustments?

Background:
* url baseUrl
Expand All @@ -8,9 +8,13 @@ Feature: Create invoice
* def invoice = read('classpath:samples/mod-invoice/invoices/global/invoice.json')
* def fiscalYearId = karate.get('fiscalYearId', null)
* def acqUnitIds = karate.get('acqUnitIds', [])
* def currency = karate.get('currency', "USD")
* def adjustments = karate.get('adjustments', [])
* set invoice.id = id
* set invoice.fiscalYearId = fiscalYearId
* set invoice.acqUnitIds = acqUnitIds
* set invoice.currency = currency
* set invoice.adjustments = adjustments

Given path 'invoice/invoices'
And request invoice
Expand Down
5 changes: 5 additions & 0 deletions acquisitions/src/test/java/org/folio/InvoicesApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ void setInvoiceFiscalYearAutomatically() {
runFeatureTest("set-invoice-fiscal-year-automatically");
}

@Test
void checkInvoiceLinesWithVatAdjustments() {
runFeatureTest("check-invoice-lines-with-vat-adjustments");
}

@BeforeAll
public void invoicesApiTestBeforeAll() {
runFeature("classpath:thunderjet/mod-invoice/invoice-junit.feature");
Expand Down