testAccountingReports.py 209 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 31 32
#############################################################################
#
# Copyright (c) 2006 Nexedi SA 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.
#
##############################################################################

"""Tests Standards ERP5 Accounting Reports
"""

import unittest
33
import os
34 35 36 37

from DateTime import DateTime

from Products.ERP5.tests.testAccounting import AccountingTestCase
38
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
39
from Products.ERP5Type.tests.utils import todo_erp5
40
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
41

42
class TestAccountingReports(AccountingTestCase, ERP5ReportTestCase):
43 44 45 46 47 48 49 50 51 52 53
  """Test Accounting reports
  
  Test basic cases of gathering data to render reports, the purpose of those
  tests is to exercise basic reporting features to make sure no regression
  happen. Input data used for tests usually contain edge cases, for example:
    * movements at the boundaries of the period.
    * movements with other simulation states.
    * movements with node in the section_category we want to exclude (Persons).
    * movements with source & destination for other sections.
    ...
  """
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75

  def testJournal(self):
    # Journal report.
    # this will be a journal for 2006/02/02, for Sale Invoice Transaction
    # portal type. Many cases are covered by this test.
    
    account_module = self.account_module
    # before the date
    self._makeOne(
              portal_type='Accounting Transaction',
              simulation_state='delivered',
              start_date=DateTime(2006, 1, 1),
              lines=(dict(source_value=account_module.equity,
                          source_debit=100),
                     dict(source_value=account_module.stocks,
                          source_credit=100)))

    # during the period
    first = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='First One',
              simulation_state='delivered',
76
              reference='1',
77 78 79 80 81 82 83 84 85 86 87 88 89
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=119.60),
                     dict(source_value=account_module.collected_vat,
                          source_credit=19.60),
                     dict(source_value=account_module.goods_sales,
                          source_credit=100.00)))

    second = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Second One',
              simulation_state='delivered',
90
              reference='2',
91
              destination_section_value=self.organisation_module.client_2,
92 93 94 95 96
              start_date=DateTime(2006, 2, 2, 1, 1), # XXX we have to force
              # different values of hour minutes, because /for now/ sorting is
              # done on date, uid. Sorting on [source|destination]_reference
              # would be too heavy, and we just want a sort on date, with a
              # stable order (hence the cheap sort on uid)
97 98 99 100 101 102 103 104 105 106 107
              lines=(dict(source_value=account_module.receivable,
                          source_debit=239.20),
                     dict(source_value=account_module.collected_vat,
                          source_credit=39.20),
                     dict(source_value=account_module.goods_sales,
                          source_credit=200.00)))

    third = self._makeOne(
              title='Third One',
              portal_type='Sale Invoice Transaction',
              simulation_state='delivered',
108
              reference='3',
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
              # with a person member of the group
              destination_section_value=self.person_module.john_smith,
              start_date=DateTime(2006, 2, 2, 2, 2), # with hour:minutes
              lines=(dict(source_value=account_module.receivable,
                          destination_value=account_module.receivable,
                          source_debit=358.80),
                     dict(source_value=account_module.collected_vat,
                          source_credit=58.80),
                     dict(source_value=account_module.goods_sales,
                          # with a title on the line
                          title='Line Title',
                          source_credit=300.00)))

    # another portal type
    self._makeOne(
              portal_type='Accounting Transaction',
              simulation_state='delivered',
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.equity,
                          source_debit=111),
                     dict(source_value=account_module.stocks,
                          source_credit=111)))

    # after the period
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_2,
              start_date=DateTime(2006, 2, 3),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=598.00),
                     dict(source_value=account_module.collected_vat,
                          source_credit=98.00),
                     dict(source_value=account_module.goods_sales,
                          source_credit=500.00)))

    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
149
    request_form['section_category_strict'] = False
150 151
    request_form['portal_type'] = ['Sale Invoice Transaction']
    request_form['simulation_state'] = ['delivered']
152
    request_form['hide_analytic'] = False
153 154
    
    report_section_list = self.getReportSectionList(
155
                               self.portal.accounting_module,
156 157
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
158 159 160
    # currency is present in the report
    self.assertEquals('currency_module/euro', self.portal.
     AccountingTransactionModule_viewJournalReport.your_currency.get_value('default'))
161 162 163 164 165 166 167 168 169 170 171 172 173
    
    # precision is set in the REQUEST (so that fields know how to format)
    precision = self.portal.REQUEST.get('precision')
    self.assertEquals(2, precision)
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 3 transactions, with 3 lines each
    self.assertEquals(9, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
174 175
        ['specific_reference', 'date', 'title', 'parent_reference',
          'node_title', 'mirror_section_title', 'debit', 'credit'])
176 177
    
    # First Transaction
178 179 180 181
    self.checkLineProperties(data_line_list[0],
                            specific_reference=first.getSourceReference(),
                            date=DateTime(2006, 2, 2),
                            title='First One',
182
                            parent_reference='1',
183 184 185 186
                            node_title='41',
                            mirror_section_title='Client 1',
                            debit=119.60,
                            credit=0)
187 188
    # some values are only present when we display the first line of the
    # transaction (this is a way to see different transactions)
189 190 191 192
    self.checkLineProperties(data_line_list[1],
                            specific_reference='',
                            date=None,
                            title='',
193
                            parent_reference='',
194 195 196 197 198 199 200 201
                            node_title='4457',
                            mirror_section_title='Client 1',
                            debit=0,
                            credit=19.60)
    self.checkLineProperties(data_line_list[2],
                            specific_reference='',
                            date=None,
                            title='',
202
                            parent_reference='',
203 204 205 206
                            node_title='7',
                            mirror_section_title='Client 1',
                            debit=0,
                            credit=100)
207 208

    # Second Transaction
209 210
    self.checkLineProperties(data_line_list[3],
                            specific_reference=second.getSourceReference(),
211
                            date=DateTime(2006, 2, 2, 1, 1),
212
                            title='Second One',
213
                            parent_reference='2',
214 215 216 217 218 219 220 221
                            node_title='41',
                            mirror_section_title='Client 2',
                            debit=239.20,
                            credit=0)
    self.checkLineProperties(data_line_list[4],
                            specific_reference='',
                            date=None,
                            title='',
222
                            parent_reference='',
223 224 225 226 227 228 229 230
                            node_title='4457',
                            mirror_section_title='Client 2',
                            debit=0,
                            credit=39.20)
    self.checkLineProperties(data_line_list[5],
                            specific_reference='',
                            date=None,
                            title='',
231
                            parent_reference='',
232 233 234 235
                            node_title='7',
                            mirror_section_title='Client 2',
                            debit=0,
                            credit=200)
236 237

    # Third Transaction
238 239 240 241 242 243
    self.checkLineProperties(data_line_list[6],
                            specific_reference=third.getSourceReference(),
                            date=DateTime(2006, 2, 2, 2, 2),# 2006/02/02 will
                              # be displayed, but this rendering level cannot
                              # be tested with this framework
                            title='Third One',
244
                            parent_reference='3',
245 246 247 248 249 250 251 252
                            node_title='41',
                            mirror_section_title='John Smith',
                            debit=358.80,
                            credit=0)
    self.checkLineProperties(data_line_list[7],
                            specific_reference='',
                            date=None,
                            title='',
253
                            parent_reference='',
254 255 256 257 258 259 260 261 262 263
                            node_title='4457',
                            mirror_section_title='John Smith',
                            debit=0,
                            credit=58.80)
    self.checkLineProperties(data_line_list[8],
                            specific_reference='',
                            date=None,
                            # If a title is set on the line, we can see it on
                            # this report
                            title='Line Title',
264
                            parent_reference='',
265 266 267 268 269
                            node_title='7',
                            mirror_section_title='John Smith',
                            debit=0,
                            credit=300)
    
270 271 272 273 274 275
    # Stat Line
    stat_line = line_list[-1]
    self.failUnless(stat_line.isStatLine())
    self.failIf(stat_line.getColumnProperty('specific_reference'))
    self.failIf(stat_line.getColumnProperty('date'))
    self.failIf(stat_line.getColumnProperty('title'))
276
    self.failIf(stat_line.getColumnProperty('parent_reference'))
277 278 279 280 281 282 283 284 285
    self.failIf(stat_line.getColumnProperty('node_title'))
    self.failIf(stat_line.getColumnProperty('mirror_section_title'))
    # when printing the report, the field does the rounding, so we can round in
    # the test
    self.assertEquals(717.60, round(stat_line.getColumnProperty('debit'),
                                    precision))
    self.assertEquals(717.60, round(stat_line.getColumnProperty('credit'),
                                    precision))

286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
  def testJournalTransactionsWithoutThirdParty(self):
    # Journal report
    
    account_module = self.account_module

    # during the period
    first = self._makeOne(
              portal_type='Accounting Transaction',
              title='First One',
              simulation_state='delivered',
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=119.60),
                     dict(source_value=account_module.collected_vat,
                          source_credit=19.60),
                     dict(source_value=account_module.goods_sales,
                          source_credit=100.00)))
    self.assertEquals(None, first.getDestinationSectionValue())

    second = self._makeOne(
              portal_type='Accounting Transaction',
              title='Second One',
              simulation_state='delivered',
              destination_section_value=self.section,
              source_section=None,
              source_section_value=None,
              start_date=DateTime(2006, 2, 2, 1, 1),
              lines=(dict(destination_value=account_module.receivable,
                          destination_debit=119.60),
                     dict(destination_value=account_module.collected_vat,
                          destination_credit=19.60),
                     dict(destination_value=account_module.goods_sales,
                          destination_credit=100.00)))
    self.assertEquals(None, second.getSourceSectionValue())


    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
326
    request_form['section_category_strict'] = False
327 328
    request_form['portal_type'] = ['Accounting Transaction']
    request_form['simulation_state'] = ['delivered']
329
    request_form['hide_analytic'] = False
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
    
    # precision is set in the REQUEST (so that fields know how to format)
    precision = self.portal.REQUEST.get('precision')
    self.assertEquals(2, precision)
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 2 transactions, with 3 lines
    self.assertEquals(6, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
348
        ['specific_reference', 'date', 'title', 'parent_reference', 'node_title',
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414
         'mirror_section_title', 'debit', 'credit'])
    
    # First Transaction
    self.checkLineProperties(data_line_list[0],
                            specific_reference=first.getSourceReference(),
                            date=DateTime(2006, 2, 2),
                            title='First One',
                            node_title='41',
                            debit=119.60,
                            credit=0)
    # some values are only present when we display the first line of the
    # transaction (this is a way to see different transactions)
    self.checkLineProperties(data_line_list[1],
                            specific_reference='',
                            date=None,
                            title='',
                            node_title='4457',
                            debit=0,
                            credit=19.60)
    self.checkLineProperties(data_line_list[2],
                            specific_reference='',
                            date=None,
                            title='',
                            node_title='7',
                            debit=0,
                            credit=100)
    # second transaction
    self.checkLineProperties(data_line_list[3],
                            specific_reference=second.getDestinationReference(),
                            date=DateTime(2006, 2, 2, 1, 1),
                            title='Second One',
                            node_title='41',
                            debit=119.60,
                            credit=0)
    # some values are only present when we display the first line of the
    # transaction (this is a way to see different transactions)
    self.checkLineProperties(data_line_list[4],
                            specific_reference='',
                            date=None,
                            title='',
                            node_title='4457',
                            debit=0,
                            credit=19.60)
    self.checkLineProperties(data_line_list[5],
                            specific_reference='',
                            date=None,
                            title='',
                            node_title='7',
                            debit=0,
                            credit=100)
    
     # Stat Line
    stat_line = line_list[-1]
    self.failUnless(stat_line.isStatLine())
    self.failIf(stat_line.getColumnProperty('specific_reference'))
    self.failIf(stat_line.getColumnProperty('date'))
    self.failIf(stat_line.getColumnProperty('title'))
    self.failIf(stat_line.getColumnProperty('node_title'))
    self.failIf(stat_line.getColumnProperty('mirror_section_title'))
    # when printing the report, the field does the rounding, so we can round in
    # the test
    self.assertEquals(239.20, round(stat_line.getColumnProperty('debit'),
                                    precision))
    self.assertEquals(239.20, round(stat_line.getColumnProperty('credit'),
                                    precision))

415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455

  def testJournalWithBankAccount(self):
    # Journal report when selecting a bank account
    # this will be a journal for 2006/02/02, whith two bank accounts
    
    account_module = self.account_module

    bank1 = self.section.newContent(portal_type='Bank Account')
    bank1.validate()
    bank2 = self.section.newContent(portal_type='Bank Account')
    bank2.validate()

    transaction = self._makeOne(
              portal_type='Payment Transaction',
              title='Good One',
              simulation_state='delivered',
              source_payment_value=bank1,
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.bank,
                          source_credit=100.0)))
    
    self._makeOne(
              portal_type='Payment Transaction',
              title='Other One',
              simulation_state='delivered',
              source_payment_value=bank2,
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=200.0),
                     dict(source_value=account_module.bank,
                          source_credit=200.0)))
    
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
456
    request_form['section_category_strict'] = False
457 458 459
    request_form['portal_type'] = ['Payment Transaction']
    request_form['simulation_state'] = ['delivered']
    request_form['payment'] = bank1.getRelativeUrl()
460
    request_form['hide_analytic'] = False
461 462
    
    report_section_list = self.getReportSectionList(
463
                               self.portal.accounting_module,
464 465 466 467 468 469 470 471
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 1 transactions with 2 lines
    self.assertEquals(2, len(data_line_list))
    
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487
    self.checkLineProperties(data_line_list[0],
                            specific_reference=transaction.getSourceReference(),
                            date=DateTime(2006, 2, 2),
                            title='Good One',
                            node_title='41',
                            mirror_section_title='Client 1',
                            debit=100,
                            credit=0)
    self.checkLineProperties(data_line_list[1],
                            specific_reference='',
                            date=None,
                            title='',
                            node_title='5',
                            mirror_section_title='Client 1',
                            debit=0,
                            credit=100)
488 489
    
    # Stat Line
490 491
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit=100, credit=100)
492

Jérome Perrin's avatar
Jérome Perrin committed
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
  def testJournalProject(self):
    self.createProjectAndFunctionDataSet()
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['portal_type'] = ['Sale Invoice Transaction']
    request_form['simulation_state'] = ['delivered']
    request_form['project'] = self.project_1.getRelativeUrl()
    request_form['hide_analytic'] = True
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
        ['specific_reference', 'date', 'title', 'parent_reference',
          'node_title', 'mirror_section_title', 'debit', 'credit'])
    
    self.checkLineProperties(data_line_list[0],
                             node_title='41',
                             mirror_section_title='Client 1',
                             debit=500,
                             credit=0)
    self.checkLineProperties(data_line_list[1],
                             node_title='7',
                             debit=0,
                             credit=500)
    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit=500, credit=500)

532
  def createAccountStatementDataSet(self, use_two_bank_accounts=1):
533
    """Create transactions for Account statement report.
534 535 536

    use_two_bank_accounts -- use two different bank accounts, otherwise always
    use one bank account for all created transactions.
537 538
    """
    account_module = self.account_module
