Commit 7afdf612 authored by Rafael Monnerat's avatar Rafael Monnerat

Reuse Previous Accounts instead always create new ones.

The reusage permit use configuration for multiple gap
definitions. Included specific test for Account Configurator Item.
parent 4216ad93
......@@ -57,23 +57,37 @@ class AccountConfiguratorItem(ConfiguratorItemMixin, XMLObject):
def _build(self, business_configuration):
account_module = self.getPortalObject().account_module
account = None
account_id = getattr(self, 'account_id', None)
extra_kw = {}
account_id = getattr(self, 'account_id', None)
if account_id:
# XXX FIXME This cause conflict when use configuration
# more then once.
#extra_kw['id'] = account_id
pass
account = account_module.newContent(
portal_type='Account',
title=self.getTitle(),
account_type=self.getAccountType(),
gap=self.getGap(),
financial_section=self.getFinancialSection(),
credit_account=self.isCreditAccount(),
description=self.getDescription(),
**extra_kw)
extra_kw['id'] = account_id
account = getattr(account_module, account_id, None)
if account is None:
account = account_module.newContent(
portal_type='Account',
title=self.getTitle(),
account_type=self.getAccountType(),
gap=self.getGap(),
financial_section=self.getFinancialSection(),
credit_account=self.isCreditAccount(),
description=self.getDescription(),
**extra_kw)
else:
# Update existing account
if (self.getAccountType() != account.getAccountType()) and \
(self.getFinancialSection() != account.getFinancialSection()):
raise ValueError("The Configurator is trying to overwritte previous configuration information (%s)" % account.getRelativeUrl())
account.edit(title=self.getTitle(), description=self.getDescription())
gap_list = account.getGapList()
# Only include only the additional gap that do not collide.
if self.getGap() not in gap_list:
gap_list.append(self.getGap())
account.setGapList(gap_list)
account.setCreditAccount(self.isCreditAccount())
if self.portal_workflow.isTransitionPossible(account, 'validate'):
account.validate(comment="Validated by Configurator")
......
......@@ -50,6 +50,7 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
'erp5_simulation',
'erp5_pdm',
'erp5_trade',
'erp5_accounting',
'erp5_configurator_standard_trade_template')
def createConfigurationSave(self):
......@@ -249,6 +250,58 @@ class TestConfiguratorItem(TestLiveConfiguratorWorkflowMixin):
self.assertNotEquals(None, security_script)
self.assertEquals(security_script(), expect_script_outcome)
def testAccountConfiguratorItem(self):
""" Test Account Configurator Item """
configuration_save = self.createConfigurationSave()
bc = configuration_save.getParentValue()
account_module = self.portal.account_module
account_dict = {
'account_type': 'asset/receivable',
'account_id': 'receivable',
'title': 'Customers',
'gap': 'ias/ifrs/4/41',
'financial_section': 'asset/current_assets/trade_receivables'}
item = configuration_save.addConfigurationItem(
"Account Configurator Item", **account_dict)
self.stepTic()
item._build(bc)
self.stepTic()
account = getattr(account_module, account_dict['account_id'], None)
self.assertNotEquals(account, None)
self.assertEquals(account.getTitle(), account_dict['title'])
self.assertEquals(account.getGap(), account_dict['gap'])
self.assertEquals(account.getFinancialSection(),
account_dict['financial_section'])
self.assertEquals(account.getAccountType(),
account_dict['account_type'])
# Update Account dict and try to create again the same account,
# the account should be only updated instead a new account be created.
account_dict['title'] = 'Clientes'
previous_gap = account_dict['gap']
account_dict['gap'] = 'br/pcg/1/1.1/1.1.2'
item = configuration_save.addConfigurationItem(
"Account Configurator Item", **account_dict)
self.stepTic()
item._build(bc)
self.stepTic()
same_account = getattr(account_module, account_dict['account_id'], None)
self.assertEquals(account, same_account)
self.assertEquals(account.getTitle(), account_dict['title'])
self.assertSameSet(account.getGapList(), [previous_gap,
account_dict['gap']])
self.assertEquals(account.getFinancialSection(),
account_dict['financial_section'])
self.assertEquals(account.getAccountType(),
account_dict['account_type'])
def testAlarmConfiguratorItem(self):
""" Test Alarm Configurator Item """
configuration_save = self.createConfigurationSave()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment