first commit
This commit is contained in:
2
modules/sale_subscription/tests/__init__.py
Normal file
2
modules/sale_subscription/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.
190
modules/sale_subscription/tests/scenario_sale_subscription.rst
Normal file
190
modules/sale_subscription/tests/scenario_sale_subscription.rst
Normal file
@@ -0,0 +1,190 @@
|
||||
==========================
|
||||
Sale Subscription Scenario
|
||||
==========================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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, assertEqual
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('sale_subscription', create_company, create_chart)
|
||||
|
||||
Create sale user::
|
||||
|
||||
>>> User = Model.get('res.user')
|
||||
>>> Group = Model.get('res.group')
|
||||
|
||||
>>> sale_user = User()
|
||||
>>> sale_user.name = 'Sale'
|
||||
>>> sale_user.login = 'sale'
|
||||
>>> sale_group, = Group.find([('name', '=', 'Sales')])
|
||||
>>> sale_user.groups.append(sale_group)
|
||||
>>> sale_user.save()
|
||||
|
||||
Create product user::
|
||||
|
||||
>>> product_user = User()
|
||||
>>> product_user.name = 'Product'
|
||||
>>> product_user.login = 'product'
|
||||
>>> product_group, = Group.find([('name', '=', 'Product Administration')])
|
||||
>>> product_user.groups.append(product_group)
|
||||
>>> product_user.save()
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create subscription recurrence rule sets::
|
||||
|
||||
>>> RecurrenceRuleSet = Model.get('sale.subscription.recurrence.rule.set')
|
||||
|
||||
>>> monthly = RecurrenceRuleSet(name='Monthly')
|
||||
>>> rule, = monthly.rules
|
||||
>>> rule.freq = 'monthly'
|
||||
>>> rule.interval = 1
|
||||
>>> monthly.save()
|
||||
|
||||
>>> daily = RecurrenceRuleSet(name='Daily')
|
||||
>>> rule, = daily.rules
|
||||
>>> rule.freq = 'daily'
|
||||
>>> rule.interval = 1
|
||||
>>> daily.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 subscription service::
|
||||
|
||||
>>> Service = Model.get('sale.subscription.service')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Uom = Model.get('product.uom')
|
||||
|
||||
>>> unit, = Uom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Rental'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> service = Service()
|
||||
>>> service.product = product
|
||||
>>> service.consumption_recurrence = daily
|
||||
>>> service.save()
|
||||
|
||||
Subscribe::
|
||||
|
||||
>>> Subscription = Model.get('sale.subscription')
|
||||
|
||||
>>> subscription = Subscription()
|
||||
>>> subscription.party = customer
|
||||
>>> subscription.start_date = datetime.date(2016, 1, 1)
|
||||
>>> subscription.invoice_start_date = datetime.date(2016, 2, 1)
|
||||
>>> subscription.invoice_recurrence = monthly
|
||||
>>> line = subscription.lines.new()
|
||||
>>> line.service = service
|
||||
>>> line.quantity = 10
|
||||
>>> assertEqual(line.start_date, subscription.start_date)
|
||||
|
||||
>>> subscription.click('quote')
|
||||
>>> subscription.state
|
||||
'quotation'
|
||||
>>> subscription.click('run')
|
||||
>>> subscription.state
|
||||
'running'
|
||||
|
||||
Create line consumption::
|
||||
|
||||
>>> LineConsumption = Model.get('sale.subscription.line.consumption')
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2016, 1, 31)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
31
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> line, = subscription.lines
|
||||
>>> line.next_consumption_date
|
||||
datetime.date(2016, 2, 1)
|
||||
|
||||
Create subscription invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2016, 2, 1)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> invoice, = Invoice.find([])
|
||||
>>> invoice.invoice_date
|
||||
datetime.date(2016, 2, 1)
|
||||
>>> line, = invoice.lines
|
||||
>>> line.quantity
|
||||
310.0
|
||||
>>> line.unit_price
|
||||
Decimal('10.0000')
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 3, 1)
|
||||
|
||||
Close subscription::
|
||||
|
||||
>>> subscription.click('draft')
|
||||
>>> subscription.state
|
||||
'draft'
|
||||
>>> line, = subscription.lines
|
||||
>>> line.end_date = datetime.date(2016, 1, 31)
|
||||
>>> subscription.click('quote')
|
||||
>>> subscription.click('run')
|
||||
>>> subscription.state
|
||||
'running'
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2016, 2, 1)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
31
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> line, = subscription.lines
|
||||
>>> line.next_consumption_date
|
||||
>>> subscription.state
|
||||
'closed'
|
||||
|
||||
Create final subscription invoice::
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2016, 3, 1)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> len(Invoice.find([]))
|
||||
1
|
||||
@@ -0,0 +1,170 @@
|
||||
================================================
|
||||
Sale Subscription with Advanced Invoice Scenario
|
||||
================================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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_subscription', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create subscription recurrence rule sets::
|
||||
|
||||
>>> RecurrenceRuleSet = Model.get('sale.subscription.recurrence.rule.set')
|
||||
|
||||
>>> monthly_in_advance = RecurrenceRuleSet(name='Monthly in advance')
|
||||
>>> rule, = monthly_in_advance.rules
|
||||
>>> rule.freq = 'monthly'
|
||||
>>> rule.interval = 1
|
||||
>>> rule.bymonthday = '-1'
|
||||
>>> monthly_in_advance.save()
|
||||
|
||||
>>> monthly = RecurrenceRuleSet(name='Monthly')
|
||||
>>> rule, = monthly.rules
|
||||
>>> rule.freq = 'monthly'
|
||||
>>> rule.interval = 1
|
||||
>>> rule.bymonthday = '1'
|
||||
>>> monthly.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 subscription service::
|
||||
|
||||
>>> Service = Model.get('sale.subscription.service')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Uom = Model.get('product.uom')
|
||||
|
||||
>>> unit, = Uom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Rental'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> service = Service()
|
||||
>>> service.product = product
|
||||
>>> service.consumption_recurrence = monthly
|
||||
>>> service.consumption_delay = datetime.timedelta(days=-1)
|
||||
>>> service.save()
|
||||
|
||||
Subscribe with start date greater than invoice start date::
|
||||
|
||||
>>> Subscription = Model.get('sale.subscription')
|
||||
|
||||
>>> subscription = Subscription()
|
||||
>>> subscription.party = customer
|
||||
>>> subscription.start_date = datetime.date(2016, 2, 1)
|
||||
>>> subscription.invoice_start_date = datetime.date(2016, 1, 31)
|
||||
>>> subscription.invoice_recurrence = monthly_in_advance
|
||||
>>> line = subscription.lines.new()
|
||||
>>> line.service = service
|
||||
>>> line.quantity = 10
|
||||
|
||||
>>> subscription.click('quote')
|
||||
>>> subscription.click('run')
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 1, 31)
|
||||
>>> line, = subscription.lines
|
||||
>>> line.next_consumption_date_delayed
|
||||
datetime.date(2016, 1, 31)
|
||||
|
||||
Create line consumption::
|
||||
|
||||
>>> LineConsumption = Model.get('sale.subscription.line.consumption')
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2016, 1, 31)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
1
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 1, 31)
|
||||
>>> line, = subscription.lines
|
||||
>>> line.next_consumption_date
|
||||
datetime.date(2016, 3, 1)
|
||||
>>> line.next_consumption_date_delayed
|
||||
datetime.date(2016, 2, 29)
|
||||
|
||||
Create subscription invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2016, 1, 31)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> invoice, = Invoice.find([])
|
||||
>>> line, = invoice.lines
|
||||
>>> line.quantity
|
||||
10.0
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 2, 29)
|
||||
|
||||
Consume and invoice again::
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2016, 2, 29)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
2
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 2, 29)
|
||||
>>> line, = subscription.lines
|
||||
>>> line.next_consumption_date
|
||||
datetime.date(2016, 4, 1)
|
||||
>>> line.next_consumption_date_delayed
|
||||
datetime.date(2016, 3, 31)
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2016, 2, 29)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> invoice2, = Invoice.find([('id', '!=', invoice.id)])
|
||||
>>> line, = invoice2.lines
|
||||
>>> line.quantity
|
||||
10.0
|
||||
|
||||
>>> subscription.reload()
|
||||
>>> subscription.next_invoice_date
|
||||
datetime.date(2016, 3, 31)
|
||||
@@ -0,0 +1,156 @@
|
||||
===================================
|
||||
Sale Subscription New Line Scenario
|
||||
===================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> 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_subscription', create_company, create_chart)
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = get_accounts()
|
||||
>>> revenue = accounts['revenue']
|
||||
|
||||
Create party::
|
||||
|
||||
>>> Party = Model.get('party.party')
|
||||
|
||||
>>> customer = Party(name='Customer')
|
||||
>>> customer.save()
|
||||
|
||||
Create subscription recurrence rule sets::
|
||||
|
||||
>>> RecurrenceRuleSet = Model.get('sale.subscription.recurrence.rule.set')
|
||||
|
||||
>>> monthly = RecurrenceRuleSet(name='Monthly')
|
||||
>>> rule, = monthly.rules
|
||||
>>> rule.freq = 'monthly'
|
||||
>>> rule.interval = 1
|
||||
>>> monthly.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 subscription service::
|
||||
|
||||
>>> Service = Model.get('sale.subscription.service')
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> Uom = Model.get('product.uom')
|
||||
|
||||
>>> unit, = Uom.find([('name', '=', 'Unit')])
|
||||
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = 'Rental'
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('10')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
>>> service = Service()
|
||||
>>> service.product = product
|
||||
>>> service.consumption_recurrence = monthly
|
||||
>>> service.save()
|
||||
|
||||
Subscribe::
|
||||
|
||||
>>> Subscription = Model.get('sale.subscription')
|
||||
|
||||
>>> subscription = Subscription()
|
||||
>>> subscription.party = customer
|
||||
>>> subscription.start_date = datetime.date(2019, 1, 1)
|
||||
>>> subscription.invoice_recurrence = monthly
|
||||
>>> line = subscription.lines.new()
|
||||
>>> line.service = service
|
||||
>>> line.quantity = 1
|
||||
>>> subscription.click('quote')
|
||||
>>> subscription.state
|
||||
'quotation'
|
||||
>>> subscription.click('run')
|
||||
>>> subscription.state
|
||||
'running'
|
||||
|
||||
Create consumption for next two months::
|
||||
|
||||
>>> LineConsumption = Model.get('sale.subscription.line.consumption')
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2019, 2, 1)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
2
|
||||
|
||||
Create invoice for next two months::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2019, 2, 1)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> invoice, = Invoice.find([])
|
||||
>>> line, = invoice.lines
|
||||
>>> line.quantity
|
||||
2.0
|
||||
>>> line.unit_price
|
||||
Decimal('10.0000')
|
||||
|
||||
Close subscription::
|
||||
|
||||
>>> subscription.click('draft')
|
||||
>>> subscription.state
|
||||
'draft'
|
||||
>>> line, = subscription.lines
|
||||
>>> line.consumed_until
|
||||
datetime.date(2019, 2, 28)
|
||||
>>> line.end_date = datetime.date(2019, 2, 28)
|
||||
>>> new_line = subscription.lines.new()
|
||||
>>> new_line.service = service
|
||||
>>> new_line.quantity = 1
|
||||
>>> new_line.start_date = datetime.date(2019, 3, 1)
|
||||
>>> new_line.unit_price = Decimal('15.00')
|
||||
>>> subscription.click('quote')
|
||||
>>> subscription.click('run')
|
||||
>>> subscription.state
|
||||
'running'
|
||||
|
||||
>>> line_consumption_create = Wizard(
|
||||
... 'sale.subscription.line.consumption.create')
|
||||
>>> line_consumption_create.form.date = datetime.date(2019, 3, 1)
|
||||
>>> line_consumption_create.execute('create_')
|
||||
|
||||
>>> len(LineConsumption.find([]))
|
||||
3
|
||||
|
||||
Create next invoice::
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
|
||||
>>> create_invoice = Wizard('sale.subscription.create_invoice')
|
||||
>>> create_invoice.form.date = datetime.date(2019, 3, 1)
|
||||
>>> create_invoice.execute('create_')
|
||||
|
||||
>>> new_invoice, = Invoice.find([('id', '!=', invoice.id)])
|
||||
>>> line, = new_invoice.lines
|
||||
>>> line.quantity
|
||||
1.0
|
||||
>>> line.unit_price
|
||||
Decimal('15.00')
|
||||
17
modules/sale_subscription/tests/test_module.py
Normal file
17
modules/sale_subscription/tests/test_module.py
Normal file
@@ -0,0 +1,17 @@
|
||||
# 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, PartyCompanyCheckEraseMixin)
|
||||
from trytond.modules.party.tests import PartyCheckReplaceMixin
|
||||
from trytond.tests.test_tryton import ModuleTestCase
|
||||
|
||||
|
||||
class SaleSubscriptionTestCase(
|
||||
PartyCompanyCheckEraseMixin, PartyCheckReplaceMixin, CompanyTestMixin,
|
||||
ModuleTestCase):
|
||||
'Test Sale Subscription module'
|
||||
module = 'sale_subscription'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/sale_subscription/tests/test_scenario.py
Normal file
8
modules/sale_subscription/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