539
    bank1 = self.section.newContent(portal_type='Bank Account', title='Bank1')
540
    bank1.validate()
541 542 543 544 545 546
    if use_two_bank_accounts:
      bank2 = self.section.newContent(portal_type='Bank Account',
                                      title='Bank2')
      bank2.validate()
    else:
      bank2 = bank1
Yusuke Muraoka's avatar
Yusuke Muraoka committed
547

548 549 550 551 552
    # before
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
553
              reference='ref1',
554 555 556 557 558 559 560 561 562 563 564 565
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.payable,
                          source_credit=100.0)))
    
    t2 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 2',
              source_reference='2',
566
              reference='ref2',
567 568 569 570 571 572 573 574 575 576 577 578 579
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1, 0, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=200.0),
                     dict(source_value=account_module.receivable,
                          source_credit=200.0)))
    
    # in the period
    t3 = self._makeOne(
              portal_type='Payment Transaction',
              title='Transaction 3',
              source_reference='3',
580
              reference='ref3',
581 582 583 584 585 586 587 588 589 590 591 592 593
              simulation_state='delivered',
              source_payment_value=bank1,
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2, 0, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=300.0),
                     dict(source_value=account_module.bank,
                          source_credit=300.0)))
    
    t4 = self._makeOne(
              portal_type='Payment Transaction',
              title='Transaction 4',
              destination_reference='4',
594
              reference='ref4',
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609
              simulation_state='delivered',
              destination_section_value=self.section,
              destination_payment_value=bank1,
              source_section_value=self.organisation_module.client_2,
              stop_date=DateTime(2006, 2, 2, 0, 3),
              start_date=DateTime(2006, 2, 1),
              lines=(dict(destination_value=account_module.receivable,
                          destination_debit=400.0),
                     dict(destination_value=account_module.bank,
                          destination_credit=400.0)))
    
    t5 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 5',
              source_reference='5',
610
              reference='ref5',
611
              simulation_state='delivered',
612
              source_payment_value=bank2,
613 614 615 616 617 618 619 620 621 622 623
              destination_section_value=self.person_module.john_smith,
              start_date=DateTime(2006, 2, 2, 0, 4),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=500.0),
                     dict(source_value=account_module.bank,
                          source_credit=500.0)))
    
    t6 = self._makeOne(
              portal_type='Purchase Invoice Transaction',
              title='Transaction 6',
              destination_reference='6',
624
              reference='ref6',
625
              simulation_state='delivered',
626
              destination_payment_value=bank2,
627 628 629 630 631 632 633 634 635 636 637 638
              source_section_value=self.organisation_module.client_1,
              stop_date=DateTime(2006, 2, 2, 0, 5),
              lines=(dict(destination_value=account_module.receivable,
                          destination_debit=600.0),
                     dict(destination_value=account_module.bank,
                          destination_credit=600.0)))
    
    # another simulation state                 
    t7 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 7',
              source_reference='7',
639
              reference='ref7',
640
              simulation_state='stopped',
641
              source_payment_value=bank2,
642 643 644 645 646 647 648 649 650 651 652 653
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2, 0, 6),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=700.0),
                     dict(source_value=account_module.bank,
                          source_credit=700.0)))
    
    # after the period
    t8 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 8',
              source_reference='8',
654
              reference='ref8',
655
              simulation_state='delivered',
656
              source_payment_value=bank2,
657 658 659 660 661 662 663 664 665
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 3),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=800.0),
                     dict(source_value=account_module.bank,
                          source_credit=800.0)))
    
    return bank1, (t1, t2, t3, t4, t5, t6, t7, t8)

666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
  def createAccountStatementDataSetOnTwoPeriods(self):
    """Create accounting transactions on two periods, one transaction in 2005,
    two transactions in 2006.
    """
    account_module = self.account_module
    
    # before
    t1 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2005, 12, 31),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=100.0)))
    
    t2 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 2',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 1, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=200.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=200.0)))
    
    t3 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 3',
              source_reference='3',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=300.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=300.0)))
708

709
    return t1, t2, t3
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727
   
  @UnrestrictedMethod
  def createProjectAndFunctionDataSet(self):
    # create some functions
    function = self.portal.portal_categories.function
    if function._getOb('a', None) is None:
      function.newContent(portal_type='Category', id='a')
    self.function_a = function['a']
    if function._getOb('b', None) is None:
      function.newContent(portal_type='Category', id='b')
    self.function_b = function['b']
    # create some projects
    self.project_1 = self.portal.project_module.newContent(
                          portal_type='Project',
                          title='Project 1')
    self.project_2 = self.portal.project_module.newContent(
                          portal_type='Project',
                          title='Project 2')
728

729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
    account_module = self.portal.account_module
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Function a Project 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              source_function_value=self.function_a,
              source_project_value=self.project_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=500.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=500.0)))
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Function b Project 2',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              source_function_value=self.function_b,
              source_project_value=self.project_2,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=300.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=300.0)))
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='No function no project',
              source_reference='3',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=700.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=700.0)))

768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792
  def createMirrorSectionRoleDataSet(self):
    account_module = self.portal.account_module
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Invoice to a client',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=500.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=500.0)))
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Invoice to a supplier',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.supplier,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=300.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=300.0)))

793
  @todo_erp5
794 795
  def test_Resource_zGetMovementHistoryList(self):
    # TODO: Fix Resource_zGetMovementHistoryList so that we don't need to workaround
796 797 798 799 800 801 802 803 804 805
    #       new behaviour of MariaDB.
    #       Indeed, https://bugs.launchpad.net/maria/+bug/985828 has been marked
    #       as WONTFIX.
    q = self.portal.erp5_sql_connection.manage_test
    q("SET optimizer_switch = 'derived_merge=on'")
    try:
      self.testAccountStatement()
    finally:
      q("SET optimizer_switch = 'derived_merge=off'")

806 807 808 809 810 811 812 813 814
  def testAccountStatement(self):
    # Simple Account Statement for "Receivable" account
    self.createAccountStatementDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 2, 2)
815
    request_form['section_category'] = 'group/demo_group/sub1'
816
    request_form['section_category_strict'] = False
817
    request_form['simulation_state'] = ['delivered']
818
    request_form['hide_analytic'] = False
819 820
    
    report_section_list = self.getReportSectionList(
821
                               self.portal.accounting_module,
822 823 824 825 826 827
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    # precision is set in the REQUEST (so that fields know how to format)
    precision = self.portal.REQUEST.get('precision')
    self.assertEquals(2, precision)
828 829 830 831

    # currency is present in the report
    self.assertEquals('currency_module/euro', self.portal.
        AccountModule_viewAccountStatementReport.your_currency.get_value('default'))
832 833 834 835 836 837 838 839 840 841 842
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 6 transactions, because 7th is after
    self.assertEquals(6, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle', 'Movement_getMirrorSectionTitle',
843
         'Movement_getExplanationReference',
Jérome Perrin's avatar
Jérome Perrin committed
844
         'debit_price', 'credit_price', 'running_total_price'])
845 846 847
    
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
848
                             Movement_getExplanationReference='ref1',
849 850 851
                             date=DateTime(2006, 2, 1),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
852 853
                             debit_price=100,
                             credit_price=0,
854 855 856 857
                             running_total_price=100)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
858
                             Movement_getExplanationReference='ref2',
859 860 861
                             date=DateTime(2006, 2, 1, 0, 1),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
862 863
                             debit_price=0,
                             credit_price=200,
864 865 866 867
                             running_total_price=-100)
    
    self.checkLineProperties(data_line_list[2],
                             Movement_getSpecificReference='3',
868
                             Movement_getExplanationReference='ref3',
869 870 871
                             date=DateTime(2006, 2, 2, 0, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
872 873
                             debit_price=300,
                             credit_price=0,
874 875 876 877
                             running_total_price=200)

    self.checkLineProperties(data_line_list[3],
                             Movement_getSpecificReference='4',
878
                             Movement_getExplanationReference='ref4',
879 880 881
                             date=DateTime(2006, 2, 2, 0, 3),
                             Movement_getExplanationTitle='Transaction 4',
                             Movement_getMirrorSectionTitle='Client 2',
Jérome Perrin's avatar
Jérome Perrin committed
882 883
                             debit_price=400,
                             credit_price=0,
884 885 886 887
                             running_total_price=600)

    self.checkLineProperties(data_line_list[4],
                             Movement_getSpecificReference='5',
888
                             Movement_getExplanationReference='ref5',
889 890 891
                             date=DateTime(2006, 2, 2, 0, 4),
                             Movement_getExplanationTitle='Transaction 5',
                             Movement_getMirrorSectionTitle='John Smith',
Jérome Perrin's avatar
Jérome Perrin committed
892 893
                             debit_price=500,
                             credit_price=0,
894 895 896 897
                             running_total_price=1100)

    self.checkLineProperties(data_line_list[5],
                             Movement_getSpecificReference='6',
898
                             Movement_getExplanationReference='ref6',
899 900 901
                             date=DateTime(2006, 2, 2, 0, 5),
                             Movement_getExplanationTitle='Transaction 6',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
902 903
                             debit_price=600,
                             credit_price=0,
904 905 906 907 908 909 910 911
                             running_total_price=1700)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
                             Movement_getSpecificReference=None,
                             date=None,
                             Movement_getExplanationTitle=None,
                             Movement_getMirrorSectionTitle=None,
Jérome Perrin's avatar
Jérome Perrin committed
912 913
                             debit_price=1900,
                             credit_price=200,
914 915 916 917 918 919 920 921 922 923 924 925 926 927
                             running_total_price=None)


  def testAccountStatementFromDateSummary(self):
    # A from date summary shows balance at the beginning of the period
    self.createAccountStatementDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
928
    request_form['section_category_strict'] = False
929
    request_form['simulation_state'] = ['delivered']
930
    request_form['hide_analytic'] = False
931 932
    
    report_section_list = self.getReportSectionList(
933
                               self.portal.accounting_module,
934 935 936 937 938 939 940 941 942 943 944 945
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 1 summary line and 4 transactions
    self.assertEquals(5, len(data_line_list))
 
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
Jérome Perrin's avatar
Jérome Perrin committed
946 947
                             debit_price=100,
                             credit_price=200,
948 949 950 951 952 953 954
                             running_total_price=-100)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2, 0, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
955 956
                             debit_price=300,
                             credit_price=0,
957 958 959 960 961 962 963
                             running_total_price=200)

    self.checkLineProperties(data_line_list[2],
                             Movement_getSpecificReference='4',
                             date=DateTime(2006, 2, 2, 0, 3),
                             Movement_getExplanationTitle='Transaction 4',
                             Movement_getMirrorSectionTitle='Client 2',
Jérome Perrin's avatar
Jérome Perrin committed
964 965
                             debit_price=400,
                             credit_price=0,
966 967 968 969 970 971 972
                             running_total_price=600)

    self.checkLineProperties(data_line_list[3],
                             Movement_getSpecificReference='5',
                             date=DateTime(2006, 2, 2, 0, 4),
                             Movement_getExplanationTitle='Transaction 5',
                             Movement_getMirrorSectionTitle='John Smith',
Jérome Perrin's avatar
Jérome Perrin committed
973 974
                             debit_price=500,
                             credit_price=0,
975 976 977 978 979 980 981
                             running_total_price=1100)

    self.checkLineProperties(data_line_list[4],
                             Movement_getSpecificReference='6',
                             date=DateTime(2006, 2, 2, 0, 5),
                             Movement_getExplanationTitle='Transaction 6',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
982 983
                             debit_price=600,
                             credit_price=0,
984 985 986
                             running_total_price=1700)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
987
    self.checkLineProperties(line_list[-1], debit_price=1900, credit_price=200,)
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001


  def testAccountStatementFromDateSummaryEmpty(self):
    # A from date summary shows balance at the beginning of the period, but
    # avoids showing a '0' line
    self.createAccountStatementDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2000, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1002
    request_form['section_category_strict'] = False
1003
    request_form['simulation_state'] = ['delivered']
1004
    request_form['hide_analytic'] = False
1005 1006
    
    report_section_list = self.getReportSectionList(
1007
                               self.portal.accounting_module,
1008 1009 1010 1011 1012 1013 1014
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertNotEquals('Previous Balance',
          data_line_list[0].getColumnProperty('Movement_getSpecificReference'))

1015

1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
  def createHideGroupingDataSet(self):
    account_module = self.account_module
    # before the date
    self._makeOne(
              portal_type='Accounting Transaction',
              simulation_state='delivered',
              start_date=DateTime(2006, 1, 1),
              lines=(dict(source_value=account_module.equity,
                          source_debit=100),
                     dict(source_value=account_module.stocks,
                          source_credit=100)))

    first = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Grouped during period',
              simulation_state='delivered',
              reference='1',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          grouping_reference='A',
                          grouping_date=DateTime(2006, 2, 2),
                          source_debit=119.60),
                     dict(source_value=account_module.collected_vat,
                          source_credit=19.60),
                     dict(source_value=account_module.goods_sales,
                          source_credit=100.00)))

    second = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Grouped after period',
              simulation_state='delivered',
              reference='ref2',
              source_reference='2',
              destination_section_value=self.organisation_module.client_2,
              start_date=DateTime(2006, 2, 3),
              lines=(dict(source_value=account_module.receivable,
                          grouping_reference='B',
                          grouping_date=DateTime(2006, 3, 2),
                          source_debit=239.20),
                     dict(source_value=account_module.collected_vat,
                          source_credit=39.20),
                     dict(source_value=account_module.goods_sales,
                          source_credit=200.00)))

  def testAccountStatementHideGrouping(self):
    """Simple test for hide grouping on account statement.
    """
    self.createHideGroupingDataSet()
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 3, 1)
    request_form['section_category'] = 'group/demo_group/sub1'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False
    request_form['omit_grouping_reference'] = True

    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 1 transactions, because 1st is grouped during the period.
    self.assertEquals(1, len(data_line_list))

    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle', 'Movement_getMirrorSectionTitle',
         'Movement_getExplanationReference',
         'debit_price', 'credit_price', 'running_total_price'])

    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='2',
                             Movement_getExplanationReference='ref2',
                             date=DateTime(2006, 2, 3),
                             Movement_getExplanationTitle='Grouped after period',
                             Movement_getMirrorSectionTitle='Client 2',
                             debit_price=239.20,
                             credit_price=0,
                             running_total_price=239.20)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
                             Movement_getSpecificReference=None,
                             date=None,
                             Movement_getExplanationTitle=None,
                             Movement_getMirrorSectionTitle=None,
                             # The bottom line remain the same as when showing
                             # grouped lines
                             debit_price=358.80,
                             credit_price=0,
                             running_total_price=None)

  def testGeneralLedgerHideGrouping(self):
    # similar to testAccountStatementHideGrouping, but in general ledger.
    self.createHideGroupingDataSet()

    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 3, 1)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False
    request_form['gap_list'] = ['my_country/my_accounting_standards/4/41']
    request_form['omit_grouping_reference'] = True

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    # Except the stat, we only have one report section, because Client 1 is
    # grouped in the period.
    self.assertEquals(2, len(report_section_list))

    self.assertEquals('41 - Receivable (Client 2)',
                      report_section_list[0].getTitle())
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]

    # report layout
    self.assertEquals(['Movement_getSpecificReference',
        'Movement_getExplanationTitle', 'date',
        'Movement_getExplanationTranslatedPortalType',
        'Movement_getExplanationReference', 'Movement_getMirrorSectionTitle',
        'debit_price', 'credit_price', 'running_total_price'],
        data_line_list[0].column_id_list)

    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Grouped after period',
          date=DateTime(2006, 2, 3),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getExplanationReference='ref2',
          Movement_getMirrorSectionTitle='Client 2',
          debit_price=239.20, credit_price=0, running_total_price=239.20, )

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
          Movement_getSpecificReference=None,
          Movement_getExplanationTitle=None,
          date=None,
          Movement_getExplanationTranslatedPortalType=None,
          Movement_getExplanationReference=None,
          Movement_getMirrorSectionTitle=None,
          debit_price=239.20, credit_price=0, )

    self.assertEquals('Total', report_section_list[1].getTitle())
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # report layout
    self.assertEquals(['debit_price', 'credit_price'], data_line_list[0].column_id_list)
    self.assertEquals(1, len(data_line_list))

    # The bottom line remain the same as when showing grouped lines
    self.checkLineProperties(data_line_list[0], debit_price=358.80, credit_price=0)


