This is an automated email from the ASF dual-hosted git repository.
akashjain pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ofbiz-framework.git The following commit(s) were added to refs/heads/trunk by this push: new 8be1705 Improved: Convert AutoAcctgTransTestsPurchase.xml to Groovy (OFBIZ-11522) 8be1705 is described below commit 8be1705765e12336b554569ea9c41594c8bfd74a Author: Akash Jain <[hidden email]> AuthorDate: Tue Jun 30 11:43:23 2020 +0530 Improved: Convert AutoAcctgTransTestsPurchase.xml to Groovy (OFBIZ-11522) Thanks, Rohit Hukkeri for the report. --- .../minilang/test/AutoAcctgTransTestsPurchase.xml | 178 +------------------ .../accounting/AutoAcctgTransTestsPurchase.groovy | 194 +++++++++++++++++++++ .../accounting/testdef/accountingtests.xml | 2 +- 3 files changed, 196 insertions(+), 178 deletions(-) diff --git a/applications/accounting/minilang/test/AutoAcctgTransTestsPurchase.xml b/applications/accounting/minilang/test/AutoAcctgTransTestsPurchase.xml index f6523a3..459e366 100644 --- a/applications/accounting/minilang/test/AutoAcctgTransTestsPurchase.xml +++ b/applications/accounting/minilang/test/AutoAcctgTransTestsPurchase.xml @@ -21,183 +21,7 @@ under the License. <simple-methods xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://ofbiz.apache.org/Simple-Method" xsi:schemaLocation="http://ofbiz.apache.org/Simple-Method http://ofbiz.apache.org/dtds/simple-methods.xsd"> - <!-- Test case for Accounting Transaction on Purchase --> - <simple-method method-name="testAcctgTransOnPoReceipts" short-description="Test case for Accounting Transaction on Receipts of Purchase Order." login-required="false"> - <!-- Precondition : shipment is created from supplier and order items are issued --> - <!-- create a purchase order using following: - Supplier : DemoSupplier - Item : WG-1111 - Quantity : 10 --> - - <!-- Post condition : Credit in account 214000 - UNINVOICED ITEM RECEIPT amount = grand total of order. - Debit in account 140000- INVENTORY amount = grand total of order. --> - - <!-- set few variables so that they can be changed easily to test with different values --> - <set field="orderId" value="DEMO10091"/> - <set field="productId" value="GZ-2644"/> - <set field="orderItemSeqId" value="00001"/> - <set field="shipmentId" value="9999"/> - - <entity-one entity-name="UserLogin" value-field="userLogin"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="serviceCtx.userLogin" from-field="userLogin"/> - <set field="serviceCtx.inventoryItemTypeId" value="NON_SERIAL_INV_ITEM"/> - <set field="serviceCtx.productId" from-field="productId"/> - <set field="serviceCtx.facilityId" value="WebStoreWarehouse"/> - <set field="serviceCtx.quantityAccepted" value="5" type="BigDecimal"/> - <set field="serviceCtx.quantityRejected" value="0" type="BigDecimal"/> - <set field="serviceCtx.shipmentId" from-field="shipmentId"/> - <set field="serviceCtx.orderId" from-field="orderId"/> - <set field="serviceCtx.orderItemSeqId" from-field="orderItemSeqId"/> - - <call-service service-name="receiveInventoryProduct" in-map-name="serviceCtx"/> - - <entity-and entity-name="AcctgTrans" list="acctgTransList"> - <field-map field-name="shipmentId"/> - </entity-and> - <assert><not><if-empty field="acctgTransList"/></not></assert> - <first-from-list list="acctgTransList" entry="acctgTrans"/> - - <assert><if-compare field="acctgTrans.glJournalId" operator="not-equals" value="ERROR_JOURNAL"/></assert> - - <get-related value-field="acctgTrans" relation-name="AcctgTransEntry" list="acctgTransEntryList"/> - <set field="productFilter.productId" from-field="productId"/> - <filter-list-by-and list="acctgTransEntryList" map="productFilter" to-list="acctgTransEntryList"/> - - <assert><not><if-empty field="acctgTransEntryList"/></not></assert> - - <call-simple-method method-name="checkEntriesBalance"/> - - <iterate list="acctgTransEntryList" entry="acctgTransEntry"> - <if-compare field="acctgTransEntry.debitCreditFlag" operator="equals" value="C"> - <assert> - <if-compare field="acctgTransEntry.glAccountTypeId" operator="equals" value="UNINVOICED_SHIP_RCPT"/> - <if-compare field="acctgTransEntry.glAccountId" operator="equals" value="214000"/> - </assert> - <else> - <if-compare field="acctgTransEntry.debitCreditFlag" operator="equals" value="D"> - <assert> - <if-compare field="acctgTransEntry.glAccountTypeId" operator="equals" value="INVENTORY_ACCOUNT"/> - <if-compare field="acctgTransEntry.glAccountId" operator="equals" value="140000"/> - </assert> - </if-compare> - </else> - </if-compare> - </iterate> - <!-- check if invoice created --> - <entity-and entity-name="OrderItemBilling" list="orderItemBillings"> - <field-map field-name="orderId"/> - </entity-and> - <assert> - <not><if-empty field="orderItemBillings"/></not> - </assert> - <check-errors/> - </simple-method> - - <simple-method method-name="testAcctgTransOnEditPoInvoice" short-description="Test case for Purchase Invoices: editing, adding taxes and shipping charges and posting to GL" login-required="false"> - <!-- Precondition: To the Purchase Invoice created add taxes and two different shipping charges - 1. for taxes: set "Invoice Item Type" = "Invoice Sales Tax" and "Unit Price" = 10$ - 2. for the first shipping charge: set "Invoice Item Type" = "Invoice Shipping And Handling" and "Unit Price" = 5$ - 3. for the second shipping charge: set "Invoice Item Type" = "Invoice Shipping And Handling", set "Override Gl Account Id" = "516100" and "Unit Price" = 5$ - --> - <!-- Post condition: When status is set to ready, an accounting transaction is automatically posted to the GL: - * Credit; in account 210000 - "ACCOUNTS PAYABLE"; amount: 290$ - * Debit; in account 214000 - "UNINVOICED ITEM RECEIPTS"; amount: 270$ - * Debit; in account 516100 - "PURCHASE ORDER ADJUSTMENTS"; amount: 10$ - * Debit; in account 510000 - "FREIGHT IN"; amount: 5$ - * Debit; in account 516100 - "PURCHASE ORDER ADJUSTMENTS"; amount: 5$ - --> - - <set field="orderId" value="DEMO10091"/> - <entity-and entity-name="OrderItemBilling" list="orderItemBillings"> - <field-map field-name="orderId"/> - </entity-and> - <first-from-list list="orderItemBillings" entry="orderItemBilling"/> - <entity-one entity-name="UserLogin" value-field="userLogin"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="serviceCtx.userLogin" from-field="userLogin"/> - <set field="serviceCtx.statusId" value="INVOICE_READY"/> - <set field="serviceCtx.invoiceId" from-field="orderItemBilling.invoiceId"/> - <call-service service-name="setInvoiceStatus" in-map-name="serviceCtx"/> - <entity-one entity-name="Invoice" value-field="invoice"> - <field-map field-name="invoiceId" from-field="orderItemBilling.invoiceId"/> - </entity-one> - <get-related value-field="invoice" relation-name="AcctgTrans" list="acctgTransList"/> - <first-from-list list="acctgTransList" entry="acctgTrans"/> - - <assert><if-compare field="acctgTrans.glJournalId" operator="not-equals" value="ERROR_JOURNAL"/></assert> - - <get-related value-field="acctgTrans" relation-name="AcctgTransEntry" list="acctgTransEntryList"/> - - <assert><not><if-empty field="acctgTransEntryList"/></not></assert> - - <call-simple-method method-name="checkEntriesBalance"/> - - <iterate list="acctgTransEntryList" entry="acctgTransEntry"> - <if-compare field="acctgTransEntry.debitCreditFlag" operator="equals" value="C"> - <assert> - <if-compare field="acctgTransEntry.glAccountTypeId" operator="equals" value="ACCOUNTS_PAYABLE"/> - <if-compare field="acctgTransEntry.glAccountId" operator="equals" value="210000"/> - </assert> - </if-compare> - </iterate> - <check-errors/> - </simple-method> - - <simple-method method-name="testAcctgTransOnPaymentSentToSupplier" short-description="Test case for Payment sent to supplier for purchase invoice." login-required="false"> - <!-- - Precondition: New payment is created for: supplierId = "DemoSupplier", "Payment Type ID" = "Vendor Payment" and - a proper "Payment Method Type" (e.g. "Electronic Funds Transfer"), amount = $290 - - Post condition: On payment's status is sent: a double-entry accounting transaction is automatically posted to the GL: - * Credit; in account 111100 - "GENERAL CHECKING ACCOUNT"; amount: 290$; however this depends on the "Payment method type" selected; - * Debit; in account 216000 - "ACCOUNTS PAYABLE - UNAPPLIED PAYMENTS"; amount: 290$ - --> - - <set field="paymentId" value="9000"/> - <entity-one entity-name="UserLogin" value-field="userLogin"> - <field-map field-name="userLoginId" value="system"/> - </entity-one> - <set field="serviceCtx.userLogin" from-field="userLogin"/> - <set field="serviceCtx.paymentId" from-field="paymentId"/> - <set field="serviceCtx.statusId" value="PMNT_SENT"/> - - <call-service service-name="setPaymentStatus" in-map-name="serviceCtx"/> - <entity-one entity-name="Payment" value-field="payment"> - <field-map field-name="paymentId" from-field="paymentId"/> - </entity-one> - <get-related value-field="payment" relation-name="AcctgTrans" list="acctgTransList"/> - <first-from-list list="acctgTransList" entry="acctgTrans"/> - - <assert><if-compare field="acctgTrans.glJournalId" operator="not-equals" value="ERROR_JOURNAL"/></assert> - - <get-related value-field="acctgTrans" relation-name="AcctgTransEntry" list="acctgTransEntryList"/> - - <assert><not><if-empty field="acctgTransEntryList"/></not></assert> - - <call-simple-method method-name="checkEntriesBalance"/> - - <iterate list="acctgTransEntryList" entry="acctgTransEntry"> - <if-compare field="acctgTransEntry.debitCreditFlag" operator="equals" value="C"> - <assert> - <if-compare field="acctgTransEntry.glAccountId" operator="equals" value="111100"/> - </assert> - <else> - <if-compare field="acctgTransEntry.debitCreditFlag" operator="equals" value="D"> - <assert> - <if-compare field="acctgTransEntry.glAccountTypeId" operator="equals" value="ACCPAYABLE_UNAPPLIED"/> - <if-compare field="acctgTransEntry.glAccountId" operator="equals" value="216000"/> - </assert> - </if-compare> - </else> - </if-compare> - </iterate> - <check-errors/> - </simple-method> - - + <!-- TODO: This method is also called from other methods. Will remove it when convert AutoAcctgTransTestsSales xml file to groovy. --> <simple-method method-name="checkEntriesBalance" login-required="false" short-description="Short util method that takes a list of AcctgTransEntry values (acctgTransEntryList) and checks that the debit and credit totals balance."> <set field="debitTotal" type="BigDecimal" value="0.0"/> diff --git a/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgTransTestsPurchase.groovy b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgTransTestsPurchase.groovy new file mode 100644 index 0000000..aad5b26 --- /dev/null +++ b/applications/accounting/src/main/groovy/org/apache/ofbiz/accounting/AutoAcctgTransTestsPurchase.groovy @@ -0,0 +1,194 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.ofbiz.accounting + +import org.apache.ofbiz.entity.GenericValue +import org.apache.ofbiz.service.ServiceUtil +import org.apache.ofbiz.service.testtools.OFBizTestCase + +class AutoAcctgTransTestsPurchase extends OFBizTestCase { + public AutoAcctgTransTestsPurchase(String name) { + super(name) + } + + // Test case for Accounting Transaction on Purchase + void testAcctgTransOnPoReceipts() { + /* + Precondition : shipment is created from supplier and order items are issued + create a purchase order using following: + Supplier : DemoSupplier + Item : WG-1111 + Quantity : 10 + + Post condition : Credit in account 214000 - UNINVOICED ITEM RECEIPT amount = grand total of order. + Debit in account 140000- INVENTORY amount = grand total of order. + */ + String orderId = 'DEMO10091' + String shipmentId = '9999' + String productId = 'GZ-2644' + + Map serviceCtx = [ + inventoryItemTypeId: 'NON_SERIAL_INV_ITEM', + productId: productId, + facilityId: 'WebStoreWarehouse', + quantityAccepted: new BigDecimal('5'), + quantityRejected: new BigDecimal('0'), + shipmentId: shipmentId, + orderId: orderId, + orderItemSeqId: '00001', + userLogin: userLogin + ] + Map serviceResult = dispatcher.runSync('receiveInventoryProduct', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + GenericValue acctgTrans = from('AcctgTrans') + .where('shipmentId', shipmentId) + .queryFirst() + assert acctgTrans + assert acctgTrans.glJournalId != 'ERROR_JOURNAL' + + List<GenericValue> acctgTransEntryList = from('AcctgTransEntry') + .where('acctgTransId', acctgTrans.acctgTransId, 'productId', productId) + .queryList() + assert acctgTransEntryList + + checkEntriesBalance(acctgTransEntryList) + + for (GenericValue acctgTransEntry : acctgTransEntryList) { + if (acctgTransEntry.debitCreditFlag == 'C') { + assert acctgTransEntry.glAccountTypeId == 'UNINVOICED_SHIP_RCPT' + assert acctgTransEntry.glAccountId == '214000' + } else if (acctgTransEntry.debitCreditFlag == 'D') { + assert acctgTransEntry.glAccountTypeId == 'INVENTORY_ACCOUNT' + assert acctgTransEntry.glAccountId == '140000' + } + } + + GenericValue orderItemBilling = from('OrderItemBilling') + .where('orderId', orderId) + .queryFirst() + assert orderItemBilling + } + + void testAcctgTransOnEditPoInvoice() { + /* + Precondition: To the Purchase Invoice created add taxes and two different shipping charges + 1. for taxes: set "Invoice Item Type" = "Invoice Sales Tax" and "Unit Price" = 10$ + 2. for the first shipping charge: set "Invoice Item Type" = "Invoice Shipping And Handling" and "Unit Price" = 5$ + 3. for the second shipping charge: set "Invoice Item Type" = "Invoice Shipping And Handling", set "Override Gl Account Id" = "516100" and "Unit Price" = 5$ + + Post condition: When status is set to ready, an accounting transaction is automatically posted to the GL: + * Credit; in account 210000 - "ACCOUNTS PAYABLE"; amount: 290$ + * Debit; in account 214000 - "UNINVOICED ITEM RECEIPTS"; amount: 270$ + * Debit; in account 516100 - "PURCHASE ORDER ADJUSTMENTS"; amount: 10$ + * Debit; in account 510000 - "FREIGHT IN"; amount: 5$ + * Debit; in account 516100 - "PURCHASE ORDER ADJUSTMENTS"; amount: 5$ + */ + GenericValue orderItemBilling = from('OrderItemBilling') + .where('orderId', 'DEMO10091') + .queryFirst() + assert orderItemBilling + + Map serviceCtx = [ + statusId: 'INVOICE_READY', + invoiceId: orderItemBilling.invoiceId, + userLogin: userLogin + ] + Map serviceResult = dispatcher.runSync('setInvoiceStatus', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + GenericValue acctgTrans = from('AcctgTrans') + .where('invoiceId', orderItemBilling.invoiceId) + .queryFirst() + assert acctgTrans + assert acctgTrans.glJournalId != 'ERROR_JOURNAL' + + List<GenericValue> acctgTransEntryList = from('AcctgTransEntry') + .where('acctgTransId', acctgTrans.acctgTransId) + .queryList() + assert acctgTransEntryList + + checkEntriesBalance(acctgTransEntryList) + + for (GenericValue acctgTransEntry : acctgTransEntryList) { + if (acctgTransEntry.debitCreditFlag == 'C') { + assert acctgTransEntry.glAccountTypeId == 'ACCOUNTS_PAYABLE' + assert acctgTransEntry.glAccountId == '210000' + } + } + } + + void testAcctgTransOnPaymentSentToSupplier() { + /* + Precondition: New payment is created for: supplierId = "DemoSupplier", "Payment Type ID" = "Vendor Payment" and + a proper "Payment Method Type" (e.g. "Electronic Funds Transfer"), amount = $290 + + Post condition: On payment's status is sent: a double-entry accounting transaction is automatically posted to the GL: + * Credit; in account 111100 - "GENERAL CHECKING ACCOUNT"; amount: 290$; however this depends on the "Payment method type" selected; + * Debit; in account 216000 - "ACCOUNTS PAYABLE - UNAPPLIED PAYMENTS"; amount: 290$ + */ + String paymentId = '9000' + + Map serviceCtx = [ + statusId: 'PMNT_SENT', + paymentId: paymentId, + userLogin: userLogin + ] + Map serviceResult = dispatcher.runSync('setPaymentStatus', serviceCtx) + assert ServiceUtil.isSuccess(serviceResult) + + GenericValue acctgTrans = from('AcctgTrans') + .where('paymentId', paymentId) + .queryFirst() + assert acctgTrans + assert acctgTrans.glJournalId != 'ERROR_JOURNAL' + + List<GenericValue> acctgTransEntryList = from('AcctgTransEntry') + .where('acctgTransId', acctgTrans.acctgTransId) + .queryList() + assert acctgTransEntryList + + checkEntriesBalance(acctgTransEntryList) + + for (GenericValue acctgTransEntry : acctgTransEntryList) { + if (acctgTransEntry.debitCreditFlag == 'C') { + assert acctgTransEntry.glAccountId == '111100' + } else if (acctgTransEntry.debitCreditFlag == 'D') { + assert acctgTransEntry.glAccountTypeId == 'ACCPAYABLE_UNAPPLIED' + assert acctgTransEntry.glAccountId == '216000' + } + } + } + + void checkEntriesBalance(List<GenericValue> acctgTransEntryList) { + BigDecimal debitTotal = new BigDecimal('0') + BigDecimal creditTotal = new BigDecimal('0') + + for (GenericValue acctgTransEntry : acctgTransEntryList) { + if (acctgTransEntry.debitCreditFlag == 'C') { + creditTotal = creditTotal.add(acctgTransEntry.origAmount) + } else if (acctgTransEntry.debitCreditFlag == 'D') { + debitTotal = debitTotal.add(acctgTransEntry.origAmount) + } + } + + assert debitTotal.compareTo(creditTotal) == 0 + } +} \ No newline at end of file diff --git a/applications/accounting/testdef/accountingtests.xml b/applications/accounting/testdef/accountingtests.xml index c3693bb..23b750c 100644 --- a/applications/accounting/testdef/accountingtests.xml +++ b/applications/accounting/testdef/accountingtests.xml @@ -34,7 +34,7 @@ <simple-method-test location="component://accounting/minilang/test/AutoAcctgTransTestsSales.xml"/> </test-case> <test-case case-name="auto-accounting-transaction-tests-purchase"> - <simple-method-test location="component://accounting/minilang/test/AutoAcctgTransTestsPurchase.xml"/> + <junit-test-suite class-name="org.apache.ofbiz.accounting.AutoAcctgTransTestsPurchase"/> </test-case> <test-case case-name="auto-accounting-admin-tests"> <junit-test-suite class-name="org.apache.ofbiz.accounting.AutoAcctgAdminTests"/> |
Free forum by Nabble | Edit this page |