From 2d857f67f6ef15879567d369054c47fa07aac26b Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 5 Sep 2024 13:59:26 +0200 Subject: [PATCH 1/2] fix: use `db_set` for updating Shipment info This is required so that On Change event will be triggered for Notifications and Server Scripts. --- erpnext_shipping/erpnext_shipping/shipping.py | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/erpnext_shipping/erpnext_shipping/shipping.py b/erpnext_shipping/erpnext_shipping/shipping.py index 96420a2..0db203d 100644 --- a/erpnext_shipping/erpnext_shipping/shipping.py +++ b/erpnext_shipping/erpnext_shipping/shipping.py @@ -152,17 +152,18 @@ def create_shipment( ) if shipment_info: - fields = [ - "service_provider", - "carrier", - "carrier_service", - "shipment_id", - "shipment_amount", - "awb_number", - ] - for field in fields: - frappe.db.set_value("Shipment", shipment, field, shipment_info.get(field)) - frappe.db.set_value("Shipment", shipment, "status", "Booked") + shipment = frappe.get_doc("Shipment", shipment) + shipment.db_set( + { + "service_provider": shipment_info.get("service_provider"), + "carrier": shipment_info.get("carrier"), + "carrier_service": shipment_info.get("carrier_service"), + "shipment_id": shipment_info.get("shipment_id"), + "shipment_amount": shipment_info.get("shipment_amount"), + "awb_number": shipment_info.get("awb_number"), + "status": "Booked", + } + ) if delivery_notes: update_delivery_note(delivery_notes=delivery_notes, shipment_info=shipment_info) @@ -232,13 +233,21 @@ def update_tracking(shipment, service_provider, shipment_id, delivery_notes=None sendcloud = SendCloudUtils() tracking_data = sendcloud.get_tracking_data(shipment_id) - if tracking_data: - fields = ["awb_number", "tracking_status", "tracking_status_info", "tracking_url"] - for field in fields: - frappe.db.set_value("Shipment", shipment, field, tracking_data.get(field)) - - if delivery_notes: - update_delivery_note(delivery_notes=delivery_notes, tracking_info=tracking_data) + if not tracking_data: + return + + shipment = frappe.get_doc("Shipment", shipment) + shipment.db_set( + { + "awb_number": tracking_data.get("awb_number"), + "tracking_status": tracking_data.get("tracking_status"), + "tracking_status_info": tracking_data.get("tracking_status_info"), + "tracking_url": tracking_data.get("tracking_url"), + } + ) + + if delivery_notes: + update_delivery_note(delivery_notes=delivery_notes, tracking_info=tracking_data) def update_delivery_note(delivery_notes, shipment_info=None, tracking_info=None): From 4040b4e3f7951c82efe776bf39cc75d8eebf483e Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 5 Sep 2024 14:19:18 +0200 Subject: [PATCH 2/2] ci: unpin semgrep to get the latest version --- .github/workflows/linters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 3da001e..b0f2583 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -50,7 +50,7 @@ jobs: - name: Run Semgrep rules run: | - pip install semgrep==0.97.0 + pip install semgrep semgrep ci --config ./frappe-semgrep-rules/rules --config r/python.lang.correctness deps-vulnerable-check: