testAccounting_l10n_fr_m9.py 10.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#                       Jerome Perrin <jerome@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

"""Test suite for erp5_accounting_l10n_m9
"""
31
import unittest
32 33

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
34
from Products.ERP5Type.tests.utils import reindex
35 36 37 38 39 40 41
from AccessControl.SecurityManagement import newSecurityManager
from Products.DCWorkflow.DCWorkflow import ValidationFailed

class TestAccounting_l10n_M9(ERP5TypeTestCase):
  """Test Accounting M9 and Invoice Transmission Sheets.
  """
  RUN_ALL_TESTS = 1
42 43
  invoice_transmission_sheet_portal_type = \
        'Invoice Transmission Sheet'
44 45 46 47

  def getTitle(self):
    return "ERP5 Accounting l10n M9"
  
48
  def getInvoiceTransmissionSheetModule(self):
49 50 51
    """Returns the module for purchase invoice transmission sheets.
    """
    return getattr( self.portal,
52
                    'invoice_transmission_sheet_module',
53 54 55 56 57 58 59 60 61 62 63 64
                    None )
  
  def getAccountingModule(self):
    """Returns the accounting module."""
    return getattr( self.portal, 'accounting_module', None)

  def getAccountModule(self):
    """Returns the account module."""
    return getattr( self.portal, 'account_module', None)

  def getBusinessTemplateList(self):
    return ( 'erp5_base',
65 66
             'erp5_trade',
             'erp5_invoicing',
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
             'erp5_pdm',
             'erp5_pdf_style',
             'erp5_accounting',
             'erp5_accounting_l10n_fr_m9',
           )

  def login(self):
    """creates a user and login"""
    uf = self.getPortal().acl_users
    uf._doAddUser('zope', 'zope', ['Member', 'Assignee', 'Assignor',
                               'Auditor', 'Author', 'Manager'], [])
    user = uf.getUserById('zope').__of__(uf)
    newSecurityManager(None, user)

  def afterSetUp(self):
    """set up """
    self.login()
    portal = self.getPortal()
    self.portal = portal
    self.category_tool = portal.portal_categories
    self.section = self._createOrganisation()
    self.mirror_section = self._createOrganisation()
89 90
  
  @reindex
91 92 93 94 95 96 97
  def _createOrganisation(self, **kw):
    """Create an organisation and index it.
    """
    org = self.getOrganisationModule().newContent(portal_type='Organisation')
    org.edit(**kw)
    return org

98
  @reindex
99 100 101 102 103 104 105 106 107
  def _getAccount(self, account_id, **kw):
    """Get an account or create it.
    """
    account_module = self.getAccountModule()
    account = getattr(account_module, account_id, None)
    if account is None:
      account = account_module.newContent(id=account_id)
    account.edit(**kw)
    return account
108 109
  
  @reindex
110 111 112 113 114 115 116 117 118 119 120 121
  def _createPurchaseInvoice(self, amount=100, **kw):
    """Create a purchase invoice and index it.
    """
    payable_account = self._getAccount('payable_account',
                                       gap='fr/m9/4/40/401/4012',
                                       account_type='liability/payable')
    expense_account = self._getAccount('expense_account',
                                       gap='fr/m9/6/60/602/6022/60225',
                                       account_type='expense')
    invoice = self.getAccountingModule().newContent(
                      portal_type='Purchase Invoice Transaction',
                      created_by_builder=1)
122
    invoice.newContent(portal_type='Purchase Invoice Transaction Line',
123 124
                       source_value=expense_account,
                       quantity=amount)
125
    invoice.newContent(portal_type='Purchase Invoice Transaction Line',
126 127 128 129 130 131
                       source_value=payable_account,
                       quantity=-amount)
    invoice.edit(**kw)
    return invoice
  
  def test_TransmissionSheetModule(self):
132 133
    """Checks the invoice transmission sheet module is installed."""
    self.assertNotEquals(None, self.getInvoiceTransmissionSheetModule())
134 135 136 137 138 139 140 141 142 143 144 145 146
  
  def test_AccountingPlanInstallation(self):
    """Tests that the accounting plan is well installed."""
    self.failUnless('m9' in self.category_tool.gap.fr.objectIds())
    self.assertNotEquals(0, len(self.category_tool.gap.fr.m9.objectIds()))
    self.failUnless('gap/fr/m9' in [x[1] for x in
           self.portal.account_module.AccountModule_getAvailableGapList()])

  def test_SimpleTransmissionSheet(self):
    """Simple use case for a transmission sheet."""
    invoice = self._createPurchaseInvoice(
                            destination_section_value=self.section,
                            source_section_value=self.mirror_section, )
