first commit
This commit is contained in:
2
modules/sale_promotion_coupon/tests/__init__.py
Normal file
2
modules/sale_promotion_coupon/tests/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,124 @@
|
||||
==============================
|
||||
Sale Promotion Coupon Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'sale_promotion_coupon', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_revenue = revenue
|
||||
>>> account_category.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.salable = True
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create Promotion with coupon::
|
||||
|
||||
>>> Promotion = Model.get('sale.promotion')
|
||||
>>> promotion = Promotion(name="10%")
|
||||
>>> promotion.formula = '0.9 * unit_price'
|
||||
>>> coupon = promotion.coupons.new()
|
||||
>>> coupon.number_of_use = 0
|
||||
>>> number = coupon.numbers.new(number="CODE10")
|
||||
>>> promotion.save()
|
||||
|
||||
Sale without promotion coupon::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale.save()
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('100.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('100.00')
|
||||
|
||||
Add promotion coupon to the sale::
|
||||
|
||||
>>> sale.click('draft')
|
||||
>>> sale.coupons.extend(sale.coupons.find([('rec_name', '=', 'CODE10')]))
|
||||
>>> len(sale.coupons)
|
||||
1
|
||||
>>> sale.save()
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('100.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('90.00')
|
||||
|
||||
Check coupon inactive after usage::
|
||||
|
||||
>>> Number = Model.get('sale.promotion.coupon.number')
|
||||
>>> coupon, = promotion.coupons
|
||||
|
||||
>>> number, = Number.find([('rec_name', '=', 'CODE10')])
|
||||
>>> bool(number.active)
|
||||
True
|
||||
|
||||
>>> with config.set_context(party=customer.id):
|
||||
... number_party, = Number.find([('rec_name', '=', 'CODE10')])
|
||||
>>> bool(number_party.active)
|
||||
True
|
||||
|
||||
>>> coupon.number_of_use = 1
|
||||
>>> coupon.save()
|
||||
>>> number.reload()
|
||||
>>> bool(number.active)
|
||||
False
|
||||
>>> Number.find([('rec_name', '=', 'CODE10')])
|
||||
[]
|
||||
>>> number_party.reload()
|
||||
>>> bool(number_party.active)
|
||||
False
|
||||
>>> with config.set_context(party=customer.id):
|
||||
... Number.find([('rec_name', '=', 'CODE10')])
|
||||
[]
|
||||
|
||||
Cancel sale remove the coupons::
|
||||
|
||||
>>> sale.click('cancel')
|
||||
>>> len(sale.coupons)
|
||||
0
|
||||
@@ -0,0 +1,55 @@
|
||||
=====================================
|
||||
Sale Promotion Coupon Unique Scenario
|
||||
=====================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
>>> tomorrow = today + dt.timedelta(days=1)
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_promotion_coupon')
|
||||
|
||||
>>> Promotion = Model.get('sale.promotion')
|
||||
|
||||
Create a company::
|
||||
|
||||
>>> _ = create_company()
|
||||
|
||||
Create a promotion with coupon::
|
||||
|
||||
>>> promotion1 = Promotion(name="Promotion 1")
|
||||
>>> promotion1.formula = 'unit_price'
|
||||
>>> coupon = promotion1.coupons.new()
|
||||
>>> number = coupon.numbers.new(number="TEST", start_date=None)
|
||||
>>> promotion1.save()
|
||||
|
||||
Try to create a second promotion with same coupon number::
|
||||
|
||||
>>> promotion2 = Promotion(name="Promotion 2")
|
||||
>>> promotion2.formula = 'unit_price'
|
||||
>>> coupon = promotion2.coupons.new()
|
||||
>>> number = coupon.numbers.new(number="TEST")
|
||||
>>> promotion2.save()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
SQLConstraintError: ...
|
||||
|
||||
End the first promotion and start the second after::
|
||||
|
||||
>>> promotion1.end_date = today
|
||||
>>> promotion1.save()
|
||||
>>> coupon1 = promotion1.coupons[0].numbers[0]
|
||||
>>> coupon1.start_date
|
||||
>>> assertEqual(coupon1.end_date, today)
|
||||
|
||||
>>> coupon2 = promotion2.coupons[0].numbers[0]
|
||||
>>> coupon2.start_date = tomorrow
|
||||
>>> promotion2.save()
|
||||
13
modules/sale_promotion_coupon/tests/test_module.py
Normal file
13
modules/sale_promotion_coupon/tests/test_module.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.modules.company.tests import CompanyTestMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class SalePromotionCouponTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Sale Promotion Coupon module'
|
||||
module = 'sale_promotion_coupon'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_promotion_coupon/tests/test_scenario.py
Normal file
8
modules/sale_promotion_coupon/tests/test_scenario.py
Normal file
@@ -0,0 +1,8 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
|
||||
from trytond.tests.test_tryton import load_doc_tests
|
||||
|
||||
|
||||
def load_tests(*args, **kwargs):
|
||||
return load_doc_tests(__name__, __file__, *args, **kwargs)
|
||||
Reference in New Issue
Block a user