Changeset - 721dadc131a0
[Not reviewed]
0 2 0
Lance Edgar (lance) - 2 years ago 2022-08-03 11:12:44
lance@edbob.org
Add "touch" logic for employee handler
2 files changed with 35 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rattail/app.py
Show inline comments
 
@@ -241,12 +241,30 @@ class AppHandler(object):
 
    def delete_setting(self, session, name, **kwargs):
 
        model = self.model
 
        setting = session.query(model.Setting).get(name)
 
        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
 
        active if it is *not* marked as archived.
 

	
 
        :param session: Reference to current DB session.
rattail/employment.py
Show inline comments
 
# -*- coding: utf-8; -*-
 
################################################################################
 
#
 
#  Rattail -- Retail Software Framework
 
#  Copyright © 2010-2021 Lance Edgar
 
#  Copyright © 2010-2022 Lance Edgar
 
#
 
#  This file is part of Rattail.
 
#
 
#  Rattail is free software: you can redistribute it and/or modify it under the
 
#  terms of the GNU General Public License as published by the Free Software
 
#  Foundation, either version 3 of the License, or (at your option) any later
 
@@ -34,12 +34,28 @@ from rattail.app import GenericHandler
 

	
 
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.
 
        """
 
        session = self.get_session(person)
 

	
0 comments (0 inline, 0 general)