Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
10-03-2019, 07:07 AM,

I'm getting the following messages when trying to delete a Credit Note

INFORMATION Message : The number of stock movements to be deleted is: 5
INFORMATION Message : The custallocns record has been deleted
INFORMATION Message : The debtortranstaxes record has been deleted
INFORMATION Message : Deleted the credit note stock move taxesinfo

Database Error 1451 : SQL to delete the stock movement record failed with the message
Cannot delete or update a parent row: a foreign key constraint fails (`weberb_test`.`stockserialmoves`, CONSTRAINT `stockserialmoves_ibfk_1` FOREIGN KEY (`stockmoveno`) REFERENCES `stockmoves` (`stkmoveno`))
Database SQL Failure : The SQL that failed was
DELETE FROM stockmoves WHERE type=11 AND transno = '76'
Database Rollback Due to Error Above : Rolling Back Transaction OK

Anyway to bypass the key constraint?

Please no rant about not using this script deleting credit notes :-)
I'm currently working on an invoice editing feature that does things by the book:
1) auto-generating a full credit with returned goods
2) auto-clone the initial order with identical lots
- if new order invoice issued, it becomes the revised order and tag the old one and new ones as revised/revision to clearly identify them as related
- if new order is discarded by user before being invoiced: the autogenerated credit note is deleted (that's why I'm using Z_DeleteCreditNote.php for: to put everything back to the original state and cancel my autogenerated Credit Note)


10-03-2019, 11:49 AM,
RE: Z_DeleteCreditNote
Hello, HDeriauFF!

Please try the attached script.
I've never worked with serial items, so there could potentially be some other delete needed. If another error occurs, post a reply, and we'll work it through one step at a time.

Attached Files
.php   Z_DeleteCreditNote.php (Size: 6.03 KB / Downloads: 4)
10-03-2019, 12:07 PM,
RE: Z_DeleteCreditNote
Yes I figured out it had to do with the stockserialmoves. All fixed, thx!

01-19-2020, 02:27 PM, (This post was last modified: 01-19-2020, 02:54 PM by TurboPT.)
RE: Z_DeleteCreditNote
SQL change from post #2 committed.

Forum Jump:

Users browsing this thread: 1 Guest(s)