Beispiel #1
0
 def get_fy(self, dt=None):
     # returns bs year for nepali fy system, ad for another
     dt = dt or today()
     calendar = get_calendar()
     if type(dt) == str or type(dt) == unicode:
         dt = tuple_from_string(dt)
     if self.use_nepali_fy_system:
         if calendar == 'ad':
             dt = ad2bs(dt)
         if type(dt) == tuple:
             dt = string_from_tuple(dt)
         month = int(dt.split('-')[1])
         year = int(dt.split('-')[0])
         if month < 4:
             year -= 1
     else:
         if type(dt) == tuple:
             dt = date_from_tuple(dt)
         if calendar == 'bs':
             dt = date_from_tuple(bs2ad(dt))
         if dt.month < self.fy_start_month:
             return dt.year - 1
         if dt.month > self.fy_start_month:
             return dt.year
         if dt.month == self.fy_start_month:
             if dt.day < self.fy_start_day:
                 return dt.year - 1
             return dt.year
     return year
Beispiel #2
0
 def get_fy_start(self, dt=None, year=None):
     calendar = get_calendar()
     year = year or self.get_fy(dt)
     if self.use_nepali_fy_system:
         # get fy start in bs
         fiscal_year_start = str(year) + '-04-01'
         tuple_value = tuple_from_string(fiscal_year_start)
         if calendar == 'ad':
             tuple_value = bs2ad(tuple_value)
     else:
         # get fy start in ad
         fiscal_year_start = str(year) + '-' + str(self.fy_start_month) + '-' + str(self.fy_start_day)
         tuple_value = tuple_from_string(fiscal_year_start)
         if calendar == 'bs':
             tuple_value = ad2bs(tuple_value)
     return tuple_value
Beispiel #3
0
 def get_fy(self, dt=None):
     # returns bs year for nepali fy system, ad for another
     dt = dt or today()
     calendar = get_calendar()
     if type(dt) == str or type(dt) == unicode:
         dt = tuple_from_string(dt)
     if self.use_nepali_fy_system:
         if calendar == 'ad':
             dt = ad2bs(dt)
         if type(dt) == tuple:
             dt = string_from_tuple(dt)
         month = int(dt.split('-')[1])
         year = int(dt.split('-')[0])
         if month < 4:
             year -= 1
     else:
         if type(dt) == tuple:
             dt = date_from_tuple(dt)
         if calendar == 'bs':
             dt = date_from_tuple(bs2ad(dt))
         if dt.month < self.fy_start_month:
             return dt.year - 1
         if dt.month > self.fy_start_month:
             return dt.year
         if dt.month == self.fy_start_month:
             if dt.day < self.fy_start_day:
                 return dt.year - 1
             return dt.year
     return year
Beispiel #4
0
 def get_fy_start(self, dt=None, year=None):
     calendar = get_calendar()
     year = year or self.get_fy(dt)
     if self.use_nepali_fy_system:
         # get fy start in bs
         fiscal_year_start = str(year) + '-04-01'
         tuple_value = tuple_from_string(fiscal_year_start)
         if calendar == 'ad':
             tuple_value = bs2ad(tuple_value)
     else:
         # get fy start in ad
         fiscal_year_start = str(year) + '-' + str(
             self.fy_start_month) + '-' + str(self.fy_start_day)
         tuple_value = tuple_from_string(fiscal_year_start)
         if calendar == 'bs':
             tuple_value = ad2bs(tuple_value)
     return tuple_value
Beispiel #5
0
 def start(year=None):
     if not year:
         year = AppSetting.get_solo().fiscal_year
     fiscal_year_start = str(year) + '-04-01'
     tuple_value = tuple_from_string(fiscal_year_start)
     calendar = get_calendar()
     if calendar == 'ad':
         tuple_value = bs2ad(tuple_value)
     return tuple_value
Beispiel #6
0
 def end(year=None):
     if not year:
         year = AppSetting.get_solo().fiscal_year
     fiscal_year_end = str(int(year) + 1) + '-03-' + str(
         bs[int(year) + 1][2])
     tuple_value = tuple_from_string(fiscal_year_end)
     calendar = get_calendar()
     if calendar == 'ad':
         tuple_value = bs2ad(tuple_value)
     return tuple_value
