-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
Refactor UPS rate calculation logic #673
Conversation
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Merging now
There was a problem hiding this comment.
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
(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 | ||
) |
There was a problem hiding this comment.
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 😅
There was a problem hiding this comment.
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 []
),
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.