From eba3daab27e1d9438153e89cd7b5cc917521ae08 Mon Sep 17 00:00:00 2001 From: Jameesh Ummer Date: Thu, 25 Jun 2026 13:20:13 +0300 Subject: [PATCH] fix: support Staff Pro iqama_expiry_date in Saudi Employee validator --- ramz_hr/countries/saudi/validators.py | 21 ++++++++++++++++++--- ramz_hr/tests/test_employee_validators.py | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ramz_hr/countries/saudi/validators.py b/ramz_hr/countries/saudi/validators.py index 11d9daf..424f0a2 100644 --- a/ramz_hr/countries/saudi/validators.py +++ b/ramz_hr/countries/saudi/validators.py @@ -27,8 +27,23 @@ def validate_employee(doc, method=None): compute_probation_end_date(doc) +def _get_iqama_number(doc): + """Get Iqama number, supporting both custom_ prefixed and standard field names.""" + return (doc.get("custom_iqama_number") or doc.get("iqama_number") or "").strip() + + +def _get_iqama_expiry(doc): + """Get Iqama expiry date, supporting both custom_ prefixed and standard field names.""" + return doc.get("custom_iqama_expiry") or doc.get("iqama_expiry_date") + + +def _get_nationality(doc): + """Get nationality, supporting both custom_ prefixed and standard field names.""" + return (doc.get("custom_nationality") or doc.get("nationality") or "").strip() + + def validate_iqama_format(doc): - iqama = (doc.get("custom_iqama_number") or "").strip() + iqama = _get_iqama_number(doc) if not iqama: return if not IQAMA_RE.match(iqama): @@ -36,9 +51,9 @@ def validate_iqama_format(doc): def validate_iqama_expiry_presence(doc): - nationality = (doc.get("custom_nationality") or "").strip() + nationality = _get_nationality(doc) if nationality and nationality != "Saudi Arabia": - if not doc.get("custom_iqama_expiry"): + if not _get_iqama_expiry(doc): frappe.throw("Iqama Expiry is required for non-Saudi employees.") diff --git a/ramz_hr/tests/test_employee_validators.py b/ramz_hr/tests/test_employee_validators.py index ffb2234..4c05d01 100644 --- a/ramz_hr/tests/test_employee_validators.py +++ b/ramz_hr/tests/test_employee_validators.py @@ -43,10 +43,26 @@ def test_iqama_expiry_required_for_non_saudi(self): with self.assertRaises(frappe.ValidationError): validate_iqama_expiry_presence(doc) + def test_iqama_expiry_required_for_non_saudi_with_staff_pro_fields(self): + """Test with Staff Pro field names (no custom_ prefix).""" + doc = _Stub(nationality="India", iqama_expiry_date=None) + with self.assertRaises(frappe.ValidationError): + validate_iqama_expiry_presence(doc) + + def test_iqama_expiry_passes_with_staff_pro_fields(self): + """Test with Staff Pro field names when expiry is provided.""" + doc = _Stub(nationality="India", iqama_expiry_date="2026-12-31") + validate_iqama_expiry_presence(doc) # should not raise + def test_iqama_expiry_optional_for_saudi(self): doc = _Stub(custom_nationality="Saudi Arabia", custom_iqama_expiry=None) validate_iqama_expiry_presence(doc) # not raised + def test_iqama_expiry_optional_for_saudi_with_staff_pro_fields(self): + """Test with Staff Pro field names for Saudi employee.""" + doc = _Stub(nationality="Saudi Arabia", iqama_expiry_date=None) + validate_iqama_expiry_presence(doc) # not raised + def test_iban_valid(self): doc = _Stub(custom_iban="SA" + "1" * 22) validate_iban_format(doc)