Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0042702Openbravo ERP03. Procurement managementpublic2020-01-06 17:352020-03-20 17:54
agonzalez 
AtulOpenbravo 
highmajoralways
closedfixed 
5
3.0PR18Q3.3 
3.0PR20Q2 
dmiguelez
Google Chrome
Core
No
0042702: Rounding problem on posting matched invoices in certain cases when the result has an inifinite number of decimals
There is a problem while calculating the expenses of the transaction being posted. When the movement quantity of the goods receipt, the quantity invoiced of the invoice and the line net amount of the first line contains certain values, it could happen that the result of the calculation of the expenses generates a result with infinite results, causing a ArithmeticException as there is not a RoundingMode defined.

Please find attached a copy of the generated exception and follow the specified steps to reproduce, as this problems can be reproduced only certain conditions.

The code fragment that needs to be changed is on the DocMatchInv class and you will find a patch attached to the issue that seems to solve the problem.
-----------------------
CONFIGURATION REQUIRED
-----------------------
* The currency used for the invoice must have a price precision of 4

-----------------------
STEPS
-----------------------

1. Create an invoice and add a line, with a product that contains "150452" as invoiced quantity and "1.059" as net unit price. (Process the invoice)

2. At this point, the line net amount for the created line should be "159,328.67"

3. Create a goods receipt, and copy the lines from the created invoice, and in the movement quantity, set the following quantity: "4156" (Process the goods receipt)

4. Go to the matched invoices window and find the recently created invoice associated with the recently created goods receipt.

5. Click on "Post". An error will be displayed: "Process failed during execution" and an exception log will be generated on the openbravo log. You will find the generated exception on the attached files.

NOTE: This case could be repeated with another quantities if the result of the following operation returns a result with infinite decimals: (line net amount * movement quantity) / quantity invoiced
Add a rounding mode to the line in the DocMatchInv where the expenses are calculated. A patch was uploaded.
No tags attached.
patch patch_rounding.patch (675) 2020-01-06 17:35
https://issues.openbravo.com/file_download.php?file_id=13757&type=bug
? RoundingProblem.clear (4,298) 2020-01-06 17:36
https://issues.openbravo.com/file_download.php?file_id=13758&type=bug
Issue History
2020-01-06 17:35agonzalezNew Issue
2020-01-06 17:35agonzalezAssigned To => Triage Finance
2020-01-06 17:35agonzalezFile Added: patch_rounding.patch
2020-01-06 17:35agonzalezWeb browser => Google Chrome
2020-01-06 17:35agonzalezModules => Core
2020-01-06 17:35agonzalezTriggers an Emergency Pack => No
2020-01-06 17:36agonzalezFile Added: RoundingProblem.clear
2020-01-20 13:37ngarciaWeb browserGoogle Chrome => Google Chrome
2020-01-22 09:17ngarciaWeb browserGoogle Chrome => Google Chrome
2020-01-22 09:17ngarciaResolution time => 1581462000
2020-01-22 09:17ngarciaPrioritynormal => high
2020-01-22 09:17ngarciaSeverityminor => major
2020-01-22 11:04dmiguelezAssigned ToTriage Finance => AtulOpenbravo
2020-01-23 08:08AtulOpenbravoStatusnew => scheduled
2020-01-24 05:58AtulOpenbravoNote Added: 0117209
2020-01-24 05:59AtulOpenbravoNote Edited: 0117209bug_revision_view_page.php?bugnote_id=0117209#r20213
2020-01-24 05:59AtulOpenbravoNote Edited: 0117209bug_revision_view_page.php?bugnote_id=0117209#r20214
2020-01-31 08:30hgbotCheckin
2020-01-31 08:30hgbotNote Added: 0117387
2020-01-31 08:30hgbotStatusscheduled => resolved
2020-01-31 08:30hgbotResolutionopen => fixed
2020-01-31 08:30hgbotFixed in SCM revision => http://code.openbravo.com/erp/devel/pi/rev/d70bc108e8d238c04608becfab7b6854eec68b1a [^]
2020-01-31 08:30hgbotCheckin
2020-01-31 08:30hgbotNote Added: 0117388
2020-01-31 08:31dmiguelezReview Assigned To => dmiguelez
2020-01-31 08:31dmiguelezNote Added: 0117389
2020-01-31 08:31dmiguelezStatusresolved => closed
2020-01-31 08:31dmiguelezFixed in Version => 3.0PR20Q2
2020-01-31 09:29hgbotCheckin
2020-01-31 09:29hgbotNote Added: 0117396
2020-03-20 17:54hudsonbotCheckin
2020-03-20 17:54hudsonbotNote Added: 0118736

Notes
(0117209)
AtulOpenbravo   
2020-01-24 05:58   
(edited on: 2020-01-24 05:59)
Test Plan

- Login as System Admin
- Navigate to Currency window, select current EUR and set Price Precision as 4
- Log Out.

In Format.xml, set

