def get(self, request): company = get_company(request.user) invoices = PaymentService.objects.filter(company=company, payment_status='Pendiente') if len(invoices) == 0: return Response(False) else: return Response(True)
def get_context_data(self, *, object_list=None, **kwargs): context = super(Sales, self).get_context_data() company = get_company(self.request.user) payment_pending = PaymentService.objects.filter( company=company, payment_status='Pendiente').count() context['have_debt'] = False if payment_pending != 0: context['have_debt'] = True return context
def get(self, request): company = get_company(request.user) invoices = PaymentService.objects.filter(company=company) array_result = [] for invoice in invoices: response = { 'period': invoice.period, 'mount': invoice.mount, 'status': invoice.payment_status, 'dateCreated': invoice.payment_date, 'datePayed': invoice.transaction_date, } array_result.append(response) return Response(array_result)
def get_context_data(self, *, object_list=None, **kwargs): context = super(SalesInMonth, self).get_context_data() total = 0 usage = 0 for order in self.object_list: total += order.total # TODO: Separate the usage formula in a separate function order.usage = apply_usage(order.total) usage += order.usage context['total'] = total context['usage'] = usage # TODO: Check if this is not necessary in the future, this is only for security payment = PaymentService.objects.get(pk=self.kwargs['pk']) context['warning'] = False if payment.mount != context['usage']: context['warning'] = True mp = mercadopago.MP(settings.MELI_TOKEN) preference = { "items": [{ "title": "Servicio de Delivery Lavalle de {} por {}".format( get_company(self.request.user), usage), "quantity": 1, "unit_price": usage }], "payment_methods": { "excluded_payment_types": [{ "id": "ticket" }, { "id": "bank_transfer" }], }, "binary_mode": True, } context_preference = mp.create_preference(preference) context['preference'] = context_preference['response']['id'] context['payment'] = payment context['payment_id'] = payment.id return context
def get_queryset(self): return ProductCategories.objects.filter( company=get_company(self.request.user))
def form_valid(self, form): self.object = form.save(commit=False) self.object.company = get_company(self.request.user) return super().form_valid(form)
def get_form(self, *args, **kwargs): form = super(CreateProducts, self).get_form(*args, **kwargs) form.fields['category'].queryset = ProductCategories.objects.filter( company=get_company(self.request.user)) return form
def get_queryset(self): return PaymentService.objects.filter( company=get_company(self.request.user)).order_by('-payment_date')
def get_queryset(self): company_id = get_company(self.request.user) query_set = Order.objects.filter(id_company=company_id, state__in=[4, 5]).order_by('-date') return query_set
def add_debit(user, order): company = get_company(user) debit = apply_usage(order.total) company.account_debit += debit company.save()
def post(self, request): availability = request.data company = get_company(request.user) company.available_now = availability company.save() return Response(company.available_now)
def get(self, request): company = get_company(request.user) return Response(company.available_now)