Commit 01208848 authored by Jérome Perrin's avatar Jérome Perrin

better check for payment: if source & dest. are in the same group, usage of a

bank account should be checked on both sides, otherwise only check for section.

use class atributes rather than storing in sequence.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10058 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d85ce1c9
...@@ -94,6 +94,9 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -94,6 +94,9 @@ class TestAccounting(ERP5TypeTestCase):
def afterSetUp(self): def afterSetUp(self):
"""Prepare the test.""" """Prepare the test."""
self.createCategories() self.createCategories()
self.createCurrencies()
self.createEntities()
self.createAccounts()
self.login() self.login()
def login(self) : def login(self) :
...@@ -127,7 +130,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -127,7 +130,7 @@ class TestAccounting(ERP5TypeTestCase):
def getNeededCategoryList(self): def getNeededCategoryList(self):
"""Returns a list of categories that should be created.""" """Returns a list of categories that should be created."""
return ('group/client', 'group/vendor', return ('group/client', 'group/vendor/sub1', 'group/vendor/sub2',
'region/%s'%self.default_region, ) 'region/%s'%self.default_region, )
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
...@@ -138,24 +141,34 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -138,24 +141,34 @@ class TestAccounting(ERP5TypeTestCase):
"""Flush activity queue. """ """Flush activity queue. """
self.tic() self.tic()
def stepCreateEntities(self, sequence, **kw) : def createEntities(self):
"""Create a vendor and a client. """ """Create entities. """
client = self.getOrganisationModule().newContent( self.client = self.getOrganisationModule().newContent(
portal_type = self.organisation_portal_type, portal_type = self.organisation_portal_type,
group = "group/client", group = "group/client",
price_currency = "currency_module/USD") price_currency = "currency_module/USD")
vendor = self.getOrganisationModule().newContent( self.vendor = self.getOrganisationModule().newContent(
portal_type = self.organisation_portal_type, portal_type = self.organisation_portal_type,
group = "group/vendor", group = "group/vendor/sub1",
price_currency = "currency_module/EUR")
self.other_vendor = self.getOrganisationModule().newContent(
portal_type = self.organisation_portal_type,
group = "group/vendor/sub2",
price_currency = "currency_module/EUR") price_currency = "currency_module/EUR")
# validate entities # validate entities
for entity in (client, vendor): for entity in (self.client, self.vendor, self.other_vendor):
entity.setRegion(self.default_region) entity.setRegion(self.default_region)
self.getWorkflowTool().doActionFor(entity, 'validate_action') self.getWorkflowTool().doActionFor(entity, 'validate_action')
get_transaction().commit()
self.tic()
sequence.edit( client = client, def stepCreateEntities(self, sequence, **kw) :
vendor = vendor, """Create entities. """
organisation = vendor ) # TODO: remove this method
sequence.edit( client=self.client,
vendor=self.vendor,
other_vendor=self.other_vendor,
organisation=self.vendor )
def stepCreateAccountingPeriod(self, sequence, **kw): def stepCreateAccountingPeriod(self, sequence, **kw):
"""Creates an Accounting Period for the Organisation.""" """Creates an Accounting Period for the Organisation."""
...@@ -217,57 +230,64 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -217,57 +230,64 @@ class TestAccounting(ERP5TypeTestCase):
self.assertEquals(accounting_period.getSimulationState(), self.assertEquals(accounting_period.getSimulationState(),
'delivered') 'delivered')
def createCurrencies(self):
def stepCreateCurrencies(self, sequence, **kw) : """Create some currencies.
"""Create a some currencies. """ This script will reuse existing currencies, because we want currency ids to
if hasattr(self.getCurrencyModule(), 'EUR'): be stable, as we use them as categories.
sequence.edit( """
EUR = self.getCurrencyModule()['EUR'], currency_module = self.getCurrencyModule()
USD = self.getCurrencyModule()['USD'], if not hasattr(currency_module, 'EUR'):
YEN = self.getCurrencyModule()['YEN'], self.EUR = currency_module.newContent(
)
return
EUR = self.getCurrencyModule().newContent(
portal_type = self.currency_portal_type, portal_type = self.currency_portal_type,
reference = "EUR", reference = "EUR", id = "EUR" )
id = "EUR" ) self.USD = currency_module.newContent(
USD = self.getCurrencyModule().newContent(
portal_type = self.currency_portal_type, portal_type = self.currency_portal_type,
reference = "USD", reference = "USD", id = "USD" )
id = "USD" ) self.YEN = currency_module.newContent(
YEN = self.getCurrencyModule().newContent(
portal_type = self.currency_portal_type, portal_type = self.currency_portal_type,
reference = "YEN", reference = "YEN", id = "YEN" )
id = "YEN" ) get_transaction().commit()
sequence.edit( EUR = EUR, USD = USD, YEN = YEN ) self.tic()
else:
self.EUR = currency_module.EUR
self.USD = currency_module.USD
self.YEN = currency_module.YEN
def stepCreateAccounts(self, sequence, **kw) : def stepCreateCurrencies(self, sequence, **kw) :
"""Create necessary accounts. """ """Create some currencies. """
receivable = self.getAccountModule().newContent( # TODO: remove
sequence.edit(EUR=self.EUR, USD=self.USD, YEN=self.YEN)
def createAccounts(self):
"""Create some accounts.
"""
receivable = self.receivable_account = self.getAccountModule().newContent(
title = 'receivable', title = 'receivable',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'asset/receivable' ) account_type = 'asset/receivable' )
payable = self.getAccountModule().newContent( payable = self.payable_account = self.getAccountModule().newContent(
title = 'payable', title = 'payable',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'liability/payable' ) account_type = 'liability/payable' )
expense = self.getAccountModule().newContent( expense = self.expense_account = self.getAccountModule().newContent(
title = 'expense', title = 'expense',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'expense' ) account_type = 'expense' )
income = self.getAccountModule().newContent( income = self.income_account = self.getAccountModule().newContent(
title = 'income', title = 'income',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'income' ) account_type = 'income' )
collected_vat = self.getAccountModule().newContent( collected_vat = self.collected_vat_account = self\
.getAccountModule().newContent(
title = 'collected_vat', title = 'collected_vat',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'liability/payable/collected_vat' ) account_type = 'liability/payable/collected_vat' )
refundable_vat = self.getAccountModule().newContent( refundable_vat = self.refundable_vat_account = self\
.getAccountModule().newContent(
title = 'refundable_vat', title = 'refundable_vat',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'asset/receivable/refundable_vat' ) account_type = 'asset/receivable/refundable_vat' )
bank = self.getAccountModule().newContent( bank = self.bank_account = self.getAccountModule().newContent(
title = 'bank', title = 'bank',
portal_type = self.account_portal_type, portal_type = self.account_portal_type,
account_type = 'asset/cash/bank') account_type = 'asset/cash/bank')
...@@ -281,7 +301,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -281,7 +301,7 @@ class TestAccounting(ERP5TypeTestCase):
refundable_vat.setDestinationValue(collected_vat) refundable_vat.setDestinationValue(collected_vat)
bank.setDestinationValue(bank) bank.setDestinationValue(bank)
account_list = [ receivable, self.account_list = [ receivable,
payable, payable,
expense, expense,
income, income,
...@@ -289,20 +309,24 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -289,20 +309,24 @@ class TestAccounting(ERP5TypeTestCase):
refundable_vat, refundable_vat,
bank ] bank ]
for account in account_list : for account in self.account_list :
account.validate() account.validate()
self.failUnless('Site Error' not in account.view()) self.failUnless('Site Error' not in account.view())
self.assertEquals(account.getValidationState(), 'validated') self.assertEquals(account.getValidationState(), 'validated')
get_transaction().commit()
self.tic()
sequence.edit( receivable_account = receivable, def stepCreateAccounts(self, sequence, **kw) :
payable_account = payable, """Create necessary accounts. """
expense_account = expense, # XXX remove me !
income_account = income, sequence.edit( receivable_account=self.receivable_account,
collected_vat_account = collected_vat, payable_account=self.payable_account,
refundable_vat_account = refundable_vat, expense_account=self.expense_account,
bank_account = bank, income_account=self.income_account,
account_list = account_list ) collected_vat_account=self.collected_vat_account,
refundable_vat_account=self.refundable_vat_account,
bank_account=self.bank_account,
account_list=self.account_list )
def stepCreateAccountingTransactionAndCheckMirrorAccount(self, def stepCreateAccountingTransactionAndCheckMirrorAccount(self,
sequence, **kw): sequence, **kw):
...@@ -655,61 +679,95 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -655,61 +679,95 @@ class TestAccounting(ERP5TypeTestCase):
accounting_transaction.getPortalType(), accounting_transaction.getPortalType(),
allowed_content_types )) allowed_content_types ))
def stepCreateValidAccountingTransaction(self, sequence, def createAccountingTransaction(self,
sequence_list=None, **kw) : portal_type=accounting_transaction_portal_type,
"""Creates a valide accounting transaction and put it in line_portal_type=accounting_transaction_line_portal_type,
the sequence as `transaction` key. """ quantity=100, reindex=1, check_consistency=1, **kw):
resource_value = sequence.get('EUR') """Creates an accounting transaction.
source_section_value = sequence.get('vendor') By default, this transaction contains 2 lines, income and receivable.
destination_section_value = sequence.get('client') quantity - The quantity property on created lines.
start_date = DateTime(2000,01,01) reindex - The transaction will be reindexed.
stop_date = DateTime(2000,02,02) check_consistency - a consistency check will be performed on the
# get a date inside openned period, if any transaction.
"""
kw.setdefault('resource_value', self.EUR)
kw.setdefault('source_section_value', self.vendor)
kw.setdefault('destination_section_value', self.client)
if 'start_date' not in kw:
start_date = DateTime(2000, 01, 01)
# get a valid date for source section
for openned_source_section_period in\ for openned_source_section_period in\
source_section_value.searchFolder( kw['source_section_value'].searchFolder(
portal_type = self.accounting_period_portal_type, portal_type=self.accounting_period_portal_type,
simulation_state = 'planned' ): simulation_state='planned' ):
start_date = openned_source_section_period.getStartDate() + 1 start_date = openned_source_section_period.getStartDate() + 1
kw['start_date'] = start_date
if 'stop_date' not in kw:
# get a valid date for destination section
stop_date = DateTime(2000, 02, 02)
for openned_destination_section_period in\ for openned_destination_section_period in\
destination_section_value.searchFolder( kw['destination_section_value'].searchFolder(
portal_type = self.accounting_period_portal_type, portal_type=self.accounting_period_portal_type,
simulation_state = 'planned' ): simulation_state='planned' ):
stop_date = openned_destination_section_period.getStartDate() + 1 stop_date = openned_destination_section_period.getStartDate() + 1
kw['stop_date'] = stop_date
# create the transaction.
transaction = self.getAccountingModule().newContent( transaction = self.getAccountingModule().newContent(
portal_type = self.accounting_transaction_portal_type, portal_type=portal_type,
start_date = start_date, start_date=kw['start_date'],
stop_date = stop_date, stop_date=kw['stop_date'],
resource_value = resource_value, resource_value=kw['resource_value'],
source_section_value = source_section_value, source_section_value=kw['source_section_value'],
destination_section_value = destination_section_value, destination_section_value=kw['destination_section_value'],
created_by_builder = 1 # XXX prevent the init script from created_by_builder = 1 # prevent the init script from
# creating lines. # creating lines.
) )
income = transaction.newContent( income = transaction.newContent(
portal_type = self.accounting_transaction_line_portal_type, id='income',
quantity = 100, portal_type=line_portal_type,
source_value = sequence.get('income_account'), quantity=quantity,
destination_value = sequence.get('expense_account'), source_value=kw.get('income_account', self.income_account),
) destination_value=kw.get('expense_account',
self.expense_account), )
self.failUnless(income.getSource() != None) self.failUnless(income.getSource() != None)
self.failUnless(income.getDestination() != None) self.failUnless(income.getDestination() != None)
receivable = transaction.newContent( receivable = transaction.newContent(
portal_type = self.accounting_transaction_line_portal_type, id='receivable',
quantity = -100, portal_type=line_portal_type,
source_value = sequence.get('receivable_account'), quantity=-quantity,
destination_value = sequence.get('payable_account'), source_value=kw.get('receivable_account',
) self.receivable_account),
destination_value=kw.get('payable_account',
self.payable_account), )
self.failUnless(receivable.getSource() != None) self.failUnless(receivable.getSource() != None)
self.failUnless(receivable.getDestination() != None) self.failUnless(receivable.getDestination() != None)
if reindex:
get_transaction().commit()
self.tic()
if check_consistency:
self.failUnless(len(transaction.checkConsistency()) == 0, self.failUnless(len(transaction.checkConsistency()) == 0,
"Check consistency failed : %s" % transaction.checkConsistency()) "Check consistency failed : %s" % transaction.checkConsistency())
return transaction
def stepCreateValidAccountingTransaction(self, sequence,
sequence_list=None, **kw) :
"""Creates a valid accounting transaction and put it in
the sequence as `transaction` key. """
transaction = self.createAccountingTransaction(
resource_value=sequence.get('EUR'),
source_section_value=sequence.get('vendor'),
destination_section_value=sequence.get('client'),
income_account=sequence.get('income_account'),
expense_account=sequence.get('expense_account'),
receivable_account=sequence.get('receivable_account'),
payable_account=sequence.get('payable_account'), )
sequence.edit( sequence.edit(
transaction = transaction, transaction = transaction,
income = income, income = transaction.income,
receivable = receivable receivable = transaction.receivable
) )
def stepValidateNoDate(self, sequence, sequence_list=None, **kw) : def stepValidateNoDate(self, sequence, sequence_list=None, **kw) :
...@@ -960,7 +1018,7 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -960,7 +1018,7 @@ class TestAccounting(ERP5TypeTestCase):
line.edit( source_value = sequence.get('bank_account'), line.edit( source_value = sequence.get('bank_account'),
destination_value = sequence.get('bank_account') ) destination_value = sequence.get('bank_account') )
self.failUnless(income_account_found) self.failUnless(income_account_found)
# XXX
transaction = sequence.get('transaction') transaction = sequence.get('transaction')
useBankAccount(transaction) useBankAccount(transaction)
self.assertRaises(ValidationFailed, self.assertRaises(ValidationFailed,
...@@ -975,11 +1033,12 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -975,11 +1033,12 @@ class TestAccounting(ERP5TypeTestCase):
portal_type = ptype, ) portal_type = ptype, )
destination_payment_value = destination_section_value.newContent( destination_payment_value = destination_section_value.newContent(
portal_type = ptype, ) portal_type = ptype, )
self.stepCreateValidAccountingTransaction(sequence) transaction = self.createAccountingTransaction(
transaction = sequence.get('transaction') destination_section_value=self.other_vendor)
useBankAccount(transaction) useBankAccount(transaction)
# payment node have to be set on both sides # payment node have to be set on both sides if both sides are member of
# the same group.
transaction.setSourcePaymentValue(source_payment_value) transaction.setSourcePaymentValue(source_payment_value)
transaction.setDestinationPaymentValue(None) transaction.setDestinationPaymentValue(None)
self.assertRaises(ValidationFailed, self.assertRaises(ValidationFailed,
...@@ -998,7 +1057,21 @@ class TestAccounting(ERP5TypeTestCase): ...@@ -998,7 +1057,21 @@ class TestAccounting(ERP5TypeTestCase):
self.getWorkflowTool().doActionFor(transaction, 'stop_action') self.getWorkflowTool().doActionFor(transaction, 'stop_action')
self.assertEquals(transaction.getSimulationState(), 'stopped') self.assertEquals(transaction.getSimulationState(), 'stopped')
except ValidationFailed, err : except ValidationFailed, err :
self.assert_(0, "Validation failed : %s" % err.msg) self.fail("Validation failed : %s" % err.msg)
# if we are not interested in the accounting for the third party, no need
# to have a destination_payment
transaction = self.createAccountingTransaction()
useBankAccount(transaction)
# only set payment for source
transaction.setSourcePaymentValue(source_payment_value)
transaction.setDestinationPaymentValue(None)
# then we should be able to validate.
try:
self.getWorkflowTool().doActionFor(transaction, 'stop_action')
self.assertEquals(transaction.getSimulationState(), 'stopped')
except ValidationFailed, err:
self.fail("Validation failed : %s" % err.msg)
def stepValidateRemoveEmptyLines(self, sequence, sequence_list=None, **kw): def stepValidateRemoveEmptyLines(self, sequence, sequence_list=None, **kw):
"""Check validating a transaction remove empty lines. """ """Check validating a transaction remove empty lines. """
......
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