136 lines
4.0 KiB
ReStructuredText
136 lines
4.0 KiB
ReStructuredText
================
|
|
Invoice Scenario
|
|
================
|
|
|
|
Imports::
|
|
>>> import datetime
|
|
>>> from dateutil.relativedelta import relativedelta
|
|
>>> 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, create_tax
|
|
>>> from trytond.modules.account_invoice.tests.tools import \
|
|
... set_fiscalyear_invoice_sequences, create_payment_term
|
|
>>> today = datetime.date.today()
|
|
|
|
Install account_invoice_taxes_required Module::
|
|
|
|
>>> config = activate_modules('account_invoice_taxes_required')
|
|
|
|
Create company::
|
|
|
|
>>> _ = create_company()
|
|
>>> company = get_company()
|
|
|
|
Create fiscal year::
|
|
|
|
>>> fiscalyear = set_fiscalyear_invoice_sequences(
|
|
... create_fiscalyear(company))
|
|
>>> fiscalyear.click('create_period')
|
|
>>> period = fiscalyear.periods[0]
|
|
|
|
Create chart of accounts::
|
|
|
|
>>> _ = create_chart(company)
|
|
>>> accounts = get_accounts(company)
|
|
>>> receivable = accounts['receivable']
|
|
>>> revenue = accounts['revenue']
|
|
>>> expense = accounts['expense']
|
|
|
|
Create tax::
|
|
|
|
>>> tax = create_tax(Decimal('.10'))
|
|
>>> tax.save()
|
|
|
|
Create party::
|
|
|
|
>>> Party = Model.get('party.party')
|
|
>>> party = Party(name='Party')
|
|
>>> party.save()
|
|
|
|
Create account categories::
|
|
|
|
>>> 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()
|
|
|
|
>>> account_category_tax, = account_category.duplicate()
|
|
>>> account_category_tax.customer_taxes.append(tax)
|
|
>>> account_category_tax.save()
|
|
|
|
Create product::
|
|
|
|
>>> ProductUom = Model.get('product.uom')
|
|
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
|
|
>>> ProductTemplate = Model.get('product.template')
|
|
>>> Product = Model.get('product.product')
|
|
>>> template = ProductTemplate()
|
|
>>> template.name = 'product'
|
|
>>> template.default_uom = unit
|
|
>>> template.type = 'service'
|
|
>>> template.list_price = Decimal('40')
|
|
>>> template.account_category = account_category_tax
|
|
>>> product, = template.products
|
|
>>> product.cost_price = Decimal('25')
|
|
>>> template.save()
|
|
>>> product, = template.products
|
|
|
|
Create payment term::
|
|
|
|
>>> payment_term = create_payment_term()
|
|
>>> payment_term.save()
|
|
|
|
Create invoice Without Taxes::
|
|
|
|
>>> Invoice = Model.get('account.invoice')
|
|
>>> invoice = Invoice()
|
|
>>> invoice.party = party
|
|
>>> invoice.payment_term = payment_term
|
|
>>> line = invoice.lines.new()
|
|
>>> line.product = product
|
|
>>> line.quantity = 5
|
|
>>> line.unit_price = Decimal(40)
|
|
>>> line = invoice.lines.new()
|
|
>>> line.account = revenue
|
|
>>> line.description = 'Test'
|
|
>>> line.quantity = 1
|
|
>>> line.unit_price = Decimal(20)
|
|
>>> invoice.untaxed_amount
|
|
Decimal('220.00')
|
|
>>> invoice.tax_amount
|
|
Decimal('20.00')
|
|
>>> invoice.total_amount
|
|
Decimal('240.00')
|
|
>>> invoice.save()
|
|
>>> invoice.click('post') # doctest: +IGNORE_EXCEPTION_DETAIL
|
|
Traceback (most recent call last):
|
|
...
|
|
UserError: ('UserError', ('Missing tax in line "Test" in invoice ID "1".', ''))
|
|
>>> invoice.reload()
|
|
>>> invoice.state
|
|
'draft'
|
|
|
|
Create invoice With Taxes::
|
|
|
|
>>> Invoice = Model.get('account.invoice')
|
|
>>> invoice = Invoice()
|
|
>>> invoice.party = party
|
|
>>> invoice.payment_term = payment_term
|
|
>>> line = invoice.lines.new()
|
|
>>> line.product = product
|
|
>>> line.quantity = 5
|
|
>>> line.unit_price = Decimal(20)
|
|
>>> line = invoice.lines.new()
|
|
>>> line.type = 'comment'
|
|
>>> line.description = 'Test'
|
|
>>> invoice.click('post')
|
|
>>> invoice.state
|
|
'posted'
|