testAdvancedInvoicing.py 42.5 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 33 34 35
##############################################################################
#
# Copyright (c) 2009 Nexedi KK and Contributors. All Rights Reserved.
#          Tatuya Kamada <tatuya@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., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
# USA.
#
##############################################################################
"""
  Tests invoice and invoice transaction creation from simulation.
  Most test-cases are based on the testInvoice.py.
"""

import transaction
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
36
from Products.ERP5Type.tests.SecurityTestCase import SecurityTestCase
37 38 39
from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime
from Products.ERP5Type.tests.Sequence import SequenceList
40
from testInvoice import TestSaleInvoiceMixin
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

class TestAdvancedInvoice(TestSaleInvoiceMixin, ERP5TypeTestCase):
  """Test methods for sale and purchase invoice.
  Subclasses must defines portal types to use.
  """
  quiet = 1
  RUN_ALL_TESTS = 1
  PACKING_LIST_DEFAULT_SEQUENCE = \
  """
  stepCreateEntities
  stepCreateCurrency
  stepCreateSaleInvoiceTransactionRule
  stepCreateOrder
  stepSetOrderProfile
  stepSetOrderPriceCurrency
  stepCreateNotVariatedResource
  stepTic
  stepCreateOrderLine
  stepSetOrderLineResource
  stepSetOrderLineDefaultValues
  stepOrderOrder
  stepTic
  stepCheckDeliveryBuilding
  stepConfirmOrder
  stepTic
  stepCheckOrderRule
  stepCheckOrderSimulation
  stepCheckDeliveryBuilding
  stepAddPackingListContainer
  stepAddPackingListContainerLine
  stepSetContainerLineFullQuantity
  stepTic
  stepCheckPackingListIsPacked
  """
  
  INVOICE_DEFAULT_SEQUENCE = PACKING_LIST_DEFAULT_SEQUENCE + \
  """
  stepStartPackingList
  stepTic
  stepStartRelatedInvoice
  stepTic
  """

  TWO_PACKING_LIST_DEFAULT_SEQUENCE = \
  """
  stepCreateEntities
  stepCreateCurrency
  stepCreateSaleInvoiceTransactionRule
  stepCreateOrder
  stepSetOrderProfile
  stepSetOrderPriceCurrency
  stepCreateNotVariatedResource
  stepTic
  stepCreateOrderLine
  stepSetOrderLineResource
  stepSetOrderLineDefaultValues
  stepOrderOrder
  stepTic
  stepCheckDeliveryBuilding
  stepConfirmOrder
  stepTic
  stepCheckOrderRule
  stepCheckOrderSimulation
  stepCheckDeliveryBuilding
  stepDecreasePackingListLineQuantity
  stepCheckPackingListIsCalculating
  stepTic
  stepCheckPackingListIsDiverged
  stepSplitAndDeferPackingList
  stepTic
  stepCheckPackingListIsSolved
  stepCheckPackingListSplitted
  stepAddPackingListContainer
  stepAddPackingListContainerLine
  stepSetContainerLineFullQuantity
  stepTic
  stepCheckPackingListIsPacked
  stepDefineNewPackingListContainer
  stepTic
  stepCheckNewPackingListIsPacked
  """

  invoice_portal_type = 'Sale Invoice'
  invoice_line_portal_type = 'Invoice Line'
  invoice_cell_portal_type = 'Invoice Cell'
  invoice_module_name = 'sale_invoice_module'
  invoice_transaction_line_portal_type = 'Sale Invoice Transaction Line'
  
  def getBusinessTemplateList(self):
    return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
