From 3cf59feab0102b0809623cfca8be5741aaf05bf2 Mon Sep 17 00:00:00 2001 From: Flatlogic Bot Date: Sun, 25 Jan 2026 17:00:23 +0000 Subject: [PATCH] adding bids --- core/__pycache__/forms.cpython-311.pyc | Bin 20174 -> 20182 bytes .../whatsapp_utils.cpython-311.pyc | Bin 11178 -> 13717 bytes core/forms.py | 2 +- core/templates/core/driver_dashboard.html | 11 ++- core/whatsapp_utils.py | 70 ++++++++++++++++-- 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/core/__pycache__/forms.cpython-311.pyc b/core/__pycache__/forms.cpython-311.pyc index 71902827d706d8b8f92ac3a4fb1cc2afb394519b..3def7a285ab8b5add9a1941296b8f892f0965e0a 100644 GIT binary patch delta 66 zcmX>%m+{(MM&9MTyj%=GFv+_tQ)eUZeoJwg$o$eG1^=|P)FOp|qRiw}1r4Xn6wS@I VEt#3wO)rX?T@f|g{M6>9AON|y74QH6 delta 58 zcmcaMm+{hg@B^Wy|Dk5Cx}0~)p^%h_cnSpDC3JL z?)|jis%knu@o_DJSuaa@b`Fx zK8DvU7^Po`puD}RBNRoXbJ>zNSeVvTE4|g?ACiTlg~hrD<9-aUSumPFvUS;V!;-d} z^%7n}-{&UK5*AV3Q|*V)Y;BNL5dwxw%UqEo(IPin8;gYUO*;;|TVxxXh-@!npupd= z00nr>f`P!r+Ph~qyh-sQs?v&!h2fD*zNDs9B`4*tDN<6NSJTp>nv_n@C)GJAnUYNhq+4K&Mj*KS;$EQvYC(aE` zjgJ=G2_t4=P9gbzso>nDe#mdyatl}JaIm8kJ_F-H)O)0_^$E|ztVBK2C-^mMP47}Fn zgWXt|0qKLamF5-!kI~<@$7~Z|7$KMFKid;cmqCtu$*WM2*BE?{!6Y3B1@Sb!6zarN zv=j za>j`M$a!f`a68K{vS=J}>oQL#BhBA&h~v( zuUm003wbx~Z4DTVy{#tW0jLee0)4%eF@ElVclUq>YXL0PSZF6-UBz-eeLm8sva_{a z&CAOCeRw+d?^HL!ysW~Z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Dg|;Gfw-7;a)rs^$zG=N{348I9~j_-&g4o{ F831Tknv(zk diff --git a/core/forms.py b/core/forms.py index 09ac040..2500420 100644 --- a/core/forms.py +++ b/core/forms.py @@ -184,7 +184,7 @@ class ParcelForm(forms.ModelForm): labels = { 'description': _('Package Description'), 'weight': _('Weight (kg)'), - 'price': _('Shipping Price (OMR)'), + 'price': _('Your Offer Price (Bid) (OMR)'), 'pickup_country': _('Pickup Country'), 'pickup_governate': _('Pickup Governate'), 'pickup_city': _('Pickup City'), diff --git a/core/templates/core/driver_dashboard.html b/core/templates/core/driver_dashboard.html index f332690..8c19b25 100644 --- a/core/templates/core/driver_dashboard.html +++ b/core/templates/core/driver_dashboard.html @@ -26,10 +26,17 @@
{{ parcel.description|truncatechars:30 }}

{% trans "Pickup" %}: {{ parcel.pickup_address }}

{% trans "Delivery" %}: {{ parcel.delivery_address }}