1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
  def testAccountStatementFromDateDetailedSummary(self):
    # Detailed from date summary shows all lines corresponding to the balance
    # at the beginning of the period.
    # For this it relies on grouping reference property.

    # create documents
    account_module = self.account_module
    bank = self.section.newContent(portal_type='Bank Account', title='Bank')
    bank.validate()
    # before
    # this one will not have grouping reference
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.payable,
                          source_credit=100.0)))
    
    t2 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 2',
              source_reference='2',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          grouping_reference='A',
                          source_debit=200.0),
                     dict(source_value=account_module.payable,
                          source_credit=200.0)))

    # payment related to t2 invoice
    t3 = self._makeOne(
              portal_type='Payment Transaction',
              title='Transaction 3',
              source_reference='3',
              simulation_state='delivered',
              causality_value=t2,
              payment_mode='payment_mode',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 3),
              lines=(dict(source_value=account_module.bank,
                          source_debit=200.0),
                     dict(source_value=account_module.receivable,
                          grouping_reference='A',
                          source_credit=200.0)))
1230 1231 1232
    # we validate t2 later, otherwise grouping reference will be cleaned up
    t2.stop()
    t2.deliver()
1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259

    # Another invoice, grouped with a payment transaction in the period
    t4 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 4',
              source_reference='4',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 4),
              lines=(dict(source_value=account_module.receivable,
                          grouping_reference='B',
                          source_debit=400.0),
                     dict(source_value=account_module.payable,
                          source_credit=400.0)))
    t5 = self._makeOne(
              portal_type='Payment Transaction',
              title='Transaction 5',
              source_reference='5',
              simulation_state='delivered',
              causality_value=t4,
              payment_mode='payment_mode',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 3, 1),
              lines=(dict(source_value=account_module.bank,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          grouping_reference='B',
                          source_credit=400.0)))
1260 1261 1262 1263
    t4.stop()
    t4.deliver()
    self.tic()

1264 1265 1266 1267 1268 1269 1270
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 25)
    request_form['at_date'] = DateTime(2006, 6, 1)
    request_form['section_category'] = 'group/demo_group'
1271
    request_form['section_category_strict'] = False
1272 1273
    request_form['simulation_state'] = ['delivered']
    request_form['detailed_from_date_summary'] = 1
1274
    request_form['hide_analytic'] = False
1275 1276
    
    report_section_list = self.getReportSectionList(
1277
                               self.portal.accounting_module,
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296
                               'AccountModule_viewAccountStatementReport')
    # the report has 4 sections, 
    self.assertEquals(4, len(report_section_list))
    # but 2 of them are only titles
    report_section_list = [r for r in report_section_list if r.form_id]
    self.assertEquals(2, len(report_section_list))
    
    # the first section contains explanation of non grouped lines before the
    # period
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # We only have lines for the transaction 1 which is not grouped, and for
    # transaction 4, which is grouped with lines in the period.
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2006, 2, 1),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1297 1298
                             debit_price=100,
                             credit_price=0,)
1299 1300 1301 1302 1303
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='4',
                             date=DateTime(2006, 2, 4),
                             Movement_getExplanationTitle='Transaction 4',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1304 1305
                             debit_price=400,
                             credit_price=0,)
1306
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1307
    self.checkLineProperties(line_list[-1], debit_price=500, credit_price=0)
1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
    
    # Second section is for previous balance summary and lines in the period,
    # ie only transaction 5
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 25),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
                             running_total_price=500,
Jérome Perrin's avatar
Jérome Perrin committed
1320 1321
                             debit_price=700,
                             credit_price=200,)
1322 1323 1324 1325 1326 1327
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='5',
                             date=DateTime(2006, 3, 1),
                             Movement_getExplanationTitle='Transaction 5',
                             Movement_getMirrorSectionTitle='Client 1',
                             running_total_price=100,
Jérome Perrin's avatar
Jérome Perrin committed
1328 1329
                             debit_price=0,
                             credit_price=400,)
1330
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1331
    self.checkLineProperties(line_list[-1], debit_price=700, credit_price=600)
1332

1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414

  def _createAccountStatementGroupedAtFromDateDataSet(self):
    # create data set where the first transaction is grouped with another
    # transaction on 2006/02/25, but with hour:minutes, which use to cause some
    # bugs with the "non grouped lines from previous period" in the account
    # statement.
    account_module = self.account_module
    bank = self.section.newContent(portal_type='Bank Account', title='Bank')
    bank.validate()
    # before
    # this one will not have grouping reference
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.payable,
                          source_credit=100.0)))

    # This one will be grouped exactly at from_date
    t2 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 2',
              source_reference='2',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          grouping_reference='A',
                          source_debit=200.0),
                     dict(source_value=account_module.payable,
                          source_credit=200.0)))

    # payment related to t2 invoice
    t3 = self._makeOne(
              portal_type='Payment Transaction',
              title='Transaction 3',
              source_reference='3',
              simulation_state='delivered',
              causality_value=t2,
              payment_mode='payment_mode',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 25, 2, 3),
              lines=(dict(source_value=account_module.bank,
                          source_debit=200.0),
                     dict(source_value=account_module.receivable,
                          grouping_reference='A',
                          source_credit=200.0)))
    # we validate t2 later, otherwise grouping reference will be cleaned up
    t2.stop()
    t2.deliver()

    # Another invoice in the period
    t4 = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 4',
              source_reference='4',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 3, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=400.0),
                     dict(source_value=account_module.payable,
                          source_credit=400.0)))
    t4.stop()
    t4.deliver()
    self.tic()


  def testAccountStatementFromDateDetailedSummaryGroupedAtFromDate(self):
    # at the exact date of the grouped transaction
    self._createAccountStatementGroupedAtFromDateDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 25)
    request_form['at_date'] = DateTime(2006, 6, 1)
    request_form['section_category'] = 'group/demo_group'
1415
    request_form['section_category_strict'] = False
1416 1417
    request_form['simulation_state'] = ['delivered']
    request_form['detailed_from_date_summary'] = 1
1418
    request_form['hide_analytic'] = False
1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    # the report has 4 sections, 
    self.assertEquals(4, len(report_section_list))
    # but 2 of them are only titles
    report_section_list = [r for r in report_section_list if r.form_id]
    self.assertEquals(2, len(report_section_list))
    
    # the first section contains explanation of non grouped lines before the
    # period
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # We only have line for transactions 1 and 2 which are not grouped
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2006, 2, 1),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1440 1441
                             debit_price=100,
                             credit_price=0,)
1442 1443 1444 1445 1446
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1447 1448
                             debit_price=200,
                             credit_price=0,)
1449
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1450
    self.checkLineProperties(line_list[-1], debit_price=300, credit_price=0)
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
    
    # Second section is for previous balance summary and lines in the period,
    # transaction 3 and transaction 4
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(3, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 25),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
                             running_total_price=300,
Jérome Perrin's avatar
Jérome Perrin committed
1463 1464
                             debit_price=300,
                             credit_price=0,)
1465 1466 1467 1468 1469 1470
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 25, 2, 3),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
                             running_total_price=100,
Jérome Perrin's avatar
Jérome Perrin committed
1471 1472
                             debit_price=0,
                             credit_price=200,)
1473 1474 1475 1476 1477 1478
    self.checkLineProperties(data_line_list[2],
                             Movement_getSpecificReference='4',
                             date=DateTime(2006, 3, 1),
                             Movement_getExplanationTitle='Transaction 4',
                             Movement_getMirrorSectionTitle='Client 1',
                             running_total_price=500,
Jérome Perrin's avatar
Jérome Perrin committed
1479 1480
                             debit_price=400,
                             credit_price=0,)
1481
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1482
    self.checkLineProperties(line_list[-1], debit_price=700, credit_price=200)
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494

  def testAccountStatementFromDateDetailedSummaryGroupedAtFromDateCase2(self):
    # The day after the date of the grouped transaction
    self._createAccountStatementGroupedAtFromDateDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 26)
    request_form['at_date'] = DateTime(2006, 6, 1)
    request_form['section_category'] = 'group/demo_group'
1495
    request_form['section_category_strict'] = False
1496 1497
    request_form['simulation_state'] = ['delivered']
    request_form['detailed_from_date_summary'] = 1
1498
    request_form['hide_analytic'] = False
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    # the report has 4 sections, 
    self.assertEquals(4, len(report_section_list))
    # but 2 of them are only titles
    report_section_list = [r for r in report_section_list if r.form_id]
    self.assertEquals(2, len(report_section_list))
    
    # the first section contains explanation of non grouped lines before the
    # period
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # We only have line for transaction 1 which are not grouped
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2006, 2, 1),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1520 1521
                             debit_price=100,
                             credit_price=0,)
1522
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1523
    self.checkLineProperties(line_list[-1], debit_price=100, credit_price=0)
1524
    
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535
    # Second section is for previous balance summary and lines in the period,
    # transaction 4
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 26),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
                             running_total_price=100,
Jérome Perrin's avatar
Jérome Perrin committed
1536 1537
                             debit_price=300,
                             credit_price=200,)
1538 1539 1540 1541 1542 1543
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='4',
                             date=DateTime(2006, 3, 1),
                             Movement_getExplanationTitle='Transaction 4',
                             Movement_getMirrorSectionTitle='Client 1',
                             running_total_price=500,
Jérome Perrin's avatar
Jérome Perrin committed
1544 1545
                             debit_price=400,
                             credit_price=0,)
1546
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1547
    self.checkLineProperties(line_list[-1], debit_price=700, credit_price=200)
1548 1549
    

1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561
  def testAccountStatementPeriodDateForExpenseAccounts(self):
    # Account statement for expense or income account will not show
    # transactions from previous periods.
    self.createAccountStatementDataSetOnTwoPeriods()
    
    # set request variables and render   
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.goods_sales.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1562
    request_form['section_category_strict'] = False
1563
    request_form['simulation_state'] = ['delivered']
1564
    request_form['hide_analytic'] = False
1565 1566
    
    report_section_list = self.getReportSectionList(
1567
                               self.portal.accounting_module,
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # we have 3 transactions, but only 2 are in the period
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 1, 1),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1581 1582
                             debit_price=0,
                             credit_price=200,
1583 1584 1585 1586 1587 1588 1589
                             running_total_price=-200)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1590 1591
                             debit_price=0,
                             credit_price=300,
1592 1593 1594
                             running_total_price=-500)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1595
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=500)
1596 1597


1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624
  def testAccountStatementPeriodDateAndInitialBalanceForStdAccounts(self):
    # Initial balance in Account Statement for standard account: the initial
    # balance is the balance at the beginning of the period + movements in the
    # period.

    self.createAccountStatementDataSetOnTwoPeriods()
    
    t1b = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 1b',
              source_reference='1b',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 1, 2),
              lines=(dict(source_value=self.account_module.goods_sales,
                          source_debit=21.0),
                     dict(source_value=self.account_module.receivable,
                          source_credit=21.0)))
    

    # set request variables and render   
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1625
    request_form['section_category_strict'] = False
1626
    request_form['simulation_state'] = ['delivered']
1627
    request_form['hide_analytic'] = False
1628 1629
    
    report_section_list = self.getReportSectionList(
1630
                               self.portal.accounting_module,
1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
Jérome Perrin's avatar
Jérome Perrin committed
1642 1643
                             debit_price=300,
                             credit_price=21,
1644 1645 1646 1647 1648 1649 1650
                             running_total_price=279)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1651 1652
                             debit_price=300,
                             credit_price=0,
1653 1654 1655
                             running_total_price=579)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1656
    self.checkLineProperties(line_list[-1], debit_price=600, credit_price=21)
1657

1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
  def testAccountStatementPeriodDateEqualsFromDate(self):
    # Initial balance in Account Statement for standard account: the initial
    # balance is the balance at the beginning of the period + movements in the
    # period.
    # This is for the special case whe the period start date is equals to the
    # start date

    self.createAccountStatementDataSetOnTwoPeriods()
    
    t1b = self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 1b',
              source_reference='1b',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2005, 12, 13),
              lines=(dict(source_value=self.account_module.goods_sales,
                          source_debit=21.0),
                     dict(source_value=self.account_module.receivable,
                          source_credit=21.0)))
    
    # set request variables and render   
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1686
    request_form['section_category_strict'] = False
1687
    request_form['simulation_state'] = ['delivered']
1688
    request_form['hide_analytic'] = False
1689 1690
    
    report_section_list = self.getReportSectionList(
1691
                               self.portal.accounting_module,
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(3, len(data_line_list))

    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 1, 1),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
Jérome Perrin's avatar
Jérome Perrin committed
1704 1705
                             debit_price=79,
                             credit_price=0,
1706 1707 1708 1709 1710 1711 1712
                             running_total_price=79)

    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 1, 1),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1713 1714
                             debit_price=200,
                             credit_price=0,
1715 1716 1717 1718 1719 1720 1721
                             running_total_price=279)

    self.checkLineProperties(data_line_list[2],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1722 1723
                             debit_price=300,
                             credit_price=0,
1724 1725 1726
                             running_total_price=579)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1727
    self.checkLineProperties(line_list[-1], debit_price=579, credit_price=0)
1728

1729

1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741
  def testAccountStatementPeriodDateAndInitialBalanceForExpenseAccounts(self):
    # Account statement for expense or income account will not show
    # transactions from previous periods (also for the Initial Balance line)
    self.createAccountStatementDataSetOnTwoPeriods()
    
    # set request variables and render   
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.goods_sales.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1742
    request_form['section_category_strict'] = False
1743
    request_form['simulation_state'] = ['delivered']
1744
    request_form['hide_analytic'] = False
