Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0032337Openbravo ERP07. Sales managementpublic2016-02-25 10:142016-03-17 10:56
ngarcia 
AtulOpenbravo 
urgentmajoralways
closedfixed 
5
 
3.0PR16Q2 
aferraz
Core
No
0032337: Division by zero error when completing an invoice associated to a closed order (quantity 0) with a promotion
Division by zero error when completing an invoice associated to a closed order (quantity 0) with a promotion
As group admin role:
   Create a record in the Discounts and Promotions window
   Create a Sales Order
   Configure it in order the previous discount to be applied
   Set its Invoice Terms as Immediate and book it
   Create a Sales Invoice header, select the previously created order lines but do not complete it
   Close the Sales Order and check the Ordered Quantity has been updated to 0
   Try to complete the invoice and check the following error message is shown:
      "Error: division by zero"
   If the product is set as Is Quantity Variable = 'N' the error message should be:
      "It is not possible to complete the invoice <> line <>. Order No. <>: Invoiced Quantity cannot be higher than Ordered Quantity."
The problem is in the following lines of the m_promotion_calculate function:

v_totalamt := round(Cur_Offer.totalamt * v_qtyinvoiced / v_qtyordered, v_precision);
v_displayedtotalamt := round(Cur_Offer.displayedtotalamt * v_qtyinvoiced / v_qtyordered, v_precision);
No tags attached.
Issue History
2016-02-25 10:14ngarciaNew Issue
2016-02-25 10:14ngarciaAssigned To => Triage Finance
2016-02-25 10:14ngarciaModules => Core
2016-02-25 10:14ngarciaResolution time => 1459202400
2016-02-25 10:14ngarciaTriggers an Emergency Pack => No
2016-02-25 10:14ngarciaIssue Monitored: networkb
2016-02-25 10:15ngarciaProposed Solution updated
2016-02-26 13:22AtulOpenbravoAssigned ToTriage Finance => AtulOpenbravo
2016-02-29 14:27AtulOpenbravoNote Added: 0084594
2016-02-29 14:28AtulOpenbravoStatusnew => scheduled
2016-03-01 09:41psanjuanNote Added: 0084612
2016-03-01 10:17psanjuanNote Edited: 0084594bug_revision_view_page.php?bugnote_id=0084594#r11279
2016-03-01 10:22psanjuanNote Edited: 0084594bug_revision_view_page.php?bugnote_id=0084594#r11280
2016-03-01 10:26psanjuanNote Edited: 0084594bug_revision_view_page.php?bugnote_id=0084594#r11281
2016-03-01 10:27psanjuanNote Edited: 0084594bug_revision_view_page.php?bugnote_id=0084594#r11282
2016-03-01 10:28psanjuanNote Edited: 0084594bug_revision_view_page.php?bugnote_id=0084594#r11283
2016-03-01 10:31psanjuanNote Added: 0084614
2016-03-01 19:00hgbotCheckin
2016-03-01 19:00hgbotNote Added: 0084649
2016-03-01 19:00hgbotStatusscheduled => resolved
2016-03-01 19:00hgbotResolutionopen => fixed
2016-03-01 19:00hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/e86261103636e5adfeb3e0f02ef7cfbb725594e2 [^]
2016-03-01 19:04aferrazReview Assigned To => aferraz
2016-03-01 19:04aferrazNote Added: 0084650
2016-03-01 19:04aferrazStatusresolved => closed
2016-03-01 19:04aferrazFixed in Version => 3.0PR16Q2
2016-03-17 10:56hudsonbotCheckin
2016-03-17 10:56hudsonbotNote Added: 0085177

Notes
(0084594)
AtulOpenbravo   
2016-02-29 14:27   
(edited on: 2016-03-01 10:28)
Test Plan I
- Login as Admin role
- Create a record in the Discounts and Promotions window. Set Discount Percentage as 10. Starting Date = 01-01-2015, Ending Date =3112-2016
  Include Product - Only those defined. In Product tab select Zumo de Pera.
  Include Business Partner - Only those defined. In Business Partner Tab select Business Partner "Hoteles", as this one does not have any "Basic Discount" setup.
- Create a Sales Order for Hoteles and in Lines select Product Zumo de Pera, ordered quantity = 10.
- Check that Unit Price is set as 1.02 whereas List Price is 1.13.
- Set its Invoice Terms as Immediate and book it.
- Create a Sales Invoice header, select the previously created order, do not complete it. Check that the net unit price is 1.02.
- Close the Sales Order and check the Ordered Quantity has been updated to 0
- Complete the invoice.
- Go to the Sales Invoice window and try to complete the invoice.
- Check that Sales Invoice can not be processed successfully as a valid error message regarding qty check is shown as "Invoiced Quantity cannot be higher than Ordered Quantity".

Test II
- Repeat same scenario as above but setting "Qty variable" flag of product as Yes.
- Process the Sales Invoice and check that Invoice is processed successfully.

Steps to show "Qty variable" flag in product window.
- Login as System Admin
- Set "Core" Module as "In Development" = Yes. Save.
- Go to "Windows, Tab and Fields" window, search "Product" window.
- Go to "Tab" tab, select "Product" tab.
- Go to "Field" sub-tab and remove the filter
- Search by "Is Quantity Variable" field, and set it as "Displayed" = Yes.
- Log out and Log in.

(0084612)
psanjuan   
2016-03-01 09:41   
Issue verified.

In the case of creating a sales order for a product/BP do not included in any Discount and Promotion, same scenario leads in below error message:

it is not possible to complete invoice 10000170 line 10. Order N1 1000165: Invoiced Quantity cannot be higher than Ordered Quantity.

Above is OK for products set as "Quantity Variable" = N, in sales.
(0084614)
psanjuan   
2016-03-01 10:31   
Test Plan above verified.

Issue can be code reviewed and closed.
(0084649)
hgbot   
2016-03-01 19:00   
Repository: erp/devel/pi
Changeset: e86261103636e5adfeb3e0f02ef7cfbb725594e2
Author: Atul Gaware <atul.gaware <at> openbravo.com>
Date: Mon Feb 29 18:07:19 2016 +0530
URL: http://code.openbravo.com/erp/devel/pi/rev/e86261103636e5adfeb3e0f02ef7cfbb725594e2 [^]

Fixes Issue 32337:Division by zero error when completing an invoice
associated to a closed order (quantity 0) with a promotion

While calculating promotion if qty ordered is non zero then only
use divide by statement else set values to zero

---
M src-db/database/model/functions/M_PROMOTION_CALCULATE.xml
---
(0084650)
aferraz   
2016-03-01 19:04   
Code review OK
(0085177)
hudsonbot   
2016-03-17 10:56   
A changeset related to this issue has been promoted main and to the
Central Repository, after passing a series of tests.

Promotion changeset: https://code.openbravo.com/erp/devel/main/rev/b22fb0500156 [^]
Maturity status: Test