def check_for_retire_and_duration (db, cl, nodeid, old_values) :
    if cl.get (nodeid, 'duration') is None :
        cl.retire (nodeid)
    elif (common.changed_values (old_values, cl, nodeid)
         not in (['tr_duration'], [])
         ) :
        drid = cl.get (nodeid, 'daily_record')
        dr = db.daily_record.getnode (drid)
        user_dynamic.invalidate_tr_duration (db, dr.user, dr.date, dr.date)
def update_timerecs (db, time_record_id, set_it) :
    """ Update list of time_records with the given time_record_id
        if do_reset is specified, we *remove* the given id from the
        list, otherwise we *add* it.
    """
    id      = int (time_record_id)
    drec_id = db.time_record.get (time_record_id, 'daily_record')
    trecs_o = [int (i) for i in db.daily_record.get (drec_id, 'time_record')]
    trecs   = dict ([(i, 1) for i in trecs_o])
    if set_it :
        trecs [id] = 1
    elif id in trecs :
        del trecs [id]
    trecs   = trecs.keys ()
    trecs.sort ()
    if trecs != trecs_o :
        dr = db.daily_record.getnode (drec_id)
        db.daily_record.set \
            ( drec_id
            , time_record    = [str (i) for i in trecs]
            , tr_duration_ok = None
            )
        user_dynamic.invalidate_tr_duration (db, dr.user, dr.date, dr.date)
示例#3
0
def check_user_dynamic(db, cl, nodeid, new_values):
    old_ot = cl.get(nodeid, 'overtime_period')
    for i in 'user', :
        if i in new_values and cl.get(nodeid, i):
            raise Reject(_("%(attr)s may not be changed") % {'attr': _(i)})
    common.require_attributes \
        ( _, cl, nodeid, new_values
        , 'valid_from'
        , 'org_location'
        , 'department'
        )
    user = new_values.get('user', cl.get(nodeid, 'user'))
    old_from = cl.get(nodeid, 'valid_from')
    val_from = new_values.get('valid_from', old_from)
    val_to = new_values.get('valid_to', cl.get(nodeid, 'valid_to'))
    olo = new_values.get('org_location', cl.get(nodeid, 'org_location'))
    dept = new_values.get('department', cl.get(nodeid, 'department'))
    # Note: The valid_to date is *not* part of the validity interval of
    # the user_dynamic record. So when checking for frozen status we
    # can allow exactly the valid_to date.
    otw = common.overtime_period_week(db)
    nvk = list(sorted(new_values.keys()))
    old_flexmax = cl.get(nodeid, 'max_flexitime')
    vac_all = ('vacation_day', 'vacation_month', 'vacation_yearly', 'vac_aliq')
    vac_aliq = cl.get(nodeid, 'vac_aliq')
    vac_fix  = \
        (   set (nvk) <= set (vac_all)
        and 'vac_aliq' not in nvk or vac_aliq is None
        and db.getuid () == '1'
        )
    flexi_fix = \
        new_values.keys () == ['max_flexitime'] and old_flexmax is None
    if (freeze.frozen(db, user, old_from)
            and (new_values.keys() != ['valid_to'] or not val_to
                 or freeze.frozen(db, user, val_to))
            and (db.getuid() != '1' or old_ot or not otw
                 or new_values != dict(overtime_period=otw.id))
            and (db.getuid() != '1' or not flexi_fix) and not vac_fix):
        raise Reject(_("Frozen: %(old_from)s") % locals())
    last = user_dynamic.last_user_dynamic(db, user)
    if (('org_location' in new_values or 'department' in new_values) and
        (not val_to or last.id == nodeid or last.valid_from < val_from)):
        update_user_olo_dept(db, user, olo, dept)
    if 'valid_from' in new_values or 'valid_to' in new_values:
        new_values ['valid_from'], new_values ['valid_to'] = \
            check_ranges (cl, nodeid, user, val_from, val_to)
        val_from = new_values['valid_from']
        val_to = new_values['valid_to']
    if not vac_fix and not flexi_fix:
        check_overtime_parameters(db, cl, nodeid, new_values)
        check_vacation(db, cl, nodeid, 'vacation_yearly', new_values)
        if not freeze.frozen(db, user, old_from):
            user_dynamic.invalidate_tr_duration(db, user, val_from, val_to)
        else:
            old_to = cl.get(nodeid, 'valid_to')
            use_to = val_to
            if old_to:
                if val_to:
                    use_to = min(old_to, val_to)
                else:
                    use_to = old_to
            user_dynamic.invalidate_tr_duration(db, user, use_to, None)
    check_weekly_hours(db, cl, nodeid, new_values)