Initial import from Docker volume
This commit is contained in:
2
modules/sale_promotion/tests/__init__.py
Executable file
2
modules/sale_promotion/tests/__init__.py
Executable 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.
|
||||
BIN
modules/sale_promotion/tests/__pycache__/__init__.cpython-311.opt-1.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/__init__.cpython-311.opt-1.pyc
Executable file
Binary file not shown.
BIN
modules/sale_promotion/tests/__pycache__/__init__.cpython-311.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/__init__.cpython-311.pyc
Executable file
Binary file not shown.
BIN
modules/sale_promotion/tests/__pycache__/test_module.cpython-311.opt-1.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/test_module.cpython-311.opt-1.pyc
Executable file
Binary file not shown.
BIN
modules/sale_promotion/tests/__pycache__/test_module.cpython-311.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/test_module.cpython-311.pyc
Executable file
Binary file not shown.
BIN
modules/sale_promotion/tests/__pycache__/test_scenario.cpython-311.opt-1.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/test_scenario.cpython-311.opt-1.pyc
Executable file
Binary file not shown.
BIN
modules/sale_promotion/tests/__pycache__/test_scenario.cpython-311.pyc
Executable file
BIN
modules/sale_promotion/tests/__pycache__/test_scenario.cpython-311.pyc
Executable file
Binary file not shown.
150
modules/sale_promotion/tests/scenario_sale_promotion.rst
Executable file
150
modules/sale_promotion/tests/scenario_sale_promotion.rst
Executable file
@@ -0,0 +1,150 @@
|
||||
=======================
|
||||
Sale Promotion Scenario
|
||||
=======================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.account.tests.tools import create_chart, get_accounts
|
||||
>>> from trytond.modules.account_invoice.tests.tools import create_payment_term
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_promotion')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = get_accounts(company)
|
||||
>>> 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')
|
||||
>>> 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]})
|
||||
>>> 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.click('quote')
|
||||
>>> sale.untaxed_amount
|
||||
Decimal('470.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')
|
||||
92
modules/sale_promotion/tests/scenario_sale_promotion_amount.rst
Executable file
92
modules/sale_promotion/tests/scenario_sale_promotion_amount.rst
Executable file
@@ -0,0 +1,92 @@
|
||||
==============================
|
||||
Sale Promotion Amount Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_promotion')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_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 = company.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')
|
||||
13
modules/sale_promotion/tests/test_module.py
Executable file
13
modules/sale_promotion/tests/test_module.py
Executable 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 SalePromotionTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Sale Promotion module'
|
||||
module = 'sale_promotion'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_promotion/tests/test_scenario.py
Executable file
8
modules/sale_promotion/tests/test_scenario.py
Executable 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