131 132
            'erp5_invoicing', 'erp5_advanced_invoicing', 'erp5_apparel',
            'erp5_project')
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

  def stepStartRelatedInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(
      portal_type=self.invoice_portal_type)
    self.assertNotEquals(invoice, None)
    invoice.start()
    self.assertEquals('started', invoice.getSimulationState())

  def stepAddInvoiceTransactionLines(self, sequence=None, sequence_list=[]):
    """
    add some invoice and accounting lines to the invoice
    """
    invoice = sequence.get('invoice')
    invoice.newContent(portal_type=self.invoice_line_portal_type,
        resource_value=sequence.get('resource'), quantity=3, price=555)
    invoice_transaction = invoice.getCausalityRelatedValue()
    invoice_transaction.newContent(portal_type=self.invoice_transaction_line_portal_type,
                                   id ='receivable', source='account_module/customer',
                                   destination='account_module/supplier', quantity=-1665)
    invoice_transaction.newContent(portal_type='Sale Invoice Transaction Line',
                                   id='income', source='account_module/sale',
                                   destination='account_module/purchase', quantity=1665)

  def stepAddInvoiceLinesManyTransactions(self, sequence=None, sequence_list=[]):
    """
    add some invoice and accounting lines to the invoice
    """
    invoice = sequence.get('invoice')
    invoice_line = invoice.newContent(portal_type='Invoice Line')
    invoice_line.edit(resource_value=sequence.get('resource'), quantity=3,
        price=555)

    invoice_transaction = invoice.getCausalityRelatedValue()
    transaction_line_1 = invoice_transaction.newContent(portal_type=self.invoice_transaction_line_portal_type)
    transaction_line_2 = invoice_transaction.newContent(portal_type=self.invoice_transaction_line_portal_type)
    transaction.commit()
    self.tic()
    transaction_line_1.edit(id ='receivable', source='account_module/customer',
        destination='account_module/supplier', quantity=-1665)
    transaction_line_2.edit(
        id='income', source='account_module/sale',
        destination='account_module/purchase', quantity=1665)

  def stepChangeQuantityDoubledOnInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(portal_type=self.invoice_portal_type)
    self.assertNotEquals(invoice, None)
    invoice_line_list = invoice.getMovementList()
    self.assertEquals(1, len(invoice_line_list))
    invoice_line = invoice_line_list[0]
    new_quantity = invoice_line.getQuantity() * 2
    invoice_line.setQuantity(new_quantity)
    sequence.edit(invoice_line_doubled_quantity=new_quantity)


  def stepAcceptDecisionOnInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(portal_type=self.invoice_portal_type)
    builder_list = invoice.getBuilderList()
