testInvoice.py 62.6 KB
Newer Older
1 2 3 4
##############################################################################
#
# Copyright (c) 2004 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
5
#          Jerome Perrin <jerome@nexedi.com>
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#
# 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.
#
##############################################################################
29 30
"""
  Tests invoice creation from simulation.
31

32 33
TODO:
  * check empty related Delivery Rule
34 35
  * check divergence

36
"""
37 38 39

from random import randint

40 41
import os, sys
if __name__ == '__main__':
42
    execfile(os.path.join(sys.path[0], 'framework.py'))
43 44 45 46 47

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'

48
from Testing import ZopeTestCase
49
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
50 51
from AccessControl.SecurityManagement import newSecurityManager, \
                                             noSecurityManager
52
from DateTime import DateTime
53
from Acquisition import aq_base, aq_inner, aq_parent
54
from zLOG import LOG
55
from Products.ERP5Type.DateUtils import addToDate
56
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
57 58 59 60 61
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName
from testPackingList import TestPackingListMixin
62
from testAccountingRules import TestAccountingRulesMixin
63

64 65
class TestInvoice(TestPackingListMixin,
                  TestAccountingRulesMixin,
Jérome Perrin's avatar
Jérome Perrin committed
66
                  ERP5TypeTestCase):
67
  """Test invoice are created from orders then packing lists. """
68

69
  RUN_ALL_TESTS = 1
70

71
  default_region = "europe/west/france"
72
  vat_gap = 'fr/pcg/4/44/445/4457/44571'
73
  vat_rate = 0.196
74 75
  sale_gap = 'fr/pcg/7/70/707/7071/70712'
  customer_gap = 'fr/pcg/4/41/411'
76

77
  # (account_id, account_gap)
78
  #XXX gap for the last 3 should be set to real values
79 80 81 82
  account_definition_list = (
      ('receivable_vat', vat_gap),
      ('sale', sale_gap),
      ('customer', customer_gap),
83 84 85
      ('refundable_vat', vat_gap),
      ('purchase', sale_gap),
      ('supplier', customer_gap),
86
      )
87
  # (line_id, source_account_id, destination_account_id, line_quantity)
88
  transaction_line_definition_list = (
89 90 91
      ('income', 'sale', 'purchase', 1.0),
      ('receivable', 'customer', 'supplier', -1.0 - vat_rate),
      ('collected_vat', 'receivable_vat', 'refundable_vat', vat_rate),
92 93
      )

94 95 96 97 98
  invoice_portal_type = 'Sale Invoice Transaction'
  invoice_line_portal_type = 'Invoice Line'
  invoice_cell_portal_type = 'Invoice Cell'
  invoice_transaction_line_portal_type = 'Sale Invoice Transaction Line'

99 100
  def getTitle(self):
    return "Invoices"
101

102
  def login(self, quiet=0, run=1):
103
    uf = self.getPortal().acl_users
104 105
    uf._doAddUser('alex', '', ['Manager', 'Assignee', 'Assignor',
                               'Associate', 'Auditor', 'Author'], [])
Jean-Paul Smets's avatar
Jean-Paul Smets committed
106
    user = uf.getUserById('alex').__of__(uf)
107
    newSecurityManager(None, user)
108

109 110 111 112 113 114 115 116 117 118
  def createCategories(self):
    """Create the categories for our test. """
    TestPackingListMixin.createCategories(self)
    # create categories
    for cat_string in self.getNeededCategoryList() :
      base_cat = cat_string.split("/")[0]
      path = self.getPortal().portal_categories[base_cat]
      for cat in cat_string.split("/")[1:] :
        if not cat in path.objectIds() :
          path = path.newContent(
Jérome Perrin's avatar
Jérome Perrin committed
119 120 121
                    portal_type='Category',
                    id=cat,
                    immediate_reindex=1 )
122
        else:
Jérome Perrin's avatar
Jérome Perrin committed
123
          path = path[cat]
124 125 126 127 128
    # check categories have been created
    for cat_string in self.getNeededCategoryList() :
      self.assertNotEquals(None,
                self.getCategoryTool().restrictedTraverse(cat_string),
                cat_string)
129

130 131
  def getNeededCategoryList(self):
    """return a list of categories that should be created."""
132
    return ('region/%s' % self.default_region,
133 134 135 136
            'gap/%s' % self.vat_gap,
            'gap/%s' % self.sale_gap,
            'gap/%s' % self.customer_gap,
        )
137

138 139 140 141
  def getBusinessTemplateList(self):
    """ """
    return TestPackingListMixin.getBusinessTemplateList(self) + (
              'erp5_accounting',)
142

143
  def stepTic(self, **kw):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
144 145
    self.tic()

146 147 148 149
  def stepCreateEntities(self, sequence, **kw) :
    """Create a vendor and a client. """
    self.stepCreateOrganisation1(sequence, **kw)
    self.stepCreateOrganisation2(sequence, **kw)
150 151 152 153 154 155 156 157 158
    self.stepCreateOrganisation3(sequence, **kw)
    sequence.edit(vendor=sequence.get('organisation1'))
    client1 = sequence.get('organisation2')
    client1.setRegion(self.default_region)
    self.assertNotEquals(client1.getRegionValue(), None)
    sequence.edit(client1=client1)
    client2 = sequence.get('organisation3')
    self.assertEquals(client2.getRegionValue(), None)
    sequence.edit(client2=client2)
159

160 161
  def stepCreateCurrency(self, sequence, **kw) :
    """Create a default currency. """
162 163 164 165 166 167
    currency_module = self.getCurrencyModule()
    if len(currency_module.objectValues(id='EUR'))==0:
      currency = self.getCurrencyModule().newContent(
            portal_type = 'Currency',
            id = "EUR" )
    currency = currency_module.objectValues(id='EUR')[0]
168
    sequence.edit(currency = currency)
169

170
  def stepSetOrderPriceCurrency(self, sequence, **kw) :
171 172 173
    """Set the price currency of the order.

    This step is not necessary.
174 175 176 177 178 179
    TODO : - include a test without this step.
           - include a test with this step late.
    """
    currency = sequence.get('currency')
    order = sequence.get('order')
    order.setPriceCurrency(currency.getRelativeUrl())
180

181 182
  def stepCreateSaleInvoiceTransactionRule(self, sequence, **kw) :
    """Create the rule for accounting. """
183 184 185

    portal = self.getPortal()
    account_module = self.getAccountModule()
186
    for account_id, account_gap in self.account_definition_list:
187 188 189 190 191
      if not account_id in account_module.objectIds():
        account = account_module.newContent(id=account_id)
        account.setGap(account_gap)
        portal.portal_workflow.doActionFor(account,
            'validate_action', wf_id='account_workflow')
Jérome Perrin's avatar
Jérome Perrin committed
192 193 194 195
    invoice_rule = self.getPortal().portal_rules\
                          .default_invoice_transaction_rule
    invoice_rule.deleteContent([x.getId()
                          for x in invoice_rule.objectValues()])
196 197 198 199 200
    region_predicate = invoice_rule.newContent(portal_type = 'Predicate')
    product_line_predicate = invoice_rule.newContent(portal_type = 'Predicate')
    region_predicate.edit(
      membership_criterion_base_category_list = ['destination_region'],
      membership_criterion_category_list =
Jérome Perrin's avatar
Jérome Perrin committed
201
                   ['destination_region/region/%s' % self.default_region ],
202 203 204 205 206 207 208 209 210 211
      int_index = 1,
      string_index = 'region'
    )
    product_line_predicate.edit(
      membership_criterion_base_category_list = ['product_line'],
      membership_criterion_category_list =
                            ['product_line/apparel'],
      int_index = 1,
      string_index = 'product'
    )
