Skip to content

Commit

Permalink
style: bulk-format with ruff and prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
barredterra committed Jul 24, 2024
1 parent 8a52bbd commit 5ee6264
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 124 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) 2020, Frappe and contributors
// For license information, please see license.txt

frappe.ui.form.on('LetMeShip', {
frappe.ui.form.on("LetMeShip", {
// refresh: function(frm) {

// }
});
16 changes: 6 additions & 10 deletions erpnext_shipping/erpnext_shipping/doctype/letmeship/letmeship.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,7 @@ def __init__(self, base_url: str, api_id: str, api_password: str):
self.api_password = api_password
self.api_id = api_id

def request(
self,
method: str,
endpoint: str,
json: dict | None = None,
params: dict | None = None
):
def request(self, method: str, endpoint: str, json: dict | None = None, params: dict | None = None):
"""Make a request to LetMeShip API."""
response = requests.request(
method,
Expand Down Expand Up @@ -131,7 +125,7 @@ def create_shipment(
pickup_date=pickup_date,
service_info=service_info,
)
try:
try:
response_data = self.request("POST", "shipments", json=payload)
if "shipmentId" in response_data:
shipment_amount = response_data["service"]["baseServiceDetails"]["priceInfo"]["totalPrice"]
Expand All @@ -157,7 +151,9 @@ def get_awb_number(self, shipment_id: str):

def get_label(self, shipment_id):
try:
shipment_label_response_data = self.request("GET", f"shipments/{shipment_id}/documents", params={"types": "LABEL"})
shipment_label_response_data = self.request(
"GET", f"shipments/{shipment_id}/documents", params={"types": "LABEL"}
)
if "documents" in shipment_label_response_data:
for label in shipment_label_response_data["documents"]:
if "data" in label:
Expand Down Expand Up @@ -337,5 +333,5 @@ def get_letmeship_utils() -> "LetMeShipUtils":
return LetMeShipUtils(
base_url=TEST_BASE_URL if settings.use_test_environment else PROD_BASE_URL,
api_id=settings.api_id,
api_password=settings.get_password("api_password")
api_password=settings.get_password("api_password"),
)
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) 2020, Frappe and contributors
// For license information, please see license.txt

frappe.ui.form.on('Parcel Service', {
frappe.ui.form.on("Parcel Service", {
// refresh: function(frm) {

// }
});
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// Copyright (c) 2020, Frappe and contributors
// For license information, please see license.txt

frappe.ui.form.on('Parcel Service Type Alias', {
parcel_type_alias: function(frm, cdt, cdn) {
frappe.ui.form.on("Parcel Service Type Alias", {
parcel_type_alias: function (frm, cdt, cdn) {
let row = locals[cdt][cdn];
if (row.parcel_type_alias) {
frappe.model.set_value(cdt, cdn, 'parcel_service', frm.doc.parcel_service);
frm.refresh_field('parcel_service_type_alias');
frappe.model.set_value(cdt, cdn, "parcel_service", frm.doc.parcel_service);
frm.refresh_field("parcel_service_type_alias");
}
}
});
},
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) 2020, Frappe and contributors
// For license information, please see license.txt

frappe.ui.form.on('SendCloud', {
frappe.ui.form.on("SendCloud", {
// refresh: function(frm) {

// }
});
14 changes: 4 additions & 10 deletions erpnext_shipping/erpnext_shipping/doctype/sendcloud/sendcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
WEIGHT_DECIMALS = 3
CURRENCY_DECIMALS = 2


class SendCloud(Document):
pass

Expand Down Expand Up @@ -55,16 +56,10 @@ def get_available_services(self, delivery_address, parcels: list[dict]):

available_services = []
for service in responses_dict.get("shipping_methods", []):
countries = [
country
for country in service["countries"]
if country["iso_2"] == to_country
]
countries = [country for country in service["countries"] if country["iso_2"] == to_country]

if countries and check_weight(service, parcels):
available_service = self.get_service_dict(
service, countries[0], parcels
)
available_service = self.get_service_dict(service, countries[0], parcels)
available_services.append(available_service)

return available_services
Expand Down Expand Up @@ -266,6 +261,5 @@ def check_weight(service: dict, parcels: list[dict]) -> bool:
max_weight_kg = float(service["max_weight"])
min_weight_kg = float(service["min_weight"])
return any(
max_weight_kg > parcel.get("weight") and min_weight_kg <= parcel.get("weight")
for parcel in parcels
max_weight_kg > parcel.get("weight") and min_weight_kg <= parcel.get("weight") for parcel in parcels
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -*- coding: utf-8 -*-
# Copyright (c) 2020, Frappe Technologies and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_fields

Expand Down
10 changes: 5 additions & 5 deletions erpnext_shipping/erpnext_shipping/shipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import frappe
from erpnext.stock.doctype.shipment.shipment import get_company_contact

from erpnext_shipping.erpnext_shipping.doctype.letmeship.letmeship import LETMESHIP_PROVIDER, get_letmeship_utils
from erpnext_shipping.erpnext_shipping.doctype.letmeship.letmeship import (
LETMESHIP_PROVIDER,
get_letmeship_utils,
)
from erpnext_shipping.erpnext_shipping.doctype.sendcloud.sendcloud import SENDCLOUD_PROVIDER, SendCloudUtils
from erpnext_shipping.erpnext_shipping.utils import (
get_address,
Expand Down Expand Up @@ -71,10 +74,7 @@ def fetch_shipping_rates(
if sendcloud_enabled and pickup_from_type == "Company":
sendcloud = SendCloudUtils()
sendcloud_prices = (
sendcloud.get_available_services(
delivery_address=delivery_address, parcels=parcels
)
or []
sendcloud.get_available_services(delivery_address=delivery_address, parcels=parcels) or []
)
sendcloud_prices = match_parcel_service_type_carrier(sendcloud_prices, "carrier", "service_name")
shipment_prices += sendcloud_prices
Expand Down
12 changes: 7 additions & 5 deletions erpnext_shipping/erpnext_shipping/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,17 @@ def get_contact(contact_name):
return contact


def match_parcel_service_type_carrier(shipment_prices: list[dict], carrier_fieldname: str, service_fieldname: str):
def match_parcel_service_type_carrier(
shipment_prices: list[dict], carrier_fieldname: str, service_fieldname: str
):
from erpnext_shipping.erpnext_shipping.doctype.parcel_service_type.parcel_service_type import (
match_parcel_service_type_alias,
)

for idx, prices in enumerate(shipment_prices):
service_name = match_parcel_service_type_alias(prices.get(carrier_fieldname), prices.get(service_fieldname))
service_name = match_parcel_service_type_alias(
prices.get(carrier_fieldname), prices.get(service_fieldname)
)
is_preferred = frappe.db.get_value(
"Parcel Service Type", service_name, "show_in_preferred_services_list"
)
Expand All @@ -89,9 +93,7 @@ def show_error_alert(action):
log = frappe.log_error(title="Shipping Error")
link_to_log = get_link_to_form("Error Log", log.name, "See what happened.")
frappe.msgprint(
msg=_("An Error occurred while {0}. {1}").format(action, link_to_log),
indicator="orange",
alert=True
msg=_("An Error occurred while {0}. {1}").format(action, link_to_log), indicator="orange", alert=True
)


Expand Down
Loading

0 comments on commit 5ee6264

Please sign in to comment.