From 526fb2cbf7fda2b9dba51f9b0e9f689d444a811d Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 24 Nov 2016 16:43:56 +0100 Subject: [PATCH] Add test for invoice payment in alternate currency with change difference --- tests/scenario_invoice_alternate_currency.rst | 63 +++++++++++++++---- 1 file changed, 51 insertions(+), 12 deletions(-) diff --git a/tests/scenario_invoice_alternate_currency.rst b/tests/scenario_invoice_alternate_currency.rst index 56aa1fe188..7bdf33e942 100644 --- a/tests/scenario_invoice_alternate_currency.rst +++ b/tests/scenario_invoice_alternate_currency.rst @@ -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