-
+ +
{% trans "Weight" %}: {{ parcel.weight }} kg - {{ parcel.price }} OMR
+ + +
+ {% trans "Shipper's Offer (Bid)" %} +
{{ parcel.price }} OMR
+
+
{% csrf_token %} diff --git a/core/whatsapp_utils.py b/core/whatsapp_utils.py index 0c14d41..94d6fb5 100644 --- a/core/whatsapp_utils.py +++ b/core/whatsapp_utils.py @@ -130,6 +130,29 @@ def send_whatsapp_message_detailed(phone_number, message): logger.error(error_msg) return False, error_msg +def notify_admin(subject, message): + """Notifies the admin via Email and WhatsApp (if configured in PlatformProfile).""" + # Email + try: + if hasattr(settings, 'CONTACT_EMAIL_TO') and settings.CONTACT_EMAIL_TO: + send_html_email( + subject=f"Admin Alert: {subject}", + message=message, + recipient_list=settings.CONTACT_EMAIL_TO, + title="Admin Alert" + ) + except Exception as e: + logger.error(f"Failed to notify admin via email: {e}") + + # WhatsApp + try: + profile = PlatformProfile.objects.first() + if profile and profile.phone_number: + # Assuming profile.phone_number is a valid WhatsApp number for Admin alerts + send_whatsapp_message(profile.phone_number, f"ADMIN ALERT: {subject}\n{message}") + except Exception: + pass + def notify_shipment_created(parcel): """Notifies the shipper that the shipment request was received via WhatsApp and Email.""" shipper_name = parcel.shipper.get_full_name() or parcel.shipper.username @@ -185,7 +208,7 @@ Your shipment is now visible to available drivers.""" except Exception as e: logger.error(f"Failed to send payment email to {parcel.shipper.email}: {e}") - # Notify Receiver (WhatsApp only usually, but good to have logic if email exists in future) + # Notify Receiver receiver_msg = f"""Hello {parcel.receiver_name}, A shipment is coming your way from {shipper_name}. @@ -194,26 +217,59 @@ Status: {parcel.get_status_display()}""" send_whatsapp_message(parcel.receiver_phone, receiver_msg) def notify_driver_assigned(parcel): - """Notifies the shipper and receiver that a driver has picked up the parcel.""" + """Notifies the shipper, receiver, driver, and admin that a driver has picked up the parcel.""" driver_name = parcel.carrier.get_full_name() or parcel.carrier.username - msg = f"""Shipment {parcel.tracking_number} has been picked up by {driver_name}. + shipper_name = parcel.shipper.get_full_name() or parcel.shipper.username + + # 1. Notify Shipper + msg_shipper = f"""Shipment {parcel.tracking_number} has been picked up by {driver_name}. Status: {parcel.get_status_display()}""" if hasattr(parcel.shipper, 'profile') and parcel.shipper.profile.phone_number: - send_whatsapp_message(parcel.shipper.profile.phone_number, msg) + send_whatsapp_message(parcel.shipper.profile.phone_number, msg_shipper) if parcel.shipper.email: try: send_html_email( subject='Driver Assigned - ' + parcel.tracking_number, - message=msg, + message=msg_shipper, recipient_list=[parcel.shipper.email], title='Driver Assigned' ) except Exception: pass - send_whatsapp_message(parcel.receiver_phone, msg) + # 2. Notify Receiver + msg_receiver = f"""Shipment {parcel.tracking_number} from {shipper_name} is on the way (Picked up). +Driver: {driver_name}""" + send_whatsapp_message(parcel.receiver_phone, msg_receiver) + + # 3. Notify Driver (Confirmation) + msg_driver = f"""You have successfully accepted Shipment {parcel.tracking_number}. +Shipper: {shipper_name} +Pickup: {parcel.pickup_address} +Delivery: {parcel.delivery_address} +Price/Bid: {parcel.price} OMR""" + + if hasattr(parcel.carrier, 'profile') and parcel.carrier.profile.phone_number: + send_whatsapp_message(parcel.carrier.profile.phone_number, msg_driver) + + if parcel.carrier.email: + try: + send_html_email( + subject='Shipment Accepted - ' + parcel.tracking_number, + message=msg_driver, + recipient_list=[parcel.carrier.email], + title='Shipment Accepted' + ) + except Exception: + pass + + # 4. Notify Admin + notify_admin( + subject=f"Shipment Accepted ({parcel.tracking_number})", + message=f"Driver {driver_name} accepted shipment {parcel.tracking_number} from {shipper_name}.\nPrice: {parcel.price} OMR" + ) def notify_status_change(parcel): """Notifies parties about general status updates (In Transit, Delivered).""" @@ -234,4 +290,4 @@ New Status: {parcel.get_status_display()}""" except Exception: pass - send_whatsapp_message(parcel.receiver_phone, msg) \ No newline at end of file + send_whatsapp_message(parcel.receiver_phone, msg)