Exemple #1
0
def update(pricing_id, **mod_data):
    pricing = pricing_store.get(pricing_id)
    new_starts = commonlib.helpers.iso2date(mod_data['starts']) if 'starts' in mod_data else pricing.starts

    #Checking time interval for which pricing will change
    if pricing.starts == new_starts:
        changed_intervals_starts = pricing.starts
        changed_intervals_ends = pricing.ends
    elif pricing.starts < new_starts:
        changed_intervals_starts = pricing.starts
        changed_intervals_ends = new_starts
    elif pricing.starts > new_starts:
        changed_intervals_starts = new_starts
        changed_intervals_ends = pricing.starts

    #Checking usages for pricing changed time interval
    if dbaccess.find_usage(start=changed_intervals_starts, end=changed_intervals_ends, resource_ids=[pricing.resource]):
        msg = "Usages are associated with this pricing, you can't delete pricing."
        raise Exception(msg)#be.errors.ErrorWithHint(msg)

    if new_starts != pricing.starts:
        mod_data['starts'] = new_starts
        crit = dict(plan=pricing.plan, resource=pricing.resource, ends=pricing.starts-datetime.timedelta(1))
        prev_pricing = pricing_store.get_by(crit)
        if prev_pricing: set(prev_pricing[0].id, 'ends', pricing.ends)
        old_pricing = dbaccess.get_resource_pricing(pricing.plan, pricing.resource, new_starts, [pricing_id])
        if old_pricing:#old_pricing contains pricing at new_starts
            if old_pricing.starts and old_pricing.starts >= new_starts:
                msg = "Pricing start date should be greater than %s" % old_pricing.starts
                raise Exception(msg)#be.errors.ErrorWithHint(msg)
            mod_data['ends'] = old_pricing.ends
            set(old_pricing.id, 'ends', mod_data['starts']-datetime.timedelta(1))
    pricing_store.update(pricing_id, **mod_data)
Exemple #2
0
 def find(self, start=None, end=None, starts_on_or_before=None, invoice_id=None, res_owner_ids=[], resource_ids=[], member_ids=[], resource_types=[], uninvoiced=False, exclude_credit_usages=False, calc_mode=[], exclude_cancelled_usages=False):
     """
     returns list of usage dicts which are filtered on the basis of specified criteria
     start end: if specified, usages with start time falling in start-end range would be searched
     """
     assert (start or end or invoice_id or res_owner_ids or resource_ids or member_ids or resource_types), 'atleast one criteria'
     return dbaccess.find_usage(start, end, starts_on_or_before, invoice_id, res_owner_ids, resource_ids, member_ids, resource_types, uninvoiced, exclude_credit_usages, calc_mode, exclude_cancelled_usages)
Exemple #3
0
def delete(pricing_id):
    pricing = pricing_store.get(pricing_id)
    if dbaccess.find_usage(start=pricing.starts, end=pricing.ends, resource_ids=[pricing.resource]):
        msg = "Usages are associated with this pricing, you can't delete pricing."
        raise Exception(msg)#be.errors.ErrorWithHint(msg)
    if not pricing.starts:
        msg = "You can't delete first pricing for Guest tariff."
        raise Exception(msg)#be.errors.ErrorWithHint(msg)
    crit = dict(plan=pricing.plan, resource=pricing.resource, ends=pricing.starts-datetime.timedelta(1))
    prev_pricing = pricing_store.get_by(crit)
    if prev_pricing: set(prev_pricing[0].id, 'ends', pricing.ends)
    return pricing_store.remove(pricing_id)