147
    transmission_sheet_module = self.getInvoiceTransmissionSheetModule()
148
    transmission_sheet = transmission_sheet_module.newContent(
149
            portal_type=self.invoice_transmission_sheet_portal_type)
150 151
    self.assertEquals(transmission_sheet.getValidationState(), 'draft')
    # add an invoice to the transamission sheet
Jérome Perrin's avatar
Jérome Perrin committed
152 153
    invoice.setAggregateValue(transmission_sheet)
    invoice.recursiveImmediateReindexObject()
154 155
    self.getWorkflowTool().doActionFor(
                            transmission_sheet,
156
                            'emit_action')
157
    self.assertEquals(transmission_sheet.getValidationState(),
158
                            'new')
159 160 161 162

  def test_TransmissionSheetEmitRefusedIfNoInvoice(self):
    """Transmission sheet cannot be emitted if it doesn't contain any invoice.
    """
163
    transmission_sheet_module = self.getInvoiceTransmissionSheetModule()
164
    transmission_sheet = transmission_sheet_module.newContent(
165
            portal_type=self.invoice_transmission_sheet_portal_type)
166 167 168 169
    self.assertEquals(transmission_sheet.getValidationState(), 'draft')
    self.assertRaises(ValidationFailed, self.getWorkflowTool().doActionFor,
                      transmission_sheet, 'emit_action')

170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
  def test_AccountTypeConstaintForExpense(self):
    account = self._getAccount('account',
                               gap='fr/m9/6/60/602/6022/60225',
                               account_type='expense')
    self.assertEquals([], account.checkConsistency())
  
  def test_AccountTypeConstaintFixForExpense(self):
    account = self._getAccount('account',
                               gap='fr/m9/6/60/602/6022/60225',
                               account_type='equity')
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
    self.assertEquals('expense', account.getAccountType())

  def test_AccountTypeConstaintForPayable(self):
    account = self._getAccount('payable_account',
                               gap='fr/m9/4/40',
                               account_type='liability/payable')
    self.assertEquals([], account.checkConsistency())
  
  def test_AccountTypeConstaintFixForPayable(self):
    account = self._getAccount('payable_account',
                               gap='fr/m9/4/40',
                               account_type='equity')
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
    self.assertEquals('liability/payable', account.getAccountType())

  def test_AccountTypeConstaintForClass4(self):
    # members of class 4 can be payable or receivable
    account = self._getAccount('class4_account',
                               gap='fr/m9/4/44',
                               account_type='liability/payable')
    self.assertEquals([], account.checkConsistency())
    
    account.edit(account_type='asset/receivable')
    self.assertEquals([], account.checkConsistency())
    
  def test_AccountTypeConstaintFixForClass4(self):
    # members of class 4 can be payable or receivable
    account = self._getAccount('class4_account',
                               gap='fr/m9/4/44',
                               account_type='equity')
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
    self.failUnless(account.getAccountType() in ('liability/payable',
                                                 'asset/receivable'))

215 216 217 218 219 220
  # Members of gap/fr/m9/4/47 are very specific
  # for now, we do not fix 476 or 477
  def test_AccountTypeConstaintFixFor4718(self):
    account = self._getAccount('4718',
                               gap='fr/m9/4/47/471/4718', )
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
221
    self.assertEquals('liability/payable', account.getAccountType())
222 223 224 225 226
  
  def test_AccountTypeConstaintFixFor4721(self):
    account = self._getAccount('4721',
                               gap='fr/m9/4/47/472/4721', )
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
227
    self.assertEquals('asset/receivable', account.getAccountType())
228

229 230 231 232 233 234 235 236 237 238 239 240
  def test_AccountTypeConstaintFixFor4731(self):
    account = self._getAccount('4731',
                               gap='fr/m9/4/47/473/4731', )
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
    self.assertEquals('asset/receivable', account.getAccountType())

  def test_AccountTypeConstaintFixFor4735(self):
    account = self._getAccount('4735',
                               gap='fr/m9/4/47/473/4735', )
    self.assertEquals(1, len(account.checkConsistency(fixit=1)))
    self.assertEquals('liability/payable', account.getAccountType())
    
241 242 243 244
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestAccounting_l10n_M9))
  return suite
245