This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "opentaps Open Source ERP CRM".
The branch, master has been updated
via 8fcf946d7e74e4df63ffac85c1baf01a84a16700 (commit)
via 3d4615c04e4f947f8555d910dd679cba2f4ad8ad (commit)
from 48437be136389fc5291f86b610a23481d684af55 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 8fcf946d7e74e4df63ffac85c1baf01a84a16700
Author: Jeremy Wickersheimer <jwickers@...>
Date: Tue Nov 2 22:14:27 2010 +0800
#1671 Fix logic the pro-rating when invoicing OrderAdjustments
* percentages do not need to be divided by the original order quantity (not related to the test failure)
* when determining if the adjustment was already invoiced, compare to the full adjustment amount instead of the pro rated adjustment amount (this fixes the invoice amount mismatch)
diff --git a/opentaps/financials/src/com/opensourcestrategies/financials/invoice/InvoiceServices.java b/opentaps/financials/src/com/opensourcestrategies/financials/invoice/InvoiceServices.java
index ea5d6cc..65a4f1e 100644
--- a/opentaps/financials/src/com/opensourcestrategies/financials/invoice/InvoiceServices.java
+++ b/opentaps/financials/src/com/opensourcestrategies/financials/invoice/InvoiceServices.java
@@ -2800,20 +2800,26 @@ public final class InvoiceServices {
while (itemAdjIter.hasNext()) {
GenericValue adj = (GenericValue) itemAdjIter.next();
+ Debug.logInfo("For OrderAdjustment [" + adj.get("orderAdjustmentId") + "] of type " + adj.get("orderAdjustmentTypeId"), MODULE);
// Check against OrderAdjustmentBilling to see how much of this adjustment has already been invoiced
BigDecimal adjAlreadyInvoicedAmount = null;
try {
Map checkResult = dispatcher.runSync("calculateInvoicedAdjustmentTotal", UtilMisc.toMap("orderAdjustment", adj));
adjAlreadyInvoicedAmount = (BigDecimal) checkResult.get("invoicedTotal");
+ Debug.logInfo("amount already invoiced for this adjustment is : " + adjAlreadyInvoicedAmount, MODULE);
} catch (GenericServiceException e) {
UtilMessage.createAndLogServiceError(e, "AccountingTroubleCallingCalculateInvoicedAdjustmentTotalService", locale, MODULE);
}
+ // to determine if the full adjustment was already invoiced
+ BigDecimal adjFullAmount = ZERO;
BigDecimal amount = ZERO;
if (adj.get("amount") != null) {
+ amount = adj.getBigDecimal("amount");
+ adjFullAmount = amount;
// pro-rate the amount
// set decimals = 100 means we don't round this intermediate value, which is very important
- amount = adj.getBigDecimal("amount").divide(originalOrderItem.getBigDecimal("quantity"), 100, rounding);
+ amount = amount.divide(originalOrderItem.getBigDecimal("quantity"), 100, rounding);
amount = amount.multiply(billingQuantity);
// Tax needs to be rounded differently from other order adjustments
if (adj.getString("orderAdjustmentTypeId").equals("SALES_TAX")) {
@@ -2821,25 +2827,28 @@ public final class InvoiceServices {
} else {
amount = amount.setScale(invoiceTypeDecimals, rounding);
}
+ Debug.logInfo("the adjustment amount was originally : " + adj.get("amount") + " and for this item is pro-rated to : " + amount, MODULE);
} else if (adj.get("sourcePercentage") != null) {
// pro-rate the amount
// set decimals = 100 means we don't round this intermediate value, which is very important
BigDecimal percent = adj.getBigDecimal("sourcePercentage");
percent = percent.divide(new BigDecimal(100), 100, rounding);
amount = billingAmount.multiply(percent);
- amount = amount.divide(originalOrderItem.getBigDecimal("quantity"), 100, rounding);
+ adjFullAmount = amount.multiply(originalOrderItem.getBigDecimal("quantity"));
amount = amount.multiply(billingQuantity);
amount = amount.setScale(invoiceTypeDecimals, rounding);
+ Debug.logInfo("the adjustment amount was originally null, percentage is : " + adj.get("sourcePercentage") + " and for this item is pro-rated to : " + amount, MODULE);
}
- // If the absolute invoiced amount >= the abs of the adjustment amount, the full amount has already been invoiced,
- // so skip this adjustment
- if (null == amount) { // JLR 17/4/7 : fix a bug coming from POS in case of use of a discount (on item(s) or sale, item(s) here) and a cash amount higher than total (hence issuing change)
+ // JLR 17/4/7 : fix a bug coming from POS in case of use of a discount (on item(s) or sale, item(s) here) and a cash amount higher than total (hence issuing change)
+ if (null == amount) {
Debug.logWarning("Null amount, skipping this adjustment.", MODULE);
continue;
}
- if (adjAlreadyInvoicedAmount.abs().compareTo(amount.setScale(invoiceTypeDecimals, rounding).abs()) > 0) {
- Debug.logWarning("Absolute invoiced amount (" + adjAlreadyInvoicedAmount.abs() + ") >= the abs of the adjustment amount (" + amount.setScale(invoiceTypeDecimals, rounding).abs() + "), the full amount has already been invoiced, skipping this adjustment [" + adj.get("orderAdjustmentId") + "].", MODULE);
+ // If the absolute invoiced amount >= the abs of the adjustment full amount, the full amount has already been invoiced,
+ // so skip this adjustment
+ if (adjAlreadyInvoicedAmount.abs().compareTo(adjFullAmount.setScale(invoiceTypeDecimals, rounding).abs()) > 0) {
+ Debug.logWarning("Absolute invoiced amount : " + adjAlreadyInvoicedAmount.abs() + " >= the absolute full amount of the adjustment : " + adjFullAmount.setScale(invoiceTypeDecimals, rounding).abs() + ", the full amount has already been invoiced, skipping this adjustment [" + adj.get("orderAdjustmentId") + "].", MODULE);
continue;
}
commit 3d4615c04e4f947f8555d910dd679cba2f4ad8ad
Author: Jeremy Wickersheimer <jwickers@...>
Date: Tue Nov 2 22:12:35 2010 +0800
#1671 Complete the testSalesTaxAndPromo and check the invoice and order totals match, and sales tax amounts are correct
diff --git a/opentaps/opentaps-tests/src/org/opentaps/tests/crmsfa/orders/SalesTaxTests.java b/opentaps/opentaps-tests/src/org/opentaps/tests/crmsfa/orders/SalesTaxTests.java
index 48ba798..9c4a4f6 100644
--- a/opentaps/opentaps-tests/src/org/opentaps/tests/crmsfa/orders/SalesTaxTests.java
+++ b/opentaps/opentaps-tests/src/org/opentaps/tests/crmsfa/orders/SalesTaxTests.java
@@ -23,15 +23,17 @@ import java.util.List;
import java.util.Map;
import javolution.util.FastMap;
-
import org.ofbiz.base.util.Debug;
import org.ofbiz.base.util.GeneralException;
import org.ofbiz.base.util.UtilMisc;
import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.order.order.OrderReadHelper;
+import org.opentaps.base.entities.InventoryItem;
+import org.opentaps.base.services.CreatePhysicalInventoryAndVarianceService;
import org.opentaps.common.domain.order.OrderSpecification;
import org.opentaps.common.order.SalesOrderFactory;
+import org.opentaps.domain.billing.invoice.Invoice;
import org.opentaps.domain.order.Order;
import org.opentaps.domain.order.OrderItem;
import org.opentaps.domain.order.OrderRepositoryInterface;
@@ -711,6 +713,49 @@ public class SalesTaxTests extends OrderTestCase {
* @throws Exception if an error occurs
*/
public void testSalesTaxAndPromo() throws Exception {
+
+ OrderRepositoryInterface repository = getOrderRepository(admin);
+
+ // force a split inventory situation, make sure there is no inventory item with an atp > 6
+ BigDecimal totalAtp = BigDecimal.ZERO;
+ BigDecimal refAtp = new BigDecimal("6");
+ for (InventoryItem ii : repository.findList(InventoryItem.class, repository.map(InventoryItem.Fields.productId, Product3.getString("productId")))) {
+ BigDecimal atp = ii.getAvailableToPromiseTotal();
+ if (atp == null) {
+ continue;
+ }
+ if (atp.compareTo(refAtp) > 0) {
+ // create a variance
+ BigDecimal var = refAtp.subtract(atp);
+ CreatePhysicalInventoryAndVarianceService varSer = new CreatePhysicalInventoryAndVarianceService();
+ varSer.setInUserLogin(admin);
+ varSer.setInInventoryItemId(ii.getInventoryItemId());
+ varSer.setInQuantityOnHandVar(var);
+ varSer.setInAvailableToPromiseVar(var);
+ varSer.setInVarianceReasonId("VAR_DAMAGED");
+ varSer.setInComments("test");
+ runAndAssertServiceSuccess(varSer);
+ totalAtp = totalAtp.add(refAtp);
+ } else {
+ totalAtp = totalAtp.add(atp);
+ }
+ }
+ // make sure we have at least refAtp
+ if (totalAtp.compareTo(refAtp) < 0) {
+ // receive some inventory
+ receiveInventoryProduct(Product3, refAtp, "NON_SERIAL_INV_ITEM", new BigDecimal("15.0"), facilityId, admin);
+ totalAtp = totalAtp.add(refAtp);
+ }
+ // now make sure we have at least 10
+ if (totalAtp.compareTo(new BigDecimal("10")) < 0) {
+ // receive the missing inventory
+ receiveInventoryProduct(Product3, new BigDecimal("10").subtract(totalAtp), "NON_SERIAL_INV_ITEM", new BigDecimal("14.0"), facilityId, admin);
+ totalAtp = totalAtp.add(refAtp);
+ }
+
+ Debug.logInfo("Having " + totalAtp.toPlainString() + " x WG-1111", MODULE);
+ pause("MySQL timestamp workaround pause", 1000);
+
/*
* 1. Create a sales order for productStoreId=9000, partyId=DemoAccount1, address=DemoAddress1 and 10 WG-1111
*/
@@ -722,7 +767,6 @@ public class SalesTaxTests extends OrderTestCase {
pause("MySQL timestamp workaround pause", 1000);
// we have to update order to get all adjustments recalculated
- OrderRepositoryInterface repository = getOrderRepository(admin);
Order order = repository.getOrderById(salesOrder.getOrderId());
OrderItem orderItem = null;
@@ -753,6 +797,20 @@ public class SalesTaxTests extends OrderTestCase {
Map<String, Object> input = UtilMisc.toMap("userLogin", admin, "facilityId", facilityId, "orderId", salesOrder.getOrderId());
runAndAssertServiceSuccess("testShipOrder", input);
+ // reload the order
+ order = repository.getOrderById(salesOrder.getOrderId());
+
+ // check the order taxes
+ checkSalesTax(order.getOrderId(), "_NA_", 1, new BigDecimal("3.599"));
+ checkSalesTax(order.getOrderId(), "CA_BOE", 1, new BigDecimal("22.496"));
+
+ // check the invoice total matches the order total
+ List<Invoice> invoices = order.getInvoices();
+ assertEquals("Should have exactly one invoice for the order [" + order.getOrderId() + "]", 1, invoices.size());
+ Invoice invoice = invoices.get(0);
+ Debug.logInfo("Order [" + order.getOrderId() + "] total = " + order.getTotal(), MODULE);
+ assertEquals("Invoice [" + invoice.getInvoiceId() + "] total and order [" + order.getOrderId() + "] total did not match", order.getTotal(), invoice.getInvoiceTotal());
+
/*
* 3. Perform ETL transformations for sales tax report
*/
-----------------------------------------------------------------------
Summary of changes:
.../financials/invoice/InvoiceServices.java | 23 +++++--
.../tests/crmsfa/orders/SalesTaxTests.java | 62 +++++++++++++++++++-
2 files changed, 76 insertions(+), 9 deletions(-)
hooks/post-receive
--
opentaps Open Source ERP CRM
|