first commit
This commit is contained in:
2
modules/sale_promotion/tests/__init__.py
Normal file
2
modules/sale_promotion/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.
166
modules/sale_promotion/tests/scenario_sale_promotion.rst
Normal file
166
modules/sale_promotion/tests/scenario_sale_promotion.rst
Normal file
@@ -0,0 +1,166 @@
|
||||
=======================
|
||||
Sale Promotion Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_tax, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import create_payment_term
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_promotion', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create a tax::
|
||||
|
||||
>>> tax = create_tax(Decimal('0.1'))
|
||||
|
||||
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.customer_taxes.append(tax)
|
||||
>>> account_category.save()
|
||||
|
||||
Create products::
|
||||
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Product = Model.get('product.product')
|
||||
>>> Category = Model.get('product.category')
|
||||
|
||||
>>> category = Category(name="Root")
|
||||
>>> category1 = category.childs.new(name="Child 1")
|
||||
>>> category1b = category1.childs.new(name="Child 1b")
|
||||
>>> category2 = category.childs.new(name="Child 2")
|
||||
>>> category.save()
|
||||
>>> category1, category2 = category.childs
|
||||
>>> category1b, = category1.childs
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Product'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'goods'
|
||||
>>> template.salable = True
|
||||
>>> template.lead_time = datetime.timedelta(0)
|
||||
>>> template.list_price = Decimal('20')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.categories.append(Category(category1b.id))
|
||||
>>> template.save()
|
||||
>>> product1 = Product()
|
||||
>>> product1.template = template
|
||||
>>> product1.save()
|
||||
>>> product2 = Product()
|
||||
>>> product2.template = template
|
||||
>>> product2.save()
|
||||
>>> product3 = Product()
|
||||
>>> product3.template = template
|
||||
>>> product3.save()
|
||||
|
||||
>>> template4, = template.duplicate(default={'categories': [category2.id]})
|
||||
>>> template4.account_category = account_category
|
||||
>>> template4.save()
|
||||
>>> product4 = Product(template4.products[0].id)
|
||||
|
||||
Create payment term::
|
||||
|
||||
>>> payment_term = create_payment_term()
|
||||
>>> payment_term.save()
|
||||
|
||||
Create Promotion::
|
||||
|
||||
>>> Promotion = Model.get('sale.promotion')
|
||||
>>> promotion = Promotion(name='10% on 10 products 1 or 2')
|
||||
>>> promotion.quantity = 10
|
||||
>>> promotion.unit = unit
|
||||
>>> promotion.products.extend([product1, product2, product4])
|
||||
>>> promotion.categories.append(Category(category1.id))
|
||||
>>> promotion.formula = '0.9 * unit_price'
|
||||
>>> promotion.save()
|
||||
|
||||
Sale enough products for promotion::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product1
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product2
|
||||
>>> sale_line.quantity = 10
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product3
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product4
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale.save()
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('500.00')
|
||||
>>> sale.tax_amount
|
||||
Decimal('50.00')
|
||||
>>> sale.total_amount
|
||||
Decimal('550.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('470.00')
|
||||
>>> sale.tax_amount
|
||||
Decimal('47.00')
|
||||
>>> sale.total_amount
|
||||
Decimal('517.00')
|
||||
>>> sale.original_untaxed_amount
|
||||
Decimal('500.00')
|
||||
>>> sale.original_tax_amount
|
||||
Decimal('50.00')
|
||||
>>> sale.original_total_amount
|
||||
Decimal('550.00')
|
||||
|
||||
Go back to draft reset the original price::
|
||||
|
||||
>>> sale.click('draft')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('500.00')
|
||||
|
||||
Sale not enough products for promotion::
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale.payment_term = payment_term
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product1
|
||||
>>> sale_line.quantity = 5
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product2
|
||||
>>> sale_line.quantity = 3
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product3
|
||||
>>> sale_line.quantity = 10
|
||||
>>> sale.save()
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('360.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('360.00')
|
||||
@@ -0,0 +1,88 @@
|
||||
==============================
|
||||
Sale Promotion Amount Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.modules.currency.tests.tools import get_currency
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_promotion', create_company)
|
||||
|
||||
Create customer::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.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.save()
|
||||
>>> product1 = Product()
|
||||
>>> product1.template = template
|
||||
>>> product1.save()
|
||||
>>> product2 = Product()
|
||||
>>> product2.template = template
|
||||
>>> product2.save()
|
||||
|
||||
Create Promotion::
|
||||
|
||||
>>> Promotion = Model.get('sale.promotion')
|
||||
>>> promotion = Promotion(name='product 2 free')
|
||||
>>> promotion.amount = Decimal('100')
|
||||
>>> promotion.currency = get_currency()
|
||||
>>> promotion.products.extend([product2])
|
||||
>>> promotion.formula = '0.0'
|
||||
>>> promotion.save()
|
||||
|
||||
Sale enough for promotion::
|
||||
|
||||
>>> Sale = Model.get('sale.sale')
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product1
|
||||
>>> sale_line.quantity = 4
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product2
|
||||
>>> sale_line.quantity = 2
|
||||
>>> sale.save()
|
||||
>>> sale.total_amount
|
||||
Decimal('120.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('80.00')
|
||||
|
||||
Sale not enough for promotion::
|
||||
|
||||
>>> sale = Sale()
|
||||
>>> sale.party = customer
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product1
|
||||
>>> sale_line.quantity = 2
|
||||
>>> sale_line = sale.lines.new()
|
||||
>>> sale_line.product = product2
|
||||
>>> sale_line.quantity = 2
|
||||
>>> sale.save()
|
||||
>>> sale.total_amount
|
||||
Decimal('80.00')
|
||||
>>> sale.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('80.00')
|
||||
14
modules/sale_promotion/tests/test_module.py
Normal file
14
modules/sale_promotion/tests/test_module.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# 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 SalePromotionTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Sale Promotion module'
|
||||
module = 'sale_promotion'
|
||||
extras = ['sale_point']
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_promotion/tests/test_scenario.py
Normal file
8
modules/sale_promotion/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