woocommerce / woocommerce-android

WooCommerce Android app
https://www.woocommerce.com/mobile
GNU General Public License v2.0
277 stars 135 forks source link

Incorrect Currency Displayed When Order Currency Differs from Store Default #12880

Closed AnirudhBhat closed 1 week ago

AnirudhBhat commented 2 weeks ago

Closes: #12865

Description

This PR disables Edit option for orders whose currency differs from store currency.

Reason We consistently use the store's default currency when editing an order, even if the order was created in a different currency. This results in inconsistencies across various sections of the editable order screen, including Items, Custom Amounts, Discounts, Coupons, and Order Totals. Additionally, when adding new products to the order, prices are displayed in the store's default currency instead of the order's currency.

This inconsistency is confusing for users.

Suggested Workaround to consider:

To completely fix this issue, we would need to receive product prices in the order’s currency so we can display them correctly during product selection. Since the REST API does not currently provide this, I suggest disabling the Edit mode for orders in a currency different from the store’s default.

Users would still be able to change the order status, create shipping labels, issue refunds, and add tracking, notes, and shipping details from the Order Details. They wouldn’t be able to add Custom Amounts, Discounts, Coupons, or new Items to the order. These actions aren’t very common for orders created on the storefront anyways.

More context peaMlT-XF-p2

Steps to reproduce

  1. In your store viewfront, create an order with some items with a currency other than the default one. You can do that by accessing the store from a country with a different currency than the default one (better in Incognito mode in the browser). For that to work, you should have enabled the Automatically switch customers to their local currency if it has been enabled in the Multicurrency setting of WooCommerce wp-admin.
  2. Open the app and go to orders.
  3. Click on Edit orders
  4. See that the currency displayed is not proper.

The tests that have been performed

Tested that edit option is disabled for orders which have different currency than store currency and enabled for those whose currency matches with that of stores.

Images/gif

https://github.com/user-attachments/assets/30ebd308-4123-4798-a49d-60ebd520028a

Reviewer (or Author, in the case of optional code reviews):

Please make sure these conditions are met before approving the PR, or request changes if the PR needs improvement:

dangermattic commented 2 weeks ago
1 Warning
:warning: This PR is assigned to the milestone 21.1. This milestone is due in less than 2 days.
Please make sure to get it merged by then or assign it to a milestone with a later deadline.
1 Message
:book:

This PR contains changes to Tracks-related logic. Please ensure (author and reviewer) the following are completed:

  • The tracks events must be validated in the Tracks system.
  • Verify the internal Tracks spreadsheet has also been updated.
  • Please consider registering any new events.
  • The PR must be assigned the category: tracks label.

Generated by :no_entry_sign: Danger

wpmobilebot commented 2 weeks ago
📲 You can test the changes from this Pull Request in WooCommerce-Wear Android by scanning the QR code below to install the corresponding build.
App Name WooCommerce-Wear Android
Platform⌚️ Wear OS
FlavorJalapeno
Build TypeDebug
Commitcf3f832f7bd51d1e773ad354085b36c12109b451
Direct Downloadwoocommerce-wear-prototype-build-pr12880-cf3f832.apk
wpmobilebot commented 2 weeks ago

📲 You can test the changes from this Pull Request in WooCommerce Android by scanning the QR code below to install the corresponding build.

App Name WooCommerce Android
Platform📱 Mobile
FlavorJalapeno
Build TypeDebug
Commitcf3f832f7bd51d1e773ad354085b36c12109b451
Direct Downloadwoocommerce-prototype-build-pr12880-cf3f832.apk
codecov-commenter commented 2 weeks ago

Codecov Report

Attention: Patch coverage is 82.75862% with 5 lines in your changes missing coverage. Please review.

Project coverage is 40.20%. Comparing base (1dc0b09) to head (cf3f832). Report is 30 commits behind head on trunk.

Files with missing lines Patch % Lines
...commerce/android/ui/orders/IsStoreCurrencyMatch.kt 83.33% 0 Missing and 2 partials :warning:
...ce/android/ui/orders/details/OrderDetailTracker.kt 0.00% 2 Missing :warning:
.../android/ui/orders/details/OrderDetailViewModel.kt 92.85% 0 Missing and 1 partial :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## trunk #12880 +/- ## ============================================ + Coverage 40.18% 40.20% +0.02% - Complexity 5790 5795 +5 ============================================ Files 1255 1256 +1 Lines 71398 71427 +29 Branches 9969 9973 +4 ============================================ + Hits 28690 28717 +27 Misses 40071 40071 - Partials 2637 2639 +2 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

AnirudhBhat commented 1 week ago

@kidinov Thanks for all the suggestions 🙏 I've refactored it and have implemented the snack bar display as we discussed on Slack. Could you please take another look?

kidinov commented 1 week ago

@AnirudhBhat

it crashes for me with on a 2 pane layout 🤔 . ~Is this because of onPrepareMenu?~ - nope

Process: com.woocommerce.android.dev, PID: 5864
java.lang.IllegalStateException: Multiple observers registered but only one is supported.
                                                                                                        at com.woocommerce.android.viewmodel.LiveDataDelegate.observe(LiveDataDelegate.kt:53)
                                                                                                        at com.woocommerce.android.ui.orders.creation.OrderCreateEditFormFragment.observeViewStateChanges(OrderCreateEditFormFragment.kt:486)
                                                                                                        at com.woocommerce.android.ui.orders.creation.OrderCreateEditFormFragment.setupObserversWith(OrderCreateEditFormFragment.kt:417)
                                                                                                        at com.woocommerce.android.ui.orders.creation.OrderCreateEditFormFragment.onViewCreated(OrderCreateEditFormFragment.kt:164)
                                                                                                        at androidx.fragment.app.Fragment.performViewCreated(Fragment.java:3152)
                                                                                                        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:608)
                                                                                                        at androidx.fragment.app.FragmentStateManager.moveToExpectedState(FragmentStateManager.java:286)
                                                                                                        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:2164)
                                                                                                        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:2065)
                                                                                                        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:2002)
                                                                                                        at androidx.fragment.app.FragmentManager$5.run(FragmentManager.java:702)
                                                                                                        at android.os.Handler.handleCallback(Handler.java:942)
                                                                                                        at android.os.Handler.dispatchMessage(Handler.java:99)
                                                                                                        at android.os.Looper.loopOnce(Looper.java:201)
                                                                                                        at android.os.Looper.loop(Looper.java:288)
                                                                                                        at android.app.ActivityThread.main(ActivityThread.java:7924)
                                                                                                        at java.lang.reflect.Method.invoke(Native Method)
                                                                                                        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
                                                                                                        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
AnirudhBhat commented 1 week ago

it crashes for me with on a 2 pane layout

It seems like the crash is unrelated to this change. The crash happens even on latest trunk. Raised this on our internal Slack channel.

I've addressed your feedback. Thanks!