-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from alyf-de/dont-delete-old-transactions
feat: delete only most recent sales transactions
- Loading branch information
Showing
5 changed files
with
43 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import frappe | ||
from frappe import _ | ||
from erpnext.controllers.selling_controller import SellingController | ||
|
||
|
||
def on_trash(doc: SellingController, event: str = None) -> None: | ||
if doc.flags.ignore_validate: | ||
return | ||
|
||
if is_not_latest(doc.doctype, doc.name, doc.creation): | ||
frappe.throw( | ||
msg=_( | ||
"Only the most recent {0} can be deleted in order to avoid gaps in numbering." | ||
).format(_(doc.doctype)), | ||
title=_("Cannot delete this transaction"), | ||
) | ||
|
||
|
||
def is_not_latest(doctype, name, creation): | ||
return frappe.db.exists( | ||
doctype, | ||
{ | ||
"creation": (">", creation), | ||
"name": ("!=", name), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters