Exemplo n.º 1
0
def terminal_from_spending(request, pk):
    spending = Spending.objects.get(id=pk)
    transfer_name = 'terminal {}'.format(spending.asset.name)
    terminal_asset_to = Asset.objects.get(name='Терминал')
    transfer = Transfer(
        name=transfer_name,
        asset_from=spending.asset,
        asset_to=terminal_asset_to,
        period=spending.period,
        amount=spending.amount,
    )
    transfer.save()
    commission_spending_name = "Коммисия банка {}".format(datetime.date.today().strftime('%B'))
    try:
        commission_spending = Spending.objects.get(
            name=commission_spending_name)
    except ObjectDoesNotExist:
        asset = Asset.objects.get(name='Терминал')
        category = SpendingCategory.objects.get(name='Затраты')
        department = Department.objects.get(name='Магазин')
        period = get_period()
        commission_spending = Spending(
            name=commission_spending_name,
            amount=0,
            asset=asset,
            department=department,
            category=category,
            period=period
        )
    commission_spending.amount += round((spending.amount * 0.02), 2)
    commission_spending.save()
    spending.delete()
    return HttpResponseRedirect('/money/?period={}'.format(get_period().id))
Exemplo n.º 2
0
class TerminalCreate(LoginRequiredMixin, CreateView):
    model = Transfer
    form_class = TerminalForm
    success_url = '/money/transfers/?period={}'.format(get_period().id)

    def form_valid(self, form):
        parameters = self.request.POST
        amount = float(parameters['amount'])
        spending_name = "Коммисия банка {}".format(
            datetime.date.today().strftime('%B'))
        try:
            spending = Spending.objects.get(name=spending_name)
        except ObjectDoesNotExist:
            asset = Asset.objects.get(name='Терминал')
            category = SpendingCategory.objects.get(name='Затраты')
            department = Department.objects.get(name='Магазин')
            period = get_period()
            spending = Spending(
                name=spending_name,
                amount=0,
                asset=asset,
                department=department,
                category=category,
                period=period
            )
        spending.amount += round((amount * 0.02), 2)
        spending.save()
        return super().form_valid(form)
Exemplo n.º 3
0
class SpendingUpdate(LoginRequiredMixin, UpdateView):
    model = Spending
    fields = '__all__'
    #success_url = reverse_lazy('spendings')
    success_url = '/money/?period={}'.format(get_period().id)
    template_name = 'spending_update.html'

    def get_context_data(self, **kwargs):
        context = super(SpendingUpdate, self).get_context_data(**kwargs)
        context['spendings'] = Spending.objects.all()
        return context
Exemplo n.º 4
0
 def form_valid(self, form):
     parameters = self.request.POST
     amount = float(parameters['amount'])
     spending_name = "Коммисия банка {}".format(
         datetime.date.today().strftime('%B'))
     try:
         spending = Spending.objects.get(name=spending_name)
     except ObjectDoesNotExist:
         asset = Asset.objects.get(name='Терминал')
         category = SpendingCategory.objects.get(name='Затраты')
         department = Department.objects.get(name='Магазин')
         period = get_period()
         spending = Spending(
             name=spending_name,
             amount=0,
             asset=asset,
             department=department,
             category=category,
             period=period
         )
     spending.amount += round((amount * 0.02), 2)
     spending.save()
     return super().form_valid(form)
Exemplo n.º 5
0
def approve_spending(request, pk):
    spending = Spending.objects.get(id=pk)
    spending.category = SpendingCategory.objects.get(name='Затраты')
    spending.department = Department.objects.get(name='Офис')
    spending.save()
    return HttpResponseRedirect('/money/?period={}'.format(get_period().id))
Exemplo n.º 6
0
 def get_success_url(self):
     user = self.request.user
     if user.is_staff:
         return '/money/?period={}'.format(get_period().id)
     return reverse_lazy('today_sales_shop')
Exemplo n.º 7
0
class SpendingCreate(LoginRequiredMixin, CreateView):
    model = Spending
    form_class = SpendingsForm
    #success_url = reverse_lazy('spendings')
    success_url = '/money/?period={}'.format(get_period().id)
Exemplo n.º 8
0
class TransferUpdate(LoginRequiredMixin, UpdateView):
    model = Transfer
    fields = '__all__'
    success_url = '/money/transfers/?period={}'.format(get_period().id)
    template_name = 'transfer_update.html'
Exemplo n.º 9
0
class TransferCreate(LoginRequiredMixin, CreateView):
    model = Transfer
    form_class = TransferForm
    success_url = '/money/transfers/?period={}'.format(get_period().id)
    template_name = 'transfer_create.html'