The fiscal years are created centered on the passed date such that if the current day change during the execution, the fiscal year is still usable. Also fiscal year can be created for a range of dates such that it is guarantee that the dates are in the fiscal year. And finally remove datetime and dateutil import when they are not used. Closes #9977
134 lines
3.7 KiB
ReStructuredText
134 lines
3.7 KiB
ReStructuredText
=========================
|
|
Analytic Invoice Scenario
|
|
=========================
|
|
|
|
Imports::
|
|
|
|
>>> from decimal import Decimal
|
|
>>> from operator import attrgetter
|
|
>>> from proteus import Model, Wizard
|
|
>>> from trytond.tests.tools import activate_modules
|
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
|
... get_company
|
|
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
|
|
... create_chart, get_accounts
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
|
|
Activate modules::
|
|
|
|
>>> config = activate_modules('analytic_invoice')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
|
... create_fiscalyear(company))
|
|
>>> fiscalyear.click('create_period')
|
|
|
|
Create chart of accounts::
|
|
|
|
>>> _ = create_chart(company)
|
|
>>> accounts = get_accounts(company)
|
|
>>> revenue = accounts['revenue']
|
|
>>> expense = accounts['expense']
|
|
|
|
Create analytic accounts::
|
|
|
|
>>> AnalyticAccount = Model.get('analytic_account.account')
|
|
>>> root = AnalyticAccount(type='root', name='Root')
|
|
>>> root.save()
|
|
>>> analytic_account = AnalyticAccount(root=root, parent=root,
|
|
... name='Analytic')
|
|
>>> analytic_account.save()
|
|
|
|
Create party::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> party = Party(name='Party')
|
|
>>> party.save()
|
|
|
|
Create account category::
|
|
|
|
>>> ProductCategory = Model.get('product.category')
|
|
>>> account_category = ProductCategory(name="Account Category")
|
|
>>> account_category.accounting = True
|
|
>>> account_category.account_expense = expense
|
|
>>> account_category.account_revenue = revenue
|
|
>>> account_category.save()
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'service'
|
|
>>> template.list_price = Decimal('40')
|
|
>>> template.account_category = account_category
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create invoice with analytic accounts::
|
|
|
|
>>> Invoice = Model.get('account.invoice')
|
|
>>> invoice = Invoice()
|
|
>>> invoice.party = party
|
|
>>> invoice.payment_term = payment_term
|
|
>>> line = invoice.lines.new()
|
|
>>> entry, = line.analytic_accounts
|
|
>>> entry.root == root
|
|
True
|
|
>>> entry.account = analytic_account
|
|
>>> line.product = product
|
|
>>> line.quantity = 5
|
|
>>> line.unit_price = Decimal('40')
|
|
>>> invoice.click('post')
|
|
>>> invoice.state
|
|
'posted'
|
|
>>> analytic_account.reload()
|
|
>>> analytic_account.credit
|
|
Decimal('200.00')
|
|
>>> analytic_account.debit
|
|
Decimal('0.00')
|
|
|
|
|
|
Create invoice with an empty analytic account::
|
|
|
|
>>> invoice = Invoice()
|
|
>>> invoice.party = party
|
|
>>> invoice.payment_term = payment_term
|
|
>>> line = invoice.lines.new()
|
|
>>> entry, = line.analytic_accounts
|
|
>>> line.product = product
|
|
>>> line.quantity = 1
|
|
>>> line.unit_price = Decimal('40')
|
|
>>> invoice.click('post')
|
|
>>> invoice.state
|
|
'posted'
|
|
>>> analytic_account.reload()
|
|
>>> analytic_account.credit
|
|
Decimal('200.00')
|
|
>>> analytic_account.debit
|
|
Decimal('0.00')
|
|
|
|
Credit invoice with refund::
|
|
|
|
>>> credit = Wizard('account.invoice.credit', [invoice])
|
|
>>> credit.form.with_refund = True
|
|
>>> credit.execute('credit')
|
|
>>> invoice.reload()
|
|
>>> invoice.state
|
|
'cancelled'
|