Skip to content

fix: paid amount handling on refunded orders#53

Open
batonac wants to merge 6 commits into
version-15from
fix-negative-paid
Open

fix: paid amount handling on refunded orders#53
batonac wants to merge 6 commits into
version-15from
fix-negative-paid

Conversation

@batonac

@batonac batonac commented Nov 13, 2024

Copy link
Copy Markdown
Collaborator

This is a very simple tweak to avoid calculating a difference amount when the "amount_paid" is a negative number. I can't speak to all channels, but at least the Shopify -> ShipStation integration changes "amount_paid" to a negative number when an order is refunded, as illustrated by the following order API result:

    "orderTotal": -213.74,
    "amountPaid": -213.74,
    "taxAmount": 0.00,
    "shippingAmount": 39.00,

This creates a real quandary with the current order handling code, leading to an error that completely freezes the order imports, since ERPNext Sales Order validation will not accept a negative order total.

I'm not sure if my fix is sufficient, but I'm at least happy with the ability to continue importing orders and the functionality from the so_status branch is sufficient for differentiating which orders have been canceled/refunded from others.

@batonac

batonac commented Nov 13, 2024

Copy link
Copy Markdown
Collaborator Author

FWIW, the linter is throwing errors on unchanged files:

+++ b/shipstation_integration/public/js/shipping.js
@@ -37,29 +37,20 @@ shipping.add_label_button = frm => {
 		args: { doc: frm.doc },
 		callback: r => {
 			if (r.message) {
-				frappe.db
-					.get_value(
-						"Shipstation Settings",
-						{ name: r.message },
-						"enable_label_generation",
-					)
-					.then((settings) => {
-						if (settings.message.enable_label_generation) {
-							frm.add_custom_button(
-								`<i class="fa fa-tags"></i> Shipping Label`,
-								() => {
-									if (!shipping.carrier_options) {
-										frappe.throw(
-											__(`No carriers found to process labels. Please ensure the current
-										document is connected to Shipstation.`),
-										);
-									} else {
-										shipping.dialog(frm);
-									}
-								},
-							);
-						}
-					});
+				frappe.db.get_value('Shipstation Settings', { name: r.message }, 'enable_label_generation').then(settings => {
+					if (settings.message.enable_label_generation) {
+						frm.add_custom_button(`<i class="fa fa-tags"></i> Shipping Label`, () => {
+							if (!shipping.carrier_options) {
+								frappe.throw(
+									__(`No carriers found to process labels. Please ensure the current
+										document is connected to Shipstation.`)
+								)
+							} else {
+								shipping.dialog(frm)
+							}
+						})
+					}
+				})
 			}
 		},
 	})

@Alchez Alchez left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@batonac the pre-commit lint is setup to run on all files. If you do the following steps, that should let the linter pass:

pre-commit install
pre-commit run --all-files

@batonac
batonac marked this pull request as draft November 14, 2024 21:32
@batonac

batonac commented Nov 14, 2024

Copy link
Copy Markdown
Collaborator Author

whoops! I thought I had tested thoroughly, but my code must have been cached. now I'm getting:

'ShipStationOrder' object has no attribute 'get'

@batonac
batonac marked this pull request as ready for review November 14, 2024 22:04
@batonac

batonac commented Nov 14, 2024

Copy link
Copy Markdown
Collaborator Author

@agritheory I think this is ready.

@github-actions

Copy link
Copy Markdown

📝 Draft Changelog Entry

Changelog

Fixed an issue where refunded orders from Shopify were causing order imports to fail. When orders are refunded through the Shopify to ShipStation integration, the system records negative amounts for both the order total and amount paid. The previous order handling logic did not account for negative paid amounts, which resulted in validation errors that would halt all order imports. This update adds a check to prevent incorrect calculations when processing refunded orders, allowing order imports to continue without interruption.

This changelog entry was automatically generated by the Changelog Generator Action.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Draft Changelog Entry

Changelog

Fixed an issue where refunded orders from Shopify were causing order imports to fail. When orders are refunded through the Shopify to ShipStation integration, the system records negative amounts for both the order total and amount paid. The previous logic attempted to calculate a difference between these values, which resulted in validation errors that halted the entire import process. The order import process now handles refunded orders correctly and continues processing without interruption.

This changelog entry was automatically generated by the Changelog Generator Action.

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.

3 participants