Skip to content

Enhance Shipping Method Management with Carrier Accounts and Broker Configuration#36

Open
JustShah wants to merge 7 commits into
1-0-feature-branchfrom
18-build-shipping-methods-manually
Open

Enhance Shipping Method Management with Carrier Accounts and Broker Configuration#36
JustShah wants to merge 7 commits into
1-0-feature-branchfrom
18-build-shipping-methods-manually

Conversation

@JustShah

Copy link
Copy Markdown

Description:

This PR introduces several enhancements to the shipping method management system, focusing on integrating carrier accounts and broker configurations. The changes aim to improve the accuracy, reliability, and flexibility of shipping method handling within the application.

Changes:

  1. Update ShippingMethodSelector to find shipping methods by carrier ID:

    • Refactored the ShippingMethodSelector to use find_by instead of find_or_create_by for locating shipping methods based on carrier, service level, and carrier ID. This ensures that only existing shipping methods are retrieved without creating new ones.
  2. Update estimator to include carrier accounts in shipment creation:

    • Modified the estimator to pass carrier accounts when creating shipments with EasyPost. This ensures that the correct carrier accounts are used, improving the accuracy and reliability of shipment creation.
    • Added a check to ensure that the shipping method is both present and available to users before proceeding in the estimator. This prevents errors and ensures that only valid shipping methods are considered.
  3. Add carrier accounts method to shipment decorator:

    • Added a method to retrieve carrier accounts from shipping methods in the shipment decorator. This is necessary to ensure that the correct carrier accounts are used when creating shipments with EasyPost.
  4. Add broker configuration fields to admin shipping method form:

    • Added a new field for selecting the broker in the admin shipping method form. This enables administrators to specify the broker for each shipping method, improving the configuration and management of shipping methods.
    • Created a partial view for the broker field in the admin shipping method form. This modular approach improves code maintainability and allows for easier updates to the broker field in the future.
    • Removed redundant fields from the admin shipping method form to streamline the user interface and reduce clutter. This makes the form easier to use and prevents confusion.
  5. Add broker enum to shipping method decorator:

    • Introduced a broker enum to the shipping method model to differentiate between different brokers (e.g., none, EasyPost). This allows for more flexible and clear handling of shipping methods based on the broker used.
  6. Add broker and carrier ID columns to shipping methods table:

    • Added new columns for broker and carrier ID to the shipping methods table. This schema change supports the new functionality for managing brokers and carrier accounts within shipping methods.

Impact:

These changes enhance the shipping method management system by integrating carrier accounts and broker configurations, leading to more accurate and reliable shipment handling. The improvements to the admin interface also make it easier for administrators to manage shipping methods effectively.

image

Added new columns for broker and carrier ID to the shipping methods table.
This schema change supports the new functionality for managing brokers and carrier accounts within shipping methods.
Introduced a broker enum to the shipping method model to differentiate between different brokers (e.g., none, EasyPost).
This allows for more flexible and clear handling of shipping methods based on the broker used.
Added a new field for selecting the broker in the admin shipping method form.
This enables administrators to specify the broker for each shipping method,
improving the configuration and management of shipping methods.

Created a partial view for the broker field in the admin shipping method form.
This modular approach improves code maintainability and allows for easier updates
to the broker field in the future.

Removed redundant fields from the admin shipping method form to
streamline the user interface and reduce clutter.
This makes the form easier to use and prevents confusion.
Added a method to retrieve carrier accounts from shipping methods in the shipment decorator.
This is necessary to ensure that the correct carrier accounts are used when creating shipments with EasyPost.
Modified the estimator to pass carrier accounts when creating shipments with EasyPost.
This ensures that the correct carrier accounts are used,
improving the accuracy and reliability of shipment creation.

Added a check to ensure that the shipping method is both
present and available to users before proceeding in the estimator.
This prevents errors and ensures that only valid shipping methods are considered.
Refactored the `ShippingMethodSelector` to use `find_by` instead of `find_or_create_by`
for locating shipping methods based on carrier, service level, and carrier ID.
This change ensures that only existing shipping methods are retrieved without creating new ones.
- Modified the shipment decorator to conditionally create pickup details only if 'pickup_day' is present in customer metadata.
- Updated the order's customer metadata to include pickup details only if they are present.
@JustShah

