Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0013493Openbravo ERP07. Sales managementpublic2010-06-01 13:502010-06-30 12:16
psarobe 
harikrishnan 
highminoralways
closedfixed 
5
2.50MP18 
2.50MP21 
Core
No
0013493: Sales order: Discounts are calculated without taking into account currency precisions
Discounts are calculated without taking into account currency precisions.

In the C_ORDER_POST stored procedure you can find this code for calculating the discount:

 IF(Cur_COrderDiscount.CASCADE='Y') THEN
              v_Discount:=(-1) * Cur_TaxDiscount.LINENETAMT * v_CumDiscount;
            ELSE
              v_Discount:=(-1) * Cur_TaxDiscount.LINENETAMT * Cur_COrderDiscount.Discount/100;
            END IF;

Later on the paramater v_Discount is used for filling the values pricelist, priceactual, pricelimit, linenetamt as you can see in this part of code:

INSERT INTO c_orderline
              (
                c_orderline_id, ad_client_id, ad_org_id, isactive, created, createdby,
                updated, updatedby, c_order_id, line, c_bpartner_id, c_bpartner_location_id,
                dateordered, datepromised, datedelivered, dateinvoiced, description,
                m_product_id, m_warehouse_id, directship, c_uom_id, qtyordered,
                qtyreserved, qtydelivered, qtyinvoiced, m_shipper_id, c_currency_id,
                pricelist, priceactual, pricelimit, linenetamt, discount, freightamt,
                c_charge_id, chargeamt, c_tax_id, s_resourceassignment_id, ref_orderline_id,
                m_attributesetinstance_id, isdescription, quantityorder, m_product_uom_id,
                m_offer_id, pricestd, C_ORDER_DISCOUNT_ID
              )
            VALUES
              (
                v_OrderLine, v_Client_ID, v_Org_ID, 'Y', TO_DATE(NOW()), v_UpdatedBy,
                TO_DATE(NOW()), v_UpdatedBy, v_Record_ID, v_OrderLineSeqNo, NULL, NULL,
                TO_DATE(NOW()), TO_DATE(NOW()), TO_DATE(NOW()), TO_DATE(NOW()), Cur_COrderDiscount.NAME,
                Cur_COrderDiscount.M_PRODUCT_ID, v_M_Warehouse_ID, 'N', Cur_COrderDiscount.C_UOM_ID, 1,
                0, 0, 0, NULL, v_c_currency_id,
                v_Discount, v_Discount, v_Discount, v_Discount, 0, 0,
                NULL, NULL, Cur_TaxDiscount.C_TAX_ID, NULL, NULL,
                NULL, 'N', NULL, NULL,
                NULL, v_Discount, NULL
              );

What it happens is that later on there is a trigger c_orderline_trg that rounds the linetamt to the standard precision of the currency which is correct so finally there is an inconsistency between the prices and the line net amount. Having this situation:
pricelist, priceactual, pricelimit=-7.79688000000000000000000 and the
linetamt=-7.8

So the solution would be to round the v_discount to the standard precision of the currency similar to what it's done in the trigger. Standard precision not priceprecision

To verify this you need to connect to the database
1. Login as Openbravo/openbravo
2. Change the user preferences to Main and Openbravo Admin role
3. Go to Master data management->Business partner-> Select Mafalda
4. Move to Discount tabs and select in this order:
  4.1 Discount 15%. Check Apply in order
  4.2 Discount 7%. Check Cascade and Apply in order
5. Go to Sales order window and click new. Select Mafalda. Save
6. Move to lines and select Hat and quantity 2
7. The same for hat and quantity 2
8. Complete the sales order

Connect to the database and see that pricelist, priceactual, pricelimit=-7.79688000000000000000000 and the linetamt=-7.8 for the newly discount lines

It should be -7.8
No tags attached.
Issue History
2010-06-01 13:50psarobeNew Issue
2010-06-01 13:50psarobeAssigned To => adrianromero
2010-06-01 13:51psarobeStatusnew => scheduled
2010-06-01 13:51psarobefix_in_branch => pi
2010-06-22 14:22harikrishnanAssigned Toadrianromero => harikrishnan
2010-06-22 14:24hgbotCheckin
2010-06-22 14:24hgbotNote Added: 0028670
2010-06-22 14:24hgbotStatusscheduled => resolved
2010-06-22 14:24hgbotResolutionopen => fixed
2010-06-22 14:24hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/b810b1c73ea0b07af1798a8e2452f397b87e1c60 [^]
2010-06-22 14:28harikrishnanNote Added: 0028673
2010-06-24 12:23sureshbabuNote Added: 0028734
2010-06-24 12:23sureshbabuStatusresolved => closed
2010-06-24 12:31sureshbabuNote Deleted: 0028734
2010-06-25 00:00anonymoussf_bug_id0 => 3021057
2010-06-30 12:16hudsonbotCheckin
2010-06-30 12:16hudsonbotNote Added: 0028892

Notes
(0028670)
hgbot   
2010-06-22 14:24   
Repository: erp/devel/pi
Changeset: b810b1c73ea0b07af1798a8e2452f397b87e1c60
Author: Harikrishnan Raja <harikrishnan.raja <at> openbravo.com>
Date: Tue Jun 22 17:54:14 2010 +0530
URL: http://code.openbravo.com/erp/devel/pi/rev/b810b1c73ea0b07af1798a8e2452f397b87e1c60 [^]

Fixes Issue 13493: Sales order: Discounts are calculated without taking into account currency precisions.

---
M src-db/database/model/functions/C_ORDER_POST1.xml
---
(0028673)
harikrishnan   
2010-06-22 14:28   
Steps to reproduce:

Follow the above to reproduce the issue.

And in the Database Query
select c_order_id from c_order where documentno='document no created'

select * from c_orderline where c_order_id='id got from the above result'

Root Cause:

*Round off is not done to the discount amount.

Impact:

*Their is no impact because of this change set,because only the round off is done according to the currency precision.
(0028892)
hudsonbot   
2010-06-30 12:16   
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/b810b1c73ea0 [^]
Merge Changeset: http://code.openbravo.com/erp/devel/main/rev/0670375d782d [^]
Tests: http://builds.openbravo.com/view/int/ [^]
OBX: http://builds.openbravo.com/erp/core/obx/OpenbravoERP-2.50CI.17726.obx [^]