diff --git a/inventory/management/commands/tenhal_plan.py b/inventory/management/commands/tenhal_plan.py index baa95ab7..e91d0b95 100644 --- a/inventory/management/commands/tenhal_plan.py +++ b/inventory/management/commands/tenhal_plan.py @@ -43,14 +43,14 @@ class Command(BaseCommand): ) # Assign quotas to plans - PlanQuota.objects.create(plan=basic_plan, quota=users_quota, value=99999) - PlanQuota.objects.create(plan=basic_plan, quota=cars_quota, value=99999) + PlanQuota.objects.create(plan=basic_plan, quota=users_quota, value=10000000) + PlanQuota.objects.create(plan=basic_plan, quota=cars_quota, value=10000000) - PlanQuota.objects.create(plan=pro_plan, quota=users_quota, value=99999) - PlanQuota.objects.create(plan=pro_plan, quota=cars_quota, value=99999) + PlanQuota.objects.create(plan=pro_plan, quota=users_quota, value=10000000) + PlanQuota.objects.create(plan=pro_plan, quota=cars_quota, value=10000000) - PlanQuota.objects.create(plan=enterprise_plan, quota=users_quota, value=99999) - PlanQuota.objects.create(plan=enterprise_plan, quota=cars_quota, value=99999) + PlanQuota.objects.create(plan=enterprise_plan, quota=users_quota, value=10000000) + PlanQuota.objects.create(plan=enterprise_plan, quota=cars_quota, value=10000000) # PlanQuota.objects.create(plan=pro_plan, quota=project_quota, value=50) # PlanQuota.objects.create(plan=pro_plan, quota=storage_quota, value=100) @@ -61,13 +61,13 @@ class Command(BaseCommand): enterprise_pricing = Pricing.objects.create(name="1 Year", period=365) PlanPricing.objects.create( - plan=basic_plan, pricing=basic_pricing, price=Decimal("2500.00") + plan=basic_plan, pricing=basic_pricing, price=Decimal("2997.00") ) PlanPricing.objects.create( - plan=pro_plan, pricing=pro_pricing, price=Decimal("4500.00") + plan=pro_plan, pricing=pro_pricing, price=Decimal("5395.00") ) PlanPricing.objects.create( - plan=enterprise_plan, pricing=enterprise_pricing, price=Decimal("8500.00") + plan=enterprise_plan, pricing=enterprise_pricing, price=Decimal("9590.00") ) # # Create quotas diff --git a/inventory/utils.py b/inventory/utils.py index 58db19d6..e1e0145e 100644 --- a/inventory/utils.py +++ b/inventory/utils.py @@ -1924,12 +1924,15 @@ def handle_payment(request, order): "last_name": last_name, "phone": phone, } - total = int(round(order.total())) * 100 + try: + total = int((order.total() + order.tax * order.total() / 100) * 100) + except (AttributeError, TypeError): + raise ValueError("Order total or tax is invalid") payload = json.dumps( { "amount": total, "currency": "SAR", - "description": f"payment issued for {'email'}", + "description": f"payment issued for {email}", "callback_url": callback_url, "source": { "type": "creditcard", diff --git a/inventory/views.py b/inventory/views.py index e764eab1..440448ae 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -52,7 +52,7 @@ from django.forms import CharField, HiddenInput, ValidationError from django.shortcuts import HttpResponse from django.db.models import Sum, F, Count -from django.db.models.functions import ExtractMonth +from django.db.models.functions import ExtractMonth,Round from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger from django.contrib.auth.models import User, Group from django.db.models import Value @@ -9734,8 +9734,12 @@ def ledger_unpost_all_journals(request, dealer_slug, entity_slug, pk): @permission_required("inventory.change_dealer", raise_exception=True) def pricing_page(request, dealer_slug): dealer=get_object_or_404(models.Dealer, slug=dealer_slug) + vat = models.VatRate.objects.filter(dealer=dealer).first() if not dealer.active_plan: - plan_list = PlanPricing.objects.all() + plan_list = PlanPricing.objects.annotate( + price_with_tax=Round(F('price') * vat.rate + F('price'), 2) + ).all() + form = forms.PaymentPlanForm() return render(request, "pricing_page.html", {"plan_list": plan_list, "form": form}) else: @@ -9784,7 +9788,6 @@ def payment_callback(request, dealer_slug): logger.info(f"Received payment callback for dealer_slug: {dealer_slug}, payment_id: {payment_id}, status: {payment_status}") order = Order.objects.filter(user=dealer.user, status=1).first() # Status 1 = NEW - print(order) if payment_status == "paid": logger.info(f"Payment successful for transaction ID {payment_id}. Processing order completion.") @@ -9805,10 +9808,11 @@ def payment_callback(request, dealer_slug): logger.debug(f"Billing info already exists for user {dealer.user}.") if not hasattr(order.user, 'userplan'): + print(order.get_plan_pricing().pricing.period) UserPlan.objects.create( user=order.user, plan=order.plan, - expire=datetime.now().date() + timedelta(days=order.get_plan_pricing().pricing.period + 30) + expire=datetime.now().date() + timedelta(days=order.get_plan_pricing().pricing.period) ) logger.info(f"Created new UserPlan for user {order.user} with plan {order.plan}.") else: diff --git a/templates/account/signup-wizard.html b/templates/account/signup-wizard.html index 09660e40..4ab3304c 100644 --- a/templates/account/signup-wizard.html +++ b/templates/account/signup-wizard.html @@ -305,7 +305,7 @@ return true } function validate_sa_phone_number(phone_number) { - const phone_numberRegex = /^05[0-10]{7}$/; + const phone_numberRegex = /^05[0-9]{8}$/; return phone_numberRegex.test(phone_number) && phone_numberRegex !== ''; } function getAllFormData() { diff --git a/templates/pricing_page.html b/templates/pricing_page.html index b235a7dc..96ff6cbb 100644 --- a/templates/pricing_page.html +++ b/templates/pricing_page.html @@ -100,7 +100,7 @@ id="plan_{{ forloop.counter }}" value="{{ pp.id }}" data-name="{{ pp.plan.name }}" - data-price="{{ pp.price }}" + data-price="{{ pp.price_with_tax }}" autocomplete="off" {% if forloop.first %}checked{% endif %}>