diff --git a/inventory/views.py b/inventory/views.py index 94d9458e..c80ab853 100644 --- a/inventory/views.py +++ b/inventory/views.py @@ -9456,10 +9456,12 @@ def submit_plan(request, dealer_slug): tax=15, status=1, ) + logger.info(f"order created {order}") except Exception as e: - print(e) + logger.error(e) if not order: messages.error(request, _("Error creating order")) + logger.error("unable to create order") return redirect("pricing_page", dealer_slug=dealer_slug) transaction_url = handle_payment(request, order) return redirect(transaction_url) @@ -9473,9 +9475,13 @@ def payment_callback(request, dealer_slug): payment_id = request.GET.get("id") history = models.PaymentHistory.objects.filter(transaction_id=payment_id).first() payment_status = request.GET.get("status") + 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.") + billing_info, created = BillingInfo.objects.get_or_create( user=dealer.user, defaults={ @@ -9487,12 +9493,20 @@ def payment_callback(request, dealer_slug): 'country': dealer.entity.country or " ", } ) + if created: + logger.info(f"Created new billing info for user {dealer.user}.") + else: + logger.debug(f"Billing info already exists for user {dealer.user}.") + if not hasattr(order.user, 'userplan'): UserPlan.objects.create( user=order.user, plan=order.plan, 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: + logger.info(f"UserPlan already exists for user {order.user}.") try: @@ -9510,7 +9524,7 @@ def payment_callback(request, dealer_slug): order.complete_order() history.status = "paid" history.save() - + logger.info(f"Order {order.id} for user {order.user} completed successfully. Payment history updated.") invoice = order.get_invoices().first() return render( request, @@ -9519,12 +9533,14 @@ def payment_callback(request, dealer_slug): ) except Exception as e: + logger.exception(f"Error completing order {order.id} for user {order.user}: {e}") logger.error(f"Plan activation failed: {str(e)}") history.status = "failed" history.save() return render(request, "payment_failed.html", {"message": "Plan activation error"}) elif payment_status == "failed": + logger.warning(f"Payment failed for transaction ID {payment_id}. Message: {message}") history.status = "failed" history.save() return render(request, "payment_failed.html", {"message": message}) diff --git a/templates/mail/change_plan_body.txt b/templates/mail/change_plan_body.txt index bcd93981..489b5100 100644 --- a/templates/mail/change_plan_body.txt +++ b/templates/mail/change_plan_body.txt @@ -1,25 +1,13 @@ {% load i18n %}{% autoescape off %} - -مرحباً {% firstof user.get_full_name user.username %}، +{% trans "Hi" %} {% firstof user.get_full_name user.username %}, {% if userplan.expire != None %} -خطتك الحالية هي {{ plan.name }} وستنتهي صلاحيتها في {{ userplan.expire }}. + {% blocktrans with plan_name=plan.name expire=userplan.expire %}Your current plan is {{ plan_name }} and it will expire on {{ expire }}. {% endblocktrans %} {% else %} -خطتك الحالية هي {{ plan.name }}. + {% blocktrans with plan_name=plan.name %}Your current plan is {{ plan_name }}. {% endblocktrans %} {% endif %} -شكراً لك، -فريق تنحل ---------------------- - -Hi {% firstof user.get_full_name user.username %}, - -{% if userplan.expire != None %} -Your current plan is {{ plan_name }} and it will expire on {{ expire }}. {% endblocktrans %} -{% else %} -Your current plan is {{ plan_name }}. {% endblocktrans %} -{% endif %} - -Thank you -The Team at Tenhal -{% endautoescape %} \ No newline at end of file +{% trans "Thank you" %} +-- +{% blocktrans %}The Team at {{ site_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/templates/mail/change_plan_title.txt b/templates/mail/change_plan_title.txt index a4a303c2..bbec277e 100644 --- a/templates/mail/change_plan_title.txt +++ b/templates/mail/change_plan_title.txt @@ -1,3 +1 @@ -{% load i18n %} -Your account {{ user }} has new plan {{ plan }} -حسابك {{ user }} لديه خطة جديدة {{ plan }} \ No newline at end of file +{% load i18n %}{% blocktrans with user=user plan=plan.name %}Your account {{ user }} has new plan {{ plan }}{% endblocktrans %} \ No newline at end of file diff --git a/templates/mail/expired_account_body.txt b/templates/mail/expired_account_body.txt index 9355474a..701ad8f9 100644 --- a/templates/mail/expired_account_body.txt +++ b/templates/mail/expired_account_body.txt @@ -1,27 +1,14 @@ {% load i18n %}{% autoescape off %} -مرحباً {% firstof user.get_full_name user.username %}، +{% trans "Hi" %} {% firstof user.get_full_name user.username %}, -لقد انتهت صلاحية حسابك للتو. +{% blocktrans %}Your account has just expired.{% endblocktrans %} -يمكنك استعادة خطتك الحالية {{ userplan.plan.name }} من هنا: +{% blocktrans with plan_name=userplan.plan.name %}You can restore your current plan {{ plan_name }} here:{% endblocktrans %} http://{{ site_domain }}{% url 'current_plan' %} -أو يمكنك ترقية خطتك من هنا: +{% blocktrans %}or you can upgrade your plan here:{% endblocktrans %} http://{{ site_domain }}{% url 'upgrade_plan' %} -شكراً لك، +{% trans "Thank you" %} -- -فريق تنحل ---------------------- -Hi {% firstof user.get_full_name user.username %}, - -Your account has just expired. - -You can restore your current plan {{ userplan.plan.name }} here: -http://{{ site_domain }}{% url 'current_plan' %} -or you can upgrade your plan here: -http://{{ site_domain }}{% url 'upgrade_plan' %} - -Thank you, --- -The Team at TENHAL -{% endautoescape %} \ No newline at end of file +{% blocktrans %}The Team at {{ site_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/templates/mail/expired_account_title.txt b/templates/mail/expired_account_title.txt index e4b758bc..54a3d3a7 100644 --- a/templates/mail/expired_account_title.txt +++ b/templates/mail/expired_account_title.txt @@ -1,5 +1 @@ -{% load i18n %}{% autoescape off %} -لقد انتهت صلاحية حسابك {{ user }} للتو. ---------------------- -Your account {{ user }} has just expired. -{% endautoescape %} \ No newline at end of file +{% load i18n %}{% blocktrans %}Your account {{ user }} has just expired{% endblocktrans %} \ No newline at end of file diff --git a/templates/mail/extend_account_body.txt b/templates/mail/extend_account_body.txt index ed64cb6a..f7e77e50 100644 --- a/templates/mail/extend_account_body.txt +++ b/templates/mail/extend_account_body.txt @@ -1,20 +1,11 @@ {% load i18n %}{% autoescape off %} -مرحباً {% firstof user.get_full_name user.username %}، +{% trans "Hi" %} {% firstof user.get_full_name user.username %}, -تم تمديد صلاحية حسابك للتو لمدة {{ pricing.period }} يوم. خطتك الحالية هي {{plan.name}} وستنتهي في {{userplan.expire}}. +{% blocktrans with days=pricing.period plan_name=plan.name expire=userplan.expire %}Your account has just been extended by {{ days }} days. Your current plan is {{ plan_name }} and it will expire on {{ expire }}. {% endblocktrans %} -سيتم إرسال فاتورة في رسالة بريد إلكتروني أخرى، في حال تم تقديم بيانات الفوترة. -شكراً لك +{% trans "An invoice will be sent with another e-mail, if billing data was provided." %} + +{% trans "Thank you" %} -- -فريق تنحل ---------------------- -Hi {% firstof user.get_full_name user.username %}, - -Your account has just been extended by {{ pricing.period }} days. Your current plan is {{plan.name}} and it will expire on {{userplan.expire}}. - -An invoice will be sent with another e-mail, if billing data was provided. - -Thank you --- -The Team at Tenhal -{% endautoescape %} \ No newline at end of file +{% blocktrans %}The Team at {{ site_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/templates/mail/extend_account_title.txt b/templates/mail/extend_account_title.txt index 2f66c163..8a984a5e 100644 --- a/templates/mail/extend_account_title.txt +++ b/templates/mail/extend_account_title.txt @@ -1,14 +1 @@ -{% load i18n %} -{% autoescape off %} -مرحباً {% firstof user.get_full_name user.username %}، -تم تمديد حسابك {{ user }} لمدة {{ pricing.period }} يوم -شكراً لك --- -فريق تنحل --------- -Hi {% firstof user.get_full_name user.username %}, -Your account {{ user }} has been extended by {{ pricing.period }} days -Thank you --- -The Team at Tenhal -{% endautoescape %} \ No newline at end of file +{% load i18n %}{% blocktrans with user=user days=pricing.period %}Your account {{ user }} has been extended by {{ days }} days{% endblocktrans %} \ No newline at end of file diff --git a/templates/mail/invoice_created_body.txt b/templates/mail/invoice_created_body.txt index 7df530ad..4367230c 100644 --- a/templates/mail/invoice_created_body.txt +++ b/templates/mail/invoice_created_body.txt @@ -1,21 +1,14 @@ {% load i18n %}{% autoescape off %} -مرحباً {% firstof user.get_full_name user.username %}، -نكتب إليك لإعلامك، أنه قد تم إصدار {{ invoice_type }} رقم {{ invoice_number }}. يمكنك الاطلاع عليها وطباعتها عبر الرابط: +{% trans "Hi" %} {% firstof user.get_full_name user.username %}, + +{% blocktrans %}We are writing to inform you, that {{ invoice_type }} {{ invoice_number }} has been issued. You can view it and print it at: http://{{ site_domain }}{{ url }} -يمكنك الاطلاع على تفاصيل الطلب عبر الرابط: +{% endblocktrans %} + +{% trans "Details of the order can be see on:" %}: http://{{ site_domain }}{% url 'order' pk=order %} -شكراً لك +{% trans "Thank you" %} -- -فريق تنحل ---------------------- -Hi {% firstof user.get_full_name user.username %}, -We are writing to inform you, that {{ invoice_type }} {{ invoice_number }} has been issued. You can view it and print it at: -http://{{ site_domain }}{{ url }} -Details of the order can be see on: -http://{{ site_domain }}{% url 'order' pk=order %} - -Thank you --- -The Team at Tenhal -{% endautoescape %} \ No newline at end of file +{% blocktrans %}The Team at {{ site_name }}{% endblocktrans %} +{% endautoescape %} diff --git a/templates/mail/invoice_created_title.txt b/templates/mail/invoice_created_title.txt index eaec9b08..3304e800 100644 --- a/templates/mail/invoice_created_title.txt +++ b/templates/mail/invoice_created_title.txt @@ -1,3 +1 @@ -{% load i18n %} -Order {{ order }} - {{ invoice_type }} {{ invoice_number }} has been issued for {{ user }} -تم إصدار {{ invoice_type }} {{ invoice_number }} للأمر {{ order }} باسم {{ user }} +{% load i18n %}{% trans 'Order' %} {{ order }} - {% blocktrans with invoice_type=invoice_type invoice_number=invoice_number user=user %}{{ invoice_type }} {{ invoice_number }} has been issued for {{ user }}{% endblocktrans %} \ No newline at end of file diff --git a/templates/mail/remind_expire_body.txt b/templates/mail/remind_expire_body.txt index 3ec99320..040dd7d8 100644 --- a/templates/mail/remind_expire_body.txt +++ b/templates/mail/remind_expire_body.txt @@ -1,29 +1,10 @@ {% load i18n %}{% autoescape off %} -Hi {% firstof user.get_full_name user.username %}, +{% trans "Hi" %} {% firstof user.get_full_name user.username %}, -Your account will expire in {{ days }} days. +{% blocktrans %}Your account will expire in {{ days }} days.{% endblocktrans %} -You can extend your current plan {{ userplan.plan.name }} on page: +{% blocktrans with plan_name=userplan.plan.name %}You can extend your current plan {{ plan_name }} on page:{% endblocktrans %} http://{{ site_domain }}{% url 'current_plan' %} -or you can upgrade your plan here: -http://{{ site_domain }}{% url 'upgrade_plan' %} - -Thank you --- -The Team at Tenhal ----------------- -مرحباً {% firstof full_name username %}، - -سينتهي حسابك في غضون {{ days }} يوم. - -يمكنك تمديد خطتك الحالية {{ userplan.plan.name }} على الصفحة التالية: -http://{{ site_domain }}{% url 'current_plan' %} - -أو يمكنك ترقية خطتك هنا: -http://{{ site_domain }}{% url 'upgrade_plan' %} - -شكراً لك --- -فريق تنحل -{% endautoescape %} +{% blocktrans %}or you can upgrade your plan here:{% endblocktrans %} +http://{{ site_domain }}{% url 'upgrade_plan' %} \ No newline at end of file diff --git a/templates/mail/remind_expire_title.txt b/templates/mail/remind_expire_title.txt index 01885ad3..b6863e01 100644 --- a/templates/mail/remind_expire_title.txt +++ b/templates/mail/remind_expire_title.txt @@ -1,3 +1 @@ -{% load i18n %} -Your account {{ user }} will expire in {{ days }} day. -سينتهي حسابك {{ user }} في غضون {{ days }} يوم. \ No newline at end of file +{% load i18n %}{% blocktrans count days as days %}Your account {{ user }} will expire in {{ days }} day{% plural %}Your account {{ user }} will expire in {{ days }} days{% endblocktrans %} \ No newline at end of file