Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0013273Openbravo ERP07. Sales managementpublic2010-05-10 09:312010-05-18 21:44
psarobe 
dalsasua 
immediatemajoralways
closedfixed 
5
2.50MP13 
2.50MP17 
Core
No
0013273: Volume discount does not work
The volume discount is no longer working. The regression is due to the project "Line net amount"
1. Login as Openbravo/openbravo
2. Go to Master data management->Business partner setup->Volume discount
3. Click new. Dates 01-01-2010 to 31-12-2010. Move to Products and select Donuts. 13%. Save
4. Move to the volume discount and for the product categories, select "Not selected". Save
5. Go to Mafalda business partner and move to volume discount tab. Select the newly volume discount
5. Go to Sales management->transactions->Sales invoice. Click new
6. Select mafalda. Save
7. Move to lines and select donuts (Sales price list, not mafalda price list). Qty=123. Save
8. Go back to header and complete
9. Go to business partner window. Select mafalda and move to the volume discount tab. Press the button create invoice

You will see the error
I have found the problem and technically what we did in the trigger is perfect. The problem comes with the procedure that creates the invoice.

The stored procedure that calculates the volume discount invoice is M_RAPPEL_INVOICE_CREATE. This procedure creates the invoice header and the line. When it creates the line, for the linenetamt:

1. It calculates first
2. Then it inserts directly the linenetmat
3. For the prices, it directly puts 0 because it doesn't matter. The same for the quantity. So finally we have qty=0 and price=0 but the linetamt is <>0. You can see the inser that the PL does. Let me say that that PL has not being change for along time. Please keep seeing my comments under the PL code

INSERT
      INTO C_INVOICELINE
        (
          C_INVOICELINE_ID, AD_CLIENT_ID, AD_ORG_ID, ISACTIVE,
          CREATED, CREATEDBY, UPDATED, UPDATEDBY,
          C_INVOICE_ID, C_ORDERLINE_ID, M_INOUTLINE_ID, LINE,
          DESCRIPTION, M_PRODUCT_ID, QTYINVOICED, PRICELIST,
          PRICEACTUAL, PRICELIMIT, LINENETAMT, C_CHARGE_ID,
          CHARGEAMT, C_UOM_ID, C_TAX_ID, S_RESOURCEASSIGNMENT_ID,
          TAXAMT, M_ATTRIBUTESETINSTANCE_ID, ISDESCRIPTION,
          QUANTITYORDER, M_PRODUCT_UOM_ID, PRICESTD, M_OFFER_ID
        )
        VALUES
        (
          v_invoicelineId, CUR_INVOICE.AD_CLIENT_ID, CUR_INVOICE.AD_ORG_ID, 'Y',
          now(), v_AD_User_ID, now(), v_AD_User_ID,
          v_invoiceId, NULL, NULL, v_line,
          v_description, CUR_INVOICE.M_PRODUCT_ID, 0, 0,
          0, 0, CUR_INVOICE.LINENET, NULL,
          0, CUR_INVOICE.C_UOM_ID, CUR_INVOICE.C_TAX_ID, NULL,
          0, NULL, 'N',
          NULL, NULL, 0, NULL
        )
        ;


In the "Line net amount" project, the project allows you to edit the line net amount and because of this there is a call-out that modifies the price so finally the qty*price=linet amount. But in addition there is a trigger that ensures you that qty*price=line net amount. Please see the below trigger code

-- Rounds linenetAmt and ChargeAmt
  IF(INSERTING OR UPDATING) THEN
    SELECT STDPRECISION
    INTO v_Prec
    FROM C_CURRENCY
    WHERE C_CURRENCY_ID=v_Currency;
    :NEW.LineNetAmt:=ROUND(:NEW.LineNetAmt, v_Prec) ;
    :NEW.ChargeAmt:=ROUND(:NEW.ChargeAmt, v_Prec) ;

    IF (ROUND(TO_NUMBER(:NEW.QTYINVOICED) * TO_NUMBER(:NEW.PRICEACTUAL),v_Prec)!=TO_NUMBER(:NEW.LINENETAMT)) THEN
      RAISE_APPLICATION_ERROR(-20000, '@LineAmountNotCorrect@') ;
    END IF;
  END IF;
END C_INVLINE_CHK_RESTRICTIONS_TRG

So we could say that the trigger does what it has to do, but because the other procedure inserts the lines that way (qty=0 * price=0 <> line net amount) the error shows up.

So since now the problem is clear we have to make a decision. To me exists two approaches:

1. To avoid further problems in MP15 and in MP16 we should add a condition on the trigger code which is to add the condition of ISEDITLINENETAMT='Y'. Take into account that this procedures and other will create the invoice line with the value ISEDITLINENETAMT='N'. Doing this we will avoid further problems that could come from other procedures that create invoice lines in a "free" manner, I mean, without taking in account the formula qty*price=line net amt. For MP17 we should investigate the procedures that might not follow this formula and look for the best solution
2. Second approach: Investigate all the procedures that creates invoice lines.

So the solution would be:

IF (ROUND(TO_NUMBER(:NEW.QTYINVOICED) * TO_NUMBER(:NEW.PRICEACTUAL),v_Prec)!=TO_NUMBER(:NEW.LINENETAMT) AND :NEW.ISEDITLINENETAMT='Y')

I have already tested with that change and it works.
Regression
Issue History
2010-05-10 09:31psarobeNew Issue
2010-05-10 09:31psarobeAssigned To => dalsasua
2010-05-10 09:32psarobeStatusnew => scheduled
2010-05-10 09:32psarobefix_in_branch => pi
2010-05-10 10:12psarobeTag Attached: Regression
2010-05-10 10:13hgbotCheckin
2010-05-10 10:13hgbotNote Added: 0027089
2010-05-10 10:13hgbotStatusscheduled => resolved
2010-05-10 10:13hgbotResolutionopen => fixed
2010-05-10 10:13hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/9db4acddd5a51b0498a2cb8b4fbde593edf07aff [^]
2010-05-14 11:25sureshbabuNote Added: 0027228
2010-05-14 11:25sureshbabuStatusresolved => closed
2010-05-15 00:00anonymoussf_bug_id0 => 3001863
2010-05-18 12:12gorka_gilTarget Version2.50MP15 => 2.50MP17
2010-05-18 21:44hudsonbotCheckin
2010-05-18 21:44hudsonbotNote Added: 0027507

Notes
(0027089)
hgbot   
2010-05-10 10:13   
Repository: erp/devel/pi
Changeset: 9db4acddd5a51b0498a2cb8b4fbde593edf07aff
Author: Víctor Martínez Romanos <victor.martinez <at> openbravo.com>
Date: Mon May 10 10:14:48 2010 +0200
URL: http://code.openbravo.com/erp/devel/pi/rev/9db4acddd5a51b0498a2cb8b4fbde593edf07aff [^]

Fixed bug 13273: Volume discount does not work

---
M src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml
---
(0027228)
sureshbabu   
2010-05-14 11:25   
tested working fine
(0027507)
hudsonbot   
2010-05-18 21:44   
A changeset related to this issue has been promoted to main after passing a series of tests and an OBX has been generated:

Changeset: http://code.openbravo.com/erp/devel/main/rev/9db4acddd5a5 [^]
Merge Changeset: http://code.openbravo.com/erp/devel/main/rev/aa11838d5f80 [^]
Tests: http://builds.openbravo.com/view/devel-int/ [^]
OBX: http://builds.openbravo.com/erp/core/obx/OpenbravoERP-2.50CI.17380.obx [^]