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.
60 lines
2.0 KiB
Python
60 lines
2.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from openerp.tests import common
|
|
|
|
|
|
class TestSaleCouponCommon(common.TransactionCase):
|
|
|
|
def setUp(self):
|
|
super(TestSaleCouponCommon, self).setUp()
|
|
|
|
# Set all the existing programs to active=False to avoid interference
|
|
self.env['sale.coupon.program'].search([]).write({'active': False})
|
|
|
|
# create partner for sale order.
|
|
self.steve = self.env['res.partner'].create({
|
|
'name': 'Steve Bucknor',
|
|
'customer': True,
|
|
'email': 'steve.bucknor@example.com',
|
|
})
|
|
|
|
self.empty_order = self.env['sale.order'].create({
|
|
'partner_id': self.steve.id
|
|
})
|
|
|
|
self.uom_unit = self.env.ref('product.product_uom_unit')
|
|
|
|
#products
|
|
self.product_A = self.env['product.product'].create({
|
|
'name': 'Product A',
|
|
'list_price': 100,
|
|
'sale_ok': True
|
|
})
|
|
|
|
self.product_B = self.env['product.product'].create({
|
|
'name': 'Product B',
|
|
'list_price': 5,
|
|
'sale_ok': True
|
|
})
|
|
|
|
# Immediate Program By A + B: get B free
|
|
# No Conditions
|
|
self.immediate_promotion_program = self.env['sale.coupon.program'].create({
|
|
'name': 'Buy A + 1 B, 1 B are free',
|
|
'promo_code_usage': 'no_code_needed',
|
|
'reward_type': 'product',
|
|
'reward_product_id': self.product_B.id,
|
|
'rule_products_domain': "[('id', 'in', [%s])]" % (self.product_A.id),
|
|
'active': True,
|
|
})
|
|
|
|
self.code_promotion_program = self.env['sale.coupon.program'].create({
|
|
'name': 'Buy 1 A + Enter code, 1 A is free',
|
|
'promo_code_usage': 'code_needed',
|
|
'reward_type': 'product',
|
|
'reward_product_id': self.product_A.id,
|
|
'rule_products_domain': "[('id', 'in', [%s])]" % (self.product_A.id),
|
|
'active': True,
|
|
})
|