diff --git a/modules/account_fr_chorus/setup.py b/modules/account_fr_chorus/setup.py index b7eae5968e..21cb788c44 100755 --- a/modules/account_fr_chorus/setup.py +++ b/modules/account_fr_chorus/setup.py @@ -47,7 +47,11 @@ for dep in info.get('depends', []): requires.append(get_require_version('trytond_%s' % dep)) requires.append(get_require_version('trytond')) -tests_require = [get_require_version('trytond_edocument_uncefact')] +tests_require = [ + get_require_version('proteus'), + get_require_version('trytond_account_fr'), + get_require_version('trytond_edocument_uncefact'), + ] setup(name=name, version=version, diff --git a/modules/account_fr_chorus/tests/scenario_account_fr_chorus_invoice.rst b/modules/account_fr_chorus/tests/scenario_account_fr_chorus_invoice.rst new file mode 100644 index 0000000000..ea3a0a992f --- /dev/null +++ b/modules/account_fr_chorus/tests/scenario_account_fr_chorus_invoice.rst @@ -0,0 +1,135 @@ +========================= +Account FR Chorus Invoice +========================= + +Imports:: + + >>> import os + >>> from decimal import Decimal + + >>> from proteus import Model + >>> from trytond.tests.tools import activate_modules + >>> from trytond.modules.currency.tests.tools import get_currency + >>> from trytond.modules.company.tests.tools import ( + ... create_company, get_company) + >>> from trytond.modules.account.tests.tools import ( + ... create_fiscalyear, create_chart, get_accounts) + >>> from trytond.modules.account_invoice.tests.tools import ( + ... set_fiscalyear_invoice_sequences) + +Patch SIRET validation:: + + >>> from unittest.mock import patch + >>> from trytond.modules.party.party import Identifier + >>> mock = patch.object( + ... Identifier, 'check_code', + ... return_value=None).start() + +Activate modules:: + + >>> config = activate_modules([ + ... 'account_fr_chorus', 'edocument_uncefact', 'account_fr']) + + >>> AccountConfig = Model.get('account.configuration') + >>> Cron = Model.get('ir.cron') + >>> Invoice = Model.get('account.invoice') + >>> InvoiceChorus = Model.get('account.invoice.chorus') + >>> Party = Model.get('party.party') + >>> Tax = Model.get('account.tax') + +Create company:: + + >>> _ = create_company(currency=get_currency('EUR')) + >>> company = get_company() + >>> company_party = company.party + >>> company_address, = company_party.addresses + >>> company_address.postal_code = '99999' + >>> company_address.street = "Street" + >>> company_address.city = "City" + >>> siret = company_party.identifiers.new(type='fr_siret') + >>> siret.code = os.getenv('CHORUS_COMPANY_SIRET') + >>> siret.address = company_address + >>> company_party.save() + +Create fiscal year:: + + >>> fiscalyear = set_fiscalyear_invoice_sequences(create_fiscalyear()) + >>> fiscalyear.click('create_period') + +Create chart of accounts:: + + >>> _ = create_chart(chart='account_fr.root') + >>> acccounts = get_accounts() + + >>> tax, = Tax.find([ + ... ('group.kind', '=', 'sale'), + ... ('name', 'ilike', '%normal%'), + ... ], limit=1) + >>> tax.template_override = True + >>> tax.unece_code = 'VAT' + >>> tax.unece_category_code = 'S' + >>> for child in tax.childs: + ... child.template_override = True + ... child.unece_code = tax.unece_code + ... child.unece_category_code = tax.unece_category_code + >>> tax.save() + +Configure Chorus:: + + >>> account_config = AccountConfig(1) + >>> account_config.chorus_piste_client_id = os.getenv( + ... 'CHORUS_PISTE_CLIENT_ID') + >>> account_config.chorus_piste_client_secret = os.getenv( + ... 'CHORUS_PISTE_CLIENT_SECRET') + >>> account_config.chorus_login = os.getenv( + ... 'CHORUS_LOGIN') + >>> account_config.chorus_password = os.getenv( + ... 'CHORUS_PASSWORD') + >>> account_config.chorus_service = 'service-qualif' + >>> account_config.chorus_syntax = 'edocument.uncefact.invoice' + >>> account_config.save() + +Create customer:: + + >>> customer = Party(name="Customer") + >>> customer.chorus = True + >>> customer.save() + >>> customer_address, = customer.addresses + >>> customer_address.street = "Street" + >>> siret = customer.identifiers.new(type='fr_siret') + >>> siret.code = os.getenv('CHORUS_CUSTOMER_SIRET') + >>> siret.address = customer_address + >>> customer.save() + +Create invoice:: + + >>> invoice = Invoice(type='out', party=customer) + >>> line = invoice.lines.new() + >>> line.account = acccounts['revenue'] + >>> line.quantity = 5 + >>> line.unit_price = Decimal('50.0000') + >>> line.taxes.append(tax) + >>> invoice.click('post') + >>> invoice.state + 'posted' + +Check Chorus invoice:: + + >>> invoice_chorus, = InvoiceChorus.find([]) + >>> invoice_chorus.syntax + 'edocument.uncefact.invoice' + >>> invoice_chorus.number + >>> invoice_chorus.date + +Send to Chorus:: + + >>> cron, = Cron.find([('method', '=', 'account.invoice.chorus|send')]) + >>> cron.click('run_once') + + >>> invoice_chorus.reload() + >>> bool(invoice_chorus.number) + True + >>> bool(invoice_chorus.date) + True + >>> bool(invoice_chorus.data) + True diff --git a/modules/account_fr_chorus/tests/test_scenario.py b/modules/account_fr_chorus/tests/test_scenario.py new file mode 100644 index 0000000000..3ee52b344c --- /dev/null +++ b/modules/account_fr_chorus/tests/test_scenario.py @@ -0,0 +1,15 @@ +# This file is part of Tryton. The COPYRIGHT file at the top level of +# this repository contains the full copyright notices and license terms. + +import os + +from trytond.tests.test_tryton import load_doc_tests + +if (os.getenv('CHORUS_PISTE_CLIENT_ID') + and os.getenv('CHORUS_PISTE_CLIENT_SECRET') + and os.getenv('CHORUS_LOGIN') + and os.getenv('CHORUS_PASSWORD') + and os.getenv('CHORUS_COMPANY_SIRET') + and os.getenv('CHORUS_CUSTOMER_SIRET')): + def load_tests(*args, **kwargs): + return load_doc_tests(__name__, __file__, *args, **kwargs)