Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: delete only most recent sales transactions #13

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ App to hold regional code for Germany, built on top of ERPNext.

Automatically checks the validity of EU VAT IDs of all your customers every three months, or manually whenever you want. Check out the [intro on Youtube](https://youtu.be/hsFMn2Y85zA) (german).

![Validate EU VAT ID](docs/vat_check.png)
![Validate EU VAT ID](docs/vat_check.png)

### HR
- Allow deletion of the most recent sales transaction only

This ensures consecutive numbering of transactions. Applies to **Quotation**, **Sales Order**, **Sales Invoice**.

- Custom fields in **Employee** (tax information, etc.)
- List of religios denominations ("Konfessionen")
Expand Down
Empty file.
26 changes: 26 additions & 0 deletions erpnext_germany/custom/sales.py
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),
},
)
18 changes: 11 additions & 7 deletions erpnext_germany/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,17 @@
# ---------------
# Hook on document methods and events

# doc_events = {
# "*": {
# "on_update": "method",
# "on_cancel": "method",
# "on_trash": "method"
# }
# }
doc_events = {
"Quotation": {
"on_trash": "erpnext_germany.custom.sales.on_trash",
},
"Sales Order": {
"on_trash": "erpnext_germany.custom.sales.on_trash",
},
"Sales Invoice": {
"on_trash": "erpnext_germany.custom.sales.on_trash",
},
}

# doc_events = {}

Expand Down
2 changes: 2 additions & 0 deletions erpnext_germany/translations/de.csv
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,5 @@ Completed,Abgeschlossen
Service Unavailable,Dienst nicht verfügbar
Invalid Input,Ungültige Eingabe
Error,Fehler
Cannot delete this transaction,Diese Transaktion kann nicht gelöscht werden
Only the most recent {0} can be deleted in order to avoid gaps in numbering.,"Nur die neueste Transaktion vom Typ {0} kann gelöscht werden, um Lücken in der Nummerierung zu vermeiden."