212 213 214
    product_line_predicate.immediateReindexObject()
    region_predicate.immediateReindexObject()

215
    invoice_rule.updateMatrix()
216 217 218
    cell_list = invoice_rule.getCellValueList(base_id='movement')
    self.assertEquals(len(cell_list),1)
    cell = cell_list[0]
219

220
    for line_id, line_source_id, line_destination_id, line_ratio in \
221
        self.transaction_line_definition_list:
222 223 224
      line = cell.newContent(id=line_id,
          portal_type=self.sale_invoice_transaction_portal_type)
      line.setQuantity(line_ratio)
225
      line.setSourceValue(account_module[line_source_id])
226
      line.setDestinationValue(account_module[line_destination_id])
227

Jérome Perrin's avatar
Jérome Perrin committed
228 229
  def modifyPackingListState(self, transition_name,
                             sequence,packing_list=None):
230
    """ calls the workflow for the packing list """
231 232
    if packing_list is None:
      packing_list = sequence.get('packing_list')
233 234
    packing_list.portal_workflow.doActionFor(packing_list,
          transition_name, wf_id='packing_list_workflow')
235

236 237 238 239 240
  def stepSetReadyPackingList(self, sequence=None, sequence_list=None, **kw):
    """ set the Packing List as Ready. This must build the invoice. """
    self.modifyPackingListState('set_ready_action', sequence=sequence)
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getSimulationState(), 'ready')
241

Jérome Perrin's avatar
Jérome Perrin committed
242 243
  def stepSetReadyNewPackingList(self, sequence=None,
                                 sequence_list=None, **kw):
244 245 246 247 248 249
    """ set the Packing List as Ready. This must build the invoice. """
    packing_list = sequence.get('new_packing_list')
    self.modifyPackingListState('set_ready_action', sequence=sequence,
                                packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'ready')

250 251 252 253
  def stepStartPackingList(self, sequence=None, sequence_list=None, **kw):
    self.modifyPackingListState('start_action', sequence=sequence)
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getSimulationState(), 'started')
254

255 256 257 258 259
  def stepStartNewPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('new_packing_list')
    self.modifyPackingListState('start_action', sequence=sequence,
                                packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'started')
260

261 262 263 264
  def stepStopPackingList(self, sequence=None, sequence_list=None, **kw):
    self.modifyPackingListState('stop_action', sequence=sequence)
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getSimulationState(), 'stopped')
265 266 267 268 269 270

  def stepDeliverPackingList(self, sequence=None, sequence_list=None, **kw):
    self.modifyPackingListState('deliver_action', sequence=sequence)
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getSimulationState(), 'delivered')

271 272 273 274
  def stepCancelPackingList(self, sequence=None, sequence_list=None, **kw):
    self.modifyPackingListState('cancel_action', sequence=sequence)
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getSimulationState(), 'cancelled')
275

