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
[FW][FIX] website_sale_loyalty: allow to remove coupon from cart #156370
Closed
fw-bot
wants to merge
1
commit into
odoo:saas-16.2
from
odoo-dev:saas-16.2-16.0-opw-3744910-remove_coupon_from_cart-alhy-D7fZ-fw
Closed
[FW][FIX] website_sale_loyalty: allow to remove coupon from cart #156370
fw-bot
wants to merge
1
commit into
odoo:saas-16.2
from
odoo-dev:saas-16.2-16.0-opw-3744910-remove_coupon_from_cart-alhy-D7fZ-fw
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Steps to reproduce - Install eCommerce app - Go to Settings and enable Discounts, Loyalty & Gift Card option - Go to Website app > eCommerce > Loyalty > Discount & Loyalty - Create a new coupon by setting the Program Type to Coupons and then save. - Generate a new coupon by clicking the GENERATE COUPONS button. - Go to Website > site > Homepage - Go to Shop page - Add a product to the cart - Apply the coupon code created - Remove the coupon code by clicking the bin icon next to the coupon code line - The coupon code is NOT removed. Investigation First, we'll take a look on what happens when a coupon code is applied - When a coupon code is applied, a new sale.order.line is created for it. - That triggers `super()._compute_website_order_line()` https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L111 which filters out the discount order line https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale/models/sale_order.py#L66 via the `_show_in_cart()` method https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order_line.py#L12 - Then a new temporary sale.order.line is created by https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L121 meaning that is has no `id` - Note that we can only apply one coupon from the same program type. Second, Let's take a look on what happens when we try to remove a coupon code - A call is made to `cart_update_json()` which calls https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale/controllers/main.py#L811-L819 which calls https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L159 - But as noted above the coupon order line has no id being a temporary record. Hence the `line_id` is None which basically cancels the cart update. opw-3744910 X-original-commit: b121f8e
This PR targets saas-16.2 and is part of the forward-port chain. Further PRs will be created up to master. More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port |
@AH-Yussef @Demesmaeker the next pull request (#156383) is in conflict. You can merge the chain up to here by saying
More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port |
@fw-bot r+ |
robodoo
pushed a commit
that referenced
this pull request
Mar 4, 2024
Steps to reproduce - Install eCommerce app - Go to Settings and enable Discounts, Loyalty & Gift Card option - Go to Website app > eCommerce > Loyalty > Discount & Loyalty - Create a new coupon by setting the Program Type to Coupons and then save. - Generate a new coupon by clicking the GENERATE COUPONS button. - Go to Website > site > Homepage - Go to Shop page - Add a product to the cart - Apply the coupon code created - Remove the coupon code by clicking the bin icon next to the coupon code line - The coupon code is NOT removed. Investigation First, we'll take a look on what happens when a coupon code is applied - When a coupon code is applied, a new sale.order.line is created for it. - That triggers `super()._compute_website_order_line()` https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L111 which filters out the discount order line https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale/models/sale_order.py#L66 via the `_show_in_cart()` method https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order_line.py#L12 - Then a new temporary sale.order.line is created by https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L121 meaning that is has no `id` - Note that we can only apply one coupon from the same program type. Second, Let's take a look on what happens when we try to remove a coupon code - A call is made to `cart_update_json()` which calls https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale/controllers/main.py#L811-L819 which calls https://github.com/odoo/odoo/blob/d8ec7735aa8759fa94fc0223945ac9b19e05312e/addons/website_sale_loyalty/models/sale_order.py#L159 - But as noted above the coupon order line has no id being a temporary record. Hence the `line_id` is None which basically cancels the cart update. opw-3744910 closes #156370 X-original-commit: b121f8e Signed-off-by: Morgane Demesmaeker <edm@odoo.com> Signed-off-by: Ali Hassan Youssef (alhy) <alhy@odoo.com>
fw-bot
deleted the
saas-16.2-16.0-opw-3744910-remove_coupon_from_cart-alhy-D7fZ-fw
branch
March 19, 2024 01:47
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Steps to reproduce
Investigation
First, we'll take a look on what happens when a coupon code is applied
sale.order.line
is created for it.super()._compute_website_order_line()
odoo/addons/website_sale_loyalty/models/sale_order.py
Line 111 in d8ec773
odoo/addons/website_sale/models/sale_order.py
Line 66 in d8ec773
_show_in_cart()
methododoo/addons/website_sale_loyalty/models/sale_order_line.py
Line 12 in d8ec773
odoo/addons/website_sale_loyalty/models/sale_order.py
Line 121 in d8ec773
id
Second, Let's take a look on what happens when we try to remove a coupon code
cart_update_json()
which callsodoo/addons/website_sale/controllers/main.py
Lines 811 to 819 in d8ec773
odoo/addons/website_sale_loyalty/models/sale_order.py
Line 159 in d8ec773
has no id
being a temporary record. Hence theline_id
is None which basically cancels the cart update.opw-3744910
Forward-Port-Of: #154680