1745 1746
    
    report_section_list = self.getReportSectionList(
1747
                               self.portal.accounting_module,
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='Previous Balance',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='',
                             Movement_getMirrorSectionTitle='',
Jérome Perrin's avatar
Jérome Perrin committed
1759 1760
                             debit_price=0,
                             credit_price=200,
1761 1762 1763 1764 1765 1766 1767
                             running_total_price=-200)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1768 1769
                             debit_price=0,
                             credit_price=300,
1770 1771 1772
                             running_total_price=-500)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1773
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=500)
1774 1775


1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830
  def testAccountStatementOverMultiplePeriodsForExpenseAccounts(self):
    # Account statement for expense or income account can be used over multiple
    # periods
    self.createAccountStatementDataSetOnTwoPeriods()
    
    # set request variables and render   
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.goods_sales.getRelativeUrl()
    request_form['from_date'] = DateTime(2005, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(3, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2005, 12, 31),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
                             debit_price=0,
                             credit_price=100,
                             running_total_price=-100)
    
    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 1, 1),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
                             debit_price=0,
                             credit_price=200,
                             running_total_price=-300)

    self.checkLineProperties(data_line_list[2],
                             Movement_getSpecificReference='3',
                             date=DateTime(2006, 2, 2),
                             Movement_getExplanationTitle='Transaction 3',
                             Movement_getMirrorSectionTitle='Client 1',
                             debit_price=0,
                             credit_price=300,
                             running_total_price=-600)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=600)


1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842
  def testAccountStatementMirrorSection(self):
    # 'Mirror Section' parameter is taken into account.
    self.createAccountStatementDataSet()
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['mirror_section'] = \
                self.portal.organisation_module.client_2.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 2, 2)
    request_form['at_date'] = DateTime(2006, 2, 2)
1843
    request_form['section_category'] = 'group/demo_group/sub1'
1844
    request_form['section_category_strict'] = False
1845
    request_form['simulation_state'] = ['delivered']
1846
    request_form['hide_analytic'] = False
1847 1848
    
    report_section_list = self.getReportSectionList(
1849
                                    self.portal.accounting_module,
1850 1851 1852 1853 1854 1855
                                    'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))

1856 1857 1858 1859 1860 1861 1862 1863
    line = data_line_list[0]
    # mirror section title is not in the list of columns, as a mirror section
    # is choosen in the dialog
    self.assertEquals(line.column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle', 'Movement_getExplanationReference',
         'debit_price', 'credit_price', 'running_total_price'])

1864 1865 1866 1867
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='4',
                             date=DateTime(2006, 2, 2, 0, 3),
                             Movement_getExplanationTitle='Transaction 4',
Jérome Perrin's avatar
Jérome Perrin committed
1868 1869
                             debit_price=400,
                             credit_price=0,
1870 1871 1872
                             running_total_price=400)
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1873
    self.checkLineProperties(line_list[-1], debit_price=400, credit_price=0)
1874 1875 1876 1877 1878 1879


  def testAccountStatementSimulationState(self):
    # Simulation State parameter is taken into account.
    self.createAccountStatementDataSet()
    
1880
    # set request variables and render
1881 1882 1883 1884 1885
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                  self.portal.account_module.receivable.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
1886
    request_form['section_category_strict'] = False
1887
    request_form['simulation_state'] = ['stopped', 'confirmed']
1888
    request_form['hide_analytic'] = False
1889 1890

    report_section_list = self.getReportSectionList(
1891
                                    self.portal.accounting_module,
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902
                                    'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='7',
                             date=DateTime(2006, 2, 2, 0, 6),
                             Movement_getExplanationTitle='Transaction 7',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1903 1904
                             debit_price=700,
                             credit_price=0,
1905 1906 1907
                             running_total_price=700)
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1908
    self.checkLineProperties(line_list[-1], debit_price=700, credit_price=0)
1909 1910


1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
  def testAccountStatementCancellationAmount(self):
    # Account statement with cancellation amount set on lines
    account_module = self.account_module
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1, 0, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=100.0,),
                     dict(source_value=account_module.receivable,
                          source_debit=-100.0,
                          cancellation_amount=True)))

    t2 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 2',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1, 0, 2),
              lines=(dict(source_value=account_module.payable,
                          source_credit=200.0),
                     dict(source_value=account_module.receivable,
                          source_credit=-200.0,
                          cancellation_amount=True)))
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
1947
    request_form['section_category_strict'] = False
1948
    request_form['simulation_state'] = ['delivered']
1949
    request_form['hide_analytic'] = False
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
 
    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2006, 2, 1, 0, 1),
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1964 1965
                             debit_price=-100,
                             credit_price=0,
1966 1967 1968 1969 1970 1971 1972
                             running_total_price=-100)

    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 2, 1, 0, 2),
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
1973 1974
                             debit_price=0,
                             credit_price=-200,
1975 1976 1977
                             running_total_price=100)

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
1978
    self.checkLineProperties(line_list[-1], debit_price=-100, credit_price=-200,)
1979 1980


1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
  def testAccountStatementSameSectionSameNode(self):
    # Account statement with a movement on the same section and the same node
    account_module = self.account_module
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='Source Reference',
              destination_reference='Destination Reference',
              simulation_state='delivered',
              source_section_value=self.section,
              destination_section_value=self.section,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          destination_value=account_module.payable,
                          source_debit=100.0,),
                     dict(source_value=account_module.receivable,
                          destination_value=account_module.receivable,
                          source_credit=100.0,)))
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2007
    request_form['section_category_strict'] = False
2008
    request_form['simulation_state'] = ['delivered']
2009
    request_form['hide_analytic'] = False
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    self.assertEquals(
        set([line.getColumnProperty('Movement_getSpecificReference') for line in
              data_line_list]),
        set(('Source Reference', 'Destination Reference')))

    for line in data_line_list:
      if line.getColumnProperty('Movement_getSpecificReference')\
              == 'Source Reference':
        self.checkLineProperties(line,
                                 Movement_getSpecificReference='Source Reference',
                                 date=DateTime(2006, 2, 1),
                                 Movement_getExplanationTitle='Transaction 1',
                                 Movement_getMirrorSectionTitle=self.section.getTitle(),
Jérome Perrin's avatar
Jérome Perrin committed
2031 2032
                                 debit_price=0,
                                 credit_price=100,)
2033 2034 2035 2036 2037 2038
      else:
        self.checkLineProperties(line,
                                 Movement_getSpecificReference='Destination Reference',
                                 date=DateTime(2006, 2, 1),
                                 Movement_getExplanationTitle='Transaction 1',
                                 Movement_getMirrorSectionTitle=self.section.getTitle(),
Jérome Perrin's avatar
Jérome Perrin committed
2039 2040
                                 debit_price=100,
                                 credit_price=0,)
2041 2042

    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
2043
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=0,)
2044 2045


2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080
  def testAccountStatementMultipleSection(self):
    # When there are multiple sections for the same group, an extra column
    # is added for the section
    account_module = self.portal.account_module
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.payable,
                          source_credit=100.0)))
    
    t2 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 2',
              source_reference='2',
              source_section_value=self.main_section,
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1, 0, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=200.0),
                     dict(source_value=account_module.receivable,
                          source_credit=200.0)))
    
    # set request variables and render                 
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.receivable.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
2081
    request_form['section_category_strict'] = False
2082
    request_form['simulation_state'] = ['delivered']
2083
    request_form['hide_analytic'] = False
2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096
    
    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.assertEquals(data_line_list[0].column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle', 'section_title',
         'Movement_getMirrorSectionTitle',
2097
         'Movement_getExplanationReference',
Jérome Perrin's avatar
Jérome Perrin committed
2098
         'debit_price', 'credit_price', 'running_total_price'])
2099 2100 2101 2102 2103 2104 2105

    self.checkLineProperties(data_line_list[0],
                             Movement_getSpecificReference='1',
                             date=DateTime(2006, 2, 1),
                             section_title='My Organisation',
                             Movement_getExplanationTitle='Transaction 1',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
2106 2107
                             debit_price=100,
                             credit_price=0,
2108 2109 2110 2111 2112 2113 2114 2115
                             running_total_price=100)

    self.checkLineProperties(data_line_list[1],
                             Movement_getSpecificReference='2',
                             date=DateTime(2006, 2, 1, 0, 1),
                             section_title='My Master Organisation',
                             Movement_getExplanationTitle='Transaction 2',
                             Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
2116 2117
                             debit_price=0,
                             credit_price=200,
2118 2119 2120
                             running_total_price=-100)
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
2121
    self.checkLineProperties(line_list[-1], debit_price=100, credit_price=200)
2122

2123 2124 2125
  def testTrialBalance(self):
    # Simple test of trial balance
    # we will use the same data set as account statement
2126
    self.createAccountStatementDataSet(use_two_bank_accounts=0)
2127 2128 2129 2130 2131 2132

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2133
    request_form['section_category_strict'] = False
2134 2135 2136
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['show_empty_accounts'] = 1
    request_form['expand_accounts'] = 0
2137
    request_form['per_account_class_summary'] = 0
2138 2139

    report_section_list = self.getReportSectionList(
2140
                                    self.portal.accounting_module,
2141 2142 2143 2144
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
2145
    
2146 2147 2148 2149
    # currency is present in the report
    self.assertEquals('currency_module/euro', self.portal.
        AccountModule_viewTrialBalanceReport.your_currency.get_value('default'))

2150
    # all accounts are present
2151 2152 2153 2154 2155
    self.assertEquals(
          len(self.portal.account_module.contentValues(portal_type='Account')),
          len(data_line_list))
    
    self.assertEquals(['node_id', 'node_title',
2156 2157
           'initial_debit_balance', 'initial_credit_balance', 'debit',
           'credit', 'final_debit_balance', 'final_credit_balance',
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167
           'final_balance_if_debit', 'final_balance_if_credit'],
           data_line_list[0].column_id_list)
    
    # account are sorted by GAP Id
    self.checkLineProperties(data_line_list[0], node_id='1',
        node_title='Equity', initial_debit_balance=0, initial_credit_balance=0,
        debit=0, credit=0, final_debit_balance=0, final_credit_balance=0,
        final_balance_if_debit=0, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='2',
2168 2169 2170 2171
        node_title='Fixed Assets', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=0, final_debit_balance=0,
        final_credit_balance=0, final_balance_if_debit=0,
        final_balance_if_credit=0)
2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201
    
    self.checkLineProperties(data_line_list[2], node_id='3',
        node_title='Stocks', initial_debit_balance=0, initial_credit_balance=0,
        debit=0, credit=0, final_debit_balance=0, final_credit_balance=0,
        final_balance_if_debit=0, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[3], node_id='40',
        node_title='Payable', initial_debit_balance=0, initial_credit_balance=0,
        debit=200, credit=100, final_debit_balance=200, final_credit_balance=100,
        final_balance_if_debit=100, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[4], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=3400, credit=200,
        final_debit_balance=3400, final_credit_balance=200,
        final_balance_if_debit=3200, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[5], node_id='4456',
        node_title='Refundable VAT 10%', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=0, final_debit_balance=0,
        final_credit_balance=0, final_balance_if_debit=0,
        final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[6], node_id='4457',
        node_title='Collected VAT 10%', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=0, final_debit_balance=0,
        final_credit_balance=0, final_balance_if_debit=0,
        final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[7], node_id='5',
2202
        node_title='Bank (Bank1)', initial_debit_balance=0,
2203 2204 2205 2206 2207 2208 2209
        initial_credit_balance=0, debit=0, credit=3300, final_debit_balance=0,
        final_credit_balance=3300, final_balance_if_debit=0,
        final_balance_if_credit=3300,)
    
    self.checkLineProperties(data_line_list[8], node_id='6',
        node_title='Goods Purchase', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=0, final_debit_balance=0,
2210 2211
        final_credit_balance=0, final_balance_if_debit=0,
        final_balance_if_credit=0)
2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222
    
    self.checkLineProperties(data_line_list[9], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=0, final_debit_balance=0,
        final_credit_balance=0, final_balance_if_debit=0,
        final_balance_if_credit=0)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=3600,
        credit=3600, final_debit_balance=3600, final_credit_balance=3600,
2223
        final_balance_if_debit=3300, final_balance_if_credit=3300)
2224

2225 2226 2227 2228 2229 2230 2231 2232 2233 2234
    
  def testTrialBalanceExpandAccounts(self):
    # Test of "expand accounts" feature of trial balance
    self.createAccountStatementDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
2235
    request_form['section_category_strict'] = False
2236 2237 2238
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 1
2239
    request_form['per_account_class_summary'] = 0
2240
    request_form['group_analytic'] = []
2241 2242

    report_section_list = self.getReportSectionList(
2243
                                    self.portal.accounting_module,
2244 2245 2246 2247 2248 2249
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(6, len(data_line_list))
2250 2251 2252 2253 2254
    
    self.assertEquals(['node_id', 'node_title', 'mirror_section_title',
      'initial_debit_balance', 'initial_credit_balance', 'debit', 'credit',
      'final_debit_balance', 'final_credit_balance', 'final_balance_if_debit',
      'final_balance_if_credit'], data_line_list[0].column_id_list)
2255 2256 2257

    # account are sorted by GAP Id
    self.checkLineProperties(data_line_list[0], node_id='40',
2258 2259 2260
        node_title='Payable', mirror_section_title='Client 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=200,
        credit=100, final_debit_balance=200, final_credit_balance=100,
2261 2262 2263
        final_balance_if_debit=100, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
2264 2265 2266
        node_title='Receivable', mirror_section_title='Client 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=1000,
        credit=200, final_debit_balance=1000, final_credit_balance=200,
2267 2268 2269
        final_balance_if_debit=800, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[2], node_id='41',
2270 2271 2272 2273
        node_title='Receivable', mirror_section_title='Client 2',
        initial_debit_balance=0, initial_credit_balance=0, debit=400, credit=0,
        final_debit_balance=400, final_credit_balance=0,
        final_balance_if_debit=400, final_balance_if_credit=0)
2274 2275
    
    self.checkLineProperties(data_line_list[3], node_id='41',
2276 2277
        node_title='Receivable', mirror_section_title='John Smith',
        initial_debit_balance=0, initial_credit_balance=0, debit=500, credit=0,
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296
        final_debit_balance=500, final_credit_balance=0,
        final_balance_if_debit=500, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[4], node_id='5',
        node_title='Bank (Bank1)', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=700,
        final_debit_balance=0, final_credit_balance=700,
        final_balance_if_debit=0, final_balance_if_credit=700,)
    
    self.checkLineProperties(data_line_list[5], node_id='5',
        node_title='Bank (Bank2)', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=1100,
        final_debit_balance=0, final_credit_balance=1100,
        final_balance_if_debit=0, final_balance_if_credit=1100,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=2100,
        credit=2100, final_debit_balance=2100, final_credit_balance=2100,
2297
        final_balance_if_debit=1800, final_balance_if_credit=1800)
2298

2299

2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320
  def testTrialBalancePreviousPeriod(self):
    # Test of trial balance and previous period
    self.createAccountStatementDataSet(use_two_bank_accounts=0)
    account_module = self.portal.account_module
    # previous period
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -1',
              source_reference='-1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2005, 2, 2),
              lines=(dict(source_value=account_module.goods_purchase,
                          source_debit=600.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=600.0),))
  
    # balance transaction
    self._makeOne(
              portal_type='Balance Transaction',
              title='Transaction 0',
2321
              destination_reference='0',
2322 2323
              simulation_state='delivered',
              start_date=DateTime(2006, 1, 1),
2324 2325 2326
              lines=(dict(destination_value=account_module.payable,
                          destination_credit=600.0,
                          source_section_value=
2327
                              self.organisation_module.client_1,),
2328 2329 2330
                     dict(destination_value=account_module.receivable,
                          destination_debit=400.0,
                          source_section_value=
2331
                              self.organisation_module.client_2,),
2332 2333
                     dict(destination_value=account_module.equity,
                          destination_debit=200)))
