[FIX] website_sale_loyalty: accrue points and create gift card codes
...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 <edm@odoo.com> Signed-off-by: Mylyna Hy (myhy) <myhy@odoo.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user