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
 
@@ -235,24 +235,42 @@ class AppHandler(object):
 
        setting = session.query(model.Setting).get(name)
 
        if not setting:
 
            setting = model.Setting(name=name)
 
            session.add(setting)
 
        setting.value = value
 

	
 
    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.
 

	
 
        :returns: Possibly-empty list of
 
           :class:`~rattail.db.model.stores.Store` records which are
 
           deemed active.
 
        """
 
        import sqlalchemy as sa
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
 
#  version.
 
#
 
#  Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
 
#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 
#  FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 
#  details.
 
@@ -28,24 +28,40 @@ from __future__ import unicode_literals, absolute_import
 

	
 
import six
 

	
 
from rattail.util import load_object
 
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)
 

	
 
        # make sure we have an employee record
 
        employee = self.ensure_employee(person)
 
        session.flush()
 

	
 
        # employee status is now *current*
 
        employee.status = self.enum.EMPLOYEE_STATUS_CURRENT
0 comments (0 inline, 0 general)