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
 
@@ -223,48 +223,66 @@ class AppHandler(object):
 

	
 
        return value
 

	
 
    def save_setting(self, session, name, value, typ=None, **kwargs):
 
        model = self.model
 

	
 
        if typ == 'utctime':
 
            if value:
 
                value = value.strftime(self.setting_utctime_format)
 
            else:
 
                value = None
 

	
 
        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
 

	
 
        model = self.model
 
        return session.query(model.Store)\
 
                      .filter(sa.or_(
 
                          model.Store.archived == False,
 
                          model.Store.archived == None))\
 
                      .order_by(model.Store.id)\
 
                      .all()
 

	
 
    def get_autocompleter(self, key, **kwargs):
 
        """
 
        Returns a new :class:`~rattail.autocomplete.base.Autocompleter`
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.
 
#
 
#  You should have received a copy of the GNU General Public License along with
 
#  Rattail.  If not, see <http://www.gnu.org/licenses/>.
 
#
 
################################################################################
 
"""
 
Employment Handler
 
"""
 

	
 
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
 

	
 
        # maybe assign/update ID
 
        employee_id = kwargs.get('employee_id')
 
        if employee_id and employee.id != employee_id:
 
            employee.id = employee_id
 

	
 
        # create new history record, with start date
 
        history = self.make_employee_history(employee, start_date)
 
        session.flush()
 

	
 
        return employee
 

	
0 comments (0 inline, 0 general)