Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0016845Openbravo ERP07. Sales managementpublic2011-04-19 10:282011-05-31 16:13
AinhoaPagola 
jonalegriaesarte 
urgentmajorhave not tried
closedfixed 
5
2.50MP28 
2.50MP312.50MP31 
Core
No
0016845: Invoice Total Amount not properly updated when lines are deleted
The invoice total amount is not properly updated when a line is deleted.
In an invoice with more than one line with the same tax amount, when a line is deleted the Total Amount of the header is not properly updated.
With sampledata in Openbravo 2.50:
- Create a new header.
- Create a new line for a product. Set unit price to 100 and taxes 16%.
The header has total amount 116 (correct) and a line is created in the tax tab.
- Create a second line for a product. Set unit price to 100 and taxes to 16.
The header has total amount 232 (correct) and the line in the tax tab is updated to 32
- Delete a line.
The tax tab is properly updated. The header has a total amount of 132, instead of 116. That is, the line net amount is decreased from the total amount, but the taxes are not.
This Bug only reproduces in Openbravo 2.50 PostgreSQL database.

The problem seem to be the order in which two triggers execute:

- C_invoiceline_trg2()
- C_invoicelinestax_trg() (this one should execute first).

No tags attached.
depends on defect 0017016 closed jonalegriaesarte Invoice Total Amount not properly updated when lines are deleted 
has duplicate defect 0012296 closed adrianromero When removing a line for an Invoice, Total Net Amount and Total Gross Amount keep the old value 
has duplicate defect 00171172.50MP30 closed adrianromero When leaving an invoice without lines tax amount still appears in invoice header 
Issue History
2011-04-19 10:28AinhoaPagolaNew Issue
2011-04-19 10:28AinhoaPagolaAssigned To => AinhoaPagola
2011-04-19 10:28AinhoaPagolaModules => Core
2011-04-19 10:45AinhoaPagolaRelationship addedrelated to 0012296
2011-04-26 16:18dalsasuaIssue Monitored: networkb
2011-05-05 08:43AinhoaPagolaStatusnew => scheduled
2011-05-05 08:43AinhoaPagolafix_in_branch => pi
2011-05-12 14:12AinhoaPagolaRelationship addeddepends on 0017117
2011-05-12 14:12AinhoaPagolaAssigned ToAinhoaPagola => jonalegriaesarte
2011-05-12 14:16AinhoaPagolafix_in_branchpi =>
2011-05-12 14:16AinhoaPagolaProposed Solution updated
2011-05-25 11:42adrianromeroversion2.50MP28 => 3.0RC7
2011-05-25 11:42adrianromeroTarget Version2.50MP30 =>
2011-05-25 11:43adrianromeroversion3.0RC7 => 2.50MP28
2011-05-25 11:43adrianromeroTarget Version => 2.50MP30
2011-05-25 11:43adrianromeroTypedefect => backport
2011-05-25 16:44adrianromeroNote Added: 0037437
2011-05-25 17:42adrianromeroRelationship replacedhas duplicate 0017117
2011-05-25 17:44adrianromeroRelationship replacedhas duplicate 0012296
2011-05-26 09:20adrianromeroTarget Version2.50MP30 => 2.50MP31
2011-05-30 13:21hgbotCheckin
2011-05-30 13:21hgbotNote Added: 0037723
2011-05-30 13:21hgbotStatusscheduled => resolved
2011-05-30 13:21hgbotResolutionopen => fixed
2011-05-30 13:21hgbotFixed in SCM revision => http://code.openbravo.com/erp/stable/2.50/rev/255e4e40f94f3a9da49bed0eda2f75a5c1447684 [^]
2011-05-30 13:21hgbotCheckin
2011-05-30 13:21hgbotNote Added: 0037726
2011-05-30 13:21hgbotFixed in SCM revisionhttp://code.openbravo.com/erp/stable/2.50/rev/255e4e40f94f3a9da49bed0eda2f75a5c1447684 [^] => http://code.openbravo.com/erp/stable/2.50/rev/e4fade7cc09c96f53f5b1c78e04bd70e5b76a861 [^]
2011-05-30 13:22hgbotCheckin
2011-05-30 13:22hgbotNote Added: 0037727
2011-05-30 13:32adrianromeroNote Added: 0037729
2011-05-31 16:13maiteNote Added: 0037832
2011-05-31 16:13maiteStatusresolved => closed
2011-05-31 16:13maiteFixed in Version => 2.50MP31

