def check_correction(db, cl, nodeid, new_values): common.require_attributes \ (_, cl, nodeid, new_values, 'user', 'date', 'day') if nodeid: common.require_attributes \ (_, cl, nodeid, new_values, 'absolute') else: if 'absolute' not in new_values: new_values['absolute'] = False user = new_values.get('user') if user is None: user = cl.get(nodeid, 'user') if 'date' in new_values: new_values['date'] = common.fix_date(new_values['date']) date = new_values.get('date') if date is None: date = cl.get(nodeid, 'date') if freeze.frozen(db, user, date): # Allow admin to add (initial) absolute correction if (nodeid is not None or db.getuid() != '1' or not new_values.get('absolute')): raise Reject(_("Frozen")) # Check that vacation parameters exist in dyn. user records dyn = user_dynamic.act_or_latest_user_dynamic(db, user) if not dyn or dyn.valid_to and dyn.valid_to < date: username = db.user.get(user, 'username') raise Reject \ (_ ('No current dyn. user record for "%(username)s"') % locals ()) while dyn and (not dyn.valid_to or dyn.valid_to > date): if (dyn.vacation_yearly is None or not dyn.vacation_month or not dyn.vacation_day): raise Reject \ (_ ('Missing vacation parameters in dyn. user record(s)')) dyn = user_dynamic.prev_user_dynamic(db, dyn)
def set_defaults (db, cl, nodeid, new_values) : for i in ('aboprice', 'subscriber') : if not new_values.has_key (i) : raise Reject, err ('mandatory', attr = i) for i in ('invoices', 'end') : if new_values.has_key (i) : raise Reject, err ('forbidden', attr = i) if not new_values.has_key ('amount') : new_values ['amount'] = \ db.abo_price.get (new_values ['aboprice'], 'amount') # if no begin-date is specified, use start of next month # or today if the start of month is today. if not new_values.has_key ('begin') : year, month, day = localtime ()[:3] if day != 1 : day = 1 month += 1 if month > 12 : month = 1 year += 1 new_values ['begin'] = Date ('%d-%d-%d' % (year, month, day)) else : new_values ['begin'] = fix_date (new_values ['begin']) if not new_values.has_key ('payer') : new_values ['payer'] = new_values ['subscriber']
def fix_dates(new_values): for d in ('first_day', 'last_day'): if d in new_values: new_values[d] = common.fix_date(new_values[d])
def check_change (db, cl, nodeid, new_values) : """ We allow closing of an abo with the end date == begin date if there is at most one un-payed invoice. In this case we remove this abo from the address and remove the corresponding invoice from the address, too. Re-opening (deletion of "end") is only possible if the last invoice for this abo is withing the current period, i.e., if the period_end of the last invoice is > now. Otherwise a new abo has to be created by hand. """ abo = cl.getnode (nodeid) for i in ('aboprice', 'begin') : if i in new_values : raise Reject, err ('nochange', attr = i) if 'amount' in new_values : if new_values ['amount'] == 0 and abo ['amount'] > 0 : raise Reject, err ('nonzero', attr = 'amount') if new_values ['amount'] > 0 and abo ['amount'] == 0 : raise Reject, err ('nochange', attr = 'amount') # Changing 'end': if 'end' in new_values : new_values ['end'] = fix_date (new_values ['end']) o_end = abo ['end'] n_end = new_values ['end'] now = Date ('.') invoice = abo_max_invoice (db, abo) # Attempt to change error-closed abo (unlinked from address) if o_end == abo ['begin'] : raise Reject, err ('openfail') # Attempt to resurrect a closed abo: if (not n_end and o_end) : if invoice : if o_end < now - month2 : raise Reject, err ('closefree') # Attempt to close (or modify close date), check end-date: if (n_end) : if n_end < abo ['begin'] : raise Reject, err ('endtime') if not invoice and (n_end < now - month or n_end > now + month) : raise Reject, err ('month') if (invoice) : if ( n_end < invoice ['period_start'] or n_end > invoice ['period_end'] ) : raise Reject, err \ ( 'period' , ** dict ([(x, invoice [x].pretty ('%Y-%m-%d')) for x in ('period_start', 'period_end') ]) ) if (invoice.get ('invoice_group')) : raise Reject, err ('marked') if n_end == abo ['begin'] : if ( len (abo ['invoices']) > 1 or (invoice and not invoice ['open']) ) : raise Reject, err ('delete') # unlink abo from payer/subscriber addresses for lattr, rattr in \ (('payer', 'payed_abos'), ('subscriber', 'abos')) : id = abo [lattr] abos = db.address.get (id, rattr) l = [a for a in abos if a != nodeid] db.address.set (id, ** {rattr : l}) # unlink invoice from payer address if invoice : id = invoice ['payer'] inv = db.address.get (id, 'invoices') l = [i for i in inv if i != invoice ['id']] db.address.set (id, invoices = l) db.invoice.retire (invoice.id)