<Number name="priceInform"
       decimal="." grouping="," formatOutput="#,##0.000" formatInternal="#0.000" />
   <Number name="priceRelation"
       decimal="." grouping="," formatOutput="#,##0.000" formatInternal="#0.000" />
   <Number name="priceEdition"
       decimal="." grouping="," formatOutput="#0.000" formatInternal="#0.000" />
   
and

<Number name="amountInform"
       decimal="." grouping="," formatOutput="#,##0.000" formatInternal="#0.000" />


- Run ant smartbuild

- Login as F&B International Group Admin
- Navigate to Purchase Invoice Window
- Create Purchase Invoice in F&B Espana Org, Bebidas Alegres, S.L. business partner.
- Create a Line for Product:Cerveza Ale 0,5L, Quantity = 150452, Price = 1.059
- Realize that Line Net amount is set 159328.67
- Complete Invoice.
- Navigate to Goods Receipt Window
- Create a Goods Receipt in F&B Espana Org, Bebidas Alegres, S.L. business partner.
- Using Create Lines from, select previously created purchase invoice in the Invoice Selector
- Realize that Line for Product Cerveza Ale 0,5L is loaded.
- Select the line, set Quantity to 4156, Storage Bin = RN-0-0-0
- Click on OK button.
- Complete the Goods Receipt.
- Schedule Costing Background process so that cost is calculated for related transactions.
- Navigate to Matched Invoice window and select the one which is linked with above Purchase Invoice Line and Goods Receipt Line.
- Post the record, Realize that posting is successful. (If there is error Account not found error then Navigate to product: Cerveza Ale 0,5L, Accounting Tab: set Invoice Price Variance account to some account to avoid error )
- Posting is as below:-

Key----Account

2120---Goods Received and not invoiced--6,386.94--Debit
5360---Product Expense------------------------6,386.94--Credit

(0117387)
hgbot   
2020-01-31 08:30   
Repository: erp/devel/pi
Changeset: d70bc108e8d238c04608becfab7b6854eec68b1a
Author: Atul Gaware <atul.gaware <at> openbravo.com>
Date: Fri Jan 24 10:32:04 2020 +0530
URL: http://code.openbravo.com/erp/devel/pi/rev/d70bc108e8d238c04608becfab7b6854eec68b1a [^]

Fixes BUG-42702:Rounding problem on posting matched invoices
in certain cases when the result has an inifinite number of
decimals

To avoid java.lang.ArithmeticException: Non-terminating
decimal expansion; no exact representable decimal result
use RoundingMode HALF_UP when doing a BigDecimal Division

---
M src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java
---
(0117388)
hgbot   
2020-01-31 08:30   
Repository: erp/devel/pi
Changeset: c95107ddf37c29e4e3a2d8963bb7ec2450f7c534
Author: Atul Gaware <atul.gaware <at> openbravo.com>
Date: Fri Jan 24 11:50:32 2020 +0530
URL: http://code.openbravo.com/erp/devel/pi/rev/c95107ddf37c29e4e3a2d8963bb7ec2450f7c534 [^]

Related To ISSUE-42702:Apply sonarlint suggestions

- Use built-in formatting to construct argument for log4jDocMatchInv.debug
- Use isEmpty() instead of MaterialMgmtMaterialTransactionList().size()
- Only the sign of the result should be examined when checking condition
lineAmount.compareTo(BigDecimal.ZERO) == 1
- Remove the literal "true" boolean value when using ternary operator
strIsSOTrx.equalsIgnoreCase("Y") ? true : false
- Use the opposite operator ("!=") instead in if condition
!(linenetamt.compareTo(BigDecimal.ZERO) == 0
- Remove useless assignment to local variable lineAmount, bdCost
- Add error log when getting std precision from invoice currency.
- "formatDate" returns a string, there's no need to call toString().
- Declare variable cr and diff on separate lines.
- Rename local variable Fact_Acct_Group_ID as factAcctGroupId,
LineNetAmt as lineNetAmt, PriceList as priceList,
AD_Client_ID as adClientId, AD_Org_ID as adOrgId,
p_inOutlines as pinOutlines, SeqNo as seqNum
names to match the regular expression '^[a-z][a-zA-Z0-9]*$'.
- Immediately return ZERO expression instead of assigning it
to the temporary variable "retValue".
- Return an empty array DocLine[0] instead of null.

---
M src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java
---
(0117389)
dmiguelez   
2020-01-31 08:31   
Code Review + Testing Ok
(0117396)
hgbot   
2020-01-31 09:29   
Repository: erp/devel/pi
Changeset: 1f3682a60c1cb3d91648e2edafe78df4aec72551
Author: David Miguelez <david.miguelez <at> openbravo.com>
Date: Fri Jan 31 09:29:36 2020 +0100
URL: http://code.openbravo.com/erp/devel/pi/rev/1f3682a60c1cb3d91648e2edafe78df4aec72551 [^]

Related To ISSUE 42702. Removed unnecessary supress warnings since the
parameter name is no longer the same as the class variable name of the
parent class

---
M src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java
---
(0118736)
hudsonbot   
2020-03-20 17:54   
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/b31620115262 [^]
Maturity status: Test