Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0009643Openbravo ERP08. Project and service managementpublic2009-06-25 18:102009-07-21 16:54
networkb 
sathiyan 
urgentminoralways
closedno change required 
5
2.40 
2.50MP4 
Core
No
0009643: Purchase invoice can not be deleted if it has been created in "Created AP Expense invoices"
When a Purchase invoice is created using "Created AP Expense invoices", the invoice can not be deleted because its lines has reference to Expense sheet.
At the same time, Expense sheet can not be unprocessed because it has a link to Purchase Invoice.

It exists an infinitive loop.
Generate an Expense Sheet (Project & Service Management > Transactions > Expense sheet).
Add lines and process it.

Execute Project & Service Management > Transactions > Created AP Expense invoices.

Go to new Purchase invoice. Try to delete it. It is not possible.

Go back to Expense Sheet. Try to unprocessed it. It is not possible
No tags attached.
related to feature request 0004526 acknowledged rmorley Process/Unprocess Expense Sheet lines individually 
Issue History
2009-06-25 18:10networkbNew Issue
2009-06-25 18:10networkbAssigned To => rafaroda
2009-06-29 19:02psarobeNote Added: 0017648
2009-06-29 19:02psarobeStatusnew => feedback
2009-06-30 10:13networkbNote Added: 0017668
2009-06-30 10:13networkbStatusfeedback => new
2009-06-30 21:19psarobeStatusnew => scheduled
2009-06-30 21:19psarobeAssigned Torafaroda => gmauleon
2009-06-30 21:19psarobefix_in_branch => pi
2009-07-03 10:50dmitry_mezentsevNote Added: 0017773
2009-07-03 11:06gmauleonAssigned Togmauleon => sathiyan
2009-07-10 11:00pjuvaraPriorityimmediate => urgent
2009-07-10 11:00pjuvarafix_in_branchpi =>
2009-07-13 06:35pjuvaraTarget Version => 2.50MP4
2009-07-13 06:35pjuvaraStatusscheduled => acknowledged
2009-07-13 06:35pjuvaraStatusacknowledged => scheduled
2009-07-13 06:35pjuvarafix_in_branch => pi
2009-07-13 08:32sathiyanNote Added: 0018142
2009-07-14 13:41rafarodaRelationship addedrelated to 0004526
2009-07-17 17:35rafarodaStatusscheduled => closed
2009-07-17 17:35rafarodaNote Added: 0018382
2009-07-17 17:35rafarodaResolutionopen => no change required
2009-07-18 00:00anonymoussf_bug_id0 => 2823349
2009-07-21 16:51networkbNote Added: 0018495
2009-07-21 16:54networkbNote Added: 0018496
2009-07-21 16:56rafarodaNote Edited: 0018495

Notes
(0017648)
psarobe   
2009-06-29 19:02   
can you please write the MP?
(0017668)
networkb   
2009-06-30 10:13   
the bug was reported in 2.40 (no MP)
(0017773)
dmitry_mezentsev   
2009-07-03 10:50   
Rafa,

As if we have already split teams I think your team has to take it?
What do you think?
(0018142)
sathiyan   
2009-07-13 08:32   
There is no loop in the process. But we have some constraint as explained below:

Case 1 : Constraint in DB(we can not update or delete invoice if any invoice line associate with):
ALTER TABLE c_invoiceline
  ADD CONSTRAINT cinvoice_cinvoiceline FOREIGN KEY (c_invoice_id)
      REFERENCES c_invoice (c_invoice_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;

update or delete on table "c_invoice" violates foreign key constraint "cinvoice_cinvoiceline" on table "c_invoiceline"

Case 2: Constraint in DB (We can not update or delete any invoice line if it is associate with any expense line)
ALTER TABLE s_timeexpenseline
  ADD CONSTRAINT cinvoiceline_stimeexpenseline FOREIGN KEY (c_invoiceline_id)
      REFERENCES c_invoiceline (c_invoiceline_id) MATCH SIMPLE
      ON UPDATE NO ACTION ON DELETE NO ACTION;

Case 3 : Condition in the process(Unprocess Expenses)
if we have any expense line associated with invoice line, we can not do unprocess.
IF (v_Processed = 'Y') THEN
    <<our target fix would be on below line>>
    IF (v_CInvoicelineId IS NULL AND v_COrderlineId IS NULL) THEN
        UPDATE S_TimeExpense SET Processed = 'N' WHERE S_TimeExpense_ID=v_Record_ID;
    ELSE
       <<other code>>


I may fix it in case 3 as enable un-process even we have invoice line id associated. However it violates business rules in many places. If you do unprocess, you can delete expense line and then invoice line and then only you can delete invoice(however you never delete invoice directly due to database constraint we have). I need to confirm on this.

Regards
Sathiyan.
(0018382)
rafaroda   
2009-07-17 17:35   
This is not a defect but the expected behavior of Openbravo ERP.

Please take into account that the Process/UnProcess button in the Expense Sheet Header has the following security implemented:
1) An employee logs his expense lines.
2) Another person, usually the manager of this employee, processes (validates/approves) those expenses.
3) A third person in the HR or the Financial department creates invoices to bill employees for their expenses (Create AP Expense Invoices process).
4) The same last person or a 4th one is in charge of managing the purchase invoices and post them.
5) Now imagine that the person in step 2 goes to the expense sheet and wants to modify a line that already went to an invoice. He should not be able to modify nor delete it because, otherwise, the origin of this invoice (that was originated by an expense sheet line) would be lost.

The normal procedure in this case would be for the person in step 2 to ask the corresponding person to void the invoice and a new expense sheet line will have to be created with the correct data.
(0018495)
networkb   
2009-07-21 16:51   
(edited on: 2009-07-21 16:56)
As a proposed solution can be:

*Void the invoice and create a new expense sheet.

*Modify the invoice created and complete it.

Both solutions work.

(0018496)
networkb   
2009-07-21 16:54   
Finally, the reason why this is not a bug, is because more than one expense sheet lines can be grouped in one invoice line, and that's why the constraint is correct.