send message to shop owners
This commit is contained in:
@@ -9,7 +9,8 @@ import ghasedak_sms
|
||||
from .tasks import send_change_status_notif, send_change_status_sms, send_shop_order_invoice_telegram_task
|
||||
from django.conf import settings
|
||||
from decimal import Decimal
|
||||
|
||||
import logging
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@receiver(pre_save, sender=OrderModel)
|
||||
def order_status_changed(sender, instance, **kwargs):
|
||||
@@ -215,6 +216,34 @@ def create_shop_orders_on_payment(sender, instance: OrderModel, created, **kwarg
|
||||
discount_amount=int(item_discount_amount),
|
||||
special_discount_amount=int(it.special_discount_amount or 0),
|
||||
)
|
||||
shop_list = []
|
||||
for order_item in instance.items.all():
|
||||
shop_to_add = order_item.product.product.shop
|
||||
shop_list.append(shop_to_add)
|
||||
shop_list = set(shop_list)
|
||||
|
||||
|
||||
for shop in shop_list:
|
||||
sms_api = ghasedak_sms.Ghasedak(api_key="8f7396f1e3c39e3a4621009c558d955336eea6d21cf257dd74ae262d6f22a458XdoDjH6egJsiZsy8")
|
||||
newotpcommand = ghasedak_sms.SendOtpInput(
|
||||
receptors=[
|
||||
ghasedak_sms.SendOtpReceptorDto(
|
||||
mobile=f'{shop.user.phone}',
|
||||
client_reference_id=str(shop.user.id)
|
||||
)
|
||||
],
|
||||
template_name='neworder',
|
||||
inputs=[
|
||||
ghasedak_sms.SendOtpInput.OtpInput(param='ShopName', value=f'{shop.shop_name}'),
|
||||
],
|
||||
udh=False
|
||||
)
|
||||
response = sms_api.send_otp_sms(newotpcommand)
|
||||
|
||||
if response['statusCode'] == 200:
|
||||
logger.error("sent order notice to shop owner")
|
||||
else:
|
||||
logger.error(f"faield to send order id {response}")
|
||||
|
||||
|
||||
@receiver(post_save, sender=ShopOrderModel)
|
||||
|
||||
Reference in New Issue
Block a user