Openbravo Issue Tracking System - Localization Pack: Spain
View Issue Details
0045428Localization Pack: SpainSIIpublic2020-11-11 18:022020-12-16 11:15
shuehner 
Mery Anelo 
normalmajorhave not tried
closedfixed 
5
 
 
0045428: FacturasEventHandler -> SIIUtils.getLegalOrganization has setAdminMode but never calls restorePreviousMode
Found via many Junit tests from backoffice failing with

Test case should take care of reseting admin mode correctly in a finally block, use OBContext.restorePreviousMode

when having org.openbravo.module.sii template installed.

For example
org.openbravo.test.costing.TestCostingSourceAdjustments.testCostingAAA
(around 60-70 in total)

Debugging this points to SIIUtils.getLegalOrganization utility Function called via FacturasEventHandler

    at org.openbravo.dal.core.OBContext.addStackTrace(OBContext.java:362)
    at org.openbravo.dal.core.OBContext.setAdminMode(OBContext.java:223)
    at org.openbravo.module.sii.utils.SIIUtils.getLegalOrganization(SIIUtils.java:308)
    at org.openbravo.module.sii.eventhandlers.FacturasEventHandler.checkInvoice(FacturasEventHandler.java:116)
    at org.openbravo.module.sii.eventhandlers.FacturasEventHandler.onUpdate(FacturasEventHandler.java:68)

Reviewing that function shows it uses setAdminMode but does never restorePreviousMode violating calling convention to always use those in pairs (typically with a finally block)



Found in specific customer instance but probably following is enough:

a.) Backoffice environment (testing in release/20Q4 branch)
b.) Add sii module
c.) run junit tests.
c.1) For example the following tests showcases the problem:
org.openbravo.test.createlinesfrom.CreateLinesFromTest
Review code and fix calling convention for adminMode by using the typical recommended pattern.

OBContext.setAdminMode(bool)
try {
  <code running with adminMode>
} finally {
  OBContext.restorePreviousMode();
}
No tags attached.
related to defect 0045429 closed shuehner Openbravo ERP Code to detect+warn about Unbalanced adminMode in OBBaseTest should be improved 
diff 45428.diff (676) 2020-11-11 18:47
https://issues.openbravo.com/file_download.php?file_id=15082&type=bug
Issue History
2020-11-11 18:02shuehnerNew Issue
2020-11-11 18:02shuehnerAssigned To => Jorge Bravo
2020-11-11 18:03shuehnerNote Added: 0124284
2020-11-11 18:27shuehnerRelationship addedrelated to 0045429
2020-11-11 18:47shuehnerFile Added: 45428.diff
2020-11-11 18:48shuehnerNote Added: 0124285
2020-11-12 08:17Jorge BravoAssigned ToJorge Bravo => Mery Anelo
2020-11-24 23:56Mery AneloNote Added: 0124602
2020-11-24 23:57hgbotNote Added: 0124603
2020-11-25 00:01Mery AneloStatusnew => scheduled
2020-12-16 11:15hgbotResolutionopen => fixed
2020-12-16 11:15hgbotStatusscheduled => closed
2020-12-16 11:15hgbotNote Added: 0124877
2020-12-16 11:15hgbotNote Added: 0124878
2020-12-16 11:15hgbotNote Added: 0124879

Notes
(0124284)
shuehner   
2020-11-11 18:03   
Note: Quick check on that SIIUtils.java class shows the same issue being present not just in this utility function but also in many others.

So apart from fixing this specific case probably the whole file (or module should be reviewed)
(0124285)
shuehner   
2020-11-11 18:47   
Attached patch is enough to fix the issue as reported affecting unrelated junit tests.
Maybe reviewing the other wrong methods should be split out into separate issue to not delay fixing this first problem.
(0124602)
Mery Anelo   
2020-11-24 23:56   
Test plan:

- From the back office
- Run JUnit test org.openbravo.test.createlinesfrom.CreateLinesFromTest
- Check that there is no WARNING for Unbalanced calls to setAdminMode and restorePreviousMode.

- Make use and check the modified methods. Verify that WARNING for Unbalanced calls to setAdminMode and restorePreviousMode is not recorded in the log.
(0124603)
hgbot   
2020-11-24 23:57   
Merge Request created: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii/-/merge_requests/6 [^]
(0124877)
hgbot   
2020-12-16 11:15   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii [^]
Changeset: fde69d1ccdf3661df161ebd5f6e7b9831f8c878f
Author: Mery Anelo <mery.anelo@smfconsulting.es>
Date: 2020-11-24T18:21:23-03:00
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii/-/commit/fde69d1ccdf3661df161ebd5f6e7b9831f8c878f [^]

Fixed issue 45428: Unbalanced AdminMode and RestorePreviousMode.

Balance admin modes and their respective restores.

---
M src/org/openbravo/module/sii/process/ConsultaFactura.java
M src/org/openbravo/module/sii/process/CorrectDuplicateInvoiceError.java
M src/org/openbravo/module/sii/process/MultiCashReceiptSIIModification.java
M src/org/openbravo/module/sii/process/MultiCashReceiptSending.java
M src/org/openbravo/module/sii/process/MultiEnvioFactura.java
M src/org/openbravo/module/sii/process/MultiInvoiceSIIModification.java
M src/org/openbravo/module/sii/process/MultiPaymentSending.java
M src/org/openbravo/module/sii/process/MultiUnsubscribeInvoice.java
M src/org/openbravo/module/sii/process/PaymentSending.java
M src/org/openbravo/module/sii/process/UpdateInvoicesPreSii.java
M src/org/openbravo/module/sii/process/background/CorrectDuplicateInvoiceErrorBackground.java
M src/org/openbravo/module/sii/process/background/SendInvoicesGroupsToAEAT.java
M src/org/openbravo/module/sii/utils/SIIUtils.java
---
(0124878)
hgbot   
2020-12-16 11:15   
Directly closing issue as related merge request is already approved.

Repository: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii [^]
Changeset: f8ffdc786234065a129e27a4b89b011082f6a4b5
Author: Mery Anelo <mery.anelo@smfconsulting.es>
Date: 2020-11-24T18:36:22-03:00
URL: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii/-/commit/f8ffdc786234065a129e27a4b89b011082f6a4b5 [^]

Fixed issue 45428: Format java.

Without changes, the java is simply formatted according to the corresponding indentation.

---
M src/org/openbravo/module/sii/process/MultiCashReceiptSIIModification.java
M src/org/openbravo/module/sii/process/MultiCashReceiptSending.java
M src/org/openbravo/module/sii/process/MultiEnvioFactura.java
M src/org/openbravo/module/sii/process/MultiInvoiceSIIModification.java
M src/org/openbravo/module/sii/process/MultiPaymentSending.java
M src/org/openbravo/module/sii/process/background/CorrectDuplicateInvoiceErrorBackground.java
M src/org/openbravo/module/sii/utils/SIIUtils.java
---
(0124879)
hgbot   
2020-12-16 11:15   
Merge request merged: https://gitlab.com/openbravo/product/pmods/org.openbravo.module.sii/-/merge_requests/6 [^]