276 277 278 279 280 281 282 283 284 285 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 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345

  def modifyInvoiceState(self, transition_name,
                             sequence,invoice=None):
    """ calls the workflow for the invoice """
    if invoice is None:
      invoice = sequence.get('invoice')
    invoice.portal_workflow.doActionFor(invoice,
          transition_name, wf_id='accounting_workflow')

  def stepConfirmInvoice(self, sequence=None, sequence_list=None, **kw):
    """ set the Packing List as Ready. This must build the invoice. """
    self.modifyInvoiceState('confirm_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'confirmed')

  def stepSetReadyInvoice(self, sequence=None, sequence_list=None, **kw):
    """ set the Packing List as Ready. This must build the invoice. """
    self.modifyInvoiceState('set_ready_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'ready')

  def stepSetReadyNewInvoice(self, sequence=None,
                                 sequence_list=None, **kw):
    """ set the Packing List as Ready. This must build the invoice. """
    invoice = sequence.get('new_invoice')
    self.modifyInvoiceState('set_ready_action', sequence=sequence,
                                invoice=invoice)
    self.assertEquals(invoice.getSimulationState(), 'ready')

  def stepStartInvoice(self, sequence=None, sequence_list=None, **kw):
    self.modifyInvoiceState('start_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'started')

  def stepStartNewInvoice(self, sequence=None, sequence_list=None, **kw):
    invoice = sequence.get('new_invoice')
    self.modifyInvoiceState('start_action', sequence=sequence,
                                invoice=invoice)
    self.assertEquals(invoice.getSimulationState(), 'started')

  def stepStopInvoice(self, sequence=None, sequence_list=None, **kw):
    self.modifyInvoiceState('stop_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'stopped')

  def stepDeliverInvoice(self, sequence=None, sequence_list=None, **kw):
    self.modifyInvoiceState('deliver_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'delivered')

  def stepCancelInvoice(self, sequence=None, sequence_list=None, **kw):
    self.modifyInvoiceState('cancel_action', sequence=sequence)
    invoice = sequence.get('invoice')
    self.assertEquals(invoice.getSimulationState(), 'cancelled')


  def stepSwitchPackingLists(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    new_packing_list = sequence.get('new_packing_list')
    #invoice = new_packing_list.getDefaultCausalityRelatedValue(
        #portal_type=self.invoice_portal_type)
    sequence.edit(packing_list=new_packing_list,
        new_packing_list=packing_list)#, invoice=invoice)

  def stepSwitchInvoices(self, sequence=None, sequence_list=None, **kw):
    invoice = sequence.get('invoice')
    new_invoice = sequence.get('new_invoice')
    sequence.edit(invoice=new_invoice, new_invoice=invoice)

  def stepCheckPackingListSimulation(self, sequence=None, sequence_list=None, **kw):
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
    """ checks that simulation movements related to the packing list are OK """
    packing_list = sequence.get('packing_list')
    order = sequence.get('order')
    order_root_applied_rule = order.getCausalityRelatedValueList(
                                  portal_type = 'Applied Rule')[0]
    # check simulation movements from this packing list
    for movement in packing_list.getMovementList() :
      simulation_movement_list = movement.getOrderRelatedValueList()
      self.assertNotEquals(len(simulation_movement_list), 0)
      total_quantity = 0
      for simulation_movement in simulation_movement_list :
        total_quantity += simulation_movement.getQuantity()
        # check that those movements come from the same root applied
        # rule than the order.
        self.assertEquals( simulation_movement.getRootAppliedRule(),
                           order_root_applied_rule)
      self.assertEquals(total_quantity, movement.getQuantity())
363

364
  def stepCheckInvoiceBuilding(self, sequence=None, sequence_list=None, **kw):
365 366 367
    """
    checks that the invoice is built with the default_invoice_builder
    """
368 369
    packing_list = sequence.get('packing_list')
    related_invoice_list = packing_list.getCausalityRelatedValueList(
Jérome Perrin's avatar
Jérome Perrin committed
370
                     portal_type=self.sale_invoice_transaction_portal_type)
371 372 373 374 375 376 377 378 379 380 381 382

    packing_list_building_state = 'started'
    packing_list_state = packing_list.getSimulationState()
    if packing_list_state != packing_list_building_state :
      self.assertEquals(0, len(related_invoice_list))
    else:
      self.assertEquals(1, len(related_invoice_list))

      invoice = related_invoice_list[0].getObject()
      self.failUnless(invoice is not None)
      # Invoices created by Delivery Builder are in planned state
      self.assertEquals(invoice.getSimulationState(), 'planned')
383

384 385 386 387 388 389 390 391 392 393
      # Get the list of simulation movements of packing list ...
      packing_list_simulation_movement_list = []
      for packing_list_movement in packing_list.getMovementList():
           packing_list_simulation_movement_list.extend(
                packing_list_movement.getDeliveryRelatedValueList())
      # ... invoice simulation movement are their childrens.
      simulation_movement_list = []
      for p_l_simulation_movement in packing_list_simulation_movement_list :
        for applied_rule in p_l_simulation_movement.objectValues() :
          simulation_movement_list.extend(applied_rule.objectValues())
394

395 396 397 398 399 400 401 402 403 404 405 406
      # First, test if each Simulation Movement is related to an
      # Invoice Movement
      invoice_relative_url = invoice.getRelativeUrl()
      for simulation_movement in simulation_movement_list:
        invoice_movement_list = simulation_movement.getDeliveryValueList()
        self.assertEquals(len(invoice_movement_list), 1)
        invoice_movement = invoice_movement_list[0]
        self.failUnless(invoice_movement is not None)
        self.assert_(invoice_movement.getRelativeUrl().\
                              startswith(invoice_relative_url))

      # Then, test if each Invoice movement is equals to the sum of somes
407
      # Simulation Movements
408 409 410 411 412 413 414 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
      for invoice_movement in invoice.getMovementList(portal_type = [
                          self.sale_invoice_cell_portal_type,
                          self.sale_invoice_line_portal_type]) :
        related_simulation_movement_list = invoice_movement.\
                 getDeliveryRelatedValueList(portal_type='Simulation Movement')
        quantity = 0
        total_price = 0
        invoice_movement_quantity = invoice_movement.getQuantity()
        for related_simulation_movement in related_simulation_movement_list:
          quantity += related_simulation_movement.getQuantity()
          total_price += related_simulation_movement.getPrice() *\
                         related_simulation_movement.getQuantity()
          # Test resource
          self.assertEquals(invoice_movement.getResource(), \
                            related_simulation_movement.getResource())
          # Test resource variation
          self.assertEquals(invoice_movement.getVariationText(), \
                            related_simulation_movement.getVariationText())
          self.assertEquals(invoice_movement.getVariationCategoryList(), \
                        related_simulation_movement.getVariationCategoryList())
          # Test acquisition
          self.checkAcquisition(invoice_movement,
                                related_simulation_movement)
          # Test delivery ratio
          self.assertEquals(related_simulation_movement.getQuantity() /\
                            invoice_movement_quantity, \
                            related_simulation_movement.getDeliveryRatio())

        self.assertEquals(quantity, invoice_movement.getQuantity())
        # Test price
        self.assertEquals(total_price / quantity, invoice_movement.getPrice())

      sequence.edit(invoice = invoice)
441

442 443 444 445
      # Test causality
      self.assertEquals(len(invoice.getCausalityValueList(
                      portal_type = self.packing_list_portal_type)), 1)
      self.assertEquals(invoice.getCausalityValue(), packing_list)
446

447 448 449 450 451 452 453 454 455 456 457 458 459
      # Finally, test getTotalQuantity and getTotalPrice on Invoice
      self.assertEquals(packing_list.getTotalQuantity(),
                        invoice.getTotalQuantity())
      self.assertEquals(packing_list.getTotalPrice(),
                        invoice.getTotalPrice())


  def stepCreateSimpleSaleOrder(self, sequence, **kw):
    """ create the Order for our test.
      It contains one line :
        resource : product_module/notebook
        quantity : 10
        price : 100
460
    """
461 462 463 464 465
    source_section = sequence.get('source_section')
    source = sequence.get('source')
    destination_section = sequence.get('destination_section')
    destination = sequence.get('destination')
    product = sequence.get('product')
466

467
    order_module = self.getSaleOrderModule()
468
    order = order_module.newContent(portal_type=self.order_portal_type)
469 470
    order.setStartDate(DateTime('2004-11-20'))
    order.setStopDate(DateTime('2004-11-24'))
471 472 473 474
    order.setDestinationValue(destination)
    order.setDestinationSectionValue(destination_section)
    order.setSourceValue(source)
    order.setSourceSectionValue(source_section)
475
    order_line = order.newContent(portal_type=order_line_portal_type, id='1')
476 477 478
    order_line.setResourceValue(product)
    order_line.setQuantity(10)
    order_line.setPrice(100)
479
    self.assertEquals(len(order.checkConsistency()), 0)
480 481 482 483 484 485 486
    sequence.edit(
      order = order,
      order_line = order_line,
      order_line_list = [order_line])
    self.assertEquals(order_line.getTotalPrice(), 10*100)

  def stepCheckOrderRule(self, sequence=None, sequence_list=None, **kw):
487
    """Check we have a related Order Rule"""
488 489 490
    order = sequence.get('order')
    simulation_tool = self.getSimulationTool()
    # Check that there is an applied rule for our packing list
491 492 493 494
    rule_list = [x for x in simulation_tool.objectValues()
                            if x.getCausalityValue()==order]
    self.assertNotEquals(len(rule_list), 0)
    sequence.edit(order_rule_list = rule_list)
495 496 497

    self.assertEquals(len(order.getMovementList()),
                  sum([len(rule.objectIds()) for rule in rule_list]))
498

499
  def stepCheckInvoicingRule(self, sequence=None, sequence_list=None, **kw):
500 501 502
    """
    Checks that the invoicing rule is applied and its values are correct.
    """
503
    order_rule_list = sequence.get('order_rule_list')
504 505
    invoicing_rule_list = []
    invoice_transaction_rule_list = []
506 507
    for order_rule in order_rule_list :
      for order_simulation_movement in order_rule.objectValues() :
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
        temp_invoicing_rule_list = order_simulation_movement.objectValues()
        self.assertEquals(len(temp_invoicing_rule_list), 1)
        invoicing_rule_list.extend(order_simulation_movement.objectValues())
    sequence.edit(invoicing_rule_list=invoicing_rule_list)
    invoicing_rule = invoicing_rule_list[0]
    sequence.edit(invoicing_rule = invoicing_rule)
    for invoicing_rule in invoicing_rule_list:
      self.assertEquals(invoicing_rule.getSpecialiseId(),
          'default_invoicing_rule')
      self.assertEquals(invoicing_rule.getPortalType(),
          'Applied Rule')
      simulation_movement_list = invoicing_rule.objectValues()
      self.assertNotEquals(len(simulation_movement_list), 0)
      for simulation_movement in simulation_movement_list :
        invoice_transaction_rule_list.extend(simulation_movement.objectValues())
        resource_list = sequence.get('resource_list')
        self.assertEquals(simulation_movement.getPortalType(),
                          'Simulation Movement')
        self.assertTrue(simulation_movement.getResourceValue() in
            resource_list)
        self.assertTrue(simulation_movement.isConvergent())
        # TODO: What is the invoice dates supposed to be ?
        # is this done through profiles ?
531 532 533 534
        #self.assertEquals(simulation_movement.getStartDate(),
        #           sequence.get('order').getStartDate())
        #self.assertEquals(simulation_movement.getStopDate(),
        #            sequence.get('order').getStopDate())
535 536 537 538 539 540 541 542 543 544 545 546 547
    sequence.edit(invoice_transaction_rule_list=invoice_transaction_rule_list)

  def stepCheckInvoiceTransactionRule(self, sequence=None, sequence_list=None,
      **kw):
    """
    Checks that the invoice_transaction_rule is expanded and its movements are
    consistent with its parent movement
    """
    invoice_transaction_rule_list = \
        sequence.get('invoice_transaction_rule_list')
    for invoice_transaction_rule in invoice_transaction_rule_list:
      parent_movement = aq_parent(invoice_transaction_rule)
      self.assertEquals(3, len(invoice_transaction_rule.objectValues()))
548
      for line_id, line_source_id, line_destination_id, line_ratio in \
549 550 551
          self.transaction_line_definition_list:
        movement = getattr(invoice_transaction_rule, line_id, None)
        self.assertTrue(movement is not None)
552 553
        self.assertEquals(movement.getCorrectedQuantity(), parent_movement.getPrice() *
            parent_movement.getCorrectedQuantity() * line_ratio)
554
        self.assertEquals(movement.getSourceId(), line_source_id)
555
        self.assertEquals(movement.getDestinationId(), line_destination_id)
556 557 558 559
        self.assertEquals(movement.getStartDate(),
            parent_movement.getStartDate())
        self.assertEquals(movement.getStopDate(),
            parent_movement.getStopDate())
560

561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
  def stepCheckInvoicesConsistency(self, sequence=None, sequence_list=None,
      **kw):
    """
    Checks that all invoices are consistent:
    - transaction lines match invoice lines
    - no movement is divergent
    """
    invoice_list = self.getPortal()['accounting_module'].objectValues()
    for invoice in invoice_list:
      accounting_state_list = \
          list(self.getPortal().getPortalCurrentInventoryStateList())
      accounting_state_list.append('cancelled')
      if invoice.getSimulationState() in accounting_state_list:
        invoice_line_list = invoice.contentValues(
            portal_type=self.invoice_line_portal_type)
        invoice_transaction_line_list = invoice.contentValues(
            portal_type=self.invoice_transaction_line_portal_type)
        self.assertEquals(3, len(invoice_transaction_line_list))
        expected_price = 0.0
        for line in invoice_line_list:
          expected_price += line.getTotalPrice()
        for line_id, line_source, line_dest, line_ratio in \
            self.transaction_line_definition_list:
          for line in invoice.contentValues(
              portal_type=self.invoice_transaction_line_portal_type):
            if line.getSource() == 'account_module/%s' % line_source and \
                line.getDestination() == 'account_module/%s' % line_dest:
              break
          else:
            self.fail('No line found that matches %s' % line_id)
          self.assertEquals(line.getQuantity(), expected_price * line_ratio)

593 594 595 596
  def stepCheckDeliveryRuleForDeferred(
                      self, sequence=None, sequence_list=None, **kw):
    """ Checks that a delivery rule has been created when we took 'split
        and defer' decision on the divergeant Packing List. """
597 598
    # TODO

599 600 601 602
  def stepCheckDeliveryRuleIsEmpty(
                      self, sequence=None, sequence_list=None, **kw):
    """ Checks that an empty delivery rule is created for the
        convergeant Packing List"""
603 604 605 606
    packing_list = sequence.get('packing_list')
    self.failUnless(packing_list is not None)
    simulation_tool = self.getSimulationTool()
    # Check that there is an applied rule for our packing list
607 608
    rule_list = [x for x in simulation_tool.objectValues()
                          if x.getCausalityValue()==packing_list]
609 610 611 612 613
    self.assertEquals(len(rule_list),1)
    packing_list_rule = rule_list[0]
    sequence.edit(packing_list_rule=packing_list_rule)
    rule_line_list = packing_list_rule.objectValues()
    packing_list_line_list = packing_list.objectValues()
614 615 616
    self.assertEquals(len(packing_list_line_list),
                      len(rule_line_list))
    self.assertEquals(1, len(rule_line_list))
617 618
    rule_line = rule_line_list[0]
    packing_list_line = packing_list_line_list[0]
619 620 621 622 623 624 625 626 627 628
    self.assertEquals(rule_line.getQuantity(), 10)
    self.assertEquals(rule_line.getPrice(), 100)
    self.assertEquals(rule_line.getDeliveryValue(),
                      packing_list_line)
    self.assertEquals(rule_line.getStartDate(),
                      packing_list_line.getStartDate())
    self.assertEquals(rule_line.getStopDate(),
                      packing_list_line.getStopDate())
    self.assertEquals(rule_line.getPortalType(),
                      'Simulation Movement')
629

630

631
  def stepCheckPackingList(self,sequence=None, sequence_list=None,**kw):
632
    """  """
633 634 635 636 637 638 639
    packing_list_module = self.getSalePackingListModule()
    order_rule = sequence.get('order_rule')
    order = sequence.get('order')
    sale_packing_list_list = []
    for o in packing_list_module.objectValues():
      if o.getCausalityValue() == order:
        sale_packing_list_list.append(o)
640
    self.assertEquals(len(sale_packing_list_list), 1)
641 642 643 644
    sale_packing_list = sale_packing_list_list[0]
    sale_packing_list_line_list = sale_packing_list.objectValues()
    self.assertEquals(len(sale_packing_list_line_list),1)
    sale_packing_list_line = sale_packing_list_line_list[0]
645 646 647 648 649 650 651 652 653 654 655 656 657
    product = sequence.get('resource')
    self.assertEquals(sale_packing_list_line.getResourceValue(),
                      product)
    self.assertEquals(sale_packing_list_line.getPrice(),
                      self.price1)
    LOG('sale_packing_list_line.showDict()',0,
          sale_packing_list_line.showDict())
    self.assertEquals(sale_packing_list_line.getQuantity(),
                      self.quantity1)
    self.assertEquals(sale_packing_list_line.getTotalPrice(),
                      self.total_price1)
    sequence.edit(packing_list = sale_packing_list)

658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
  def stepCheckTwoInvoices(self,sequence=None, sequence_list=None, **kw):
    """ checks invoice properties are well set. """
    # New we will check that we have two invoices
    packing_list = sequence.get('packing_list')
    invoice_list = packing_list.getCausalityRelatedValueList(
         portal_type=self.sale_invoice_transaction_portal_type)
    self.assertEquals(len(invoice_list),1)
    invoice = invoice_list[0]
    sequence.edit(invoice=invoice)
    new_packing_list = sequence.get('new_packing_list')
    new_invoice_list = new_packing_list.getCausalityRelatedValueList(
        portal_type=self.sale_invoice_transaction_portal_type)
    self.assertEquals(len(new_invoice_list),1)
    new_invoice = new_invoice_list[0]
    sequence.edit(new_invoice=new_invoice)

  def stepConfirmTwoInvoices(self,sequence=None, sequence_list=None, **kw):
    """ confirme both invoices. """
    portal = self.getPortal()
    invoice = sequence.get('invoice')
    new_invoice = sequence.get('new_invoice')
    portal.portal_workflow.doActionFor(invoice,
        'confirm_action',wf_id='accounting_workflow')
    portal.portal_workflow.doActionFor(new_invoice,
        'confirm_action',wf_id='accounting_workflow')

Jérome Perrin's avatar
Jérome Perrin committed
684 685
  def stepCheckTwoInvoicesTransactionLines(self,sequence=None,
                                           sequence_list=None, **kw):
686 687 688 689 690 691 692
    """ checks invoice properties are well set. """
    invoice = sequence.get('invoice')
    new_invoice = sequence.get('new_invoice')
    self.assertEquals(3,len(invoice.objectValues(
        portal_type=self.sale_invoice_transaction_line_portal_type)))
    self.assertEquals(3,len(new_invoice.objectValues(
        portal_type=self.sale_invoice_transaction_line_portal_type)))
693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
    account_module = self.getAccountModule()
    found_dict = {}
    for line in invoice.objectValues(
        portal_type=self.sale_invoice_transaction_line_portal_type):
      source_id = line.getSourceId()
      found_dict[source_id] = line.getQuantity()
    total_price = (self.default_quantity-1) * self.default_price
    expected_dict = {
      'sale' : total_price,
      'receivable_vat' : total_price * self.vat_rate,
      'customer' : - (total_price + total_price * self.vat_rate)
      }
    self.failIfDifferentSet(expected_dict.keys(),found_dict.keys())
    for key in found_dict.keys():
      self.assertAlmostEquals(expected_dict[key],found_dict[key],places=2)
    found_dict = {}
    for line in new_invoice.objectValues(
        portal_type=self.sale_invoice_transaction_line_portal_type):
      source_id = line.getSourceId()
      found_dict[source_id] = line.getQuantity()
    total_price = 1 * self.default_price
    expected_dict = {
      'sale' : total_price,
      'receivable_vat' : total_price * self.vat_rate,
      'customer' : - (total_price + total_price * self.vat_rate)
      }
Jérome Perrin's avatar
Jérome Perrin committed
719
    self.failIfDifferentSet(expected_dict.keys(), found_dict.keys())
720
    for key in found_dict.keys():
Jérome Perrin's avatar
Jérome Perrin committed
721
      self.assertAlmostEquals(expected_dict[key], found_dict[key], places=2)
722

723 724 725 726
  def stepRebuildAndCheckNothingIsCreated(self, sequence=None,
                                           sequence_list=None, **kw):
    """Rebuilds with sale_invoice_builder and checks nothing more is
    created. """
727
    accounting_module = self.getAccountingModule()
728 729 730 731 732
    sale_invoice_transaction_count = len(accounting_module.objectValues())
    for builder in self.getPortal().portal_deliveries.objectValues():
      builder.build()
    self.assertEquals(sale_invoice_transaction_count,
                      len(accounting_module.objectValues()))
733 734 735

  def stepModifyInvoicesDate(self, sequence=None,
                                           sequence_list=None, **kw):
736
    """Change invoice date"""
737 738 739 740 741 742 743 744
    invoice = sequence.get('invoice')
    new_invoice = sequence.get('new_invoice')
    invoice.edit(start_date=self.datetime,
                 stop_date=self.datetime+1)
    new_invoice.edit(start_date=self.datetime,
                 stop_date=self.datetime+1)

  def stepRemoveDateMovementGroupForTransactionBuilder(self, sequence=None,
745
            sequence_list=None, **kw):
746 747 748 749 750 751 752 753 754
    """
    Remove DateMovementGroup
    """
    portal = self.getPortal()
    builder = portal.portal_deliveries.sale_invoice_transaction_builder
    previous_list = builder.getDeliveryCollectOrderList()
    new_list = [x for x in previous_list if x != 'DateMovementGroup']
    new_list.append('ParentExplanationMovementGroup')
    builder.setDeliveryCollectOrderList(new_list)
755

756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
  def stepEditInvoice(self, sequence=None, sequence_list=None, **kw):
    """Edit the current invoice, to trigger updateAppliedRule."""
    invoice = sequence.get('invoice')
    invoice.edit()

    # call updateAppliedRule directly, don't rely on edit interactions
    rule_id = 'default_invoice_rule'
    self.failUnless(rule_id in
                    self.getPortal().portal_rules.objectIds())
    invoice.updateAppliedRule(rule_id=rule_id)

  def stepCheckInvoiceRuleNotAppliedOnInvoiceEdit(self,
                    sequence=None, sequence_list=None, **kw):
    """If we call edit on the invoice, invoice rule should not be
    applied on lines created by delivery builder."""
    invoice = sequence.get('invoice')
    # FIXME: empty applied rule should not be created
    #self.assertEquals(len(invoice.getCausalityRelatedValueList(
    #         portal_type=self.applied_rule_portal_type)), 0)
    for invoice_mvt in invoice.getMovementList():
      self.assertEquals(len(invoice_mvt.getOrderRelatedValueList(
            portal_type=self.simulation_movement_portal_type)), 0)

  def stepEditPackingList(self, sequence=None, sequence_list=None, **kw):
    """Edit the current packing list, to trigger updateAppliedRule."""
    packing_list = sequence.get('packing_list')
    packing_list.edit()
783

784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
    # call updateAppliedRule directly, don't rely on edit interactions
    rule_id = 'default_delivery_rule'
    self.failUnless(rule_id in
                    self.getPortal().portal_rules.objectIds())
    packing_list.updateAppliedRule(rule_id=rule_id)

  def stepCheckDeliveryRuleNotAppliedOnPackingListEdit(self,
                    sequence=None, sequence_list=None, **kw):
    """If we call edit on the packing list, delivery rule should not be
    applied on lines created by delivery builder."""
    packing_list = sequence.get('packing_list')
    # FIXME: empty applied rule should not be created
    #self.assertEquals(len(packing_list.getCausalityRelatedValueList(
    #         portal_type=self.applied_rule_portal_type)), 0)
    for delivery_mvt in packing_list.getMovementList():
      self.assertEquals(len(delivery_mvt.getOrderRelatedValueList(
            portal_type=self.simulation_movement_portal_type)), 0)
801

802 803 804 805 806 807 808
  def stepDecreaseInvoiceLineQuantity(self, sequence=None, sequence_list=None,
      **kw):
    """
    Set a decreased quantity on invoice lines
    """
    invoice = sequence.get('invoice')
    quantity = sequence.get('line_quantity',default=self.default_quantity)
809
    quantity = quantity - 1
810 811 812 813
    sequence.edit(line_quantity=quantity)
    for invoice_line in invoice.objectValues(
        portal_type=self.invoice_line_portal_type):
      invoice_line.edit(quantity=quantity)
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) - 1.0)

  def stepIncreaseInvoiceLineQuantity(self, sequence=None, sequence_list=None,
      **kw):
    """
    Set a Increased quantity on invoice lines
    """
    invoice = sequence.get('invoice')
    quantity = sequence.get('line_quantity',default=self.default_quantity)
    quantity = quantity + 1
    sequence.edit(line_quantity=quantity)
    for invoice_line in invoice.objectValues(
        portal_type=self.invoice_line_portal_type):
      invoice_line.edit(quantity=quantity)
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) + 1.0)

  def stepSetInvoiceLineQuantityToZero(self, sequence=None, sequence_list=None,
      **kw):
    """
    Set the quantity on invoice lines to zero
    """
    invoice = sequence.get('invoice')
    #default_quantity = sequence.get('line_quantity',default_quantity)
    quantity = 0.0
    sequence.edit(line_quantity=quantity)
    for invoice_line in invoice.objectValues(
        portal_type=self.invoice_line_portal_type):
      invoice_line.edit(quantity=quantity)
    sequence.edit(last_delta = - self.default_quantity)
843

844 845 846 847 848 849 850
  def stepChangeInvoiceStartDate(self, sequence=None, sequence_list=None, **kw):
    """
      Change the start_date of the invoice.
    """
    invoice = sequence.get('invoice')
    invoice.edit(start_date=self.datetime + 15)

851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
  def stepCheckInvoiceIsCalculating(self, sequence=None, sequence_list=None,
      **kw):
    """
    Test if invoice is calculating
    """
    invoice = sequence.get('invoice')
    self.assertEquals('calculating',invoice.getCausalityState())

  def stepCheckInvoiceIsDiverged(self, sequence=None, sequence_list=None,
      **kw):
    """
    Test if invoice is diverged
    """
    invoice = sequence.get('invoice')
    self.assertEquals('diverged',invoice.getCausalityState())

  def stepCheckInvoiceIsSolved(self, sequence=None, sequence_list=None,
      **kw):
    """
    Test if invoice is solved
    """
    invoice = sequence.get('invoice')
    self.assertEquals('solved',invoice.getCausalityState())

  def stepCheckInvoiceIsDivergent(self, sequence=None, sequence_list=None,
      **kw):
    """
    Test if invoice is divergent
    """
    invoice = sequence.get('invoice')
    self.assertTrue(invoice.isDivergent())

  def stepCheckInvoiceIsNotDivergent(self, sequence=None, sequence_list=None,
      **kw):
    """
    Test if invoice is not divergent
    """
    invoice = sequence.get('invoice')
    self.assertFalse(invoice.isDivergent())

891
  def stepSplitAndDeferInvoice(self, sequence=None, sequence_list=None,
892 893
      **kw):
    """
894
    split and defer at the invoice level
895 896 897 898 899 900
    """
    invoice = sequence.get('invoice')
    invoice.portal_workflow.doActionFor(invoice,'split_prevision_action',
        wf_id='invoice_causality_workflow', start_date=self.datetime +
        15, stop_date=self.datetime + 25)

901 902 903 904 905 906 907 908
  def stepAcceptDecisionInvoice(self, sequence=None, sequence_list=None,
      **kw):
    """
    accept decision at the invoice level
    """
    invoice = sequence.get('invoice')
    invoice.portal_workflow.doActionFor(invoice,'accept_decision_action')

909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931
  def stepCheckInvoiceSplitted(self, sequence=None, sequence_list=None, **kw):
    """
    Test if invoice was splitted
    """
    packing_list = sequence.get('packing_list')
    invoice_list = packing_list.getCausalityRelatedValueList(
        portal_type=self.invoice_portal_type)
    self.assertEquals(2,len(invoice_list))
    invoice1 = None
    invoice2 = None
    for invoice in invoice_list:
      if invoice.getUid() == sequence.get('invoice').getUid():
        invoice1 = invoice
      else:
        invoice2 = invoice
    sequence.edit(new_invoice=invoice2)
    for line in invoice1.objectValues(
          portal_type=self.invoice_line_portal_type):
      self.assertEquals(self.default_quantity-1,line.getQuantity())
    for line in invoice2.objectValues(
          portal_type=self.invoice_line_portal_type):
      self.assertEquals(1,line.getQuantity())

932 933 934 935 936 937 938 939 940 941 942 943
  def stepCheckInvoiceNotSplitted(self, sequence=None, sequence_list=None, **kw):
    """
    Test if invoice was not splitted
    """
    packing_list = sequence.get('packing_list')
    invoice_list = packing_list.getCausalityRelatedValueList(
        portal_type=self.invoice_portal_type)
    self.assertEquals(1,len(invoice_list))
    invoice1 = None
    for invoice in invoice_list:
      if invoice.getUid() == sequence.get('invoice').getUid():
        invoice1 = invoice
944
    last_delta = sequence.get('last_delta', 0.0)
945 946
    for line in invoice1.objectValues(
        portal_type=self.invoice_line_portal_type):
947 948
      self.assertEquals(self.default_quantity + last_delta,
          line.getQuantity())
949

950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975
  # default sequence for one line of not varianted resource.
  PACKING_LIST_DEFAULT_SEQUENCE = """
      stepCreateSaleInvoiceTransactionRule
      stepCreateEntities
      stepCreateCurrency
      stepCreateOrder
      stepSetOrderProfile
      stepSetOrderPriceCurrency
      stepCreateNotVariatedResource
      stepTic
      stepCreateOrderLine
      stepSetOrderLineResource
      stepSetOrderLineDefaultValues
      stepOrderOrder
      stepTic
      stepCheckDeliveryBuilding
      stepConfirmOrder
      stepTic
      stepCheckOrderRule
      stepCheckOrderSimulation
      stepCheckDeliveryBuilding
      stepAddPackingListContainer
      stepAddPackingListContainerLine
      stepSetContainerLineFullQuantity
      stepTic
      stepCheckPackingListIsPacked
976
    """
977

978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010
  # default sequence for two lines of not varianted resource.
  PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE = """
      stepCreateSaleInvoiceTransactionRule
      stepCreateEntities
      stepCreateCurrency
      stepCreateOrder
      stepSetOrderProfile
      stepSetOrderPriceCurrency
      stepCreateNotVariatedResource
      stepTic
      stepCreateOrderLine
      stepSetOrderLineResource
      stepSetOrderLineDefaultValues
      stepCreateNotVariatedResource
      stepTic
      stepCreateOrderLine
      stepSetOrderLineResource
      stepSetOrderLineDefaultValues
      stepOrderOrder
      stepTic
      stepCheckDeliveryBuilding
      stepConfirmOrder
      stepTic
      stepCheckOrderRule
      stepCheckOrderSimulation
      stepCheckDeliveryBuilding
      stepAddPackingListContainer
      stepAddPackingListContainerLine
      stepTic
      stepSetContainerFullQuantity
      stepTic
      stepCheckPackingListIsPacked
    """
1011

1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032
  # default sequence for one line of not varianted resource.
  TWO_PACKING_LIST_DEFAULT_SEQUENCE = """
      stepCreateSaleInvoiceTransactionRule
      stepCreateEntities
      stepCreateCurrency
      stepCreateOrder
      stepSetOrderProfile
      stepSetOrderPriceCurrency
      stepCreateNotVariatedResource
      stepTic
      stepCreateOrderLine
      stepSetOrderLineResource
      stepSetOrderLineDefaultValues
      stepOrderOrder
      stepTic
      stepCheckDeliveryBuilding
      stepConfirmOrder
      stepTic
      stepCheckOrderRule
      stepCheckOrderSimulation
      stepCheckDeliveryBuilding
1033 1034 1035 1036 1037
      stepDecreasePackingListLineQuantity
      stepCheckPackingListIsCalculating
      stepSplitAndDeferPackingList
      stepTic
      stepCheckPackingListIsSolved
1038
      stepCheckPackingListSplitted
1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
      stepAddPackingListContainer
      stepAddPackingListContainerLine
      stepSetContainerLineFullQuantity
      stepTic
      stepCheckPackingListIsPacked
      stepDefineNewPackingListContainer
      stepTic
      stepCheckNewPackingListIsPacked
    """

1049
  def test_01_SimpleInvoice(self, quiet=0, run=RUN_ALL_TESTS):
1050 1051 1052
    """
    Checks that a Simple Invoice is created from a Packing List
    """
1053
    if not run: return
1054 1055
    self.logMessage('Simple Invoice')
    sequence_list = SequenceList()
1056
    for base_sequence in (self.PACKING_LIST_DEFAULT_SEQUENCE, ) :
1057
      sequence_list.addSequenceString(
1058 1059 1060 1061 1062 1063 1064 1065 1066
        base_sequence +
      """
        stepSetReadyPackingList
        stepTic
        stepStartPackingList
        stepCheckInvoicingRule
        stepTic
        stepCheckInvoiceBuilding
        stepRebuildAndCheckNothingIsCreated
1067
        stepCheckInvoicesConsistency
1068
      """)
1069
    sequence_list.play(self)
1070

1071
  def test_02_TwoInvoicesFromTwoPackingList(self, quiet=0, run=RUN_ALL_TESTS):
1072 1073
    """
    This test was created for the following bug:
1074 1075 1076 1077 1078 1079 1080 1081
        - an order is created and confirmed
        - the packing list is split
        - the 2 packing list are delivered (at different date)
        - 2 invoices are built, then we set the same date on both of them
        - the accounting rules are generated and put in only one invoice !!,
          so we have an invoice with twice the number of accounting rules
          and an invoice with no accounting rules. both invoices are wrong
    """
1082
    if not run: return
1083 1084
    self.logMessage('Two Invoices from Two Packing List')
    sequence_list = SequenceList()
1085
    for base_sequence in (self.TWO_PACKING_LIST_DEFAULT_SEQUENCE, ) :
1086
      sequence_list.addSequenceString(
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099
        base_sequence +
      """
        stepSetReadyPackingList
        stepSetReadyNewPackingList
        stepTic
        stepStartPackingList
        stepStartNewPackingList
        stepTic
        stepCheckTwoInvoices
        stepRemoveDateMovementGroupForTransactionBuilder
        stepConfirmTwoInvoices
        stepTic
        stepCheckTwoInvoicesTransactionLines
1100
        stepCheckInvoicesConsistency
1101
      """)
1102
    sequence_list.play(self)
1103

1104
  def test_03_InvoiceEditAndInvoiceRule(self, quiet=0, run=RUN_ALL_TESTS):
1105 1106
    """
    Invoice Rule should not be applied on invoice lines created from\
1107 1108
    Packing List.

1109
    We want to prevent this from happening:
1110 1111 1112 1113 1114 1115
      - Create a packing list
      - An invoice is created from packing list
      - Invoice is edited, updateAppliedRule is called
      - A new Invoice Rule is created for this invoice, and accounting
        movements for this invoice are present twice in the simulation.
    """
1116
    if not run: return
1117 1118
    self.logMessage('Invoice Edit')
    sequence_list = SequenceList()
1119
    for base_sequence in (self.PACKING_LIST_DEFAULT_SEQUENCE, ) :
1120
      sequence_list.addSequenceString(
1121 1122 1123 1124 1125 1126 1127 1128 1129 1130
        base_sequence +
      """
        stepSetReadyPackingList
        stepTic
        stepStartPackingList
        stepCheckInvoicingRule
        stepTic
        stepCheckInvoiceBuilding
        stepEditInvoice
        stepCheckInvoiceRuleNotAppliedOnInvoiceEdit
1131
        stepCheckInvoicesConsistency
1132
      """)
1133 1134
    sequence_list.play(self)

1135
  def test_04_PackingListEditAndInvoiceRule(self, quiet=0, run=RUN_ALL_TESTS):
1136 1137
    """
    Delivery Rule should not be applied on packing list lines created\
1138 1139
    from Order.
    """
1140
    if not run: return
1141 1142
    self.logMessage('Packing List Edit')
    sequence_list = SequenceList()
1143
    for base_sequence in (self.PACKING_LIST_DEFAULT_SEQUENCE, ) :
1144
      sequence_list.addSequenceString(
1145 1146 1147 1148
        base_sequence +
      """
        stepEditPackingList
        stepCheckDeliveryRuleNotAppliedOnPackingListEdit
1149
        stepCheckInvoicesConsistency
1150
      """)
1151
    sequence_list.play(self)
1152

1153
  def test_05_InvoiceEditPackingListLine(self, quiet=0, run=RUN_ALL_TESTS):
1154 1155 1156 1157
    """
    Checks that editing a Packing List Line still creates a correct
    Invoice
    """
1158
    if not run: return
1159 1160
    self.logMessage('Packing List Line Edit')
    sequence_list = SequenceList()
1161
    for base_sequence in (self.PACKING_LIST_DEFAULT_SEQUENCE, ) :
1162
      sequence_list.addSequenceString(
1163
        base_sequence +
1164
    """
1165 1166 1167 1168 1169 1170 1171 1172
      stepEditPackingListLine
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepCheckInvoicingRule
      stepTic
      stepCheckInvoiceBuilding
      stepRebuildAndCheckNothingIsCreated
1173
      stepCheckInvoicesConsistency
1174
    """)
1175
    sequence_list.play(self)
1176

1177 1178
  def test_06_InvoiceDeletePackingListLine(self, quiet=0,
      run=RUN_ALL_TESTS):
1179 1180 1181 1182
    """
    Checks that deleting a Packing List Line still creates a correct
    Invoice
    """
1183
    if not run: return
1184 1185
    self.logMessage('Packing List Line Delete')
    sequence_list = SequenceList()
1186
    for base_sequence in (self.PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE, ) :
1187
      sequence_list.addSequenceString(
1188
        base_sequence +
1189
    """
1190 1191 1192 1193 1194 1195 1196 1197
      stepDeletePackingListLine
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepCheckInvoicingRule
      stepTic
      stepCheckInvoiceBuilding
      stepRebuildAndCheckNothingIsCreated
1198
      stepCheckInvoicesConsistency
1199
    """)
1200
    sequence_list.play(self)
1201

1202
  def test_07_InvoiceAddPackingListLine(self, quiet=0, run=RUN_ALL_TESTS):
1203 1204 1205 1206
    """
    Checks that adding a Packing List Line still creates a correct
    Invoice
    """
1207
    if not run: return
1208 1209
    self.logMessage('Packing List Line Add')
    sequence_list = SequenceList()
1210 1211
    for base_sequence in (self.PACKING_LIST_DEFAULT_SEQUENCE,
        self.PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE) :
1212
      sequence_list.addSequenceString(
1213 1214 1215
        base_sequence +
    """
      stepAddPackingListLine
1216 1217
      stepSetContainerFullQuantity
      stepTic
1218 1219 1220 1221 1222 1223 1224
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepCheckInvoicingRule
      stepTic
      stepCheckInvoiceBuilding
      stepRebuildAndCheckNothingIsCreated
1225
      stepCheckInvoicesConsistency
1226
    """)
1227
    sequence_list.play(self)
1228

1229
  def test_08_InvoiceDecreaseQuantity(self, quiet=0, run=RUN_ALL_TESTS):
1230 1231 1232 1233 1234
    """
    Change the quantity of a Invoice Line,
    check that the invoice is divergent,
    then split and defer, and check everything is solved
    """
1235
    if not run: return
1236
    self.logMessage('Invoice Decrease Qantity')
1237 1238 1239 1240 1241 1242
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
1243
    stepCheckInvoiceTransactionRule
1244 1245 1246 1247
    stepTic
    stepCheckInvoiceBuilding

    stepDecreaseInvoiceLineQuantity
1248
    stepCheckInvoiceIsDivergent
1249
    stepCheckInvoiceIsCalculating
1250
    stepSplitAndDeferInvoice
1251
    stepTic
1252 1253

    stepCheckInvoiceIsNotDivergent
1254 1255
    stepCheckInvoiceIsSolved
    stepCheckInvoiceSplitted
1256 1257 1258

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
1259
    stepCheckInvoiceTransactionRule
1260 1261

    stepRebuildAndCheckNothingIsCreated
1262
    stepCheckInvoicesConsistency
1263 1264
    """
    self.playSequence(sequence)
1265

1266
  def test_09_InvoiceChangeStartDate(self, quiet=0, run=RUN_ALL_TESTS):
1267 1268 1269 1270 1271
    """
    Change the start_date of a Invoice Line,
    check that the invoice is divergent,
    then accept decision, and check everything is solved
    """
1272
    if not run: return
1273
    self.logMessage('Invoice Change Sart Date')
1274 1275 1276 1277 1278 1279
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
1280
    stepCheckInvoiceTransactionRule
1281 1282 1283 1284
    stepTic
    stepCheckInvoiceBuilding

    stepChangeInvoiceStartDate
1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 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 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepAcceptDecisionInvoice
    stepTic

    stepCheckInvoiceNotSplitted
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """
    self.playSequence(sequence)

  def test_10_AcceptDecisionOnPackingList(self, quiet=0, run=RUN_ALL_TESTS):
    """
    - Increase or Decrease the quantity of a Packing List line
    - Accept Decision on Packing List
    - Packing List must not be divergent and use new quantity
    - Invoice must not be divergent and use new quantity
    """
    if not run: return
    self.logMessage('InvoiceAcceptDecisionOnPackingList')
    end_sequence = \
    """
    stepSetContainerFullQuantity
    stepCheckPackingListIsCalculating
    stepAcceptDecisionPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted

    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceNotSplitted
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """

    mid_sequence_list = ["""
    stepCheckInvoicingRule
    stepDecreasePackingListLineQuantity
    """, """
    stepCheckInvoicingRule
    stepIncreasePackingListLineQuantity
    """]

    sequence_list = SequenceList()
    for seq in mid_sequence_list:
      sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
          seq + end_sequence
      sequence_list.addSequenceString(sequence)
    sequence_list.play(self)

  def test_11_AcceptDecisionOnPackingListAndInvoice(self, quiet=0,
      run=RUN_ALL_TESTS):
    """
    - Increase or Decrease the quantity of a Packing List line
    - Accept Decision on Packing List
    - Packing List must not be divergent and use new quantity
    - Put old quantity on Invoice
    - Accept Decision on Invoice
    - Packing List must not be divergent and use new quantity
    - Invoice must not be divergent and use old quantity
    """
    if not run: return
    self.logMessage('InvoiceAcceptDecisionOnPackingListAndInvoice')
    mid_sequence = \
    """
    stepSetContainerFullQuantity
    stepCheckPackingListIsCalculating
    stepAcceptDecisionPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted

    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule
    """
    end_sequence = \
    """
    stepCheckInvoiceIsDiverged
    stepAcceptDecisionInvoice
    stepTic
    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule
    stepCheckInvoiceNotSplitted
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """

    mid_sequence_list = [("""
    stepCheckInvoicingRule
    stepDecreasePackingListLineQuantity
    """, """
    stepIncreaseInvoiceLineQuantity
    stepTic
    """), ("""
    stepCheckInvoicingRule
    stepIncreasePackingListLineQuantity
    """, """
    stepDecreaseInvoiceLineQuantity
    stepTic
    """)]

    sequence_list = SequenceList()
    for seq1, seq2 in mid_sequence_list:
      sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
          seq1 + mid_sequence + seq2 + end_sequence
      sequence_list.addSequenceString(sequence)
    sequence_list.play(self)

  def test_12_SplitPackingListAndAcceptInvoice(self, quiet=0,
      run=RUN_ALL_TESTS):
    """
    - Decrease the quantity of a Packing List line
    - Split and Defer on Packing List
    - Packing List must not be divergent and use new quantity
    - splitted Packing List must not be divergent and use old - new quantity

    - Put old quantity on Invoice1
    - Accept Decision on Invoice1
    - Packing List must not be divergent and use new quantity
    - splitted Packing List must not be divergent and use old - new quantity
    - Invoice1 must not be divergent and use old quantity

    - set Invoice2 quantity to 0
    - Accept Decision on Invoice2
    - Packing List must not be divergent and use new quantity
    - splitted Packing List must not be divergent and use old - new quantity
    - Invoice1 must not be divergent and use old quantity
    - Invoice2 must not be divergent and use 0 as quantity
    """
    if not run: return
    self.logMessage('InvoiceSplitPackingListAndAcceptInvoice')
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepCheckInvoicingRule
    stepDecreasePackingListLineQuantity
    stepSetContainerFullQuantity
    stepCheckPackingListIsCalculating
    stepSplitAndDeferPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListSplitted

    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding
    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListSplitted

    stepIncreaseInvoiceLineQuantity
1496 1497 1498
    stepCheckInvoiceIsCalculating
    stepAcceptDecisionInvoice
    stepTic
1499 1500 1501 1502 1503 1504
    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
1505 1506
    stepCheckInvoiceIsSolved
    stepCheckInvoiceNotSplitted
1507 1508
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
1509
    stepCheckInvoiceTransactionRule
1510

1511
    stepRebuildAndCheckNothingIsCreated
1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
    stepCheckInvoicesConsistency

    stepSwitchPackingLists

    stepAddPackingListContainer
    stepSetContainerFullQuantity
    stepTic
    stepCheckPackingListIsSolved
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding
    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsSolved

    stepSetInvoiceLineQuantityToZero
    stepCheckInvoiceIsCalculating
    stepAcceptDecisionInvoice
    stepTic
    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceIsSolved
    stepCheckInvoiceNotSplitted
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """
    self.playSequence(sequence)

  def test_13_SplitAndDeferInvoice(self, quiet=0, run=RUN_ALL_TESTS):
    """
    - Accept Order, Accept Packing List
    - Decrease quantity on Invoice
    - Split and defer Invoice
    - Accept Invoice
    - Accept splitted Invoice
    - Packing List must not be divergent and use old quantity
    - Invoice must not be divergent and use new quantity
    - splitted Invoice must not be divergent and use old - new quantity
    """
    if not run: return
    self.logMessage('InvoiceSplitAndDeferInvoice')
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding
    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted

    stepDecreaseInvoiceLineQuantity
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepSplitAndDeferInvoice
    stepTic
    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved
    stepCheckInvoiceSplitted

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepSwitchInvoices

    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
1618 1619
    """
    self.playSequence(sequence)
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 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 test_14_AcceptDecisionOnInvoice(self, quiet=0, run=RUN_ALL_TESTS):
    """
    - Accept Order, Accept Packing List
    - Increase or Decrease quantity on Invoice
    - Accept Decision on Invoice
    - Accept Invoice
    - Packing List must not be divergent and use old quantity
    - Invoice must not be divergent and use new quantity
    """
    if not run: return
    self.logMessage('InvoiceAcceptDecisionOnInvoice')
    mid_sequence = \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding
    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted
    """
    end_sequence = \
    """
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepAcceptDecisionInvoice
    stepTic
    stepConfirmInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepCheckInvoiceNotSplitted
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """

    mid_sequence_list = ["""
    stepDecreaseInvoiceLineQuantity
    """, """
    stepIncreaseInvoiceLineQuantity
    """]

    sequence_list = SequenceList()
    for seq in mid_sequence_list:
      sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
          mid_sequence + seq + end_sequence
      sequence_list.addSequenceString(sequence)
    sequence_list.play(self)

1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706
  def testCopyAndPaste(self, run=RUN_ALL_TESTS):
    """Test copy on paste on Invoice.
    When an invoice is copy/pasted, references should be resetted.
    """
    if not run:
      return
    accounting_module = self.getAccountingModule()
    invoice = accounting_module.newContent(
                    portal_type=self.invoice_portal_type)
    invoice.edit(reference='reference',
                 source_reference='source_reference',
                 destination_reference='destination_reference',)
    cb_data = accounting_module.manage_copyObjects([invoice.getId()])
    copied, = accounting_module.manage_pasteObjects(cb_data)
    new_invoice = accounting_module[copied['new_id']]
    self.assertNotEquals(invoice.getReference(),
                         new_invoice.getReference())
    self.assertNotEquals(invoice.getSourceReference(),
                         new_invoice.getSourceReference())
    self.assertNotEquals(invoice.getDestinationReference(),
                         new_invoice.getDestinationReference())
1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721

#class TestPurchaseInvoice(TestInvoice):
#  order_portal_type = 'Purchase Order'
#  order_line_portal_type = 'Purchase Order Line'
#  order_cell_portal_type = 'Purchase Order Cell'
#  packing_list_portal_type = 'Purchase Packing List'
#  packing_list_line_portal_type = 'Purchase Packing List Line'
#  packing_list_cell_portal_type = 'Purchase Packing List Cell'
#  delivery_builder_id = 'purchase_packing_list_builder'
#  invoice_portal_type = 'Purchase Invoice Transaction'
#  invoice_transaction_line_portal_type = 'Purchase Invoice Transaction Line'
#
#  def getTitle(self):
#    return "Purchase Invoices"

1722 1723 1724 1725 1726 1727 1728 1729
if __name__ == '__main__':
  framework()
else:
  import unittest
  def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestInvoice))
    return suite
1730