diff --git a/__init__.py b/__init__.py index ab705ab9b9..c28d8fea0e 100644 --- a/__init__.py +++ b/__init__.py @@ -11,3 +11,6 @@ def register(): account.BEVATCustomer, account.BEVATCustomerContext, module='account_be', type_='model') + Pool.register( + account.CreateChart, + module='account_be', type_='wizard') diff --git a/account.py b/account.py index 4523feef33..f85f23dff1 100644 --- a/account.py +++ b/account.py @@ -37,6 +37,27 @@ class AccountTemplate(metaclass=PoolMeta): super(AccountTemplate, cls).__register__(module_name) +class CreateChart(metaclass=PoolMeta): + __name__ = 'account.create_chart' + + def default_properties(self, fields): + pool = Pool() + ModelData = pool.get('ir.model.data') + defaults = super().default_properties(fields) + for lang in ['fr', 'nl']: + try: + template_id = ModelData.get_id('account_be.root_' + lang) + except KeyError: + continue + if self.account.account_template.id == template_id: + defaults['account_receivable'] = self.get_account( + 'account_be.400_' + lang) + defaults['account_payable'] = self.get_account( + 'account_be.440_' + lang) + break + return defaults + + class BEVATCustomer(ModelSQL, ModelView): "Belgium VAT Customer" __name__ = 'account.be.vat_customer' diff --git a/tests/test_account_be.py b/tests/test_account_be.py index f3b2c65ec6..2ae205e171 100644 --- a/tests/test_account_be.py +++ b/tests/test_account_be.py @@ -2,7 +2,10 @@ # this repository contains the full copyright notices and license terms. import unittest import trytond.tests.test_tryton -from trytond.tests.test_tryton import ModuleTestCase +from trytond.tests.test_tryton import ModuleTestCase, with_transaction + +from trytond.modules.company.tests import create_company, set_company +from trytond.modules.account.tests import create_chart class AccountBETestCase(ModuleTestCase): @@ -10,6 +13,12 @@ class AccountBETestCase(ModuleTestCase): module = 'account_be' language = 'fr' + @with_transaction() + def test_create_chart(self): + company = create_company() + with set_company(company): + create_chart(company, chart=self.module + '.root_' + self.language) + def suite(): suite = trytond.tests.test_tryton.suite()