Files
tryton/modules/account_invoice/tests/scenario_invoice_supplier.rst
T

247 lines
7.1 KiB
ReStructuredText
Raw Normal View History

2013-02-23 17:44:03 +01:00
=========================
Invoice Supplier Scenario
=========================
Imports::
>>> import datetime as dt
2013-02-23 17:44:03 +01:00
>>> from decimal import Decimal
2024-01-14 19:21:56 +01:00
2016-08-26 09:58:16 +02:00
>>> from proteus import Model, Wizard
2024-01-14 19:21:56 +01:00
>>> from trytond.modules.account.tests.tools import (
... create_chart, create_fiscalyear, create_tax, create_tax_code, get_accounts)
>>> from trytond.modules.account_invoice.tests.tools import (
... set_fiscalyear_invoice_sequences)
>>> from trytond.modules.company.tests.tools import create_company, get_company
>>> from trytond.tests.tools import activate_modules
2024-01-14 19:21:56 +01:00
>>> today = dt.date.today()
2013-02-23 17:44:03 +01:00
Activate modules::
2013-02-23 17:44:03 +01:00
>>> config = activate_modules('account_invoice')
2013-02-23 17:44:03 +01:00
Create company::
>>> _ = create_company()
>>> company = get_company()
2013-02-23 17:44:03 +01:00
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
... create_fiscalyear(company, today))
>>> fiscalyear.click('create_period')
2018-03-24 15:29:47 +01:00
>>> period_ids = [p.id for p in fiscalyear.periods]
2013-02-23 17:44:03 +01:00
Create chart of accounts::
>>> _ = create_chart(company)
>>> accounts = get_accounts(company)
>>> payable = accounts['payable']
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> account_tax = accounts['tax']
2013-02-23 17:44:03 +01:00
Create tax::
2018-03-24 15:29:47 +01:00
>>> TaxCode = Model.get('account.tax.code')
2018-03-25 23:34:44 +02:00
>>> tax = create_tax(Decimal('.10'))
2013-02-23 17:44:03 +01:00
>>> tax.save()
2018-03-25 23:34:44 +02:00
>>> invoice_base_code = create_tax_code(tax, 'base', 'invoice')
>>> invoice_base_code.save()
>>> invoice_tax_code = create_tax_code(tax, 'tax', 'invoice')
>>> invoice_tax_code.save()
>>> credit_note_base_code = create_tax_code(tax, 'base', 'credit')
>>> credit_note_base_code.save()
>>> credit_note_tax_code = create_tax_code(tax, 'tax', 'credit')
>>> credit_note_tax_code.save()
2013-02-23 17:44:03 +01:00
Create party::
>>> Party = Model.get('party.party')
>>> party = Party(name='Party')
>>> party.save()
2018-06-20 12:09:41 +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.supplier_taxes.append(tax)
>>> account_category.save()
2013-02-23 17:44:03 +01:00
Create product::
>>> ProductUom = Model.get('product.uom')
>>> unit, = ProductUom.find([('name', '=', 'Unit')])
2013-03-20 22:50:23 +01:00
>>> 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:41 +02:00
>>> template.account_category = account_category
2013-03-20 22:50:23 +01:00
>>> template.save()
>>> product, = template.products
2013-02-23 17:44:03 +01:00
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
>>> payment_term = PaymentTerm(name='Term')
>>> line = payment_term.lines.new(type='remainder')
2013-02-23 17:44:03 +01:00
>>> payment_term.save()
Create invoice::
>>> Invoice = Model.get('account.invoice')
>>> InvoiceLine = Model.get('account.invoice.line')
>>> invoice = Invoice()
2016-03-20 22:58:13 +01:00
>>> invoice.type = 'in'
2013-02-23 17:44:03 +01:00
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> invoice.invoice_date = today
>>> invoice.reference = 'FAC001'
2013-02-23 17:44:03 +01:00
>>> line = InvoiceLine()
>>> invoice.lines.append(line)
>>> line.product = product
>>> line.quantity = 5
>>> line.unit_price = Decimal('20')
2013-02-23 17:44:03 +01:00
>>> line = InvoiceLine()
>>> invoice.lines.append(line)
>>> line.account = expense
>>> line.description = 'Test'
>>> line.quantity = 1
>>> line.unit_price = Decimal(10)
2014-01-31 00:03:05 +01:00
>>> invoice.untaxed_amount
Decimal('110.00')
>>> invoice.tax_amount
Decimal('10.00')
>>> invoice.total_amount
Decimal('120.00')
2017-01-13 20:13:52 +01:00
>>> invoice.save()
>>> invoice.state
2018-06-26 19:11:42 +02:00
'draft'
2017-01-13 20:13:52 +01:00
>>> bool(invoice.move)
False
>>> invoice.click('validate_invoice')
>>> invoice.state
2018-06-26 19:11:42 +02:00
'validated'
2017-01-13 20:13:52 +01:00
>>> bool(invoice.move)
True
>>> invoice.move.state
2018-06-26 19:11:42 +02:00
'draft'
>>> invoice.click('post')
2013-02-23 17:44:03 +01:00
>>> invoice.state
2018-06-26 19:11:42 +02:00
'posted'
2017-01-13 20:13:52 +01:00
>>> bool(invoice.move)
True
>>> invoice.move.state
2018-06-26 19:11:42 +02:00
'posted'
2014-01-31 00:03:05 +01:00
>>> invoice.untaxed_amount
Decimal('110.00')
>>> invoice.tax_amount
Decimal('10.00')
>>> invoice.total_amount
Decimal('120.00')
2013-02-23 17:44:03 +01:00
>>> payable.reload()
2014-01-31 00:03:05 +01:00
>>> payable.debit
Decimal('0.00')
>>> payable.credit
Decimal('120.00')
2013-02-23 17:44:03 +01:00
>>> expense.reload()
2014-01-31 00:03:05 +01:00
>>> expense.debit
Decimal('110.00')
>>> expense.credit
Decimal('0.00')
2013-02-23 17:44:03 +01:00
>>> account_tax.reload()
2014-01-31 00:03:05 +01:00
>>> account_tax.debit
Decimal('10.00')
>>> account_tax.credit
Decimal('0.00')
2018-03-24 15:29:47 +01:00
>>> with config.set_context(periods=period_ids):
... invoice_base_code = TaxCode(invoice_base_code.id)
2018-03-25 23:34:44 +02:00
... invoice_base_code.amount
2014-01-31 00:03:05 +01:00
Decimal('100.00')
2018-03-24 15:29:47 +01:00
>>> with config.set_context(periods=period_ids):
... invoice_tax_code = TaxCode(invoice_tax_code.id)
2018-03-25 23:34:44 +02:00
... invoice_tax_code.amount
2014-01-31 00:03:05 +01:00
Decimal('10.00')
2018-03-24 15:29:47 +01:00
>>> with config.set_context(periods=period_ids):
... credit_note_base_code = TaxCode(credit_note_base_code.id)
2018-03-25 23:34:44 +02:00
... credit_note_base_code.amount
2014-01-31 00:03:05 +01:00
Decimal('0.00')
2018-03-24 15:29:47 +01:00
>>> with config.set_context(periods=period_ids):
... credit_note_tax_code = TaxCode(credit_note_tax_code.id)
2018-03-25 23:34:44 +02:00
... credit_note_tax_code.amount
2014-01-31 00:03:05 +01:00
Decimal('0.00')
2013-02-23 17:44:03 +01:00
Credit invoice::
>>> credit = Wizard('account.invoice.credit', [invoice])
>>> credit.form.with_refund = False
>>> credit.execute('credit')
2016-03-20 22:58:13 +01:00
>>> credit_note, = Invoice.find(
... [('type', '=', 'in'), ('id', '!=', invoice.id)])
2013-02-23 17:44:03 +01:00
>>> credit_note.state
2018-06-26 19:11:42 +02:00
'draft'
>>> credit_note.untaxed_amount
Decimal('-110.00')
>>> credit_note.tax_amount
Decimal('-10.00')
>>> credit_note.total_amount
Decimal('-120.00')
A warning is raised when creating an invoice with same reference::
>>> invoice = Invoice()
>>> invoice.type = 'in'
>>> invoice.party = party
>>> invoice.invoice_date = today
>>> invoice.reference = 'FAC001'
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> line.unit_price = Decimal('20')
>>> invoice.click('post')
Traceback (most recent call last):
...
InvoiceSimilarWarning: ...
>>> invoice.reference = 'FAC002'
>>> invoice.click('post')
>>> invoice.state
'posted'
Create a posted and a draft invoice to cancel::
>>> invoice = Invoice()
2016-03-20 22:58:13 +01:00
>>> invoice.type = 'in'
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> invoice.invoice_date = today
>>> line = invoice.lines.new()
>>> line.product = product
>>> line.quantity = 1
>>> line.unit_price = Decimal('20')
>>> invoice.click('post')
>>> invoice_draft, = Invoice.duplicate([invoice])
Cancel draft invoice::
>>> invoice_draft.click('cancel')
>>> invoice_draft.state
'cancelled'
>>> invoice_draft.move
>>> invoice_draft.reconciled
Cancel posted invoice::
>>> invoice.click('cancel')
>>> invoice.state
'cancelled'
>>> invoice.cancel_move is not None
True
>>> bool(invoice.reconciled)
True