first commit
This commit is contained in:
2
modules/account_invoice_defer/tests/__init__.py
Normal file
2
modules/account_invoice_defer/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.
Binary file not shown.
@@ -0,0 +1,124 @@
|
||||
==============================
|
||||
Account Invoice Defer Scenario
|
||||
==============================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.account_invoice_defer.tests.tools import (
|
||||
... add_deferred_accounts)
|
||||
>>> from trytond.modules.company.tests.tools import create_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules(
|
||||
... 'account_invoice_defer', create_company, create_chart)
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> InvoiceDeferred = Model.get('account.invoice.deferred')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(today=today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
Get accounts::
|
||||
|
||||
>>> accounts = add_deferred_accounts(get_accounts())
|
||||
|
||||
Create party::
|
||||
|
||||
>>> party = Party(name="Insurer")
|
||||
>>> party.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.account_revenue = accounts['revenue']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Insurance"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('1000')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> invoice = Invoice(type='in')
|
||||
>>> invoice.party = party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('1000')
|
||||
>>> line.defer_from = period.start_date
|
||||
>>> line.defer_to = line.defer_from + dt.timedelta(days=499)
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
>>> invoice_line, = invoice.lines
|
||||
|
||||
Check invoice deferred and run it::
|
||||
|
||||
>>> deferral, = InvoiceDeferred.find([])
|
||||
>>> assertEqual(deferral.invoice_line, invoice_line)
|
||||
>>> deferral.amount
|
||||
Decimal('1000.00')
|
||||
>>> assertEqual(deferral.start_date, invoice_line.defer_from)
|
||||
>>> assertEqual(deferral.end_date, invoice_line.defer_to)
|
||||
>>> deferral.click('run')
|
||||
|
||||
Check moves on invoice deferred::
|
||||
|
||||
>>> deferral.reload()
|
||||
>>> deferral.state
|
||||
'running'
|
||||
>>> len(deferral.moves)
|
||||
13
|
||||
>>> accounts['deferred_expense'].reload()
|
||||
>>> Decimal('268') <= accounts['deferred_expense'].balance <= Decimal('271')
|
||||
True
|
||||
|
||||
Define next fiscal year::
|
||||
|
||||
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
|
||||
>>> renew_fiscalyear.execute('create_')
|
||||
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
|
||||
|
||||
Create moves::
|
||||
|
||||
>>> create_moves = Wizard('account.invoice.deferred.create_moves')
|
||||
|
||||
Check moves on invoice deferred::
|
||||
|
||||
>>> deferral.reload()
|
||||
>>> deferral.state
|
||||
'closed'
|
||||
>>> len(deferral.moves)
|
||||
18
|
||||
>>> accounts['deferred_expense'].reload()
|
||||
>>> accounts['deferred_expense'].balance
|
||||
Decimal('0.00')
|
||||
@@ -0,0 +1,112 @@
|
||||
===================================
|
||||
Account Invoice Defer Once Scenario
|
||||
===================================
|
||||
|
||||
Imports::
|
||||
|
||||
>>> import datetime as dt
|
||||
>>> from decimal import Decimal
|
||||
|
||||
>>> from proteus import Model, Wizard
|
||||
>>> from trytond.modules.account.tests.tools import (
|
||||
... create_chart, create_fiscalyear, get_accounts)
|
||||
>>> from trytond.modules.account_invoice.tests.tools import (
|
||||
... set_fiscalyear_invoice_sequences)
|
||||
>>> from trytond.modules.account_invoice_defer.tests.tools import (
|
||||
... add_deferred_accounts)
|
||||
>>> from trytond.modules.company.tests.tools import create_company, get_company
|
||||
>>> from trytond.tests.tools import activate_modules, assertEqual
|
||||
|
||||
>>> today = dt.date.today()
|
||||
|
||||
Activate modules::
|
||||
|
||||
>>> config = activate_modules('account_invoice_defer')
|
||||
|
||||
>>> Invoice = Model.get('account.invoice')
|
||||
>>> InvoiceDeferred = Model.get('account.invoice.deferred')
|
||||
>>> Party = Model.get('party.party')
|
||||
>>> ProductCategory = Model.get('product.category')
|
||||
>>> ProductUom = Model.get('product.uom')
|
||||
|
||||
Create company::
|
||||
|
||||
>>> _ = create_company()
|
||||
>>> company = get_company()
|
||||
|
||||
Create fiscal year::
|
||||
|
||||
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
||||
... create_fiscalyear(company, today))
|
||||
>>> fiscalyear.click('create_period')
|
||||
>>> period = fiscalyear.periods[0]
|
||||
|
||||
>>> renew_fiscalyear = Wizard('account.fiscalyear.renew')
|
||||
>>> renew_fiscalyear.execute('create_')
|
||||
>>> new_fiscalyear, = renew_fiscalyear.actions[0]
|
||||
|
||||
Create chart of accounts::
|
||||
|
||||
>>> _ = create_chart(company)
|
||||
>>> accounts = add_deferred_accounts(get_accounts(company))
|
||||
|
||||
Create party::
|
||||
|
||||
>>> party = Party(name="Insurer")
|
||||
>>> party.save()
|
||||
|
||||
Create account category::
|
||||
|
||||
>>> account_category = ProductCategory(name="Account Category")
|
||||
>>> account_category.accounting = True
|
||||
>>> account_category.account_expense = accounts['expense']
|
||||
>>> account_category.account_revenue = accounts['revenue']
|
||||
>>> account_category.save()
|
||||
|
||||
Create product::
|
||||
|
||||
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
||||
>>> ProductTemplate = Model.get('product.template')
|
||||
>>> template = ProductTemplate()
|
||||
>>> template.name = "Insurance"
|
||||
>>> template.default_uom = unit
|
||||
>>> template.type = 'service'
|
||||
>>> template.list_price = Decimal('1000')
|
||||
>>> template.account_category = account_category
|
||||
>>> template.save()
|
||||
>>> product, = template.products
|
||||
|
||||
Create invoice::
|
||||
|
||||
>>> invoice = Invoice(type='in')
|
||||
>>> invoice.party = party
|
||||
>>> line = invoice.lines.new()
|
||||
>>> line.product = product
|
||||
>>> line.quantity = 1
|
||||
>>> line.unit_price = Decimal('1000')
|
||||
>>> line.defer_from = period.start_date
|
||||
>>> line.defer_to = line.defer_from + dt.timedelta(days=499)
|
||||
>>> invoice.invoice_date = today
|
||||
>>> invoice.click('post')
|
||||
>>> invoice_line, = invoice.lines
|
||||
|
||||
Check invoice deferred and run it::
|
||||
|
||||
>>> deferral, = InvoiceDeferred.find([])
|
||||
>>> assertEqual(deferral.invoice_line, invoice_line)
|
||||
>>> deferral.amount
|
||||
Decimal('1000.00')
|
||||
>>> assertEqual(deferral.start_date, invoice_line.defer_from)
|
||||
>>> assertEqual(deferral.end_date, invoice_line.defer_to)
|
||||
>>> deferral.click('run')
|
||||
|
||||
Check moves on invoice deferred::
|
||||
|
||||
>>> deferral.reload()
|
||||
>>> deferral.state
|
||||
'closed'
|
||||
>>> len(deferral.moves)
|
||||
18
|
||||
>>> accounts['deferred_expense'].reload()
|
||||
>>> accounts['deferred_expense'].balance
|
||||
Decimal('0.00')
|
||||
13
modules/account_invoice_defer/tests/test_module.py
Normal file
13
modules/account_invoice_defer/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 AccountInvoiceDeferTestCase(CompanyTestMixin, ModuleTestCase):
|
||||
'Test Account Invoice Defer module'
|
||||
module = 'account_invoice_defer'
|
||||
|
||||
|
||||
del ModuleTestCase
|
||||
8
modules/account_invoice_defer/tests/test_scenario.py
Normal file
8
modules/account_invoice_defer/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)
|
||||
49
modules/account_invoice_defer/tests/tools.py
Normal file
49
modules/account_invoice_defer/tests/tools.py
Normal file
@@ -0,0 +1,49 @@
|
||||
# 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 proteus import Model
|
||||
from proteus.config import get_config
|
||||
from trytond.modules.company.tests.tools import get_company
|
||||
|
||||
|
||||
def add_deferred_accounts(accounts, company=None, config=None):
|
||||
"Add deferred to accounts"
|
||||
if not config:
|
||||
config = get_config()
|
||||
Account = Model.get('account.account', config=config)
|
||||
AccountType = Model.get('account.account.type')
|
||||
Configuration = Model.get('account.configuration', config=config)
|
||||
|
||||
if not company:
|
||||
company = get_company(config=config)
|
||||
|
||||
root, = Account.find([('parent', '=', None)], limit=1)
|
||||
asset_type, = AccountType.find([
|
||||
('statement', '=', 'balance'),
|
||||
('name', '=', "Current Assets"),
|
||||
('company', '=', company.id),
|
||||
], limit=1)
|
||||
liability_type, = AccountType.find([
|
||||
('statement', '=', 'balance'),
|
||||
('name', '=', "Liabilities"),
|
||||
('company', '=', company.id),
|
||||
], limit=1)
|
||||
|
||||
accounts['deferred_revenue'] = Account(
|
||||
parent=root,
|
||||
name="Deferred Revenue",
|
||||
type=asset_type,
|
||||
company=company)
|
||||
accounts['deferred_revenue'].save()
|
||||
accounts['deferred_expense'] = Account(
|
||||
parent=root,
|
||||
name="Deferred Expense",
|
||||
type=liability_type,
|
||||
company=company)
|
||||
accounts['deferred_expense'].save()
|
||||
|
||||
with config.set_context(company=company.id):
|
||||
configuration = Configuration(1)
|
||||
configuration.deferred_account_revenue = accounts['deferred_revenue']
|
||||
configuration.deferred_account_expense = accounts['deferred_expense']
|
||||
configuration.save()
|
||||
return accounts
|
||||
Reference in New Issue
Block a user