This PR fixes #3990 by enabling fields for coupon and b2bcoupon to be editable, and fixes name collision.
Screenshots (if appropriate):
[ ] Desktop screenshots
[ ] Mobile width screenshots
Steps to Reproduce(Coupon name collision)
Create a coupon code for a regular checkout
Or, Use /ecommerce/admin in your xPRO app and generate a coupon through the form
Get the coupon name(not coupon code) of the above created coupon and use it as a coupon code in B2BCoupon creation.
Try to redeem above created B2B coupon through /ecommerce/bulk
You will see an exception about the unique constraint failure in the Coupon Payment Name.
How can this be tested?
Verify that the fields in the Coupon and B2B Coupon models are editable.
Along with that, test, if there is no unique constraint failure in the Coupon Payment Name.
Create a coupon code for a regular checkout
you can use /ecommerce/admin in your xPRO app and generate a coupon through the form.
Create a coupon in B2BCoupon with the same Coupon Payment Name/Coupon name(not coupon code) as above.
Try to redeem above created B2B coupon through /ecommerce/bulk
It should be redeemed without any exception.
For the second point, ensure that completing a B2B order is tested with different discount percentages applied to the B2BCoupon:
Test completing a B2B order with and without full discounts applied.
This will facilitate testing of the changes being used in api/b2b/checkout/ and api/order_fulfillment/, with and without involvement from CyberSource.
Additional Context
This PR also addresses another edge case revealed during testing, which occurs in B2BCoupon redemption if an existing coupon payment name/coupon name is used as a coupon code for B2BCoupon creation. The fix for this edge case is included in this PR, as it is closely related to the main issue and its parent, rather than creating a separate issue and PR for the specific edge case.
@mudassir-hafeez Can you also add a test that checks the use case(s) of editing the same coupon? This will help us avoid hitting this bug in the future. e.g.
A test that checks the duplicate coupons is not allowed and a proper error is thrown
A test that checks that users can edit the coupon and perform other operations on it
What are the relevant tickets?
#3990
Description (What does it do?)
This PR fixes #3990 by enabling fields for coupon and b2bcoupon to be editable, and fixes name collision.
Screenshots (if appropriate):
Steps to Reproduce(Coupon name collision)
/ecommerce/admin
in your xPRO app and generate a coupon through the formB2BCoupon
creation./ecommerce/bulk
How can this be tested?
/ecommerce/admin
in your xPRO app and generate a coupon through the form./ecommerce/bulk
For the second point, ensure that completing a B2B order is tested with different discount percentages applied to the B2BCoupon:
Additional Context