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

[FW][FIX] website_sale_loyalty: allow to remove coupon from cart #156370

Conversation

fw-bot
Copy link
Contributor

@fw-bot fw-bot commented 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

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
    values = order._cart_update(
    product_id=product_id,
    line_id=line_id,
    add_qty=add_qty,
    set_qty=set_qty,
    product_custom_attribute_values=product_custom_attribute_values,
    no_variant_attribute_values=no_variant_attribute_values,
    **kw
    )
    which calls
    def _cart_update(self, *args, **kwargs):
  • 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

Forward-Port-Of: #154680

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
@robodoo
Copy link
Contributor

robodoo commented Mar 4, 2024

@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 4, 2024

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

@robodoo robodoo added the forwardport This PR was created by @fw-bot label Mar 4, 2024
@fw-bot
Copy link
Contributor Author

fw-bot commented Mar 4, 2024

@AH-Yussef @Demesmaeker the next pull request (#156383) is in conflict. You can merge the chain up to here by saying

@fw-bot r+

More info at https://github.com/odoo/odoo/wiki/Mergebot#forward-port

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 4, 2024
@AH-Yussef
Copy link
Contributor

@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>
@robodoo robodoo closed this Mar 5, 2024
@fw-bot 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
forwardport This PR was created by @fw-bot OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants