From 721dadc131a0f46d79b099828df186dea50a2c1b 2022-08-03 11:12:44 From: Lance Edgar Date: 2022-08-03 11:12:44 Subject: [PATCH] Add "touch" logic for employee handler --- diff --git a/rattail/app.py b/rattail/app.py index 91cd863a190ea58d253ae28bdbdc6d44eddbccb8..ce4c42699ed41d69f529e8ecda39b3ef0b3ac05a 100644 --- a/rattail/app.py +++ b/rattail/app.py @@ -244,6 +244,24 @@ class AppHandler(object): if setting: session.delete(setting) + def touch_object(self, session, obj): + """ + Mark the given object as having been changed, such that the + datasync will pick it up and propagate the object to other + nodes. + + Note that this is *minimal* logic; only the given object will + be "touched" in this way, i.e. no related records will be + touched. So if those also need it, you must call this method + for each related object separately. + """ + model = self.model + change = model.Change() + change.class_name = obj.__class__.__name__ + change.instance_uuid = obj.uuid + change = session.merge(change) + change.deleted = False + def get_active_stores(self, session, **kwargs): """ Returns the list of "active" stores. A store is considered diff --git a/rattail/employment.py b/rattail/employment.py index d52b618bddcc38168ab7bb9eb022186aa3ffa91f..11381cbc16b880182430cded8e5911cad7c907a5 100644 --- a/rattail/employment.py +++ b/rattail/employment.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2022 Lance Edgar # # This file is part of Rattail. # @@ -37,6 +37,22 @@ class EmploymentHandler(GenericHandler): Base class and default implementation for employment handlers. """ + def touch_employee(self, session, employee): + self.app.touch_object(session, employee) + self.app.touch_object(session, employee.person) + + for email in employee.emails: + self.app.touch_object(session, email) + + for phone in employee.phones: + self.app.touch_object(session, phone) + + for store in employee._stores: + self.app.touch_object(session, store) + + for department in employee._departments: + self.app.touch_object(session, department) + def begin_employment(self, person, start_date, **kwargs): """ Begin employment for the given person.