From e63220544cbbbd3899d55e90b3524b01e435e475 Mon Sep 17 00:00:00 2001 From: Korbinian Preisler Date: Fri, 1 Nov 2019 23:18:11 +0100 Subject: [PATCH] Add credit note test scenario issue8401 review249441002 --- tests/scenario_credit_note.rst | 141 +++++++++++++++++++++++++++++++++ tests/test_account_invoice.py | 4 + 2 files changed, 145 insertions(+) create mode 100644 tests/scenario_credit_note.rst diff --git a/tests/scenario_credit_note.rst b/tests/scenario_credit_note.rst new file mode 100644 index 0000000000..053c8a4958 --- /dev/null +++ b/tests/scenario_credit_note.rst @@ -0,0 +1,141 @@ +==================== +Credit Note Scenario +==================== + +Imports:: + + >>> from decimal import Decimal + >>> 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 + +Install account_invoice:: + + >>> config = activate_modules('account_invoice') + +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) + >>> receivable = accounts['receivable'] + >>> revenue = accounts['revenue'] + >>> expense = accounts['expense'] + >>> account_cash = accounts['cash'] + +Create tax:: + + >>> TaxCode = Model.get('account.tax.code') + >>> tax = create_tax(Decimal('.10')) + >>> tax.save() + +Create payment method:: + + >>> Journal = Model.get('account.journal') + >>> PaymentMethod = Model.get('account.invoice.payment.method') + >>> Sequence = Model.get('ir.sequence') + >>> journal_cash, = Journal.find([('type', '=', 'cash')]) + >>> payment_method = PaymentMethod() + >>> payment_method.name = 'Cash' + >>> payment_method.journal = journal_cash + >>> payment_method.credit_account = account_cash + >>> payment_method.debit_account = account_cash + >>> payment_method.save() + +Create party:: + + >>> Party = Model.get('party.party') + >>> party = Party(name='Party') + >>> party.save() + +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.customer_taxes.append(tax) + >>> account_category.save() + +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') + >>> template.account_category = account_category + >>> template.save() + >>> product, = template.products + +Create credit note:: + + >>> Invoice = Model.get('account.invoice') + >>> invoice = Invoice() + >>> invoice.party = party + >>> line = invoice.lines.new() + >>> line.product = product + >>> line.quantity = -5 + >>> line.unit_price = Decimal('40') + >>> invoice.total_amount + Decimal('-220.00') + >>> invoice.save() + +Post credit note:: + + >>> invoice.click('post') + >>> invoice.state + 'posted' + +Pay credit note:: + + >>> pay = Wizard('account.invoice.pay', [invoice]) + >>> pay.form.amount + Decimal('-220.00') + >>> pay.form.amount = Decimal('-120.00') + >>> pay.form.payment_method = payment_method + >>> pay.execute('choice') + >>> pay.form.type = 'partial' + >>> pay.form.amount + Decimal('-120.00') + >>> len(pay.form.lines_to_pay) + 1 + >>> len(pay.form.payment_lines) + 0 + >>> len(pay.form.lines) + 1 + >>> pay.form.amount_writeoff + Decimal('-100.00') + >>> pay.execute('pay') + >>> pay.state + 'end' + + >>> pay = Wizard('account.invoice.pay', [invoice]) + >>> pay.form.amount + Decimal('-100.00') + >>> pay.form.amount = Decimal('-100.00') + >>> pay.form.payment_method = payment_method + >>> pay.execute('choice') + >>> invoice.state + 'paid' + >>> sorted(l.debit for l in invoice.reconciliation_lines) + [Decimal('100.00'), Decimal('120.00')] diff --git a/tests/test_account_invoice.py b/tests/test_account_invoice.py index a3231ef7e4..6069181e59 100644 --- a/tests/test_account_invoice.py +++ b/tests/test_account_invoice.py @@ -229,6 +229,10 @@ def suite(): tearDown=doctest_teardown, encoding='utf-8', checker=doctest_checker, optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) + suite.addTests(doctest.DocFileSuite('scenario_credit_note.rst', + tearDown=doctest_teardown, encoding='utf-8', + checker=doctest_checker, + optionflags=doctest.REPORT_ONLY_FIRST_FAILURE)) suite.addTests(doctest.DocFileSuite( 'scenario_invoice_customer_sequential.rst', tearDown=doctest_teardown, encoding='utf-8',