Fill default accounts when creating chart

issue10602
review359871002
This commit is contained in:
Cédric Krier
2021-10-03 00:42:46 +02:00
parent bbb36aa30c
commit c0e40df74d
3 changed files with 34 additions and 1 deletions
+3
View File
@@ -11,3 +11,6 @@ def register():
account.BEVATCustomer,
account.BEVATCustomerContext,
module='account_be', type_='model')
Pool.register(
account.CreateChart,
module='account_be', type_='wizard')
+21
View File
@@ -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'
+10 -1
View File
@@ -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()