From 1a9929c73401628039244e564790ed868deb4f93 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 24 Jan 2025 19:35:14 -0600 Subject: [PATCH] fix: add `get_office_employee_url()` method for corepos handler --- src/wutta_corepos/handler.py | 22 ++++++++++++++++++++++ tests/test_handler.py | 10 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/wutta_corepos/handler.py b/src/wutta_corepos/handler.py index 6422f66..f52ef8e 100644 --- a/src/wutta_corepos/handler.py +++ b/src/wutta_corepos/handler.py @@ -180,6 +180,28 @@ class CoreposHandler(GenericHandler): if office_url: return f'{office_url}/item/departments/DepartmentEditor.php?did={dept_id}' + def get_office_employee_url( + self, + employee_id, + office_url=None, + require=False): + """ + Returns the CORE Office URL for an Employee. + + :param employee_id: Employee ID for the URL. + + :param office_url: Root URL from :meth:`get_office_url()`. + + :param require: If true, an error is raised when URL cannot be + determined. + + :returns: URL as string. + """ + if not office_url: + office_url = self.get_office_url(require=require) + if office_url: + return f'{office_url}/admin/Cashiers/CashierEditor.php?emp_no={employee_id}' + def get_office_likecode_url( self, likecode_id, diff --git a/tests/test_handler.py b/tests/test_handler.py index 74f6f7b..f751f22 100644 --- a/tests/test_handler.py +++ b/tests/test_handler.py @@ -115,6 +115,16 @@ class TestCoreposHandler(ConfigTestCase): self.config.setdefault('corepos.office.url', 'http://localhost/fannie/') self.assertEqual(handler.get_office_department_url(7), 'http://localhost/fannie/item/departments/DepartmentEditor.php?did=7') + def test_get_office_employee_url(self): + handler = self.make_handler() + + # null + self.assertIsNone(handler.get_office_employee_url(7)) + + # typical + self.config.setdefault('corepos.office.url', 'http://localhost/fannie/') + self.assertEqual(handler.get_office_employee_url(7), 'http://localhost/fannie/admin/Cashiers/CashierEditor.php?emp_no=7') + def test_get_office_likecode_url(self): handler = self.make_handler()