2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353
    
    # one more transaction in the period, because our testing data does not
    # include the sales
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Transaction 0.5',
              source_reference='0.5',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_2,
              start_date=DateTime(2006, 1, 1),
              lines=(dict(source_value=account_module.goods_sales,
                          source_credit=50.0),
                     dict(source_value=account_module.receivable,
                          source_debit=50.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
2354
    request_form['section_category_strict'] = False
2355 2356 2357
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
2358
    request_form['per_account_class_summary'] = 0
2359
    request_form['group_analytic'] = []
2360 2361

    report_section_list = self.getReportSectionList(
2362
                                    self.portal.accounting_module,
2363 2364 2365 2366
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
2367
    
2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405
    self.assertEquals(5, len(data_line_list))

    # account are sorted by GAP Id
    # TODO: sort by "gap normalized path"
    self.checkLineProperties(data_line_list[0], node_id='1',
        node_title='Equity', initial_debit_balance=200,
        initial_credit_balance=0, debit=0, credit=0,
        final_debit_balance=200, final_credit_balance=0,
        final_balance_if_debit=200, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='40',
        node_title='Payable', initial_debit_balance=0,
        initial_credit_balance=600, debit=200, credit=100,
        final_debit_balance=200, final_credit_balance=700,
        final_balance_if_debit=0, final_balance_if_credit=500)
    
    self.checkLineProperties(data_line_list[2], node_id='41',
        node_title='Receivable', initial_debit_balance=400,
        initial_credit_balance=0, debit=1950, credit=200,
        final_debit_balance=2350, final_credit_balance=200,
        final_balance_if_debit=2150, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[3], node_id='5',
        node_title='Bank (Bank1)', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=1800,
        final_debit_balance=0, final_credit_balance=1800,
        final_balance_if_debit=0, final_balance_if_credit=1800,)
    
    self.checkLineProperties(data_line_list[4], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=50,
        final_debit_balance=0, final_credit_balance=50,
        final_balance_if_debit=0, final_balance_if_credit=50,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=600, initial_credit_balance=600, debit=2150,
        credit=2150, final_debit_balance=2750, final_credit_balance=2750,
2406
        final_balance_if_debit=2350, final_balance_if_credit=2350)
2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439
    
  def testTrialBalanceInitialBalance(self):
    # Test of trial balance and initial balance
    account_module = self.portal.account_module
    # previous period
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -2',
              source_reference='-2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=400.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -1',
              source_reference='-1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=600.0),
                     dict(source_value=account_module.payable,
                          source_credit=600.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2440
    request_form['section_category_strict'] = False
2441 2442 2443
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
2444
    request_form['per_account_class_summary'] = 0
2445
    request_form['group_analytic'] = []
2446 2447

    report_section_list = self.getReportSectionList(
2448
                                    self.portal.accounting_module,
2449 2450 2451 2452 2453 2454 2455 2456
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
2457
        node_title='Payable', initial_debit_balance=0,
2458 2459 2460
        initial_credit_balance=200, debit=0, credit=0,
        final_debit_balance=0, final_credit_balance=200,
        final_balance_if_debit=0, final_balance_if_credit=200)
2461 2462 2463 2464 2465 2466
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=200,
        initial_credit_balance=0, debit=0, credit=0,
        final_debit_balance=200, final_credit_balance=0,
        final_balance_if_debit=200, final_balance_if_credit=0)
2467 2468 2469 2470 2471 2472

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=200, initial_credit_balance=200, debit=0,
        credit=0, final_debit_balance=200, final_credit_balance=200,
        final_balance_if_debit=200, final_balance_if_credit=200)
2473

2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505
  def testTrialBalanceInitialBalanceMultiMirrorSectionExpandAccount(self):
    # Test of trial balance and initial balance with multiple mirror_section
    account_module = self.portal.account_module
    # previous period
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -2',
              source_reference='-2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=400.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -1',
              source_reference='-1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_2,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=600.0),
                     dict(source_value=account_module.payable,
                          source_credit=600.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2506
    request_form['section_category_strict'] = False
2507 2508 2509 2510
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 1
    request_form['per_account_class_summary'] = 0
2511
    request_form['group_analytic'] = []
2512 2513

    report_section_list = self.getReportSectionList(
2514
                                    self.portal.accounting_module,
2515 2516 2517 2518 2519 2520 2521
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(4, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
2522 2523
        node_title='Payable', mirror_section_title='Client 1',
        initial_debit_balance=400, initial_credit_balance=0, debit=0, credit=0,
2524 2525 2526 2527
        final_debit_balance=400, final_credit_balance=0,
        final_balance_if_debit=400, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='40',
2528 2529
        node_title='Payable', mirror_section_title='Client 2',
        initial_debit_balance=0, initial_credit_balance=600, debit=0, credit=0,
2530 2531 2532 2533
        final_debit_balance=0, final_credit_balance=600,
        final_balance_if_debit=0, final_balance_if_credit=600)
    
    self.checkLineProperties(data_line_list[2], node_id='41',
2534
        node_title='Receivable', mirror_section_title='Client 1', initial_debit_balance=0,
2535 2536 2537 2538 2539
        initial_credit_balance=400, debit=0, credit=0,
        final_debit_balance=0, final_credit_balance=400,
        final_balance_if_debit=0, final_balance_if_credit=400)

    self.checkLineProperties(data_line_list[3], node_id='41',
2540 2541
        node_title='Receivable', mirror_section_title='Client 2',
        initial_debit_balance=600, initial_credit_balance=0, debit=0, credit=0,
2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586
        final_debit_balance=600, final_credit_balance=0,
        final_balance_if_debit=600, final_balance_if_credit=0)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=1000, initial_credit_balance=1000, debit=0,
        credit=0, final_debit_balance=1000, final_credit_balance=1000,
        final_balance_if_debit=1000, final_balance_if_credit=1000)

  def testTrialBalanceInitialBalanceMultiMirrorSectionNoExpandAccount(self):
    # Test of trial balance and initial balance with multiple mirror_section,
    # without expanding accounts. This is the same as
    # testTrialBalanceInitialBalanceMultiMirrorSectionExpandAccount, but we
    # don't use the "Expand other parties". The initial debit & credit must be
    # the same as without this option
    account_module = self.portal.account_module
    # previous period
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -2',
              source_reference='-2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=400.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -1',
              source_reference='-1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_2,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=600.0),
                     dict(source_value=account_module.payable,
                          source_credit=600.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2587
    request_form['section_category_strict'] = False
2588 2589 2590 2591
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 0
2592
    request_form['group_analytic'] = []
2593 2594

    report_section_list = self.getReportSectionList(
2595
                                    self.portal.accounting_module,
2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=400,
        initial_credit_balance=600, debit=0, credit=0,
        final_debit_balance=400, final_credit_balance=600,
        final_balance_if_debit=0, final_balance_if_credit=200)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=600,
        initial_credit_balance=400, debit=0, credit=0,
        final_debit_balance=600, final_credit_balance=400,
        final_balance_if_debit=200, final_balance_if_credit=0)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=1000, initial_credit_balance=1000, debit=0,
        credit=0, final_debit_balance=1000, final_credit_balance=1000,
        final_balance_if_debit=200, final_balance_if_credit=200)


2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655
  def testTrialBalanceInitialBalanceBalanceTransaction(self):
    # Test of trial balance and initial balance with balance transactions.
    # Unlike other transactions balance transactions passed the first day of
    # the period will count as "initial balance", not as movement in the period
    account_module = self.portal.account_module

    self._makeOne(
              portal_type='Balance Transaction',
              title='Transaction 0',
              destination_reference='0',
              simulation_state='delivered',
              source_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 1),
              lines=(dict(destination_value=account_module.payable,
                          destination_debit=100.0),
                     dict(destination_value=account_module.receivable,
                          destination_credit=100.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=10.0),
                     dict(source_value=account_module.receivable,
                          source_credit=10.0),))

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2656 2657 2658 2659 2660
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 0
2661
    request_form['group_analytic'] = []
2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=100,
        initial_credit_balance=0, debit=10, credit=0,
        final_debit_balance=110, final_credit_balance=0,
        final_balance_if_debit=110, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=100, debit=0, credit=10,
        final_debit_balance=0, final_credit_balance=110,
        final_balance_if_debit=0, final_balance_if_credit=110)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=100, initial_credit_balance=100, debit=10,
        credit=10, final_debit_balance=110, final_credit_balance=110,
        final_balance_if_debit=110, final_balance_if_credit=110)


  def testTrialBalanceInitialBalanceBalanceTransactionDifferentFromDate(self):
    # Test of trial balance and initial balance with balance transactions, but
    # with a from_date which differs from the balance transaction date.
    account_module = self.portal.account_module

    self._makeOne(
              portal_type='Balance Transaction',
              title='Transaction 0',
              destination_reference='0',
              simulation_state='delivered',
              source_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 1),
              lines=(dict(destination_value=account_module.payable,
                          destination_debit=100.0),
                     dict(destination_value=account_module.receivable,
                          destination_credit=100.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 3),
              lines=(dict(source_value=account_module.payable,
                          source_debit=10.0),
                     dict(source_value=account_module.receivable,
                          source_credit=10.0),))

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 2)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2724
    request_form['section_category_strict'] = False
2725 2726 2727 2728
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 0
2729
    request_form['group_analytic'] = []
2730 2731

    report_section_list = self.getReportSectionList(
2732
                                    self.portal.accounting_module,
2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=100,
        initial_credit_balance=0, debit=10, credit=0,
        final_debit_balance=110, final_credit_balance=0,
        final_balance_if_debit=110, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=100, debit=0, credit=10,
        final_debit_balance=0, final_credit_balance=110,
        final_balance_if_debit=0, final_balance_if_credit=110)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=100, initial_credit_balance=100, debit=10,
        credit=10, final_debit_balance=110, final_credit_balance=110,
        final_balance_if_debit=110, final_balance_if_credit=110)


2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804
  def testTrialBalanceInitialBalanceWithPeriod(self):
    # Test of trial balance and initial balance
    account_module = self.portal.account_module

    # previous period
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -2',
              source_reference='-2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=400.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction -1',
              source_reference='-1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=600.0),
                     dict(source_value=account_module.payable,
                          source_credit=600.0),))
    
    # current period, but before from date
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 0',
              source_reference='0',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 3),
              lines=(dict(source_value=account_module.payable,
                          source_debit=111.0),
                     dict(source_value=account_module.receivable,
                          source_credit=111.0),))

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 2, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2805
    request_form['section_category_strict'] = False
2806 2807 2808
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
2809
    request_form['per_account_class_summary'] = 0
2810
    request_form['group_analytic'] = []
2811 2812

    report_section_list = self.getReportSectionList(
2813
                                    self.portal.accounting_module,
2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=111,
        initial_credit_balance=200, debit=0, credit=0,
        final_debit_balance=111, final_credit_balance=200,
        final_balance_if_debit=0, final_balance_if_credit=89)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=200,
        initial_credit_balance=111, debit=0, credit=0,
        final_debit_balance=200, final_credit_balance=111,
        final_balance_if_debit=89, final_balance_if_credit=0)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=311, initial_credit_balance=311, debit=0,
        credit=0, final_debit_balance=311, final_credit_balance=311,
        final_balance_if_debit=89, final_balance_if_credit=89)


2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873
  def testTrialBalanceInitialBalancePeriodStartDateBalanceTransaction(self):
    # Test of trial balance and initial balance with balance transactions and
    # transactions between period start date and from date
    # This is a combination of 
    account_module = self.portal.account_module

    self._makeOne(
              portal_type='Balance Transaction',
              title='Transaction 0',
              destination_reference='0',
              simulation_state='delivered',
              source_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 1),
              lines=(dict(destination_value=account_module.payable,
                          destination_debit=100.0),
                     dict(destination_value=account_module.receivable,
                          destination_credit=100.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2007, 1, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=10.0),
                     dict(source_value=account_module.receivable,
                          source_credit=10.0),))

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2007, 1, 1)
    request_form['at_date'] = DateTime(2007, 12, 31)
    request_form['section_category'] = 'group/demo_group'
2874
    request_form['section_category_strict'] = False
2875 2876 2877 2878
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 0
2879
    request_form['group_analytic'] = []
2880 2881

    report_section_list = self.getReportSectionList(
2882
                                    self.portal.accounting_module,
2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=100,
        initial_credit_balance=0, debit=10, credit=0,
        final_debit_balance=110, final_credit_balance=0,
        final_balance_if_debit=110, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=100, debit=0, credit=10,
        final_debit_balance=0, final_credit_balance=110,
        final_balance_if_debit=0, final_balance_if_credit=110)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=100, initial_credit_balance=100, debit=10,
        credit=10, final_debit_balance=110, final_credit_balance=110,
        final_balance_if_debit=110, final_balance_if_credit=110)


2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946
  def testTrialBalanceDifferentCurrencies(self):
    # Test of trial balance and different currencies
    account_module = self.portal.account_module
    
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction in EUR (our currency)',
              resource_value='currency_module/euro',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.payable,
                          source_debit=200.0),
                     dict(source_value=account_module.receivable,
                          source_credit=200.0),))
  
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction in USD',
              resource='currency_module/usd',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.payable,
                          source_debit=600.0,
                          source_asset_debit=300.0,
                          destination_asset_credit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=600.0,
                          source_asset_credit=300.0,
                          destination_asset_debit=400.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
2947
    request_form['section_category_strict'] = False
2948 2949 2950
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
2951
    request_form['per_account_class_summary'] = 0
2952
    request_form['group_analytic'] = []
2953 2954

    report_section_list = self.getReportSectionList(
2955
                                    self.portal.accounting_module,
2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=0,
        initial_credit_balance=0, debit=500, credit=0,
        final_debit_balance=500, final_credit_balance=0,
        final_balance_if_debit=500, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=500,
        final_debit_balance=0, final_credit_balance=500,
        final_balance_if_debit=0, final_balance_if_credit=500)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=500,
        credit=500, final_debit_balance=500, final_credit_balance=500,
2979
        final_balance_if_debit=500, final_balance_if_credit=500)
Jérome Perrin's avatar
Jérome Perrin committed
2980

