Add test for invoice payment in alternate currency with change difference

This commit is contained in:
Sergi Almacellas Abellana committed 2016-11-24 16:43:56 +01:00
1 parent a7d6b4e3a7
commit 526fb2cbf7
1 file changed
+51 -12
+51 -12
View File
@@ -18,6 +18,7 @@ Imports::
>>> from trytond.modules.account_invoice.tests.tools import \
... set_fiscalyear_invoice_sequences
>>> today = datetime.date.today()
>>> tomorrow = today + relativedelta(days=1)
Install account_invoice::
@@ -30,6 +31,16 @@ Create company::
>>> _ = create_company(currency=currency)
>>> company = get_company()
Set alternate currency rates::
>>> rate = eur.rates.new()
>>> rate.date = today
>>> rate.rate = eur.rates[0].rate
>>> rate = eur.rates.new()
>>> rate.date = tomorrow
>>> rate.rate = eur.rates[0].rate + Decimal('0.5')
>>> eur.save()
Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences(
@@ -43,6 +54,7 @@ Create chart of accounts::
>>> revenue = accounts['revenue']
>>> expense = accounts['expense']
>>> account_tax = accounts['tax']
>>> account_cash = accounts['cash']
Create tax::
@@ -53,6 +65,23 @@ Create tax::
>>> credit_note_base_code = tax.credit_note_base_code
>>> credit_note_tax_code = tax.credit_note_tax_code
Set Cash journal::
>>> Journal = Model.get('account.journal')
>>> journal_cash, = Journal.find([('type', '=', 'cash')])
>>> journal_cash.credit_account = account_cash
>>> journal_cash.debit_account = account_cash
>>> journal_cash.save()
Create Write-Off journal::
>>> Sequence = Model.get('ir.sequence')
>>> sequence_journal, = Sequence.find([('code', '=', 'account.journal')])
>>> journal_writeoff = Journal(name='Write-Off', type='write-off',
... sequence=sequence_journal,
... credit_account=revenue, debit_account=expense)
>>> journal_writeoff.save()
Create party::
>>> Party = Model.get('party.party')
@@ -79,22 +108,11 @@ Create product::
>>> product.template = template
>>> product.save()
Create payment term::
>>> PaymentTerm = Model.get('account.invoice.payment_term')
>>> payment_term = PaymentTerm(name='Term')
>>> line = payment_term.lines.new(type='percent', ratio=Decimal('.5'))
>>> delta = line.relativedeltas.new(days=20)
>>> line = payment_term.lines.new(type='remainder')
>>> delta = line.relativedeltas.new(days=40)
>>> payment_term.save()
Create invoice with alternate currency::
>>> Invoice = Model.get('account.invoice')
>>> invoice = Invoice()
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> invoice.currency = eur
>>> line = invoice.lines.new()
>>> line.product = product
@@ -125,6 +143,28 @@ Create invoice with alternate currency::
>>> invoice.total_amount
Decimal('460.00')
Pay the invoice with rate change::
>>> pay = Wizard('account.invoice.pay', [invoice])
>>> pay.form.amount
Decimal('460.00')
>>> pay.form.journal = journal_cash
>>> pay.form.date = tomorrow
>>> pay.execute('choice')
>>> pay.form.type = 'writeoff'
>>> pay.form.journal_writeoff = journal_writeoff
>>> pay.form.amount
Decimal('460.00')
>>> pay.form.currency == eur
True
>>> pay.form.amount_writeoff
Decimal('46.00')
>>> pay.form.currency_writeoff == currency
True
>>> pay.execute('pay')
>>> invoice.state
u'paid'
Create negative tax::
>>> negative_tax = set_tax_code(create_tax(Decimal('-.10')))
@@ -134,7 +174,6 @@ Create invoice with alternate currency and negative taxes::
>>> invoice = Invoice()
>>> invoice.party = party
>>> invoice.payment_term = payment_term
>>> invoice.currency = eur
>>> line = invoice.lines.new()
>>> line.product = product