193
    self.assertEquals(1, len(builder_list))
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
    divergence_list = invoice.getDivergenceList()
    for builder in builder_list:
      builder.solveDivergence(invoice.getRelativeUrl(),
                              divergence_to_accept_list=divergence_list)

  def stepCheckDivergenceOnInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(portal_type=self.invoice_portal_type)
    self.assertEquals('solved', invoice.getCausalityState())
    new_quantity = sequence.get('invoice_line_doubled_quantity')
    self.assertEquals([], invoice.getDivergenceList())

    invoice_line_list = invoice.getMovementList()
    self.assertEquals(1, len(invoice_line_list))
    invoice_line = invoice_line_list[0]
    self.assertEquals(new_quantity, invoice_line.getQuantity())
    self.assertEquals(new_quantity,
          invoice_line.getDeliveryRelatedValue(portal_type='Simulation Movement'
              ).getQuantity())

  def stepCheckDivergedOnPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self.assertEquals('diverged', packing_list.getCausalityState())

  def stepCheckSolvedOnPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self.assertEquals('solved', packing_list.getCausalityState())

  def stepCheckDivergedQuantityOnInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(portal_type=self.invoice_portal_type)
    self.assertTrue(invoice.isDivergent())
    divergence_list = invoice.getDivergenceList()
    self.assertEquals(1, len(divergence_list))

    divergence = divergence_list[0]
    self.assertEquals('quantity', divergence.tested_property)

  def stepCheckDivergedQuantityOnPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    divergence_list = packing_list.getDivergenceList()
    self.assertEquals(1, len(divergence_list))

    divergence = divergence_list[0]
    self.assertEquals('quantity', divergence.tested_property)

  def stepAdoptPrevisionOnPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    divergence_list = packing_list.getDivergenceList()
    for builder in packing_list.getBuilderList():
      builder.solveDivergence(packing_list.getRelativeUrl(),
                              divergence_to_adopt_list=divergence_list)

  def stepAdoptPrevisionOnInvoice(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue()
 
    divergence_list = invoice.getDivergenceList()
    builder_list = invoice.getBuilderList()
253
    self.assertEquals(1, len(builder_list))
254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 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 346 347 348 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 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 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 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 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 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 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 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 684 685 686 687 688 689 690 691 692 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 719 720 721 722 723 724 725 726 727 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 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 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 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 843 844 845 846 847 848 849 850 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 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 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 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 1011 1012 1013 1014 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
    for builder in builder_list:
      builder.solveDivergence(invoice.getRelativeUrl(),
                              divergence_to_adopt_list=divergence_list)
               
  def test_CreatingAccountingTransactionThroughInvoice(self, quiet=quiet, run=RUN_ALL_TESTS):
    """test creating simple invoice and accounting transaction"""
    if not run: return
    sequence_list = SequenceList()
    sequence = sequence_list.addSequenceString(self.INVOICE_DEFAULT_SEQUENCE)
    sequence_list.play(self, quiet=quiet)
    
    packing_list = sequence.get('packing_list')
    self.assertEquals('solved', packing_list.getCausalityState())
    invoice = packing_list.getCausalityRelatedValue()
    self.assertEquals(self.invoice_portal_type, invoice.getPortalType())
    self.assertEquals('solved', invoice.getCausalityState())
    self.assertEquals([], invoice.getDivergenceList())

    invoice_transaction  = invoice.getCausalityRelatedValue()
    self.assertNotEquals(invoice_transaction, None)
    self.assertEquals('draft', invoice_transaction.getCausalityState())
    
  def test_AcceptQuantityDivergenceOnInvoiceWithStoppedPackingList(self, quiet=quiet, run=RUN_ALL_TESTS):
    """Accept divergence with stopped packing list"""
    if not run: return
    sequence_list = SequenceList()
    sequence = sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepTic
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepStopPackingList
      stepTic
      stepChangeQuantityDoubledOnInvoice
      stepTic
      stepCheckDivergedQuantityOnInvoice
      stepAcceptDecisionOnInvoice
      stepTic
      stepCheckDivergenceOnInvoice
      stepCheckSolvedOnPackingList
      """)

    sequence_list.play(self, quiet=quiet)
    packing_list = sequence.get('packing_list')
    self.assertEquals([], packing_list.getDivergenceList())
    self.assertEquals('solved', packing_list.getCausalityState())
 
  def test_AdoptQuantityDivergenceOnInvoiceLineWithStoppedPackingList(self, quiet=quiet,
                                                                      run=RUN_ALL_TESTS):
    """Adopt quantity with stopped packing list"""
    if not run: return
    sequence_list = SequenceList()
    sequence = sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE + \
      """
      stepStartPackingList
      stepStopPackingList
      stepTic
      stepChangeQuantityDoubledOnInvoice
      stepTic
      stepCheckDivergedQuantityOnInvoice
      stepAdoptPrevisionOnInvoice
      stepTic
      """)
    sequence_list.play(self, quiet=quiet)
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue()
    self.assertEquals([], invoice.getDivergenceList())
    self.assertEquals('solved', invoice.getCausalityState())

    self.assertEquals(1,
        len(invoice.getMovementList(portal_type=self.invoice_line_portal_type)))
    invoice_line = invoice.getMovementList(portal_type=self.invoice_line_portal_type)[0]
    self.assertEquals(99.0, invoice_line.getQuantity())
    self.assertEquals(555.0, invoice_line.getPrice())
    self.assertEquals(99.0,
          invoice_line.getDeliveryRelatedValue(portal_type='Simulation Movement'
              ).getQuantity())
    self.assertEquals([], packing_list.getDivergenceList())
    self.assertEquals('solved', packing_list.getCausalityState())

  def test_PackingListEditAndInvoiceRule(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Delivery Rule should not be applied on packing list lines created\
    from Order.
    """
    if not run: return
    if not quiet:
      self.logMessage('Packing List Edit')
    sequence_list = SequenceList()
    sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepEditPackingList
      stepCheckDeliveryRuleNotAppliedOnPackingListEdit
      stepCheckInvoicesConsistency
      """)
    sequence_list.play(self, quiet=quiet)

  def test_InvoiceViewAsODT(self):
    """Create ODT printout """
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    invoice = self.portal.getDefaultModule(self.invoice_portal_type).newContent(
                              portal_type=self.invoice_portal_type,
                              start_date=DateTime(2008, 12, 31),
                              title='Invoice',
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = invoice.newContent(portal_type=self.invoice_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    invoice.confirm()
    transaction.commit()
    self.tic()

    odt = invoice.Invoice_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))


class TestAdvancedSaleInvoice(TestAdvancedInvoice):
  quiet = 1
  RUN_ALL_TESTS = 1
  login = TestAdvancedInvoice.login
  
  def stepCheckInvoicesAndTransactionsConsistency(self, sequence=None, sequence_list=None,
                                                  **kw):
    """
    - to check transaction lines match invoice lines
    """
    invoice_list = self.getPortal()[self.invoice_module_name].objectValues()
    for invoice in invoice_list:
      state_list = \
          list(self.getPortal().getPortalCurrentInventoryStateList())
      state_list.append('cancelled')
      if invoice.getSimulationState() in state_list:
        invoice_line_list = invoice.contentValues(
            portal_type=self.invoice_line_portal_type)
        expected_price = 0.0
        for line in invoice_line_list:
          expected_price += line.getTotalPrice()
        invoice_transaction  = invoice.getCausalityRelatedValue()
        if invoice_transaction.getSimulationState() in state_list:
          invoice_transaction_line_list = invoice_transaction.contentValues(
            portal_type=self.invoice_transaction_line_portal_type)
          self.assertEquals(3, len(invoice_transaction_line_list))
          
          for line_id, line_source, line_dest, line_ratio in \
                  self.transaction_line_definition_list:
            for line in invoice_transaction.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)
              resource_precision = line.getResourceValue().getQuantityPrecision()
              self.assertEquals(round(line.getQuantity(), resource_precision),
                                round(expected_price * line_ratio, resource_precision))

  def stepRemoveDateMovementGroupForAdvancedTransactionBuilder(self, sequence=None, sequence_list=None, **kw):
    """
    Remove DateMovementGroup
    """
    portal = self.getPortal()
    builder = portal.portal_deliveries.advanced_sale_invoice_transaction_builder
    delivery_movement_group_list = builder.getDeliveryMovementGroupList()
    uf = self.getPortal().acl_users
    uf._doAddUser('admin', '', ['Manager'], [])
    user = uf.getUserById('admin').__of__(uf)
    newSecurityManager(None, user)
    for movement_group in delivery_movement_group_list:
      if movement_group.getPortalType() == 'Property Movement Group':
        # it contains 'start_date' and 'stop_date' only, so we remove
        # movement group itself.
        builder.deleteContent(movement_group.getId())
        builder.newContent(
          portal_type = 'Parent Explanation Movement Group',
          collect_order_group='delivery',
          int_index=len(delivery_movement_group_list)+1
          )
        user = uf.getUserById('test_invoice_user').__of__(uf)
        newSecurityManager(None, user)
                                                                            
  def test_01_TwoInvoicesFromTwoPackingList(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    This test was created for the following bug:
        - 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
    """
    if not run: return
    if not quiet:
      self.logMessage('Two Invoices from Two Packing List')
    sequence_list = SequenceList()
    sequence_list.addSequenceString(
      self.TWO_PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepSetReadyPackingList
      stepSetReadyNewPackingList
      stepTic
      stepStartPackingList
      stepStartNewPackingList
      stepTic
      stepCheckTwoInvoices
      stepRemoveDateMovementGroupForAdvancedTransactionBuilder
      stepStartTwoInvoices
      stepTic
      stepCheckInvoicesAndTransactionsConsistency
      """)
    sequence_list.play(self, quiet=quiet)

  def test_02_InvoiceDeletePackingListLine(self, quiet=quiet,
      run=RUN_ALL_TESTS):
    """
    Checks that deleting a Packing List Line still creates a correct
    Invoice
    """
    if not run: return
    if not quiet:
      self.logMessage('Packing List Line Delete')
    sequence_list = SequenceList()
    for base_sequence in (self.PACKING_LIST_TWO_LINES_DEFAULT_SEQUENCE, ) :
      sequence_list.addSequenceString(
        base_sequence +
    """
    stepDeletePackingListLine
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepTic
    stepCheckInvoiceBuilding
    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """)
    sequence_list.play(self, quiet=quiet)

  def test_03_InvoiceDecreaseQuantity(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Change the quantity of a Invoice Line,
    check that the invoice is divergent,
    then split and defer, and check everything is solved
    """
    if not run: return
    if not quiet:
      self.logMessage('Invoice Decrease Qantity')
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepDecreaseInvoiceLineQuantity
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepTic
    stepCheckInvoiceIsDiverged
    stepSplitAndDeferInvoice
    stepTic

    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved
    stepCheckInvoiceSplitted

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """
    self.playSequence(sequence, quiet=quiet)

  def test_04_InvoiceChangeStartDateFail(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Change the start_date of a Invoice Line,
    check that the invoice is divergent,
    then accept decision, and check Packing list is divergent
    """
    if not run: return
    if not quiet:
      self.logMessage('Invoice Change Sart Date')
    sequence = self.PACKING_LIST_DEFAULT_SEQUENCE + \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepChangeInvoiceStartDate
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepTic
    stepCheckInvoiceIsDiverged
    stepUnifyStartDateWithDecisionInvoice
    stepTic

    stepCheckInvoiceNotSplitted
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepCheckPackingListIsDivergent
    """
    self.playSequence(sequence, quiet=quiet)

  def test_05_AcceptDecisionOnPackingList(self, quiet=quiet, 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
    if not quiet:
      self.logMessage('InvoiceAcceptDecisionOnPackingList')
    end_sequence = \
    """
    stepSetContainerFullQuantity
    stepCheckPackingListIsCalculating
    stepTic
    stepCheckPackingListIsDiverged
    stepAcceptDecisionQuantity
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted

    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepStartInvoice
    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, quiet=quiet)

  def test_06_AcceptDecisionOnPackingListAndInvoice(self, quiet=quiet,
      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
    if not quiet:
      self.logMessage('InvoiceAcceptDecisionOnPackingListAndInvoice')
    mid_sequence = \
    """
    stepSetContainerFullQuantity
    stepCheckPackingListIsCalculating
    stepTic
    stepCheckPackingListIsDiverged
    stepAcceptDecisionQuantity
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted

    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding

    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule
    """
    end_sequence = \
    """
    stepCheckInvoiceIsDiverged
    stepAcceptDecisionQuantityInvoice
    stepTic
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved
    stepStartInvoice
    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, quiet=quiet)

  def test_07_SplitAndDeferInvoice(self, quiet=quiet, 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
    if not quiet:
      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
    stepTic
    stepCheckInvoiceIsDiverged
    stepSplitAndDeferInvoice
    stepTic
    stepStartInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved
    stepCheckInvoiceSplitted
   
    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency

    stepCheckPackingListIsNotDivergent
    stepCheckPackingListIsSolved
    stepCheckInvoiceTransactionRule

    stepSwitchInvoices

    stepStartInvoice
    stepTic
    stepStopInvoice
    stepTic
    stepDeliverInvoice
    stepTic
    stepCheckInvoiceIsNotDivergent
    stepCheckInvoiceIsSolved

    stepRebuildAndCheckNothingIsCreated
    stepCheckInvoicesConsistency
    """
    self.playSequence(sequence, quiet=quiet)

  def test_08_AcceptDecisionOnInvoice(self, quiet=quiet, 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
    if not quiet:
      self.logMessage('InvoiceAcceptDecisionOnInvoice')
    mid_sequence = \
    """
    stepSetReadyPackingList
    stepTic
    stepStartPackingList
    stepCheckInvoicingRule
    stepCheckInvoiceTransactionRule
    stepTic
    stepCheckInvoiceBuilding
    stepStopPackingList
    stepTic
    stepDeliverPackingList
    stepTic
    stepCheckPackingListIsSolved
    stepCheckPackingListNotSplitted
    """
    end_sequence = \
    """
    stepCheckInvoiceIsDivergent
    stepCheckInvoiceIsCalculating
    stepTic
    stepCheckInvoiceIsDiverged
    stepAcceptDecisionQuantityInvoice
    stepTic
    stepStartInvoice
    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, quiet=quiet)

  def test_09_Reference(self, quiet=quiet, run=RUN_ALL_TESTS):
    if not run: return
    if not quiet:
      self.logMessage('test Reference')

    # A reference is set automatically on Sale Invoice Transaction
    supplier = self.portal.organisation_module.newContent(
                            portal_type='Organisation',
                            title='Supplier')
    client = self.portal.organisation_module.newContent(
                            portal_type='Organisation',
                            title='Client')
    currency = self.portal.currency_module.newContent(
                            portal_type='Currency')
    invoice = self.portal.accounting_module.newContent(
                    portal_type='Sale Invoice Transaction',
                    start_date=DateTime(),
                    price_currency_value=currency,
                    resource_value=currency,
                    source_section_value=supplier,
                    destination_section_value=client)
    self.portal.portal_workflow.doActionFor(invoice, 'confirm_action')

    # We could generate a better reference here.
    self.assertEquals('1', invoice.getReference())

  def test_10_ManuallyAddedMovements(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Checks that adding invoice lines and accounting lines to one invoice
    generates correct simulation
    """
    if not run: return
    if not quiet:
      self.logMessage('Invoice with Manually Added Movements')
    sequence_list = SequenceList()
    sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
          """
          stepSetReadyPackingList
          stepTic
          stepStartPackingList
          stepCheckInvoicingRule
          stepTic
          stepCheckInvoiceBuilding
          stepRebuildAndCheckNothingIsCreated
          stepCheckInvoicesConsistency
          stepStartInvoice
          stepTic
          stepAddInvoiceTransactionLines
          stepTic
          stepCheckSimulationTrees
          """)
    sequence_list.play(self, quiet=quiet)


  def test_11_ManuallyAddedMovementsManyTransactions(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Checks that adding invoice lines and accounting lines
    generates correct simulation

    In this case checks what is happening, where movements are added in
    one transaction and edited in another
    """
    if not run: return
    if not quiet:
      self.logMessage('Invoice with Manually Added Movements in separate transactions')
    sequence_list = SequenceList()
    sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepCheckInvoicingRule
      stepTic
      stepCheckInvoiceBuilding
      stepRebuildAndCheckNothingIsCreated
      stepCheckInvoicesConsistency
      stepTic
      stepCheckInvoiceIsSolved
      stepStartInvoice
      stepTic
      stepAddInvoiceLinesManyTransactions
      stepTic
      stepCheckSimulationTrees
      """)
    sequence_list.play(self, quiet=quiet)

  def test_12_compareInvoiceAndPackingList(self, quiet=quiet, run=RUN_ALL_TESTS):
    """
    Checks that a Simple Invoice is created from a Packing List
    """
    if not run: return
    if not quiet:
      self.logMessage('Compare Simple Invoice and Packing List')
    sequence_list = SequenceList()
    sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepCheckInvoicingRule
      stepTic
      stepCheckInvoiceBuilding
      stepCheckInvoicesConsistency
      stepCheckPackingListInvoice
      """)
    sequence_list.play(self, quiet=quiet)


  def test_13_acceptQuantityDivergenceOnInvoiceWithStartedPackingList(
    self, quiet=quiet, run=RUN_ALL_TESTS):
    if not run: return
    if not quiet:
      self.logMessage('Accept Quantity Divergence on Invoice')

    sequence_list = SequenceList()
    sequence = sequence_list.addSequenceString(
      self.PACKING_LIST_DEFAULT_SEQUENCE +
      """
      stepSetReadyPackingList
      stepTic
      stepStartPackingList
      stepTic
      stepChangeQuantityDoubledOnInvoice
      stepTic
      stepCheckDivergedQuantityOnInvoice
      stepAcceptDecisionOnInvoice
      stepTic
      stepCheckDivergenceOnInvoice
      stepCheckDivergedOnPackingList
      stepCheckDivergedQuantityOnPackingList
      stepAdoptPrevisionOnPackingList
      stepTic
      """)
    
    sequence_list.play(self, quiet=quiet)
    packing_list = sequence.get('packing_list')
    invoice = packing_list.getCausalityRelatedValue(portal_type=self.invoice_portal_type)
    self.assertEquals('solved', packing_list.getCausalityState())
    self.assertEquals('solved', invoice.getCausalityState())

class TestAdvancedPurchaseInvoice(TestAdvancedInvoice):
  """Tests for purchase invoice.
  """
  resource_portal_type = 'Product'
  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'
  invoice_portal_type = 'Purchase Invoice'
  invoice_transaction_line_portal_type = 'Purchase Invoice Transaction Line'
  invoice_line_portal_type = 'Invoice Line'
  invoice_cell_portal_type = 'Invoice Cell'
  invoice_module_name = 'sale_invoice_module'

  login = TestAdvancedInvoice.login
  
  PACKING_LIST_DEFAULT_SEQUENCE = \
  """
  stepCreateEntities
  stepCreateCurrency
  stepCreateSaleInvoiceTransactionRule
  stepCreateOrder
  stepSetOrderProfile
  stepSetOrderPriceCurrency
  stepCreateNotVariatedResource
  stepTic
  stepCreateOrderLine
  stepSetOrderLineResource
  stepSetOrderLineDefaultValues
  stepOrderOrder
  stepTic
  stepCheckDeliveryBuilding
  stepConfirmOrder
  stepTic
  stepCheckOrderRule
  stepCheckOrderSimulation
  stepCheckDeliveryBuilding
  stepTic
  """

  INVOICE_DEFAULT_SEQUENCE = PACKING_LIST_DEFAULT_SEQUENCE + \
  """
  stepReceivePackingList
  stepTic
  stepStartRelatedInvoice
  stepTic
  """

  def stepReceivePackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    packing_list.setReady()
    packing_list.start()
    packing_list.stop()
    self.assertEquals('stopped', packing_list.getSimulationState())
    transaction.commit()

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

class TestWorkflow(SecurityTestCase):
  def getBusinessTemplateList(self):
    return ('erp5_core', 'erp5_base', 'erp5_pdm',
            'erp5_trade', 'erp5_accounting',
            'erp5_invoicing', 'erp5_advanced_invoicing')

  def afterSetUp(self):
    skin_folder = self.portal.portal_skins.custom
    security_mapping_script_id = 'ERP5Type_getSecurityMapping'
    if getattr(skin_folder, security_mapping_script_id, None) is None:
      skin_folder.manage_addProduct['PythonScripts'].manage_addPythonScript(id=security_mapping_script_id)
      skin_folder[security_mapping_script_id].ZPythonScript_edit('', 'return (("ERP5Type_getSecurityCategoryFromAssignment", ["function"]),)')

    role_list = [
        {'role_name_list': ('Assignee',), 'role_category_list': ('function/assignee',)},
        {'role_name_list': ('Assignor',), 'role_category_list': ('function/assignor',)},
        {'role_name_list': ('Auditor',), 'role_category_list': ('function/auditor',)},
        {'role_name_list': ('Author',), 'role_category_list': ('function/author',)},
        {'role_name_list': ('Associate',), 'role_category_list': ('function/associate',)},
        {'role_name_list': ('Manager',), 'role_category_list': ('function/manager',)},
        ]

    sale_invoice_type = self.portal.portal_types['Sale Invoice']
    if len(sale_invoice_type.contentIds(filter={'portal_type': 'Role Infomation'})) == 0:
      for role in role_list:
        type_document = sale_invoice_type.newContent(portal_type='Role Information')
        type_document.edit(**role)
      transaction.commit()
      self.tic()

    for role in role_list:
      for role_category in role['role_category_list']:
        category_id_list = role_category.split('/')[1:]
        node = self.portal.portal_categories.function
        while category_id_list:
          category_id = category_id_list.pop(0)
          if node.get(category_id, None) is None:
            node = node.newContent(id=category_id, portal_type='Category')
          else:
            node = node.get(category_id)
    transaction.commit()
    self.tic()

    person_list = [
        {'id': 'other'},
        {'id': 'assignee', 'assignment_list': ({'function': 'assignee'},)},
        {'id': 'assignor', 'assignment_list': ({'function': 'assignor'},)},
        {'id': 'associate', 'assignment_list': ({'function': 'associate'},)},
        {'id': 'auditor', 'assignment_list': ({'function': 'auditor'},)},
        {'id': 'author', 'assignment_list': ({'function': 'author'},)},
        {'id': 'manager', 'assignment_list': ({'function': 'manager'},)},
        ]

    person_module = self.portal.person_module
    for person in person_list:
      if person_module.get(person['id'], None) is None:
        person_document = person_module.newContent(id=person['id'], portal_type='Person')
        person_document.edit(reference=person['id'])
        for assignment in person.get('assignment_list', []):
          assignment_document = person_document.newContent(portal_type='Assignment')
          assignment_document.edit(function=assignment['function'])
          self.portal.portal_workflow.doActionFor(assignment_document, 'open_action')
        transaction.commit()
        self.tic()
        setattr(self, person['id'], person_document)

  def test_autoplanned(self):
    sale_invoice = self.portal.getDefaultModule('Sale Invoice').newContent(portal_type='Sale Invoice')
    self.assertEquals(sale_invoice.getSimulationState(), 'draft')
1147
    sale_invoice.autoPlan()
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 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202
    self.assertEquals(sale_invoice.getSimulationState(), 'auto_planned')

    # other as anonymous
    self.failIfUserCanAccessDocument(self.other.getId(), sale_invoice)
    self.failIfUserCanAddDocument(self.other.getId(), sale_invoice)
    self.failIfUserCanDeleteDocument(self.other.getId(), sale_invoice)
    self.failIfUserCanModifyDocument(self.other.getId(), sale_invoice)
    self.failIfUserCanViewDocument(self.other.getId(), sale_invoice)

    # assignee
    self.assertUserCanAccessDocument(self.assignee.getId(), sale_invoice)
    self.assertUserCanAddDocument(self.assignee.getId(), sale_invoice)
    self.assertUserCanDeleteDocument(self.assignee.getId(), sale_invoice)
    self.assertUserCanModifyDocument(self.assignee.getId(), sale_invoice)
    self.assertUserCanViewDocument(self.assignee.getId(), sale_invoice)

    # assignor
    self.assertUserCanAccessDocument(self.assignor.getId(), sale_invoice)
    self.assertUserCanAddDocument(self.assignor.getId(), sale_invoice)
    self.assertUserCanDeleteDocument(self.assignor.getId(), sale_invoice)
    self.assertUserCanModifyDocument(self.assignor.getId(), sale_invoice)
    self.assertUserCanViewDocument(self.assignor.getId(), sale_invoice)

    # associate
    self.assertUserCanAccessDocument(self.associate.getId(), sale_invoice)
    self.assertUserCanAddDocument(self.associate.getId(), sale_invoice)
    self.assertUserCanDeleteDocument(self.associate.getId(), sale_invoice)
    self.assertUserCanModifyDocument(self.associate.getId(), sale_invoice)
    self.assertUserCanViewDocument(self.associate.getId(), sale_invoice)

    # auditor
    self.assertUserCanAccessDocument(self.auditor.getId(), sale_invoice)
    self.failIfUserCanAddDocument(self.auditor.getId(), sale_invoice)
    self.failIfUserCanDeleteDocument(self.auditor.getId(), sale_invoice)
    self.failIfUserCanModifyDocument(self.auditor.getId(), sale_invoice)
    self.assertUserCanViewDocument(self.auditor.getId(), sale_invoice)

    # author
    self.failIfUserCanAccessDocument(self.author.getId(), sale_invoice)
    self.failIfUserCanAddDocument(self.author.getId(), sale_invoice)
    self.failIfUserCanDeleteDocument(self.author.getId(), sale_invoice)
    self.failIfUserCanModifyDocument(self.author.getId(), sale_invoice)
    self.failIfUserCanViewDocument(self.author.getId(), sale_invoice)

    # manager
    self.assertUserCanAccessDocument(self.manager.getId(), sale_invoice)
    self.assertUserCanAddDocument(self.manager.getId(), sale_invoice)
    self.assertUserCanDeleteDocument(self.manager.getId(), sale_invoice)
    self.assertUserCanModifyDocument(self.manager.getId(), sale_invoice)
    self.assertUserCanViewDocument(self.manager.getId(), sale_invoice)

    self.assertSameSet(('confirm_action', 'plan_action',),
        [action['id'] for action in self.portal.portal_workflow.getActionsFor(sale_invoice)
          if action['category'] == 'workflow'])

1203 1204 1205 1206 1207
import unittest
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestAdvancedSaleInvoice))
  suite.addTest(unittest.makeSuite(TestAdvancedPurchaseInvoice))
1208
  suite.addTest(unittest.makeSuite(TestWorkflow))
1209
  return suite