2981 2982 2983 2984 2985 2986 2987 2988 2989
  def testTrialBalanceGAPFilter(self):
    # Test of GAP filter on trial balance
    self.createAccountStatementDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
2990
    request_form['section_category_strict'] = False
2991 2992 2993
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 1
Jérome Perrin's avatar
Jérome Perrin committed
2994
    request_form['gap_list'] = ['my_country/my_accounting_standards/4']
2995
    request_form['per_account_class_summary'] = 0
2996
    request_form['group_analytic'] = []
2997 2998

    report_section_list = self.getReportSectionList(
2999
                                    self.portal.accounting_module,
3000 3001 3002 3003 3004 3005 3006 3007 3008
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(4, len(data_line_list))

    # account are sorted by GAP Id
    self.checkLineProperties(data_line_list[0], node_id='40',
3009 3010 3011
        node_title='Payable', mirror_section_title='Client 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=200,
        credit=100, final_debit_balance=200, final_credit_balance=100,
3012 3013 3014
        final_balance_if_debit=100, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
3015 3016 3017
        node_title='Receivable', mirror_section_title='Client 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=1000,
        credit=200, final_debit_balance=1000, final_credit_balance=200,
3018 3019 3020
        final_balance_if_debit=800, final_balance_if_credit=0)
    
    self.checkLineProperties(data_line_list[2], node_id='41',
3021 3022 3023 3024
        node_title='Receivable', mirror_section_title='Client 2',
        initial_debit_balance=0, initial_credit_balance=0, debit=400, credit=0,
        final_debit_balance=400, final_credit_balance=0,
        final_balance_if_debit=400, final_balance_if_credit=0)
3025 3026
    
    self.checkLineProperties(data_line_list[3], node_id='41',
3027 3028
        node_title='Receivable', mirror_section_title='John Smith',
        initial_debit_balance=0, initial_credit_balance=0, debit=500, credit=0,
3029 3030 3031 3032 3033 3034 3035 3036
        final_debit_balance=500, final_credit_balance=0,
        final_balance_if_debit=500, final_balance_if_credit=0,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=2100,
        credit=300, final_debit_balance=2100, final_credit_balance=300,
        final_balance_if_debit=1800, final_balance_if_credit=0)
Jérome Perrin's avatar
Jérome Perrin committed
3037

3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069

  def testTrialBalanceAccountClassSummary(self):
    # Test of trial balance with per "account class" summary
    account_module = self.portal.account_module
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=400.0),
                     dict(source_value=account_module.receivable,
                          source_credit=400.0),))
    self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 2',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=600.0),
                     dict(source_value=account_module.payable,
                          source_credit=600.0),))
    
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
3070
    request_form['section_category_strict'] = False
3071 3072 3073 3074
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 1
3075
    request_form['group_analytic'] = []
3076 3077

    report_section_list = self.getReportSectionList(
3078
                                    self.portal.accounting_module,
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(4, len(data_line_list))

    self.checkLineProperties(data_line_list[0], node_id='40',
        node_title='Payable', initial_debit_balance=0,
        initial_credit_balance=0, debit=400, credit=600,
        final_debit_balance=400, final_credit_balance=600,
        final_balance_if_debit=0, final_balance_if_credit=200)
    
    self.checkLineProperties(data_line_list[1], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=600, credit=400,
        final_debit_balance=600, final_credit_balance=400,
        final_balance_if_debit=200, final_balance_if_credit=0)

    # The summary line for 4 class 
    self.checkLineProperties(data_line_list[2],
        node_title='Total for class 4', initial_debit_balance=0,
        initial_credit_balance=0, debit=1000, credit=1000,
        final_debit_balance=1000, final_credit_balance=1000,
        final_balance_if_debit=200, final_balance_if_credit=200)
    # an empty line for style
    self.checkLineProperties(data_line_list[3], node_title=' ')

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=1000,
        credit=1000, final_debit_balance=1000, final_credit_balance=1000,
        final_balance_if_debit=200, final_balance_if_credit=200)

3113 3114 3115 3116 3117 3118 3119 3120 3121
  def testTrialBalancePortalType(self):
    # portal_type filter on trial balance
    self.createAccountStatementDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
3122
    request_form['section_category_strict'] = False
3123 3124 3125 3126 3127
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['per_account_class_summary'] = 0
    request_form['portal_type'] = ['Purchase Invoice Transaction']
3128
    request_form['group_analytic'] = []
3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=600, credit=0,
        final_debit_balance=600, final_credit_balance=0,
        final_balance_if_debit=600, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[1], node_id='5',
        node_title='Bank (Bank2)', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=600, final_debit_balance=0,
        final_credit_balance=600, final_balance_if_debit=0,
        final_balance_if_credit=600,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=600,
        credit=600, final_debit_balance=600, final_credit_balance=600,
        final_balance_if_debit=600, final_balance_if_credit=600)

3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169
  def testTrialBalanceFunction(self):
    # trial balance restricted to a function
    self.createProjectAndFunctionDataSet()
    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['per_account_class_summary'] = 0
    request_form['show_empty_accounts'] = 0
    request_form['per_account_class_summary'] = 0
    request_form['function'] = 'function/a'
3170
    request_form['group_analytic'] = []
3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=500, credit=0,
        final_debit_balance=500, final_credit_balance=0,
        final_balance_if_debit=500, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=500, final_debit_balance=0,
        final_credit_balance=500, final_balance_if_debit=0,
        final_balance_if_credit=500,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=500,
        credit=500, final_debit_balance=500, final_credit_balance=500,
        final_balance_if_debit=500, final_balance_if_credit=500)

  def testTrialBalanceProject(self):
    # trial balance restricted to a project
    self.createProjectAndFunctionDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['per_account_class_summary'] = 0
    request_form['show_empty_accounts'] = 0
    request_form['per_account_class_summary'] = 0
    request_form['project'] = self.project_1.getRelativeUrl()
3213
    request_form['group_analytic'] = []
3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=500, credit=0,
        final_debit_balance=500, final_credit_balance=0,
        final_balance_if_debit=500, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=500, final_debit_balance=0,
        final_credit_balance=500, final_balance_if_debit=0,
        final_balance_if_credit=500,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=500,
        credit=500, final_debit_balance=500, final_credit_balance=500,
        final_balance_if_debit=500, final_balance_if_credit=500)

Jérome Perrin's avatar
Jérome Perrin committed
3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283
  def testTrialBalanceNoProject(self):
    # trial balance restricted to no project
    self.createProjectAndFunctionDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['per_account_class_summary'] = 0
    request_form['show_empty_accounts'] = 0
    request_form['per_account_class_summary'] = 0
    request_form['project'] = 'None'
    request_form['group_analytic'] = []

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=700, credit=0,
        final_debit_balance=700, final_credit_balance=0,
        final_balance_if_debit=700, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=700, final_debit_balance=0,
        final_credit_balance=700, final_balance_if_debit=0,
        final_balance_if_credit=700,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=700,
        credit=700, final_debit_balance=700, final_credit_balance=700,
        final_balance_if_debit=700, final_balance_if_credit=700)

3284

3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328
  def testTrialBalanceMirrorSectionRole(self):
    # trial balance restricted to a mirror section role
    self.createMirrorSectionRoleDataSet()

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['stopped', 'delivered']
    request_form['mirror_section_category_list'] = ['role/supplier']
    request_form['per_account_class_summary'] = 0
    request_form['show_empty_accounts'] = 0
    request_form['per_account_class_summary'] = 0
    request_form['group_analytic'] = []

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    self.checkLineProperties(data_line_list[0], node_id='41',
        node_title='Receivable', initial_debit_balance=0,
        initial_credit_balance=0, debit=300, credit=0,
        final_debit_balance=300, final_credit_balance=0,
        final_balance_if_debit=300, final_balance_if_credit=0,)
    
    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', initial_debit_balance=0,
        initial_credit_balance=0, debit=0, credit=300, final_debit_balance=0,
        final_credit_balance=300, final_balance_if_debit=0,
        final_balance_if_credit=300,)
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], node_id=None, node_title=None,
        initial_debit_balance=0, initial_credit_balance=0, debit=300,
        credit=300, final_debit_balance=300, final_credit_balance=300,
        final_balance_if_debit=300, final_balance_if_credit=300)


Jérome Perrin's avatar
Jérome Perrin committed
3329 3330 3331 3332 3333 3334 3335 3336 3337 3338
  def testGeneralLedger(self):
    # Simple test of general ledger
    # we will use the same data set as account statement
    self.createAccountStatementDataSet(use_two_bank_accounts=0)

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
3339
    request_form['section_category_strict'] = False
Jérome Perrin's avatar
Jérome Perrin committed
3340
    request_form['simulation_state'] = ['delivered']
3341
    request_form['hide_analytic'] = False
Jérome Perrin's avatar
Jérome Perrin committed
3342 3343

    report_section_list = self.getReportSectionList(
3344
                                    self.portal.accounting_module,
Jérome Perrin's avatar
Jérome Perrin committed
3345 3346 3347
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(6, len(report_section_list))

3348
    self.assertEquals('40 - Payable (Client 1)',
Jérome Perrin's avatar
Jérome Perrin committed
3349 3350 3351 3352
                      report_section_list[0].getTitle())
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
3353 3354 3355 3356 3357 3358 3359 3360 3361 3362
    # The box showing parameters summary in
    # Account_viewAccountingTransactionList is not rendered here.
    report_section = report_section_list[0]
    report_section.pushReport(self.portal)
    form = getattr(self.portal, report_section.form_id)
    # we test that this form only shows a listbox
    for group in form.get_groups():
      if group != 'hidden':
        for field in form.get_fields_in_group(group):
          if field.getId() != 'listbox':
3363
            self.fail('Field %s should not be visible' % field.getId())
3364
    report_section.popReport(self.portal)
3365 3366 3367 3368

    # currency is present in the report
    self.assertEquals('currency_module/euro', self.portal.
        AccountModule_viewGeneralLedgerReport.your_currency.get_value('default'))
3369
    
Jérome Perrin's avatar
Jérome Perrin committed
3370 3371 3372 3373 3374
    # report layout
    self.assertEquals(['Movement_getSpecificReference',
        'Movement_getExplanationTitle', 'date',
        'Movement_getExplanationTranslatedPortalType',
        'Movement_getExplanationReference', 'Movement_getMirrorSectionTitle',
Jérome Perrin's avatar
Jérome Perrin committed
3375
        'debit_price', 'credit_price', 'running_total_price'],
Jérome Perrin's avatar
Jérome Perrin committed
3376 3377 3378 3379 3380 3381 3382 3383
        data_line_list[0].column_id_list)
    
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Transaction 1',
          date=DateTime(2006, 2, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3384
          Movement_getExplanationReference='ref1',
Jérome Perrin's avatar
Jérome Perrin committed
3385
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3386
          debit_price=0, credit_price=100, running_total_price=-100, )
Jérome Perrin's avatar
Jérome Perrin committed
3387 3388 3389 3390 3391 3392
    
    self.checkLineProperties(data_line_list[1],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Transaction 2',
          date=DateTime(2006, 2, 1, 0, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3393
          Movement_getExplanationReference='ref2',
Jérome Perrin's avatar
Jérome Perrin committed
3394
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3395
          debit_price=200, credit_price=0, running_total_price=100, )
Jérome Perrin's avatar
Jérome Perrin committed
3396 3397 3398 3399 3400 3401 3402 3403 3404
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
          Movement_getSpecificReference=None,
          Movement_getExplanationTitle=None,
          date=None,
          Movement_getExplanationTranslatedPortalType=None,
          Movement_getExplanationReference=None,
          Movement_getMirrorSectionTitle=None,
Jérome Perrin's avatar
Jérome Perrin committed
3405
          debit_price=200, credit_price=100, )
Jérome Perrin's avatar
Jérome Perrin committed
3406
    
3407
    self.assertEquals('41 - Receivable (Client 1)',
Jérome Perrin's avatar
Jérome Perrin committed
3408 3409 3410 3411 3412 3413 3414 3415 3416
                      report_section_list[1].getTitle())
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(5, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Transaction 1',
          date=DateTime(2006, 2, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3417
          Movement_getExplanationReference='ref1',
Jérome Perrin's avatar
Jérome Perrin committed
3418
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3419
          debit_price=100, credit_price=0, running_total_price=100, )
Jérome Perrin's avatar
Jérome Perrin committed
3420 3421 3422 3423 3424 3425
    
    self.checkLineProperties(data_line_list[1],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Transaction 2',
          date=DateTime(2006, 2, 1, 0, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3426
          Movement_getExplanationReference='ref2',
Jérome Perrin's avatar
Jérome Perrin committed
3427
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3428
          debit_price=0, credit_price=200, running_total_price=-100, )
Jérome Perrin's avatar
Jérome Perrin committed
3429 3430 3431 3432 3433 3434
    
    self.checkLineProperties(data_line_list[2],
          Movement_getSpecificReference='3',
          Movement_getExplanationTitle='Transaction 3',
          date=DateTime(2006, 2, 2, 0, 2),
          Movement_getExplanationTranslatedPortalType='Payment Transaction',
3435
          Movement_getExplanationReference='ref3',
Jérome Perrin's avatar
Jérome Perrin committed
3436
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3437
          debit_price=300, credit_price=0, running_total_price=200, )
Jérome Perrin's avatar
Jérome Perrin committed
3438 3439 3440 3441 3442 3443 3444
    
    self.checkLineProperties(data_line_list[3],
          Movement_getSpecificReference='6',
          Movement_getExplanationTitle='Transaction 6',
          date=DateTime(2006, 2, 2, 0, 5),
          Movement_getExplanationTranslatedPortalType
                ='Purchase Invoice Transaction',
3445
          Movement_getExplanationReference='ref6',
Jérome Perrin's avatar
Jérome Perrin committed
3446
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3447
          debit_price=600, credit_price=0, running_total_price=800, )
Jérome Perrin's avatar
Jérome Perrin committed
3448 3449 3450 3451 3452 3453
    
    self.checkLineProperties(data_line_list[4],
          Movement_getSpecificReference='8',
          Movement_getExplanationTitle='Transaction 8',
          date=DateTime(2006, 2, 3),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3454
          Movement_getExplanationReference='ref8',
Jérome Perrin's avatar
Jérome Perrin committed
3455
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3456
          debit_price=800, credit_price=0, running_total_price=1600, )
Jérome Perrin's avatar
Jérome Perrin committed
3457 3458 3459 3460 3461 3462 3463 3464 3465
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
          Movement_getSpecificReference=None,
          Movement_getExplanationTitle=None,
          date=None,
          Movement_getExplanationTranslatedPortalType=None,
          Movement_getExplanationReference=None,
          Movement_getMirrorSectionTitle=None,
Jérome Perrin's avatar
Jérome Perrin committed
3466
          debit_price=1800, credit_price=200, )
Jérome Perrin's avatar
Jérome Perrin committed
3467

3468
    self.assertEquals('41 - Receivable (Client 2)',
Jérome Perrin's avatar
Jérome Perrin committed
3469 3470 3471 3472 3473 3474 3475 3476 3477
                      report_section_list[2].getTitle())
    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='4',
          Movement_getExplanationTitle='Transaction 4',
          date=DateTime(2006, 2, 2, 0, 3),
          Movement_getExplanationTranslatedPortalType='Payment Transaction',
3478
          Movement_getExplanationReference='ref4',
Jérome Perrin's avatar
Jérome Perrin committed
3479
          Movement_getMirrorSectionTitle='Client 2',
Jérome Perrin's avatar
Jérome Perrin committed
3480
          debit_price=400, credit_price=0, running_total_price=400, )
Jérome Perrin's avatar
Jérome Perrin committed
3481 3482
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3483
    self.checkLineProperties(line_list[-1], debit_price=400, credit_price=0, )
Jérome Perrin's avatar
Jérome Perrin committed
3484

3485
    self.assertEquals('41 - Receivable (John Smith)',
Jérome Perrin's avatar
Jérome Perrin committed
3486 3487 3488 3489 3490 3491 3492 3493 3494
                      report_section_list[3].getTitle())
    line_list = self.getListBoxLineList(report_section_list[3])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='5',
          Movement_getExplanationTitle='Transaction 5',
          date=DateTime(2006, 2, 2, 0, 4),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3495
          Movement_getExplanationReference='ref5',
Jérome Perrin's avatar
Jérome Perrin committed
3496
          Movement_getMirrorSectionTitle='John Smith',
Jérome Perrin's avatar
Jérome Perrin committed
3497
          debit_price=500, credit_price=0, running_total_price=500, )
