Files
tryton/modules/analytic_invoice/tests/scenario_analytic_invoice.rst
T

135 lines
3.8 KiB
ReStructuredText
Raw Normal View History

2015-02-15 13:11:01 +01:00
=========================
Analytic Invoice Scenario
=========================
Imports::
>>> import datetime
>>> from dateutil.relativedelta import relativedelta
>>> from decimal import Decimal
>>> from operator import attrgetter
2016-08-26 09:58:41 +02:00
>>> from proteus import Model, Wizard
>>> from trytond.tests.tools import activate_modules
2015-02-15 13:11:01 +01:00
>>> from trytond.modules.company.tests.tools import create_company, \
... get_company
>>> from trytond.modules.account.tests.tools import create_fiscalyear, \
... create_chart, get_accounts
2016-02-29 22:43:13 +01:00
>>> from trytond.modules.account_invoice.tests.tools import \
2015-02-15 13:11:01 +01:00
... set_fiscalyear_invoice_sequences, create_payment_term
>>> today = datetime.date.today()
Activate modules::
2015-02-15 13:11:01 +01:00
>>> config = activate_modules('analytic_invoice')
2015-02-15 13:11:01 +01:00
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()
2018-06-20 12:09:44 +02:00
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()
2015-02-15 13:11:01 +01:00
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')
2018-06-20 12:09:44 +02:00
>>> template.account_category = account_category
2015-02-15 13:11:01 +01:00
>>> template.save()
>>> product, = template.products
2015-02-15 13:11:01 +01:00
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()
2019-02-18 18:39:29 +01:00
>>> entry, = line.analytic_accounts
2015-02-15 13:11:01 +01:00
>>> entry.root == root
True
>>> entry.account = analytic_account
>>> line.product = product
>>> line.quantity = 5
2015-07-16 19:32:28 +02:00
>>> line.unit_price = Decimal('40')
2015-02-15 13:11:01 +01:00
>>> invoice.click('post')
>>> invoice.state
2018-06-26 19:11:45 +02:00
'posted'
2015-02-15 13:11:01 +01:00
>>> 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()
2019-02-18 18:39:29 +01:00
>>> entry, = line.analytic_accounts
2015-02-15 13:11:01 +01:00
>>> line.product = product
>>> line.quantity = 1
2015-07-16 19:32:28 +02:00
>>> line.unit_price = Decimal('40')
2015-02-15 13:11:01 +01:00
>>> invoice.click('post')
>>> invoice.state
2018-06-26 19:11:45 +02:00
'posted'
2015-02-15 13:11:01 +01:00
>>> 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'