Beispiel #7
0
 def get_fy_start(self, date=None):
     year = self.get_fy_from_date(date)
     if self.use_nepali_fy_system:
         fiscal_year_start = str(year) + '-04-01'
     else:
         fiscal_year_start = str(year) + '-' + str(self.voucher_number_start_date.month) + '-' + str(
             self.voucher_number_start_date.day)
     tuple_value = tuple_from_string(fiscal_year_start)
     calendar = get_calendar()
     if calendar == 'ad':
         tuple_value = bs2ad(tuple_value)
     return tuple_value
Beispiel #8
0
    def get_fy_end(self, date=None):

        year = self.get_fy_from_date(date)
        if self.use_nepali_fy_system:
            fiscal_year_end = str(int(year) + 1) + '-03-' + str(bs[int(year) + 1][2])
        else:
            # import ipdb
            # ipdb.set_trace()
            fiscal_year_end = str(int(year) + 1) + '-' + str(self.voucher_number_start_date.month) + '-' + str(12)
        tuple_value = tuple_from_string(fiscal_year_end)
        calendar = get_calendar()
        if calendar == 'ad':
            tuple_value = bs2ad(tuple_value)
        return tuple_value
Beispiel #9
0
 def get_fy_end(self, dt=None, year=None):
     calendar = get_calendar()
     year = year or self.get_fy(dt)
     if self.use_nepali_fy_system:
         # get fy end in bs
         fiscal_year_end = str(int(year) + 1) + '-03-' + str(bs[int(year) + 1][2])
         tuple_value = tuple_from_string(fiscal_year_end)
         if calendar == 'ad':
             tuple_value = bs2ad(tuple_value)
     else:
         # get fy end in ad
         fiscal_year_end = date(int(year) + 1, self.fy_start_month, self.fy_start_day) - timedelta(days=1)
         tuple_value = tuple_from_date(fiscal_year_end)
         if calendar == 'bs':
             tuple_value = ad2bs(tuple_value)
     return tuple_value
Beispiel #10
0
def validate_in_fy(value):
    fiscal_year = AppSetting.get_solo().fiscal_year
    if fiscal_year is None:
        return True
    fiscal_year_start = str(fiscal_year) + '-04-01'
    fiscal_year_end = str(int(fiscal_year) + 1) + '-03-' + str(
        bs[int(fiscal_year) + 1][2])
    calendar = get_calendar()
    if calendar == 'ad':
        if type(value) == tuple:
            value_tuple = value
        else:
            value_tuple = tuple_from_string(value)
    else:
        value_tuple = bs2ad(value)
    if not bs2ad(fiscal_year_start) <= value_tuple <= bs2ad(fiscal_year_end):
        raise ValidationError(
            '%s %s' % (localize(value), _('is not in current fiscal year.')))
Beispiel #11
0
 def get_fy_from_date(self, date):
     calendar = get_calendar()
     if type(date) == str or type(date) == unicode:
         date = tuple_from_string(date)
     if calendar == 'ad':
         date = ad2bs(date)
     if type(date) == tuple:
         date = string_from_tuple(date)
     month = int(date.split('-')[1])
     year = int(date.split('-')[0])
     if self.use_nepali_fy_system:
         if month < 4:
             year -= 1
     else:
         day = int(date.split('-')[2])
         if month <= self.voucher_number_start_date.month and day < self.voucher_number_start_date.day:
             year -= 1
     return year
Beispiel #12
0
 def get_fy_end(self, dt=None, year=None):
     calendar = get_calendar()
     year = year or self.get_fy(dt)
     if self.use_nepali_fy_system:
         # get fy end in bs
         fiscal_year_end = str(int(year) + 1) + '-03-' + str(
             bs[int(year) + 1][2])
         tuple_value = tuple_from_string(fiscal_year_end)
         if calendar == 'ad':
             tuple_value = bs2ad(tuple_value)
     else:
         # get fy end in ad
         fiscal_year_end = date(
             int(year) + 1, self.fy_start_month,
             self.fy_start_day) - timedelta(days=1)
         tuple_value = tuple_from_date(fiscal_year_end)
         if calendar == 'bs':
             tuple_value = ad2bs(tuple_value)
     return tuple_value