Jérome Perrin's avatar
Jérome Perrin committed
3498 3499
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3500
    self.checkLineProperties(line_list[-1], debit_price=500, credit_price=0, )
Jérome Perrin's avatar
Jérome Perrin committed
3501

3502
    self.assertEquals('5 - Bank (Bank1)',
Jérome Perrin's avatar
Jérome Perrin committed
3503 3504 3505 3506 3507 3508 3509 3510 3511
                      report_section_list[4].getTitle())
    line_list = self.getListBoxLineList(report_section_list[4])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(5, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='3',
          Movement_getExplanationTitle='Transaction 3',
          date=DateTime(2006, 2, 2, 0, 2),
          Movement_getExplanationTranslatedPortalType='Payment Transaction',
3512
          Movement_getExplanationReference='ref3',
Jérome Perrin's avatar
Jérome Perrin committed
3513
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3514
          debit_price=0, credit_price=300, running_total_price=-300, )
Jérome Perrin's avatar
Jérome Perrin committed
3515 3516 3517 3518 3519 3520
    
    self.checkLineProperties(data_line_list[1],
          Movement_getSpecificReference='4',
          Movement_getExplanationTitle='Transaction 4',
          date=DateTime(2006, 2, 2, 0, 3),
          Movement_getExplanationTranslatedPortalType='Payment Transaction',
3521
          Movement_getExplanationReference='ref4',
Jérome Perrin's avatar
Jérome Perrin committed
3522
          Movement_getMirrorSectionTitle='Client 2',
Jérome Perrin's avatar
Jérome Perrin committed
3523
          debit_price=0, credit_price=400, running_total_price=-700, )
Jérome Perrin's avatar
Jérome Perrin committed
3524 3525 3526 3527 3528 3529

    self.checkLineProperties(data_line_list[2],
          Movement_getSpecificReference='5',
          Movement_getExplanationTitle='Transaction 5',
          date=DateTime(2006, 2, 2, 0, 4),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3530
          Movement_getExplanationReference='ref5',
Jérome Perrin's avatar
Jérome Perrin committed
3531
          Movement_getMirrorSectionTitle='John Smith',
Jérome Perrin's avatar
Jérome Perrin committed
3532
          debit_price=0, credit_price=500, running_total_price=-1200, )
Jérome Perrin's avatar
Jérome Perrin committed
3533 3534 3535 3536 3537 3538 3539

    self.checkLineProperties(data_line_list[3],
          Movement_getSpecificReference='6',
          Movement_getExplanationTitle='Transaction 6',
          date=DateTime(2006, 2, 2, 0, 5),
          Movement_getExplanationTranslatedPortalType
                              ='Purchase Invoice Transaction',
3540
          Movement_getExplanationReference='ref6',
Jérome Perrin's avatar
Jérome Perrin committed
3541
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3542
          debit_price=0, credit_price=600, running_total_price=-1800, )
Jérome Perrin's avatar
Jérome Perrin committed
3543 3544 3545 3546 3547 3548

    self.checkLineProperties(data_line_list[4],
          Movement_getSpecificReference='8',
          Movement_getExplanationTitle='Transaction 8',
          date=DateTime(2006, 2, 3),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3549
          Movement_getExplanationReference='ref8',
Jérome Perrin's avatar
Jérome Perrin committed
3550
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3551
          debit_price=0, credit_price=800, running_total_price=-2600, )
Jérome Perrin's avatar
Jérome Perrin committed
3552 3553
    
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3554
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=2600, )
Jérome Perrin's avatar
Jérome Perrin committed
3555 3556 3557 3558 3559

    self.assertEquals('Total', report_section_list[5].getTitle())
    line_list = self.getListBoxLineList(report_section_list[5])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # report layout
Jérome Perrin's avatar
Jérome Perrin committed
3560
    self.assertEquals(['debit_price', 'credit_price'], data_line_list[0].column_id_list)
Jérome Perrin's avatar
Jérome Perrin committed
3561
    self.assertEquals(1, len(data_line_list))
Jérome Perrin's avatar
Jérome Perrin committed
3562
    self.checkLineProperties(data_line_list[0], debit_price=2900, credit_price=2900)
3563
 
3564 3565 3566 3567 3568 3569 3570 3571 3572 3573

  def testGeneralLedgerGAPFilter(self):
    # General Ledger filtered by GAP category
    # we will use the same data set as account statement
    self.createAccountStatementDataSet(use_two_bank_accounts=0)

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
Jérome Perrin's avatar
Jérome Perrin committed
3574
    request_form['gap_list'] = ['my_country/my_accounting_standards/4/40']
3575 3576 3577
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
3578
    request_form['hide_analytic'] = False
3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(2, len(report_section_list))

    self.assertEquals('40 - Payable (Client 1)',
                      report_section_list[0].getTitle())
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    
    self.assertEquals(2, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Transaction 1',
          date=DateTime(2006, 2, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3596
          Movement_getExplanationReference='ref1',
3597
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3598
          debit_price=0, credit_price=100, running_total_price=-100, )
3599 3600 3601 3602 3603 3604
    
    self.checkLineProperties(data_line_list[1],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Transaction 2',
          date=DateTime(2006, 2, 1, 0, 1),
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
3605
          Movement_getExplanationReference='ref2',
3606
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3607
          debit_price=200, credit_price=0, running_total_price=100, )
3608 3609 3610 3611 3612 3613 3614 3615 3616
    
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
          Movement_getSpecificReference=None,
          Movement_getExplanationTitle=None,
          date=None,
          Movement_getExplanationTranslatedPortalType=None,
          Movement_getExplanationReference=None,
          Movement_getMirrorSectionTitle=None,
Jérome Perrin's avatar
Jérome Perrin committed
3617
          debit_price=200, credit_price=100, )
3618 3619 3620 3621 3622
    
    self.assertEquals('Total', report_section_list[1].getTitle())
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
Jérome Perrin's avatar
Jérome Perrin committed
3623
    self.checkLineProperties(data_line_list[0], debit_price=200, credit_price=100)
3624
 
3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635
  def testGeneralLedgerFunction(self):
    # general ledger restricted to a function
    self.createProjectAndFunctionDataSet()
    
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['function'] = 'function/a'
3636
    request_form['hide_analytic'] = False
3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Function a Project 1',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3652
          debit_price=500, credit_price=0, running_total_price=500, )
3653
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3654
    self.checkLineProperties(line_list[-1], debit_price=500, credit_price=0)
3655 3656 3657 3658 3659 3660 3661 3662 3663 3664

    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Function a Project 1',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3665
          debit_price=0, credit_price=500, running_total_price=-500, )
3666
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3667
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=500)
3668 3669 3670 3671

    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
Jérome Perrin's avatar
Jérome Perrin committed
3672
    self.checkLineProperties(data_line_list[0], debit_price=500, credit_price=500)
3673

Jérome Perrin's avatar
Jérome Perrin committed
3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723
  def testGeneralLedgerNoProject(self):
    # general ledger restricted to no project
    self.createProjectAndFunctionDataSet()
    
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['project'] = 'None'
    request_form['hide_analytic'] = False

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='3',
          Movement_getExplanationTitle='No function no project',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
          debit_price=700, credit_price=0, running_total_price=700, )
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=700, credit_price=0)

    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='3',
          Movement_getExplanationTitle='No function no project',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
          debit_price=0, credit_price=700, running_total_price=-700, )
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=700)

    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0], debit_price=700,
        credit_price=700)

3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734
  def testGeneralLedgerProject(self):
    # general ledger restricted to a project
    self.createProjectAndFunctionDataSet()
    
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['project'] = self.project_1.getRelativeUrl()
3735
    request_form['hide_analytic'] = False
3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Function a Project 1',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3751
          debit_price=500, credit_price=0, running_total_price=500, )
3752
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3753
    self.checkLineProperties(line_list[-1], debit_price=500, credit_price=0)
3754 3755 3756 3757 3758 3759 3760 3761 3762 3763

    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='1',
          Movement_getExplanationTitle='Function a Project 1',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Client 1',
Jérome Perrin's avatar
Jérome Perrin committed
3764
          debit_price=0, credit_price=500, running_total_price=-500, )
3765
    self.failUnless(line_list[-1].isStatLine())
Jérome Perrin's avatar
Jérome Perrin committed
3766
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=500)
3767 3768 3769 3770

    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
Jérome Perrin's avatar
Jérome Perrin committed
3771
    self.checkLineProperties(data_line_list[0], debit_price=500, credit_price=500)
3772

3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822
  def testGeneralLedgerMirrorSectionRole(self):
    # general ledger restricted to a mirror section role
    self.createMirrorSectionRoleDataSet()
    
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['mirror_section_category_list'] = ['role/supplier']
    request_form['hide_analytic'] = False

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Invoice to a supplier',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Supplier',
          debit_price=300, credit_price=0, running_total_price=300, )
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=300, credit_price=0)

    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
          Movement_getSpecificReference='2',
          Movement_getExplanationTitle='Invoice to a supplier',
          date=DateTime(2006, 2, 2),
          Movement_getExplanationTranslatedPortalType='Sale Invoice Transaction',
          Movement_getMirrorSectionTitle='Supplier',
          debit_price=0, credit_price=300, running_total_price=-300, )
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=300)

    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0], debit_price=300,
                             credit_price=300)

3823 3824 3825 3826 3827 3828 3829 3830
  def testProfitAndLoss(self):
    # Simple test of profit and loss
    self.createAccountStatementDataSet(use_two_bank_accounts=1)

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
3831
    request_form['section_category_strict'] = False
3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851
    request_form['simulation_state'] = ['delivered']
    
    # for now, we simply check that that the report is rendered with no error
    # and it produces valid odf
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    odf = self.portal.account_module.AccountModule_viewProfitAndLossReport()
    err_list = odf_validator.validate(odf)
    if err_list:
      self.fail(''.join(err_list))


  def testBalanceSheet(self):
    # Simple test of balance sheet
    self.createAccountStatementDataSet(use_two_bank_accounts=1)

    # set request variables and render
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
3852
    request_form['section_category_strict'] = False
3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863
    request_form['simulation_state'] = ['delivered']
    
    # for now, we simply check that that the report is rendered with no error
    # and it produces valid odf
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    odf = self.portal.account_module.AccountModule_viewBalanceSheetReport()
    err_list = odf_validator.validate(odf)
    if err_list:
      self.fail(''.join(err_list))

Jérome Perrin's avatar
Jérome Perrin committed
3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893
  def testOtherPartiesReport(self):
    # Other parties report
    account_module = self.portal.account_module
    t1 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 1',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=100.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=100.0)))
    
    t2 = self._makeOne(
              portal_type='Accounting Transaction',
              title='Transaction 2',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.organisation_module.client_1,
              start_date=DateTime(2006, 2, 1, 0, 1),
              lines=(dict(source_value=account_module.payable,
                          source_debit=200.0),
                     dict(source_value=account_module.goods_sales,
                          source_credit=200.0)))

    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 1)
    request_form['section_category'] = 'group/demo_group'
3894
    request_form['section_category_strict'] = False
Jérome Perrin's avatar
Jérome Perrin committed
3895 3896
    request_form['simulation_state'] = ['delivered']
    request_form['omit_balanced_accounts'] = False
3897
    request_form['omit_grouping_reference'] = True
Jérome Perrin's avatar
Jérome Perrin committed
3898 3899 3900 3901 3902
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewOtherPartiesReport')
    self.assertEquals(1, len(report_section_list))
3903
    # the role is displayed in parenthesis
Jérome Perrin's avatar
Jérome Perrin committed
3904
    self.assertEquals(report_section_list[0].getTitle(),
3905
                      'Client 1 (Client)')
3906 3907 3908
    # currency is present in the report
    self.assertEquals('currency_module/euro', self.portal.
        AccountModule_viewOtherPartiesReport.your_currency.get_value('default'))
Jérome Perrin's avatar
Jérome Perrin committed
3909 3910 3911 3912 3913 3914 3915 3916 3917

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))

    self.checkLineProperties(data_line_list[0],
          Movement_getExplanationTitle='Transaction 1',
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
          Movement_getNodeGapId='41',
Jérome Perrin's avatar
Jérome Perrin committed
3918 3919
          credit_price=0,
          debit_price=100,
Jérome Perrin's avatar
Jérome Perrin committed
3920 3921 3922 3923 3924 3925 3926 3927
          date=DateTime('2006/02/01'),
          getTranslatedSimulationStateTitle='Closed',
          running_total_price=100.0)

    self.checkLineProperties(data_line_list[1],
          Movement_getExplanationTitle='Transaction 2',
          Movement_getExplanationTranslatedPortalType='Accounting Transaction',
          Movement_getNodeGapId='40',
Jérome Perrin's avatar
Jérome Perrin committed
3928 3929
          credit_price=0,
          debit_price=200,
Jérome Perrin's avatar
Jérome Perrin committed
3930 3931 3932 3933 3934 3935
          date=DateTime(2006, 2, 1, 0, 1),
          getTranslatedSimulationStateTitle='Closed',
          running_total_price=300.0)

    self.assertTrue(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
Jérome Perrin's avatar
Jérome Perrin committed
3936 3937
          credit_price=0,
          debit_price=300,)
Jérome Perrin's avatar
Jérome Perrin committed
3938

3939

3940 3941
class TestAccountingReportsWithAnalytic(AccountingTestCase, ERP5ReportTestCase):

3942 3943 3944
  def afterSetUp(self):
    AccountingTestCase.afterSetUp(self)
    self.login()