Copy link
Copy Markdown
Author

Tested Scenarios

1) Service Level Not Present:

  • Expected Result: Shipping method is not shown.

2) Carrier ID Mismatch:

  • Expected Result: Shipping method is not shown.

3) Rate Methods Discrepancy:

  • Scenario: Rate object has 3 methods, but the database has only 2.
  • Expected Result: Only the 2 existing methods are shown; a 3rd method is not created.
  • Explanation:
    API object:
"rates": [
  {
    "id": "rate_181925ae630243d4a694c233812fc27b",
    "object": "Rate",
    "created_at": "2025-03-10T07:50:49Z",
    "updated_at": "2025-03-10T07:50:49Z",
    "mode": "test",
    "service": "Express",
    "carrier": "USPS",
    "rate": "38.40",
    "currency": "USD",
    "retail_rate": "44.50",
    "retail_currency": "USD",
    "list_rate": "38.40",
    "list_currency": "USD",
    "billing_type": "easypost",
    "delivery_days": 1,
    "delivery_date": null,
    "delivery_date_guaranteed": false,
    "est_delivery_days": 1,
    "shipment_id": "shp_bc8a3fd6bd0b4401924cb87907aa2d98",
    "carrier_account_id": "ca_7245c55776664adebbd53676c1bf5ad7"
  },
  {
    "id": "rate_563e5a6aaf224b57b0b6707865a292d0",
    "object": "Rate",
    "created_at": "2025-03-10T07:50:49Z",
    "updated_at": "2025-03-10T07:50:49Z",
    "mode": "test",
    "service": "Priority",
    "carrier": "USPS",
    "rate": "8.01",
    "currency": "USD",
    "retail_rate": "13.10",
    "retail_currency": "USD",
    "list_rate": "10.21",
    "list_currency": "USD",
    "billing_type": "easypost",
    "delivery_days": 3,
    "delivery_date": null,
    "delivery_date_guaranteed": false,
    "est_delivery_days": 3,
    "shipment_id": "shp_bc8a3fd6bd0b4401924cb87907aa2d98",
    "carrier_account_id": "ca_7245c55776664adebbd53676c1bf5ad7"
  },
  {
    "id": "rate_4630a9e0e75f47c2bb8939161230cc3f",
    "object": "Rate",
    "created_at": "2025-03-10T07:50:49Z",
    "updated_at": "2025-03-10T07:50:49Z",
    "mode": "test",
    "service": "GroundAdvantage",
    "carrier": "USPS",
    "rate": "4.33",
    "currency": "USD",
    "retail_rate": "5.75",
    "retail_currency": "USD",
    "list_rate": "4.33",
    "list_currency": "USD",
    "billing_type": "easypost",
    "delivery_days": 4,
    "delivery_date": null,
    "delivery_date_guaranteed": false,
    "est_delivery_days": 4,
    "shipment_id": "shp_bc8a3fd6bd0b4401924cb87907aa2d98",
    "carrier_account_id": "ca_7245c55776664adebbd53676c1bf5ad7"
  }
]

In our database, we only have USPS Express and USPS Priority in shipping methods. We will not create a new shipping method for USPS GroundAdvantage.

4) No Matching Shipping Method:

  • Scenario: No shipping method matches the rate object.
  • Expected Result: Displays "Unable to calculate shipping rates" notice.

5) Invalid Carrier ID:

  • Scenario: Invalid carrier ID is passed.
  • Expected Result: Methods are not considered even if the carrier name and service match; displays notice.

6) Unavailable Shipping Methods:

  • Scenario: Shipping methods are present but not available to users.
  • Expected Result: Displays notice.

7) Available Shipping Methods:

  • Scenario: Shipping methods are present and available to users.
  • Expected Result: Only available shipping methods are shown.

8) Partial Match on Carrier Name:

  • Scenario: Carrier name partially matches but not exactly.
  • Expected Result: Shipping method is not shown.

9) No Match on Carrier Name:

  • Scenario: Carrier name does not match.
  • Expected Result: Shipping method is not shown.

Please review all the scenarios. Let me know if I missed any or if you would like to add any others.

@fthobe

fthobe commented Mar 12, 2025

Copy link
Copy Markdown

Look good!

@JustShah JustShah linked an issue Apr 3, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build Shipping Methods manually

2 participants