Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use db_set for updating Shipment info #30

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 27 additions & 18 deletions erpnext_shipping/erpnext_shipping/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down
Loading