Пример #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
Пример #2
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
Пример #3
0
 def from_date(date):
     calendar = get_calendar()
     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 month < 4:
         year -= 1
     return FiscalYear.get(year)
Пример #4
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
Пример #5
0
 def post(self, request, *args, **kwargs):
     try:
         fiscal_year = int(request.POST.get('fiscal_year'))
         company = self.request.company
         str_fiscal_year = string_from_tuple(
             request.company.get_fy_end(
                 year=request.POST.get('fiscal_year')))
         closing_account = self.model(company=company, fy=fiscal_year)
         # queryset = InventoryTransaction.objects.filter(journal_entry__date__lte=request.company.get_fy_start(str_fiscal_year))
         queryset = InventoryTransaction.objects.filter(
             journal_entry__date__lte=str_fiscal_year)
         inventory_account = InventoryAccount.objects.filter(
             company=self.request.company).prefetch_related(
                 Prefetch('account_transaction',
                          queryset=queryset.order_by('-pk'),
                          to_attr='last_transaction'),
                 'item',
             )
         sum = 0
         total_cost = 0
         for inv in inventory_account:
             value = 0
             cost = 0
             if len(inv.last_transaction) > 0:
                 value = inv.last_transaction[0].current_balance
                 if hasattr(inv, 'item') and inv.item.cost_price > 0:
                     cost = value * inv.item.cost_price
             sum += value
             total_cost += cost
         # from django.db import connection
         # print len(connection.queries)
         closing_account.inventory_balance = sum
         closing_account.total_cost = total_cost
         closing_account.save()
     except IntegrityError:
         messages.error(
             request,
             _('%d fiscal year account have already been closed.' %
               int(request.POST.get('fiscal_year'))))
     except Exception as e:
         messages.error(request, _('Enter year correctly.'))
     return HttpResponseRedirect(reverse('report:closing_account'))
Пример #6
0
 def post(self, request, *args, **kwargs):
     try:
         fiscal_year = int(request.POST.get('fiscal_year'))
         company = self.request.company
         str_fiscal_year = string_from_tuple(request.company.get_fy_end(year=request.POST.get('fiscal_year')))
         closing_account = self.model(company=company, fy=fiscal_year)
         # queryset = InventoryTransaction.objects.filter(journal_entry__date__lte=request.company.get_fy_start(str_fiscal_year))
         queryset = InventoryTransaction.objects.filter(journal_entry__date__lte=str_fiscal_year)
         inventory_account = InventoryAccount.objects.filter(company=self.request.company).prefetch_related(
             Prefetch(
                 'account_transaction',
                 queryset=queryset.order_by('-pk'),
                 to_attr='last_transaction'),
             'item',
         )
         sum = 0
         total_cost = 0
         for inv in inventory_account:
             value = 0
             cost = 0
             if len(inv.last_transaction) > 0:
                 value = inv.last_transaction[0].current_balance
                 if hasattr(inv, 'item') and inv.item.cost_price > 0:
                     cost = value * inv.item.cost_price
             sum += value
             total_cost += cost
         # from django.db import connection
         # print len(connection.queries)
         closing_account.inventory_balance = sum
         closing_account.total_cost = total_cost
         closing_account.save()
     except IntegrityError:
         messages.error(request, _('%d fiscal year account have already been closed.' % int(request.POST.get('fiscal_year'))))
     except Exception as e:
         messages.error(request, _('Enter year correctly.'))
     return HttpResponseRedirect(reverse('report:closing_account'))