Purpose ======= Currently we are updating the coupon rewards on the fly when creating/modifying/deleting a sales order line. To avoid multiple searches on res_partners and product to know whether the customer/product is valid on the sale coupon program, we store the applicable customers and products on the program according to the domain defined on it. This brings 2 issues: - The customers/products stored on the program are not updated (Was the original spec) - The checks are numerous and maybe overkill for the given results Specification ============= - Don't recompute the reward lines on SO modifications. Add a button to compute the line by hand and make an automatic compute on the SO validation or on the page shop/payment. - When recomputing the reward lines, make a search on the res_partners and products instead. Now that the action is not triggered so often we can afford to make a search. - Don't use the fields rule_partners_domain and rule_products_domain. This should be removed in master. - The field is_public_included is useless now. And we decided to make the coupon available for all the partners if they fit the domain on the program.
64 lines
2.3 KiB
Python
64 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from openerp.addons.sale_coupon.tests.common import TestSaleCouponCommon
|
|
|
|
class TestSaleCouponProgramRules(TestSaleCouponCommon):
|
|
# Test all the kind of reward a customer can receive.
|
|
# The product reward is already tested in the basic operations test
|
|
|
|
def test_program_rewards(self):
|
|
# Test case: Based on the partners domain
|
|
|
|
self.immediate_promotion_program.write({'reward_type': "discount"})
|
|
|
|
order = self.empty_order
|
|
order.write({'order_line': [
|
|
(0, False, {
|
|
'product_id': self.product_A.id,
|
|
'name': '1 Product A',
|
|
'product_uom': self.uom_unit.id,
|
|
'product_uom_qty': 1.0,
|
|
}),
|
|
(0, False, {
|
|
'product_id': self.product_B.id,
|
|
'name': '2 Product B',
|
|
'product_uom': self.uom_unit.id,
|
|
'product_uom_qty': 1.0,
|
|
})
|
|
]})
|
|
order.recompute_coupon_lines()
|
|
self.assertEqual(len(order.order_line.ids), 3, "The promo offert should have been applied as the partner is correct, the discount is not created")
|
|
|
|
|
|
def test_program_rewards_discount(self):
|
|
|
|
# Test case 1: 1% discount on total order
|
|
program = self.env['sale.coupon.program'].create({
|
|
'name': 'Buy at least 1000 EUR, ',
|
|
'rule_minimum_amount': 1000.0,
|
|
'promo_code_usage': 'no_code_needed',
|
|
'reward_type': 'discount',
|
|
'discount_type': 'percentage',
|
|
'discount_percentage': 1.0,
|
|
'discount_apply_on': 'on_order',
|
|
'active': True,
|
|
})
|
|
order = self.env['sale.order'].create({
|
|
'partner_id': self.steve.id
|
|
})
|
|
self.env['sale.order.line'].create({
|
|
'product_id': self.product_A.id,
|
|
'name': '1 Product A',
|
|
'product_uom': self.uom_unit.id,
|
|
'product_uom_qty': 11.0,
|
|
'order_id': order.id,
|
|
})
|
|
self.env['sale.order.line'].create({
|
|
'product_id': self.product_B.id,
|
|
'name': '2 Product B',
|
|
'product_uom': self.uom_unit.id,
|
|
'product_uom_qty': 1.0,
|
|
'order_id': order.id,
|
|
})
|