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

Refactor UPS rate calculation logic #673

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

jacobshilitz
Copy link
Collaborator

Simplify the logic for determining total charges by consolidating conditional checks. Added BaseServiceCharge handling and mapped SurchargeType codes to descriptive names for improved readability.

See #672

ups, in fact, send the base rate of the negotiated rate, so putting the original rate does not make sense.

image

Simplify the logic for determining total charges by consolidating conditional checks. Added BaseServiceCharge handling and mapped SurchargeType codes to descriptive names for improved readability.
Improve the surcharge type mapping logic for readability and efficiency. Capitalize mapped surcharge type names and ensure consistent formatting by handling cases where the type name is not available.
Adjusted the base charge amounts and renamed surcharge codes to 'Fuel surcharge' in UPS rate tests. This change ensures consistency and accuracy in the test data for various UPS services.

changed to use `BaseServiceCharge` instead of `TransportationCharges` because the docs state that `BaseServiceCharge` is The base value of the specific service for the shipment. This is equal to transportation charges - fuel surcharges. and the fuel charge has a separate itemized charge and appears as code 375
Deleted zero-amount extra charge entries from various test cases in the UPS rate tests. This streamlines the test cases and clarifies the relevant charges being tested.
@jacobshilitz jacobshilitz marked this pull request as ready for review September 5, 2024 13:25
Copy link
Member

@danh91 danh91 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Merging now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to handle this. But for future reference, the schema python files are automatically generated based on the JSON schema files here so you want to make the change on the JSON file and regenerate not change directly the Python files

Comment on lines +43 to +59
(rate.Service.Code, rate.ServiceOptionsCharges.MonetaryValue)
if lib.to_int(rate.ServiceOptionsCharges.MonetaryValue) > 0
else []
),
*(
(
(
provider_units.SurchargeType.map(
str(getattr(c, "Code", None) or getattr(c, "Type", None))
).name.capitalize().replace("_", " ")
if provider_units.SurchargeType.map(
str(getattr(c, "Code", None) or getattr(c, "Type", None))
).name
else (getattr(c, "Code", None) or getattr(c, "Type", None))
),
c.MonetaryValue
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will read this to see if it can be simplified. I might be hard to understand for the next person who will debug this 😅

Copy link
Collaborator Author

@jacobshilitz jacobshilitz Sep 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, also please look into this line, if we need this part at all, I allways saw it empty

*(
            (rate.Service.Code, rate.ServiceOptionsCharges.MonetaryValue)
            if lib.to_int(rate.ServiceOptionsCharges.MonetaryValue) > 0
            else []
        ),
        

@danh91 danh91 changed the base branch from main to patch-2024.6.4 September 11, 2024 18:40
@danh91 danh91 merged commit bb75e15 into karrioapi:patch-2024.6.4 Sep 11, 2024
1 of 2 checks passed
@danh91 danh91 mentioned this pull request Sep 11, 2024
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.

2 participants