Notes
(0037437)
adrianromero   
2011-05-25 16:44   
This issue can be reproduced in Orders and Invoices, for both types: Purchases and Sales

This issue can be reproduced only in PosgreSQL and not in Oracle because in posgresql the trigger in line taxes is executed after the trigger in lines when line taxes are deleted because of the ON DELETE CASCADE option on the line taxes table.

In Oracle the behavior is exactly the opposite and makes the logic work as expected.

The proposed solution is to remove the ON DELETE CASCADE option on the line taxes table and simulate this option in an ON BEFORE trigger in the table lines.
(0037723)
hgbot   
2011-05-30 13:21   
Repository: erp/stable/2.50
Changeset: 255e4e40f94f3a9da49bed0eda2f75a5c1447684
Author: Adrián Romero <adrianromero <at> openbravo.com>
Date: Wed May 25 17:34:14 2011 +0200
URL: http://code.openbravo.com/erp/stable/2.50/rev/255e4e40f94f3a9da49bed0eda2f75a5c1447684 [^]

Fixes issue 0016845: Invoice Total Amount not properly updated when lines are deleted
To execute the triggers in the correct order in postgresql it has been removed the ON DELETE CASCADE option and has been replaced simulating exactly the same logic in the related trigger

---
M src-db/database/model/tables/C_INVOICELINETAX.xml
M src-db/database/model/tables/C_ORDERLINETAX.xml
M src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml
M src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml
---
(0037726)
hgbot   
2011-05-30 13:21   
Repository: erp/stable/2.50
Changeset: e4fade7cc09c96f53f5b1c78e04bd70e5b76a861
Author: Adrián Romero <adrianromero <at> openbravo.com>
Date: Mon May 30 13:11:43 2011 +0200
URL: http://code.openbravo.com/erp/stable/2.50/rev/e4fade7cc09c96f53f5b1c78e04bd70e5b76a861 [^]

Fixes issue 0016845: Invoice Total Amount not properly updated when lines are deleted
Adding comments in triggers code

---
M src-db/database/model/triggers/C_INVLINE_CHK_RESTRICTIONS_TRG.xml
M src-db/database/model/triggers/C_ORDLINE_CHK_RESTRICTIONS_TRG.xml
---
(0037727)
hgbot   
2011-05-30 13:22   
Repository: erp/stable/api-checks-2.50
Changeset: 9e20363c3c8e470ef43936be77eba563c8f57e0b
Author: Adrián Romero <adrianromero <at> openbravo.com>
Date: Mon May 30 13:19:33 2011 +0200
URL: http://code.openbravo.com/erp/stable/api-checks-2.50/rev/9e20363c3c8e470ef43936be77eba563c8f57e0b [^]

False positive. The delete is done in triggers instead of foreign key to force trigger execution. It is changed in issue 0016845: Invoice Total Amount not properly updated when lines are deleted

---
M model/model/tables/C_INVOICELINETAX.xml
M model/model/tables/C_ORDERLINETAX.xml
---
(0037729)
adrianromero   
2011-05-30 13:32   
* Testing the issue

Kindly follow the steps to test and verify that now the total amount in the header shows the correct value after deleting a line. This must be verified in Orders and Invoices and in Purchases and Sales

Verify also that duplicated issues 12296 and 17117 are also fixed

Because of the changes in triggers, it must also be verified that records can be deleted in invoices and order lines without any issue.

* Other areas affected

No other areas affected appart from the tables involved
(0037832)
maite   
2011-05-31 16:13   
verified.