예제 #1
0
def pay_back_generator(value):
    today = jdatetime.datetime.now().date()
    now_time = datetime.datetime.now().time()

    booking_object = get_object_or_404(BookingModel, pk=value)
    session = booking_object.session
    ceil_date = jdate(today.year, today.month, today.day) + jtimedelta(days=2)
    ceil_time = (datetime.datetime.combine(datetime.date(1, 1, 1), now_time) +
                 timedelta(hours=5)).time()
    if booking_object.session.day >= ceil_date:  # percent harm 3 for sportclub 2 for company
        if booking_object.is_contract:
            contract_discount = booking_object.contract_discount
            pay_back = (booking_object.final_price *
                        (100 - contract_discount - 5)) / 100
        else:
            pay_back = booking_object.final_price * (95 / 100)

    elif booking_object.session.day == today and booking_object.session.time < ceil_time:
        payback = False
    elif booking_object.session.day < today:
        payback = False
    else:
        if not booking_object.is_contract:
            pay_back = (booking_object.final_price * 85) / 100
        else:
            contract_discount = booking_object.contract_discount
            pay_back = (booking_object.final_price *
                        (85 - contract_discount)) / 100
    return pay_back
예제 #2
0
파일: forms.py 프로젝트: ijami/sepas_iran
    def to_python(self, value):
        date_regex = re.compile('^(?P<year>\d+)/(?P<month>\d+)/(?P<day>\d+)$')
        test = date_regex.match(value)
        if test:
            jyear = int(test.group('year'))
            jmonth = int(test.group('month'))
            jday = int(test.group('day'))

            try:
                python_date = jdate(jyear, jmonth, jday).togregorian()
                return python_date
            except Exception:
                raise forms.ValidationError(self.default_error_messages['invalid'], code='invalid')
        else:
            raise forms.ValidationError(self.default_error_messages['invalid'], code='invalid')
예제 #3
0
def find_any_date(str_or_match) -> datetime.date or None:
    """Try to find a date in input string and return it as a date object.

    If there is no matching date, return None.
    The returned date can't be from the future.

    """
    if isinstance(str_or_match, str):
        match = ANYDATE_SEARCH(str_or_match)
    else:
        match = str_or_match
    if not match:
        return None
    groupdict = match.groupdict()
    day = int(groupdict['d'])
    year = int(groupdict['Y'])
    month = groupdict.get('jB')
    today = datetime.today().date()
    if month:
        date = jdate(year, jB_TO_NUM[month], day).togregorian()
        if date <= today:
            return date
        return
    month = groupdict.get('B')
    if month:
        date = datetime_date(year, B_TO_NUM[month.lower()], day)
        if date <= today:
            return date
        return
    month = groupdict.get('b')
    if month:
        date = datetime_date(year, b_TO_NUM[month.lower()], day)
        if date <= today:
            return date
        return
    month = groupdict.get('m')
    if month:
        date = datetime_date(year, int(month), day)
        if date <= today:
            return date
        return
예제 #4
0
파일: commons.py 프로젝트: 5j9/yadkard
def find_any_date(str_or_match) -> datetime.date or None:
    """Try to find a date in input string and return it as a date object.

    If there is no matching date, return None.
    The returned date can't be from the future.
    """
    if isinstance(str_or_match, str):
        match = ANYDATE_SEARCH(str_or_match)
    else:
        match = str_or_match
    if not match:
        return None
    groupdict = match.groupdict()
    day = int(groupdict['d'])
    year = int(groupdict['Y'])
    month = groupdict.get('jB')
    today = datetime.today().date()
    if month:
        date = jdate(year, jB_TO_NUM[month], day).togregorian()
        if date <= today:
            return date
        return
    month = groupdict.get('B')
    if month:
        date = datetime_date(year, B_TO_NUM[month.lower()], day)
        if date <= today:
            return date
        return
    month = groupdict.get('b')
    if month:
        date = datetime_date(year, b_TO_NUM[month.lower()], day)
        if date <= today:
            return date
        return
    month = groupdict.get('m')
    if month:
        date = datetime_date(year, int(month), day)
        if date <= today:
            return date
        return
예제 #5
0
def CancellingView(request, pk):
    try:
        today = jdatetime.datetime.now().date()
        now_time = datetime.datetime.now().time()

        booking_object = get_object_or_404(BookingModel, pk=pk)
        session = booking_object.session
        ceil_date = jdate(today.year, today.month,
                          today.day) + jtimedelta(days=2)
        ceil_time = (
            datetime.datetime.combine(datetime.date(1, 1, 1), now_time) +
            timedelta(hours=5)).time()
        final_price = booking_object.final_price
        if booking_object.session.day >= ceil_date:
            if booking_object.is_contract:
                session.is_booked = False
                session.booker = None
                contract_discount = booking_object.contract_discount
                booking_object.pay_back = (booking_object.final_price *
                                           (92 - contract_discount)) / 100
                booking_object.company_portion = final_price * (3 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    5 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.cancelled_at_time = now_time
                booking_object.save()
            else:
                session.is_booked = False
                session.booker = None
                booking_object.pay_back = booking_object.final_price * (95 /
                                                                        100)
                booking_object.company_portion = final_price * (2 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    3 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.cancelled_at_time = now_time
                booking_object.save()
        elif booking_object.session.day == today and booking_object.session.time < ceil_time:
            return HttpResponseRedirect(reverse('booking:cantcancell'))
        elif booking_object.session.day < today:
            return HttpResponseRedirect(reverse('booking:cancellingerror'))
        else:
            if not booking_object.is_contract:
                session.is_booked = False
                session.booker = None
                booking_object.pay_back = (booking_object.final_price *
                                           85) / 100
                booking_object.company_portion = final_price * (3 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    12 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.save()
            else:
                session.is_booked = False
                session.booker = None
                contract_discount = booking_object.contract_discount
                booking_object.pay_back = (booking_object.final_price *
                                           (80 - contract_discount)) / 100
                booking_object.company_portion = final_price * (5 / 100)
                booking_object.sportclub_portion = booking_object.pay_back + final_price * (
                    15 / 100)
                booking_object.cancelled = True
                booking_object.cancelled_at_date = today
                booking_object.save()
        booking_object.cancelled_at_time = now_time
        booking_object.save()
        session.save()
        return HttpResponseRedirect(reverse('booking:cancelsuccess'))
    except:
        return HttpResponseRedirect(reverse('booking:cancellingerror'))