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

[Order form] Use order item data for products in order creation/editing #13305

Merged
merged 8 commits into from
Jul 17, 2024

Conversation

staskus
Copy link
Collaborator

@staskus staskus commented Jul 11, 2024

Closes: #11455
Investigation: pdfdoF-4rm-p2

Description

This PR addresses an issue where iOS uses Product price, instead of the Order Item price in the Order Creation / Editing view.

It results in a couple of issues when Yes, I will enter prices inclusive of tax setting is enabled.

image

  1. iOS Order Creation/Editing view is inconsistent with Android, and Web.
  2. iOS Order Creation/Editing view is inconsistent with the iOS Order Details view.
  3. Product prices displayed in the Products Section include taxes while product prices displayed in Order Summary exclude taxes, which results in different Product totals shown.
    3.1 When discounts are applied, discounted totals in the Product Section are calculated with included taxes, again resulting in different product prices displayed in Order Summary.
    3.2. Individually-priced bundle products are shown with full price, rather than an individual price within the bundle, which sums up to a different total that is shown in the Order Summary.

Solution

The simplest solution I found is to pass a single pre-tax pre-discount order item price to CollapsibleProductRowCardViewModel rather than Product.price. This mimics what Android implemented (https://github.com/woocommerce/woocommerce-android/blob/1e2829c413233e7a1a8602137ea8b2858b377386/WooCommerce/src/main/kotlin/com/woocommerce/android/model/Order.kt#L126) with introducing basePrice to Order Item. This is also could be considered a continuation of another fix #11012 which started using this single order item subtotal price to address order total calculation issues.

basePrice behaves as we would expect because it:

  • Shows a consistent price independent of Yes, I will enter prices inclusive of tax
  • Does not change when the quantity increases
  • Does not contain a discount
  • Works for simple products, variable products, individually priced product bundle products
  • Correctly sums up to what we see in the Order Summary at the bottom of the Order view
  • Reaches parity with Android, and web

Other existing Order Item properties do not satisfy these requirements:

  • OrderItem subtotal - excludes discounts and depends on item quantity
  • OrderItem total - includes discounts and depends on item quantity
  • OrderItem price - includes discounts
  • Product price - always static and doesn't take into account whether taxes are included or excluded from the product

Other not-addressed issues:

Simple Product

The product price is correctly displayed before tax which matches the "Products" line in the Order Summary

Before After
Simple Product - Before Simple Product - After

Simple Product + Discount

The product price is correctly displayed before which matches the "Products" line in the Order Summary

Before After
Simple Product - Product Discount - Before Simple Product - Product Discount - After

Variable Product + Discount

Before After
Variable Product - Product Discount - Before Variable Product - Product Discount - After

Product Bundle + Child item custom price

  • Before: Bundle products appear for $100, child items for $55 and $16 which totals to $171, however "Products" line shows $152.55
  • After: Bundle product appears for $90.91, child items for $50 and $11.64, which correctly totals to $152.55 as in "Products" line
Before After
Bundled Product - Before Bundled Product - After

Testing information

Checklist borrowed from pdfdoF-4rm-p2:

  1. With the Prices entered with tax setting – Yes, I will enter prices inclusive of tax
    1.1 When adding an item to an order –
    - The item's total should be equal to the item's price, excluding taxes.
    - Taxes total should be calculated based on the item's price excluding taxes.
    1.2 When incrementing a quantity of the item –
    - The items' total should be updated accordingly, excluding taxes.
    - Taxes total should be calculated based on the sum of items' prices excluding taxes.
    1.3 When adding a discount to the item –
    - The item's total should be reduced according to the discount amount.
    - Taxes total for that item should be calculated based on the item's total excluding taxes reduced by the discount amount.

  2. With the Prices entered with tax setting – No, I will enter prices exclusive of tax
    2.1 When adding an item to an order –
    - The item's total should be equal to the item's price, excluding taxes.
    - Taxes total should be calculated based on the item's price excluding taxes.
    2.2 When incrementing a quantity of the item –
    - The items' total should be updated accordingly, excluding taxes.
    - Taxes total should be calculated based on the sum of items' prices excluding taxes.
    2.3 When adding a discount to the item –
    - The item's total should be reduced according to the discount amount.
    - Taxes total for that item should be calculated based on the item's total excluding taxes reduced by the discount amount.

Testing steps (Borrowed from #11431)

  • Enable Yes, I will enter prices inclusive of tax tax setting
  • Go to the Orders tab
  • Tap on + to create an order
  • Add at least one product to the order -> Confirm the product appears in the order form with the expected product details, and with price excluding tax
  • Expand any product card and confirm you can update the product as expected (change quantity, add discount, remove product)
  • Tap "Create" to create the order -> Confirm the created order contains the products and quantities you added, and make a note of the prices shown in order details
  • Tap "Edit" to edit the order -> Confirm the order loads with the expected products and quantities, and with prices matching what was shown in order details

  • I have considered if this change warrants user-facing release notes and have added them to RELEASE-NOTES.txt if necessary.

@staskus staskus added type: bug A confirmed bug. feature: order creation All tasks related to creating an order labels Jul 11, 2024
@staskus staskus added this to the 19.6 milestone Jul 11, 2024
@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 11, 2024

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

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr13305-d7f137c
Version19.5
Bundle IDcom.automattic.alpha.woocommerce
Commitd7f137c
App Center BuildWooCommerce - Prototype Builds #10027
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

@staskus staskus marked this pull request as ready for review July 12, 2024 09:52
@staskus
Copy link
Collaborator Author

staskus commented Jul 12, 2024

@rachelmcr I would appreciate it if you could take a look at this 🙇 .

I opted to make as simple changes as possible to address the main issue - showing misleading prices in the product section when Yes, I will enter prices inclusive of tax setting is enabled.

In your previous PR #11431 you made further improvements around loading states and chose to pass additional properties to the collapsable card rather than using the existing price parameter. I will address loading states and other issues separately. However, as I tested it works fine passing single order item price to price parameter to make it all work. Let me know how you see it. Thanks again!

Copy link
Contributor

@iamgabrielma iamgabrielma left a comment

Choose a reason for hiding this comment

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

Thanks for taking care of this!

I found two things that behave oddly, but I think both precedes your changes and seem related to displaying the price without taking into account the store settings regarding inclusive/exclusive of taxes:

  1. When testing custom amounts note how using Yes, I will enter prices inclusive of tax still allows us to add additional tax on top of a custom amount, since can be edited by toggling the button.
Custom amount Toggle taxes
Simulator Screenshot - iPad Pro (12 9-inch) (6th generation) - 2024-07-16 at 12 08 23 Simulator Screenshot - iPad Pro (12 9-inch) (6th generation) - 2024-07-16 at 12 08 35
  1. Having products inclusive/exclusive of taxes seems to be ignored if we "Set new tax rate". In this example prices should already have taxes baked in, but upon setting a new tax it adds it to the current price 🤔

Simulator Screen Recording - iPad Pro (12 9-inch) (6th generation) - 2024-07-16 at 12 30 44

I don't have full context of the custom amounts/set tax features, but as mentioned these exist before your PR, so we should log/address them separately

@@ -137,7 +137,7 @@ public struct ProductInputTransformer {
product: product,
quantity: quantity,
discount: discount ?? defaultDiscount,
baseSubtotal: baseSubtotal(on: item),
baseSubtotal: item.pricePreDiscount.decimalValue,
Copy link
Contributor

Choose a reason for hiding this comment

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

While not part of this PR, the same as above: How about netPrice or basePrice for the property? I'd say baseSubtotal feels off since both base and subtotal should mean the same price-wise ( a base price without any modifiers).

@staskus staskus changed the title Use order item data for products in order creation/editing [Order form] Use order item data for products in order creation/editing Jul 16, 2024
…m price

When making order, we need to show a order item price for a single item without discounts and taxes. There's no property to support all of these requirements so we need to calculate it ourselves. This mimics the functionality that Android already has.
…diting/creation flow

When we have Tax setting "Yes, I will enter prices inclusive of tax" enabled, using product.price in Order view results in different information shown in Product List and Order Summary within Order View. Order Summary shows product prices without taxes, while Product List shows full price including the tax.

Use pre-discount single order item price which mimics the behavior on Android and on the web when displaying products within order.
…tTransformer

When calculating prices, Yosemite already uses pricePreDiscount logic within baseSubtotal method.
@staskus
Copy link
Collaborator Author

staskus commented Jul 16, 2024

Thanks for the review, @iamgabrielma!

When testing custom amounts note how using Yes, I will enter prices inclusive of tax still allows us to add additional tax on top of a custom amount, since can be edited by toggling the button.

I think it's fine behavior, no? Regardless of this setting, we still allow users to select whether a tax will be applied to the Custom Amount or not. Even if Yes, I will enter prices inclusive of tax is enabled but we choose not to charge taxes, then the taxes are not charged for this Custom Amount.

Your expected behavior would be that if Yes, I will enter prices inclusive of tax enabled, then tax should be applied by default to Custom Amount?

Having products inclusive/exclusive of taxes seems to be ignored if we "Set new tax rate". In this example prices should already have taxes baked in, but upon setting a new tax it adds it to the current price 🤔

I see what you mean and that's a very good point. I agree that if the product already includes taxes, then the total shouldn't change, just the pricePreDiscount. I cannot get it to work in the same way on wp-admin as well. It may be a problematic area in the app.

I created an issue: #13342 and may file a CUW p1721127325826489-slack-C025A8VV728

Edit: This issue is also reported on the web (woocommerce/woocommerce#30702). Even if it's a bug, it's not an app issue.

@staskus staskus force-pushed the fix/11389-use-order-item-data-in-order-form branch from 49e68f0 to 402e091 Compare July 16, 2024 10:57
@rachelmcr
Copy link
Contributor

I haven't looked closely at the code to see what's causing it, but these changes aren't working well for me in testing. Here's an example:

  • On my test store, my product prices include tax and tax is based on my store address.
  • My store address is in a location with a 6% sales tax.
  • I have a product that is $15.

When I add that product to an order on the web or in trunk, the order total is $15 ($14.15 for the product + $0.85 in tax). However, when I add that product to an order in this branch, it still shows the product with the price including tax, and it adds more tax on top of it for an order total of $15.90 ($15 for the product + $0.90 in tax).

Web App (trunk) App (this branch)
image image Simulator Screenshot - iPhone 15 Plus - 2024-07-16 at 18 32 34

I'm out of time to review this further today, but I'll take another look tomorrow to see if I can sort out why it isn't working for me.

@rachelmcr
Copy link
Contributor

Nevermind, you can ignore my last comment. I'm not sure what was happening with my testing on this branch earlier, but it's now all working as expected. Looks good!

The only issue I've seen is with the "Price after discount" amount when editing a product discount where the product quantity is > 1, but it looks like that is resolved with #13313.

In your previous PR #11431 you made further improvements around loading states and chose to pass additional properties to the collapsable card rather than using the existing price parameter. I will address loading states and other issues separately. However, as I tested it works fine passing single order item price to price parameter to make it all work. Let me know how you see it.

Your solution looks good to me! I can't remember why I approached it the way I did before, and this approach looks clean and easy to follow.

@staskus
Copy link
Collaborator Author

staskus commented Jul 17, 2024

Thanks for the review @rachelmcr! Appreciate that 🙇

I'm not sure what was happening with my testing on this branch earlier, but it's now all working as expected. Looks good!

Good to hear! Not sure what happened there as well 🤔

The only issue I've seen is with the "Price after discount" amount when editing a product discount where the product quantity is > 1, but it looks like that is resolved with #13313.

Yes, it was resolved there. I haven't merged this branch with trunk after merging the other PR.

@staskus staskus merged commit e2f8639 into trunk Jul 17, 2024
22 checks passed
@staskus staskus deleted the fix/11389-use-order-item-data-in-order-form branch July 17, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: order creation All tasks related to creating an order type: bug A confirmed bug.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Order form] Use order item data (especially price-related data) for products in order creation/editing
4 participants