details: https://code.openbravo.com/erp/devel/pi/rev/24cf2ca5a3c4 changeset: 30324:24cf2ca5a3c4 user: Sanjota <sanjota.nelagi <at> promantia.com> date: Tue Sep 27 17:14:31 2016 +0530 summary: Fixes issue 34021: Fixes to Concurrency problem with processing of transaction
Fix to Concurrency problem: is possible to process same transaction document more than one time when accessing from different sessions. Fix: Along with filter on process button name, included status of the transaction as filter to process the transaction details: https://code.openbravo.com/erp/devel/pi/rev/c679132719ab changeset: 30325:c679132719ab user: Mark <markmm82 <at> gmail.com> date: Tue Sep 27 11:06:10 2016 -0400 summary: Fixes issue 34103: No discounts are applied to product prices in Purchase flows Price adjustments are not executed if is processing a Purchase Order/Invoice using a product with a promotion or discount, because this functionality should be only available for Sales flows. details: https://code.openbravo.com/erp/devel/pi/rev/e94a1240a358 changeset: 30326:e94a1240a358 user: Mark <markmm82 <at> gmail.com> date: Fri Sep 23 15:37:24 2016 -0400 summary: Fixes issue 33975: Fixed Prices in sales order and invoice lines if discounts Modified the calculatePriceActual and calculatePriceStd methods of PriceAdjustment class to rounds correctly the price precision when discount percentage is applied. diffstat: modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java | 4 +- src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml | 57 ++++----- src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java | 24 ++- 3 files changed, 44 insertions(+), 41 deletions(-) diffs (155 lines): diff -r 16237efcd170 -r e94a1240a358 modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java --- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java Tue Sep 27 19:56:43 2016 +0000 +++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_TransactionProcess.java Fri Sep 23 15:37:24 2016 -0400 @@ -96,7 +96,7 @@ String msg = ""; try { OBContext.setAdminMode(false); - if (strAction.equals("P")) { + if (strAction.equals("P") && !transaction.isProcessed()) { // *********************** // Process Transaction // *********************** @@ -177,7 +177,7 @@ OBDal.getInstance().save(financialAccount); OBDal.getInstance().save(transaction); - } else if (strAction.equals("R")) { + } else if (strAction.equals("R") && transaction.isProcessed()) { // *********************** // Reactivate Transaction // *********************** diff -r 16237efcd170 -r e94a1240a358 src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml --- a/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml Tue Sep 27 19:56:43 2016 +0000 +++ b/src-db/database/model/functions/M_PROMOTION_ADJUSTMENT.xml Fri Sep 23 15:37:24 2016 -0400 @@ -61,38 +61,32 @@ v_multiple NUMBER; v_issotrx CHAR(1); BEGIN - select fixed, coalesce(addamt, 0), coalesce(discount, 0), - qty_From, qty_To, apply_next, ismultiple, multiple - into v_fixed, v_add, v_discount, - v_qty_From, v_qty_To, v_apply_next, v_ismultiple, v_multiple - from m_offer - where m_offer_id = p_rule_id; - if (p_type ='O') then - select gross_unit_price, c_tax_id, qtyordered, priceactual, - line_gross_amount, linenetamt - into v_unitprice, v_tax, v_qty, v_priceactual, - v_origGrossAmt, v_origLineNetAmt - from c_orderline - where c_orderline_id = p_line_id; + IF (p_type ='O') THEN + SELECT ol.gross_unit_price, ol.c_tax_id, ol.qtyordered, ol.priceactual, ol.line_gross_amount, ol.linenetamt, o.issotrx + INTO v_unitprice, v_tax, v_qty, v_priceactual, v_origGrossAmt, v_origLineNetAmt, v_issotrx + FROM c_order o + JOIN c_orderline ol + ON o.c_order_id = ol.c_order_id + WHERE ol.c_orderline_id = p_line_id; + ELSE + SELECT il.gross_unit_price, il.c_tax_id, il.qtyinvoiced, il.priceactual, il.line_gross_amount, il.linenetamt, i.issotrx + INTO v_unitprice, v_tax, v_qty, v_priceactual, v_origGrossAmt, v_origLineNetAmt, v_issotrx + FROM c_invoice i + JOIN c_invoiceline il + ON i.c_invoice_id = il.c_invoice_id + WHERE c_invoiceline_id = p_line_id; + END IF; - select issotrx into v_issotrx - from c_order - where c_order_id in (select c_order_id from c_orderline - where c_orderline_id = p_line_id); - else - select gross_unit_price, c_tax_id, qtyinvoiced, priceactual, - line_gross_amount, linenetamt - into v_unitprice, v_tax, v_qty, v_priceactual, - v_origGrossAmt, v_origLineNetAmt - from c_invoiceline - where c_invoiceline_id = p_line_id; + -- Discounts and Promotions only work for Sales flow + IF (v_issotrx = 'N') THEN + RETURN v_apply_next; + END IF; - select issotrx into v_issotrx - from c_invoice - where c_invoice_id in (select c_invoice_id from c_invoiceline - where c_invoiceline_id = p_line_id); - end if; + SELECT fixed, coalesce(addamt, 0), coalesce(discount, 0), qty_From, qty_To, apply_next, ismultiple, multiple + INTO v_fixed, v_add, v_discount, v_qty_From, v_qty_To, v_apply_next, v_ismultiple, v_multiple + FROM m_offer + WHERE m_offer_id = p_rule_id; if (v_qty_From is not null and v_qty < v_qty_From) or (v_qty_To is not null and v_qty > v_qty_To) or (v_ismultiple = 'Y' and ((v_multiple is null) or (MOD(v_qty, v_multiple) <> 0))) then return 'Y'; -- rule not applied, apply next one if present @@ -122,10 +116,9 @@ v_totalPromotion := v_origLineNetAmt - v_newNetAmt; v_basePrice := v_priceactual; end if; - --verify the sales flow - if(v_issotrx='Y') then + M_PROMOTION_ADD(p_type, p_line_id, p_rule_id, p_taxIncluded, v_newUnitPrice, v_newGrossAmt, v_newNetPrice, v_newNetAmt, v_totalPromotion, v_totalPromotion, v_basePrice, p_user_id); - end if; + return v_apply_next; END M_PROMOTION_ADJUSTMENT ]]></body> diff -r 16237efcd170 -r e94a1240a358 src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java --- a/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java Tue Sep 27 19:56:43 2016 +0000 +++ b/src/org/openbravo/erpCommon/businessUtility/PriceAdjustment.java Fri Sep 23 15:37:24 2016 -0400 @@ -61,6 +61,12 @@ BigDecimal qty, BigDecimal priceStd) { BigDecimal priceActual = priceStd; try { + + // Discounts and Promotions only work for Sales flow + if (!(Boolean) orderOrInvoice.get(Invoice.PROPERTY_SALESTRANSACTION)) { + return priceStd; + } + int precision = ((Currency) orderOrInvoice.get(Invoice.PROPERTY_CURRENCY)) .getPricePrecision().intValue(); for (org.openbravo.model.pricing.priceadjustment.PriceAdjustment promo : getApplicablePriceAdjustments( @@ -78,8 +84,7 @@ priceActual = priceActual .subtract(promo.getDiscountAmount()) .multiply( - BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100), - precision, BigDecimal.ROUND_HALF_UP))) + BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100)))) .setScale(precision, BigDecimal.ROUND_HALF_UP); } } @@ -105,6 +110,12 @@ BigDecimal qty, BigDecimal priceActual) { BigDecimal priceStd = priceActual; try { + + // Discounts and Promotions only work for Sales flow + if (!(Boolean) orderOrInvoice.get(Invoice.PROPERTY_SALESTRANSACTION)) { + return priceActual; + } + int precision = ((Currency) orderOrInvoice.get(Invoice.PROPERTY_CURRENCY)) .getPricePrecision().intValue(); for (org.openbravo.model.pricing.priceadjustment.PriceAdjustment promo : getApplicablePriceAdjustments( @@ -117,12 +128,11 @@ log.debug("promo: " + promo + "- " + promo.getDiscount()); if (applyDiscount) { // Avoids divide by zero error - if (BigDecimal.ONE.subtract( - promo.getDiscount().divide(BigDecimal.valueOf(100), precision, - BigDecimal.ROUND_HALF_UP)).compareTo(BigDecimal.ZERO) != 0) { + if (BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100))) + .compareTo(BigDecimal.ZERO) != 0) { priceStd = priceStd.add(promo.getDiscountAmount()).divide( - BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100), - precision, BigDecimal.ROUND_HALF_UP)), precision, BigDecimal.ROUND_HALF_UP); + BigDecimal.ONE.subtract(promo.getDiscount().divide(BigDecimal.valueOf(100))), + precision, BigDecimal.ROUND_HALF_UP); } else { // 100 % Discount in price adjustment results in priceStd = Zero priceStd = BigDecimal.ZERO; ------------------------------------------------------------------------------ _______________________________________________ Openbravo-commits mailing list Openbravo-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/openbravo-commits