This commit is contained in:
javad committed 2026-10-11 19:04:20 +03:30
1 parent 1dea3509a7
commit e3a6d1f9d4
42 files changed
+33086 -15779

No files matched your search

+15 -2
View File
@@ -12,6 +12,7 @@ from persiantools import digits
from ..models import (Customer, StoreRoom, Factor, FactorIteam, Product,
ProductInStore, Article, Sarresid)
from ..sms.triggers import notify_factor_survey, notify_payment_thanks
from ._helpers import logger, _safe_int, _parse_jalali_date, _parse_timestamp, InventoryException
@@ -196,6 +197,8 @@ def newFactor2(request, c_id):
if not str(item.get('garanty_Esh', '')).strip()
)
new_factor = None
payment_articles = []
try:
with transaction.atomic():
@@ -231,7 +234,7 @@ def newFactor2(request, c_id):
if key in payment_map:
nahve_pardakht = payment_map[key]
Article.objects.create(
payment_articles.append((Article.objects.create(
debit=0,
credit=amount,
customer=customer_obj,
@@ -240,7 +243,7 @@ def newFactor2(request, c_id):
nahvePardakht=nahve_pardakht,
payStatus="true",
user=user_op
)
), nahve_pardakht))
elif key in ['l_nesiye', 'l_checkPrice']:
is_nesiye = (key == 'l_nesiye')
@@ -359,6 +362,16 @@ def newFactor2(request, c_id):
logger.error(f"Error creating factor for customer {c_id}: {str(e)}", exc_info=True)
return HttpResponse("خطایی غیرمنتظره در سرور رخ داد. اطلاعات ذخیره نشد.", status=500)
# تریگرهای پیامک پس از تأیید تراکنش (خارج از atomic تا در صورت rollback ساخته نشوند).
if new_factor is not None:
# نظرسنجی بی‌واسطه پس از ثبت فاکتور.
notify_factor_survey(customer_obj, new_factor, created_by=user_op)
# تشکر برای هر پرداخت نقدی/کارتیِ ثبت‌شده روی همین فاکتور (تخفیف مستثناست).
for art, method in payment_articles:
notify_payment_thanks(customer_obj, art.credit,
article_id=art.id, method=method,
created_by=user_op)
return redirect(f'/panel/customer/{c_id}/factors/')