3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968
    # create some functions
    function = self.portal.portal_categories.function
    if function._getOb('a', None) is None:
      function.newContent(portal_type='Category', id='a')
    self.function_a = function['a']
    if function._getOb('b', None) is None:
      function.newContent(portal_type='Category', id='b')
    self.function_b = function['b']

    # create some product lines
    product_line = self.portal.portal_categories.product_line
    if product_line._getOb('pl1', None) is None:
      product_line.newContent(portal_type='Category', id='pl1')
    self.product_line_1 = product_line['pl1']

    # create some projects
    self.project_1 = self.portal.project_module.newContent(
                          portal_type='Project',
                          title='Project 1')
    self.project_2 = self.portal.project_module.newContent(
                          portal_type='Project',
                          title='Project 2')

    preference = self.portal.portal_preferences.getActivePreference()
3969
    preference._edit(
3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006
        preferred_accounting_transaction_line_function_base_category='function',
        preferred_accounting_transaction_line_analytic_base_category_list=(
                                              'product_line', ),)
    account_module = self.portal.account_module
    uid_list = sorted([
        self.portal.portal_catalog.newUid(),
        self.portal.portal_catalog.newUid(),
        self.portal.portal_catalog.newUid(),])
     
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Detailed Transaction',
              source_reference='1',
              simulation_state='delivered',
              destination_section_value=self.portal.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=account_module.receivable,
                          source_debit=1500.0),
                     dict(source_value=account_module.goods_sales,
                          uid=uid_list[0],
                          source_function_value=self.function_a,
                          source_project_value=self.project_1,
                          product_line_value=self.product_line_1,
                          source_credit=300.0),
                     dict(source_value=account_module.goods_sales,
                          uid=uid_list[1],
                          source_function_value=self.function_b,
                          source_project_value=self.project_1,
                          product_line_value=self.product_line_1,
                          source_credit=500.0),
                     dict(source_value=account_module.goods_sales,
                          uid=uid_list[2],
                          source_function_value=self.function_b,
                          source_project_value=self.project_2,
                          product_line_value=None,
                          source_credit=700.0),
                     ))
4007
    self.tic()
4008 4009 4010
    self.login(self.username)

  def beforeTearDown(self):
4011
    AccountingTestCase.beforeTearDown(self)
4012
    preference = self.portal.portal_preferences.getActivePreference()
4013
    preference._edit(
4014 4015
        preferred_accounting_transaction_line_function_base_category=None,
        preferred_accounting_transaction_line_analytic_base_category_list=())
4016
    self.commit()
4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038

  def testJournalAnalyticsShown(self):
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['portal_type'] = ['Sale Invoice Transaction']
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(4, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
4039
        [ 'specific_reference', 'date', 'title', 'parent_reference',
4040
          'function', 'project', 'product_line_translated_title',
4041 4042 4043
          'node_title', 'mirror_section_title', 'debit', 'credit'])
    
    self.checkLineProperties(data_line_list[0],
Jérome Perrin's avatar
Jérome Perrin committed
4044
                             project='',
4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097
                             function=None,
                             product_line_translated_title=None,
                             node_title='41',
                             mirror_section_title='Client 1',
                             debit=1500,
                             credit=0)
    self.checkLineProperties(data_line_list[1],
                             project='Project 1',
                             function='a',
                             product_line_translated_title='pl1',
                             node_title='7',
                             debit=0,
                             credit=300)
    self.checkLineProperties(data_line_list[2],
                             project='Project 1',
                             function='b',
                             product_line_translated_title='pl1',
                             node_title='7',
                             debit=0,
                             credit=500)
    self.checkLineProperties(data_line_list[3],
                             project='Project 2',
                             function='b',
                             product_line_translated_title=None,
                             node_title='7',
                             debit=0,
                             credit=700)

    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit=1500, credit=1500)

  def testJournalAnalyticsHidden(self):
    request_form = self.portal.REQUEST.form
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['portal_type'] = ['Sale Invoice Transaction']
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = True
    
    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountingTransactionModule_viewJournalReport')
    self.assertEquals(1, len(report_section_list))
    
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))
    
    # test columns values
    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
4098
        ['specific_reference', 'date', 'title', 'parent_reference',
4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137
          'node_title', 'mirror_section_title', 'debit', 'credit'])
    
    self.checkLineProperties(data_line_list[0],
                             node_title='41',
                             mirror_section_title='Client 1',
                             debit=1500,
                             credit=0)
    # this line is the aggregation of 3 lines
    self.checkLineProperties(data_line_list[1],
                             node_title='7',
                             debit=0,
                             credit=1500)
    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit=1500, credit=1500)

  def testAccountStatementAnalyticsShown(self):
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.goods_sales.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group/sub1'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False

    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(3, len(data_line_list))

    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle',
4138
         'function', 'project', 'product_line_translated_title',
4139
         'Movement_getMirrorSectionTitle',
4140
         'Movement_getExplanationReference',
4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192
         'debit_price', 'credit_price', 'running_total_price'])

    self.checkLineProperties(data_line_list[0],
                             project='Project 1',
                             function='a',
                             product_line_translated_title='pl1',
                             debit_price=0,
                             credit_price=300,
                             running_total_price=-300)
    self.checkLineProperties(data_line_list[1],
                             project='Project 1',
                             function='b',
                             product_line_translated_title='pl1',
                             debit_price=0,
                             credit_price=500,
                             running_total_price=-800)
    self.checkLineProperties(data_line_list[2],
                             project='Project 2',
                             function='b',
                             product_line_translated_title=None,
                             debit_price=0,
                             credit_price=700,
                             running_total_price=-1500)

    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=1500)
 
  def testAccountStatementAnalyticsHidden(self):
    request_form = self.portal.REQUEST.form
    request_form['node'] = \
                self.portal.account_module.goods_sales.getRelativeUrl()
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group/sub1'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = True

    report_section_list = self.getReportSectionList(
                               self.portal.accounting_module,
                               'AccountModule_viewAccountStatementReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))

    line = data_line_list[0]
    self.assertEquals(line.column_id_list,
        ['Movement_getSpecificReference', 'date',
         'Movement_getExplanationTitle',
         'Movement_getMirrorSectionTitle',
4193
         'Movement_getExplanationReference',
4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225
         'debit_price', 'credit_price', 'running_total_price'])

    self.checkLineProperties(data_line_list[0],
                             debit_price=0,
                             credit_price=1500,
                             running_total_price=-1500)

    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=1500)

  def testGeneralLedgerAnalyticsShown(self):
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = False

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    # FIXME: order of columns is inconsistant in GL and Account Statement
    self.assertEquals(['Movement_getSpecificReference',
        'Movement_getExplanationTitle', 'date',
        'Movement_getExplanationTranslatedPortalType',
        'Movement_getExplanationReference', 'Movement_getMirrorSectionTitle',
4226
        'function', 'project', 'product_line_translated_title',
4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313
        'debit_price', 'credit_price', 'running_total_price'],
        data_line_list[0].column_id_list)

    self.checkLineProperties(data_line_list[0],
                             project='Project 1',
                             function='a',
                             product_line_translated_title='pl1',
                             debit_price=0,
                             credit_price=300,
                             running_total_price=-300)
    self.checkLineProperties(data_line_list[1],
                             project='Project 1',
                             function='b',
                             product_line_translated_title='pl1',
                             debit_price=0,
                             credit_price=500,
                             running_total_price=-800)
    self.checkLineProperties(data_line_list[2],
                             project='Project 2',
                             function='b',
                             product_line_translated_title=None,
                             debit_price=0,
                             credit_price=700,
                             running_total_price=-1500)

    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=1500)

    line_list = self.getListBoxLineList(report_section_list[2])
    
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             debit_price=1500,
                             credit_price=1500,)

  def testGeneralLedgerAnalyticsHidden(self):
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 12, 31)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['hide_analytic'] = True

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewGeneralLedgerReport')
    self.assertEquals(3, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(['Movement_getSpecificReference',
        'Movement_getExplanationTitle', 'date',
        'Movement_getExplanationTranslatedPortalType',
        'Movement_getExplanationReference', 'Movement_getMirrorSectionTitle',
        'debit_price', 'credit_price', 'running_total_price'],
        data_line_list[0].column_id_list)
    # receivable account
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             debit_price=1500,
                             credit_price=0,
                             running_total_price=1500)
    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=1500, credit_price=0)
    # good sales account
    line_list = self.getListBoxLineList(report_section_list[1])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             debit_price=0,
                             credit_price=1500,
                             running_total_price=-1500)
    stat_line = line_list[-1]
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1], debit_price=0, credit_price=1500)
    # summary
    line_list = self.getListBoxLineList(report_section_list[2])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(1, len(data_line_list))
    self.checkLineProperties(data_line_list[0],
                             debit_price=1500,
                             credit_price=1500,)

4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515
  def testTrialBalanceGroupByProject(self):
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['gap_list'] = ['my_country/my_accounting_standards/7']
    request_form['per_account_class_summary'] = 0
    request_form['group_analytic'] = ['project']

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(2, len(data_line_list))

    self.assertEquals(['node_id', 'node_title', 'project_uid',
      'initial_debit_balance', 'initial_credit_balance', 'debit', 'credit',
      'final_debit_balance', 'final_credit_balance', 'final_balance_if_debit',
      'final_balance_if_credit'], data_line_list[0].column_id_list)

    self.checkLineProperties(data_line_list[0], node_id='7',
        node_title='Goods Sales', project_uid='Project 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=800, final_debit_balance=0, final_credit_balance=800,
        final_balance_if_debit=0, final_balance_if_credit=800)

    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', project_uid='Project 2',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=700, final_debit_balance=0, final_credit_balance=700,
        final_balance_if_debit=0, final_balance_if_credit=700)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=1500, final_debit_balance=0, final_credit_balance=1500,
        final_balance_if_debit=0, final_balance_if_credit=1500)

  def testTrialBalanceGroupByFunction(self):
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['gap_list'] = ['my_country/my_accounting_standards/7']
    request_form['per_account_class_summary'] = 0
    request_form['group_analytic'] = ['function']

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(2, len(data_line_list))

    self.assertEquals(['node_id', 'node_title', 'function_uid',
      'initial_debit_balance', 'initial_credit_balance', 'debit', 'credit',
      'final_debit_balance', 'final_credit_balance', 'final_balance_if_debit',
      'final_balance_if_credit'], data_line_list[0].column_id_list)

    self.checkLineProperties(data_line_list[0], node_id='7',
        node_title='Goods Sales', function_uid='a',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=300, final_debit_balance=0, final_credit_balance=300,
        final_balance_if_debit=0, final_balance_if_credit=300)

    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', function_uid='b',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=1200, final_debit_balance=0, final_credit_balance=1200,
        final_balance_if_debit=0, final_balance_if_credit=1200)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=1500, final_debit_balance=0, final_credit_balance=1500,
        final_balance_if_debit=0, final_balance_if_credit=1500)

  def testTrialBalanceGroupByProjectAndFunction(self):
    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['gap_list'] = ['my_country/my_accounting_standards/7']
    request_form['per_account_class_summary'] = 0
    request_form['group_analytic'] = ['function', 'project']

    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(3, len(data_line_list))

    self.assertEquals(['node_id', 'node_title', 'function_uid', 'project_uid',
      'initial_debit_balance', 'initial_credit_balance', 'debit', 'credit',
      'final_debit_balance', 'final_credit_balance', 'final_balance_if_debit',
      'final_balance_if_credit'], data_line_list[0].column_id_list)

    self.checkLineProperties(data_line_list[0], node_id='7',
        node_title='Goods Sales', function_uid='a', project_uid='Project 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=300, final_debit_balance=0, final_credit_balance=300,
        final_balance_if_debit=0, final_balance_if_credit=300)

    self.checkLineProperties(data_line_list[1], node_id='7',
        node_title='Goods Sales', function_uid='b', project_uid='Project 1',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=500, final_debit_balance=0, final_credit_balance=500,
        final_balance_if_debit=0, final_balance_if_credit=500)

    self.checkLineProperties(data_line_list[2], node_id='7',
        node_title='Goods Sales', function_uid='b', project_uid='Project 2',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=700, final_debit_balance=0, final_credit_balance=700,
        final_balance_if_debit=0, final_balance_if_credit=700)

    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=1500, final_debit_balance=0, final_credit_balance=1500,
        final_balance_if_debit=0, final_balance_if_credit=1500)

  def testTrialBalanceGroupByProductLine(self):
    self._makeOne(
              portal_type='Sale Invoice Transaction',
              title='Noise',
              source_reference='2',
              simulation_state='delivered',
              destination_section_value=self.portal.organisation_module.client_1,
              start_date=DateTime(2006, 2, 2),
              lines=(dict(source_value=self.portal.account_module.receivable,
                          source_debit=1100.0),
                     dict(source_value=self.portal.account_module.payable,
                          source_function_value=self.function_a,
                          source_project_value=self.project_1,
                          product_line_value=self.product_line_1,
                          source_credit=1100.0),))

    request_form = self.portal.REQUEST.form
    request_form['from_date'] = DateTime(2006, 1, 1)
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['section_category_strict'] = False
    request_form['simulation_state'] = ['delivered']
    request_form['show_empty_accounts'] = 0
    request_form['expand_accounts'] = 0
    request_form['gap_list'] = ['my_country/my_accounting_standards/7']
    request_form['per_account_class_summary'] = 0
    # in the dialog, categories are in the '_translated_title' form
    request_form['group_analytic'] = ['product_line_translated_title']
    self.assertTrue(
        ('Product Line', 'product_line_translated_title') in
      self.portal.accounting_module.AccountModule_viewTrialBalanceReportDialog\
        .your_group_analytic.get_value('items'))
    
    report_section_list = self.getReportSectionList(
                                    self.portal.accounting_module,
                                    'AccountModule_viewTrialBalanceReport')
    self.assertEquals(1, len(report_section_list))
    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
 
    self.assertEquals(1, len(data_line_list))

    self.assertEquals(['node_id', 'node_title', 'strict_product_line_uid',
      'initial_debit_balance', 'initial_credit_balance', 'debit', 'credit',
      'final_debit_balance', 'final_credit_balance', 'final_balance_if_debit',
      'final_balance_if_credit'], data_line_list[0].column_id_list)

    self.checkLineProperties(data_line_list[0], node_id='7',
        node_title='Goods Sales', strict_product_line_uid='pl1',
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=800, final_debit_balance=0, final_credit_balance=800,
        final_balance_if_debit=0, final_balance_if_credit=800)

    # Lines that does not have a product line are not displayed. This is a
    # technical limitation, we would have to left join to support this.
    self.failUnless(line_list[-1].isStatLine())
    self.checkLineProperties(line_list[-1],
        initial_debit_balance=0, initial_credit_balance=0, debit=0,
        credit=800, final_debit_balance=0, final_credit_balance=800,
        final_balance_if_debit=0, final_balance_if_credit=800)

4516

4517 4518 4519
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestAccountingReports))
4520
  suite.addTest(unittest.makeSuite(TestAccountingReportsWithAnalytic))
4521 4522
  return suite