Skip to content

Commit 1e5ad6f

Browse files
authored
fix: Bei deaktivierter TSE sollte der bisherige Ablauf nicht unterbrochen werden und erst bei aktiverter TSE greifen (#52)
1 parent 3d401de commit 1e5ad6f

3 files changed

Lines changed: 43 additions & 14 deletions

File tree

erpnext_tse/erpnext_tse/doctype/tse_transaction/tse_transaction.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ def create_tse_transaction_for_pos_invoice(doc, method: str | None = None):
306306
if doc.doctype != "POS Invoice":
307307
return
308308

309+
if not frappe.db.get_single_value("TSE Settings", "enabled"):
310+
return
311+
309312
# 3. POS Profile holen
310313
if not getattr(doc, "pos_profile", None):
311314
frappe.throw(_("POS Invoice is missing a POS Profile."))

erpnext_tse/erpnext_tse/pos/pos_invoice/pos_invoice_hooks.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
from frappe import _
66

77

8+
def _is_tse_enabled():
9+
return bool(frappe.db.get_single_value("TSE Settings", "enabled"))
10+
11+
812
def ensure_tse_transaction_present_and_finished(doc, method):
13+
if not _is_tse_enabled():
14+
return
915
# Sicherstellen, dass eine TSE Transaction vorhanden ist und den Status Finished hat
1016
# Ohne sollte um auch rechtlich sicher zu sein keine Buchung erfolgen
1117
if not doc.tse_transaction:
@@ -30,6 +36,8 @@ def show_tse_signing_success_toast(doc, method=None):
3036
- Grün: TSE Transaction FINISHED
3137
- Rot + Abbruch: TSE Transaction hat nicht Status FINISHED oder andere Fehler
3238
"""
39+
if not _is_tse_enabled():
40+
return
3341

3442
# Keine verknüpfte TSE Transaction
3543
if not getattr(doc, "tse_transaction", None):

erpnext_tse/erpnext_tse/pos/pos_invoice/test_pos_invoice_hooks.py

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,39 @@ class TestPosInvoiceHooks(FrappeTestCase):
1414
def test_ensure_requires_transaction(self):
1515
doc = SimpleNamespace(tse_transaction=None)
1616

17-
with self.assertRaises(frappe.MandatoryError):
18-
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
17+
with patch("frappe.db.get_single_value", return_value=1):
18+
with self.assertRaises(frappe.MandatoryError):
19+
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
1920

2021
def test_ensure_requires_finished(self):
2122
doc = SimpleNamespace(tse_transaction="TX-1")
2223

23-
with patch("frappe.get_doc", return_value=SimpleNamespace(transaction_status="ACTIVE")):
24-
with self.assertRaises(frappe.ValidationError):
25-
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
24+
with patch("frappe.db.get_single_value", return_value=1):
25+
with patch("frappe.get_doc", return_value=SimpleNamespace(transaction_status="ACTIVE")):
26+
with self.assertRaises(frappe.ValidationError):
27+
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
2628

2729
def test_ensure_passes_finished(self):
2830
doc = SimpleNamespace(tse_transaction="TX-1")
2931

30-
with patch("frappe.get_doc", return_value=SimpleNamespace(transaction_status="FINISHED")):
31-
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
32+
with patch("frappe.db.get_single_value", return_value=1):
33+
with patch("frappe.get_doc", return_value=SimpleNamespace(transaction_status="FINISHED")):
34+
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
3235

3336
def test_show_toast_requires_transaction(self):
3437
doc = SimpleNamespace(tse_transaction=None)
3538

36-
with self.assertRaises(frappe.ValidationError):
37-
pos_invoice_hooks.show_tse_signing_success_toast(doc)
39+
with patch("frappe.db.get_single_value", return_value=1):
40+
with self.assertRaises(frappe.ValidationError):
41+
pos_invoice_hooks.show_tse_signing_success_toast(doc)
3842

3943
def test_show_toast_success(self):
4044
doc = SimpleNamespace(tse_transaction="TX-1")
4145
tse_doc = SimpleNamespace(name="TX-1", transaction_status="FINISHED")
4246

43-
with patch("frappe.get_doc", return_value=tse_doc), patch("frappe.msgprint") as msgprint:
44-
pos_invoice_hooks.show_tse_signing_success_toast(doc)
47+
with patch("frappe.db.get_single_value", return_value=1):
48+
with patch("frappe.get_doc", return_value=tse_doc), patch("frappe.msgprint") as msgprint:
49+
pos_invoice_hooks.show_tse_signing_success_toast(doc)
4550

4651
_, kwargs = msgprint.call_args
4752
self.assertEqual(kwargs.get("indicator"), "green")
@@ -50,6 +55,19 @@ def test_show_toast_failure(self):
5055
doc = SimpleNamespace(tse_transaction="TX-1")
5156
tse_doc = SimpleNamespace(name="TX-1", transaction_status="ACTIVE")
5257

53-
with patch("frappe.get_doc", return_value=tse_doc):
54-
with self.assertRaises(frappe.ValidationError):
55-
pos_invoice_hooks.show_tse_signing_success_toast(doc)
58+
with patch("frappe.db.get_single_value", return_value=1):
59+
with patch("frappe.get_doc", return_value=tse_doc):
60+
with self.assertRaises(frappe.ValidationError):
61+
pos_invoice_hooks.show_tse_signing_success_toast(doc)
62+
63+
def test_ensure_skips_when_disabled(self):
64+
doc = SimpleNamespace(tse_transaction=None)
65+
66+
with patch("frappe.db.get_single_value", return_value=0):
67+
pos_invoice_hooks.ensure_tse_transaction_present_and_finished(doc, None)
68+
69+
def test_show_toast_skips_when_disabled(self):
70+
doc = SimpleNamespace(tse_transaction=None)
71+
72+
with patch("frappe.db.get_single_value", return_value=0):
73+
pos_invoice_hooks.show_tse_signing_success_toast(doc)

0 commit comments

Comments
 (0)