From 57ecc833fddc2ad2c1886f03b68f4e7e0a0d203a Mon Sep 17 00:00:00 2001 From: Mylyna Hy Date: Mon, 18 Dec 2023 16:36:10 -0800 Subject: [PATCH] [FIX] website_sale_loyalty: accrue points and create gift card codes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ...for orders made through Sales with loyalty programs that uses websites Problem: For loyalty & gift card programs that has sales and website enabled along with a specified website, the loyalty points will not accrue and gift card codes will generates for products if the SO was created with the Sales app. Solution: The SO ordered through the website should filter based on the website_id. SOs created through Sales will not have a website_id, thus, no need to add an extra filter for website_id. Gift card codes will generate and loyalty points will accrue for orders made through Sales even if the program has a website specified. Steps to Reproduce on Runbot 16: Create a new product of the type consumable Go to Sales > Products > Gift cards & eWallet and click on NEW For the Gift Card Products field add the previously created product For the website field specify a specific website (e.g. My Website) Create a new sale order for the originally created product Confirm the sale order Click on the Customer Preview smart button You won’t see a gift card code anywhere when it should have been generated & Loyalty points are not accrued opw-3550278 opw-3587226 closes odoo/odoo#149320 X-original-commit: eed913463ea4824586373cae608d7cfcb2ff20fc Signed-off-by: Morgane Demesmaeker Signed-off-by: Mylyna Hy (myhy) --- .../website_sale_loyalty/models/sale_order.py | 8 ++--- .../tests/test_sale_coupon_multiwebsite.py | 30 +++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/addons/website_sale_loyalty/models/sale_order.py b/addons/website_sale_loyalty/models/sale_order.py index d43e4232190..9efa1a22368 100644 --- a/addons/website_sale_loyalty/models/sale_order.py +++ b/addons/website_sale_loyalty/models/sale_order.py @@ -24,8 +24,8 @@ class SaleOrder(models.Model): if leaf[0] != 'sale_ok': continue res[idx] = ('ecommerce_ok', '=', True) - break - return expression.AND([res, [('website_id', 'in', (self.website_id.id, False))]]) + return expression.AND([res, [('website_id', 'in', (self.website_id.id, False))]]) + return res def _get_trigger_domain(self): res = super()._get_trigger_domain() @@ -35,8 +35,8 @@ class SaleOrder(models.Model): if leaf[0] != 'program_id.sale_ok': continue res[idx] = ('program_id.ecommerce_ok', '=', True) - break - return expression.AND([res, [('program_id.website_id', 'in', (self.website_id.id, False))]]) + return expression.AND([res, [('program_id.website_id', 'in', (self.website_id.id, False))]]) + return res def _try_pending_coupon(self): if not request: diff --git a/addons/website_sale_loyalty/tests/test_sale_coupon_multiwebsite.py b/addons/website_sale_loyalty/tests/test_sale_coupon_multiwebsite.py index 744577279aa..a0d2af492f9 100644 --- a/addons/website_sale_loyalty/tests/test_sale_coupon_multiwebsite.py +++ b/addons/website_sale_loyalty/tests/test_sale_coupon_multiwebsite.py @@ -55,9 +55,16 @@ class TestSaleCouponMultiwebsite(TestSaleCouponNumbersCommon): # make program specific self.p1.website_id = self.website.id - # 3. Backend - Specific + # 3. Backend - Specific - sale_ok disabled + self.p1.sale_ok = False with self.assertRaises(UserError): - _apply_code(self.p1.rule_ids.code) # the order has no website_id so not possible to use a website specific code + _apply_code(self.p1.rule_ids.code) # the program is not enabled for Sales (backend) + + # 3.5. Backend - Specific - sale_ok enabled + self.p1.sale_ok = True + _apply_code(self.p1.rule_ids.code) + self.assertEqual(len(order.order_line.ids), 2, "Should get the discount line as it is enabled for Sales(backend)") + _remove_reward() # 4. Frontend - Specific - Correct website order.website_id = self.website.id @@ -96,9 +103,16 @@ class TestSaleCouponMultiwebsite(TestSaleCouponNumbersCommon): # make program specific self.discount_coupon_program.website_id = self.website.id - # 3. Backend - Specific + # 3. Backend - Specific - sale_ok disabled + self.discount_coupon_program.sale_ok = False with self.assertRaises(UserError): - _apply_code(coupons[2].code) # the order has no website_id so not possible to use a website specific code + _apply_code(coupons[2].code) # the program is not enabled for Sales (backend) + + # 3.5. Backend - Specific - sale_ok enabled + self.discount_coupon_program.sale_ok = True + _apply_code(coupons[2].code) + self.assertEqual(len(order.order_line.ids), 2, "Should get the discount line as it is enabled for Sales(backend)") + _remove_reward() # 4. Frontend - Specific - Correct website order.website_id = self.website.id @@ -136,8 +150,14 @@ class TestSaleCouponMultiwebsite(TestSaleCouponNumbersCommon): # make program specific self.p1.website_id = self.website.id # 3. Backend - Specific + self.p1.sale_ok = False self._auto_rewards(order, all_programs) - self.assertEqual(len(order.order_line.ids), 1, "The order has no website_id so not possible to use a website specific code") + self.assertEqual(len(order.order_line.ids), 1, "The program is not enabled for Sales (backend)") + + # 3.5. Backend - Specific - sale_ok enabled + self.p1.sale_ok = True + self._auto_rewards(order, all_programs) + self.assertEqual(len(order.order_line.ids), 2, "Should get the discount line as it is a generic promo program") # 4. Frontend - Specific - Correct website order.website_id = self.website.id