60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
import requests
|
|
from inventory import models
|
|
from django.conf import settings
|
|
from django.core.mail import send_mail
|
|
from django.utils.translation import gettext_lazy as _
|
|
from inventory.utilities.financials import get_financial_value
|
|
|
|
|
|
def get_jwt_token():
|
|
url = 'https://carapi.app/api/auth/login'
|
|
headers = {
|
|
'accept': 'text/plain',
|
|
'Content-Type': 'application/json',
|
|
}
|
|
data = {
|
|
"api_token": "f5204a00-6f31-4de2-96d8-ed998e0d230c",
|
|
"api_secret": "8c11320781a5b8f4f327b6937e6f8241"
|
|
}
|
|
try:
|
|
response = requests.post(url, headers=headers, json=data)
|
|
response.raise_for_status()
|
|
return response.text
|
|
except requests.exceptions.RequestException as e:
|
|
print(f"Error obtaining JWT token: {e}")
|
|
return None
|
|
|
|
|
|
def localize_some_words():
|
|
success = _('success')
|
|
error = _('error')
|
|
forget = _('Forgot Password?')
|
|
|
|
return None
|
|
|
|
|
|
def get_calculations(quotation):
|
|
context = {}
|
|
qc_len = quotation.quotation_cars.count()
|
|
cars = [x.car for x in quotation.quotation_cars.all()]
|
|
finances = models.CarFinance.objects.filter(car__in=cars)
|
|
|
|
services = models.AdditionalServices.objects.filter(additional_finances__in=finances).all()
|
|
data = [{"name":x.name,"price":x.price,"total_price":x.price * qc_len,"vated":float(x.price) * 0.15 * float(qc_len),"total_price_vat":float(x.price) + (float(x.price) * 0.15 * float(qc_len))} for x in services]
|
|
context["services"] = data
|
|
context["total_cost"] = 0
|
|
context["total_vat"] = 0
|
|
context["total_cost_vat"] = 0
|
|
for k in context["services"]:
|
|
context["total_cost"] += k["total_price"]
|
|
context["total_vat"] += k["vated"]
|
|
context["total_cost_vat"] = float(context["total_cost"])+float(context["total_vat"])
|
|
return context
|
|
|
|
|
|
def send_email(from_, to_, subject, message):
|
|
subject = subject
|
|
message = message
|
|
from_email = from_
|
|
recipient_list = [to_]
|
|
send_mail(subject, message, from_email, recipient_list) |