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

import unittest

31
from DateTime import DateTime
32
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
33
from Products.ERP5Type.tests.utils import reindex
34
from AccessControl.SecurityManagement import newSecurityManager
35
from Products.ERP5Type.tests.Sequence import SequenceList
36
from Products.ERP5.tests.testInvoice import TestSaleInvoiceMixin
37 38
from Products.ERP5.tests.utils import newSimulationExpectedFailure

39

40
class TestItemMixin(TestSaleInvoiceMixin):
41 42 43 44
  item_portal_type = 'Item'

  def getBusinessTemplateList(self):
    """
45 46 47 48 49 50
    custom list of business templates for testItem

    erp5_trade_proxy_field_legacy is added only for a temporary
    period until wrongly proxyfied business template (erp5_item here) stops
    using obsolete field libraries. erp5_trade_proxy_field_legacy must be
    removed as soon as possible.
51
    """
52 53
    return TestSaleInvoiceMixin.getBusinessTemplateList(self) + \
         ('erp5_item',) + ('erp5_trade_proxy_field_legacy',)
54
  
Jérome Perrin's avatar
Jérome Perrin committed
55
  def login(self):
56 57 58 59 60
    uf = self.getPortal().acl_users
    uf._doAddUser('rc', '', ['Manager', 'Member', 'Assignee'], [])
    user = uf.getUserById('rc').__of__(uf)
    newSecurityManager(None, user)
    
Jérome Perrin's avatar
Jérome Perrin committed
61
  def createOrganisation(self, title=None):
62
    organisation_portal_type = 'Organisation'
Jérome Perrin's avatar
Jérome Perrin committed
63
    organisation_module = self.portal.getDefaultModule(
64
                                   portal_type=organisation_portal_type)
Jérome Perrin's avatar
Jérome Perrin committed
65
    organisation = organisation_module.newContent(
66 67 68 69
                                   portal_type=organisation_portal_type)
    if title is None:
      organisation.edit(title='organisation%s' % organisation.getId())
    else:
Jérome Perrin's avatar
Jérome Perrin committed
70 71 72
      organisation.edit(title=title)
    return organisation

73 74 75 76 77
  def createNotVariatedResource(self,title=None):
    """
      Create a resource with no variation
    """
    resource_portal_type = 'Product'
Jérome Perrin's avatar
Jérome Perrin committed
78
    resource_module = self.portal.getDefaultModule(resource_portal_type)
79 80 81 82 83 84 85 86
    resource = resource_module.newContent(portal_type=resource_portal_type)
    resource.edit(
      title = "NotVariatedResource%s" % resource.getId(),
      quantity_unit='unit/piece',
      aggregated_portal_type_list=['Item'],
      required_aggregated_portal_type_list=['Item']
    )
    return resource
Jérome Perrin's avatar
Jérome Perrin committed
87
  
88 89
  def createVariatedResource(self,title=None):
    resource_portal_type = 'Product'
Jérome Perrin's avatar
Jérome Perrin committed
90
    resource_module = self.portal.getDefaultModule(resource_portal_type)
91 92 93 94
    resource = resource_module.newContent(portal_type=resource_portal_type)
    resource.edit(
      title = "VariatedResource%s" % resource.getId(),
    )
95
    resource.setIndividualVariationBaseCategoryList(('size',))
96 97 98 99 100 101 102 103 104 105 106 107 108 109
    resource.setQuantityUnit('unit/piece')
    resource.setAggregatedPortalTypeList('Item')
    resource.setRequiredAggregatedPortalTypeList('Item')

    # Add size variation
    size_variation_count = 3
    for i in range(size_variation_count):
      variation_portal_type = 'Product Individual Variation'
      variation = resource.newContent(portal_type = variation_portal_type)
      variation.edit(
        title = 'SizeVariation%s' % str(i)
      )

    return resource
Jérome Perrin's avatar
Jérome Perrin committed
110

111 112 113 114 115 116 117
  def createPackingList(self,
                        resource=None,
                        organisation=None,
                        portal_type='Purchase Packing List'):
    portal = self.portal
    packing_list_module = portal.getDefaultModule(portal_type=portal_type)
    pac_list = packing_list_module.newContent(portal_type=portal_type)
118 119
    pac_list.edit(
      title = "PPL%s" % pac_list.getId(),
120 121
      start_date = self.datetime + 20,
      stop_date = self.datetime + 10,
122
    )
123

124 125 126 127 128 129 130 131 132 133 134
    if organisation is not None:
      pac_list.edit(source_value=organisation,
                 source_section_value=organisation,
                 destination_value=organisation,
                 destination_section_value=organisation,
                 source_decision_value=organisation,
                 destination_decision_value=organisation,
                 source_administration_value=organisation,
                 destination_administration_value=organisation,
                 )
    return pac_list
Jérome Perrin's avatar
Jérome Perrin committed
135

136 137 138 139 140
  def createPackingListLine(self,
                            packing_list=None,
                            resource=None,
                            portal_type='Purchase Packing List Line'):
    packing_list_line = packing_list.newContent(portal_type=portal_type)
141 142 143 144
    packing_list_line.edit(
      title = "Packing List Line"
    )
    packing_list_line.setResourceValue(resource)
Jérome Perrin's avatar
Jérome Perrin committed
145 146
    return packing_list_line

147 148 149 150
  def stepCreateItemList(self, sequence=None, sequence_list=None, **kw):
    """ Create some items """
    item_module = self.getPortal().item_module
    resource = sequence.get('resource')
151
    item = item_module.newContent(portal_type=self.item_portal_type)
152

Jérome Perrin's avatar
Jérome Perrin committed
153
    sequence.edit(item_list=[item])
154 155 156

  def stepOrderLineSetAggregationList(self, sequence=None,
                                          sequence_list=None, **kw):
157
    """  Aggregate Items """
158 159
    order_line = sequence.get('order_line')
    item_list = sequence.get('item_list')
Jérome Perrin's avatar
Jérome Perrin committed
160
    order_line.setAggregateValueList(item_list)
161

Sebastien Robin's avatar
Sebastien Robin committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175
  def stepOrderSetAggregationList(self, sequence=None,
                                          sequence_list=None, **kw):
    """  Aggregate Items """
    order = sequence.get('order')
    item_module = self.getPortal().item_module
    item_list = item_module.contentValues()
    # this step expect that number of order lines
    # and number of item list is same.
    order_line_list = order.contentValues(portal_type=self.order_line_portal_type)
    self.assertEqual(len(order_line_list), len(item_list))
    for order_line, item in zip(order_line_list, item_list):
      order_line.setAggregateValueList([item])


Jérome Perrin's avatar
Jérome Perrin committed
176
  def stepCheckOrderLineAggregate(self, sequence=None,
177 178 179
                                          sequence_list=None, **kw):
    """ Check items """
    order_line = sequence.get('order_line')
180 181 182 183 184 185
    self.checkAggregate(line=order_line, sequence=sequence)

  def stepCheckSimulationAggregate(self, sequence=None,
                                          sequence_list=None, **kw):
    """ Check items """
    order_line = sequence.get('order_line')
186
    simulation_movement = order_line.getDeliveryRelatedValue()
187
    self.failIf(simulation_movement is None)
188 189 190 191 192 193 194 195
    self.checkAggregate(line=simulation_movement, sequence=sequence)

  def stepCheckPackingListLineAggregate(self, sequence=None,
                                          sequence_list=None, **kw):
    """ Check items """
    packing_list_line = sequence.get('packing_list_line')
    self.checkAggregate(line=packing_list_line, sequence=sequence)

Sebastien Robin's avatar
Sebastien Robin committed
196 197 198 199 200 201 202
  def stepCheckPackingListLineAggregateList(self, sequence=None,
                                          sequence_list=None, **kw):
    """ Check items """
    packing_list_line = sequence.get('packing_list_line')
    self.checkAggregateList(line=packing_list_line, sequence=sequence)


203 204 205 206 207 208 209
  def stepCheckInvoiceLineAggregate(self, sequence=None,
                                          sequence_list=None, **kw):
    """ Check items """
    invoice = sequence.get('invoice')
    invoice_line_list = invoice.contentValues(
                         portal_type=self.invoice_line_portal_type)
    self.checkAggregate(line=invoice_line_list[0], sequence=sequence)
210

Sebastien Robin's avatar
Sebastien Robin committed
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
  def stepCheckToRender_Delivery_viewAggregatedItemList(self, sequence=None,
                                                        sequence_list=None, **kw):
    """Check to render the view"""
    packing_list = sequence.get('packing_list')
    packing_list.Delivery_viewAggregatedItemList()

  def stepCheckPackingListStartDateAfterStartDateAdopt(self,sequence=None, sequence_list=None, **kw):
    """
      Check that start date is adopted.
    """
    packing_list = sequence.get('packing_list')
    self.assertEquals(packing_list.getStartDate(),self.datetime+15)


  def stepModifyOrderLinesQuantity(self,sequence=None, sequence_list=None, **kw):
    """
      modify order line quantities
    """
    order = sequence.get('order')
    order_line_list = order.contentValues(portal_type=self.order_line_portal_type)
    for order_line in order_line_list:
      order_line.edit(quantity=self.default_quantity-1)

  def stepModifyOneOrderLineStartDate(self,sequence=None, sequence_list=None, **kw):
    """
      modify order line start date
    """
    order = sequence.get('order')
    resource_list = sequence.get('resource_list')
    order_line_list = order.contentValues(portal_type=self.order_line_portal_type)
    self.assertEquals(len(order_line_list),len(resource_list))
    order_line_list[-1].edit(start_date=self.datetime+15)


  def stepModifyOrderLinesDate(self,sequence=None, sequence_list=None, **kw):
    """
      modify order line date
    """
    order = sequence.get('order')
    for order_line in order.contentValues(portal_type=self.order_line_portal_type):
      order_line.edit(start_date=self.datetime+15)

253 254 255 256
  def checkAggregate(self, line=None, sequence=None):
    """ Check items """
    item_list = sequence.get('item_list')
    self.assertEquals(len(line.getAggregateList()),1)
Jérome Perrin's avatar
Jérome Perrin committed
257
    self.failUnless(item_list[0] in line.getAggregateValueList())
Sebastien Robin's avatar
Sebastien Robin committed
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

  def checkAggregateList(self, line=None, sequence=None):
    """ Check items """
    item_list = self.portal.item_module.contentValues(portal_type='Item')
    self.failUnless(line.getAggregateValueList()[0] in item_list)


  DEFAULT_ITEM_WITH_ORDER_SEQUENCE = \
                      'stepCreateEntities \
                       stepCreateCurrency \
                       stepCreateItemList \
                       stepCreateOrder \
                       stepSetOrderProfile \
                       stepSetOrderPriceCurrency \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderLineSetAggregationList \
                       '
  DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE = DEFAULT_ITEM_WITH_ORDER_SEQUENCE + '\
                       stepOrderOrder \
                       stepTic \
                       stepConfirmOrder \
                       stepTic \
284 285
                       stepPackingListBuilderAlarm \
                       stepTic \
Sebastien Robin's avatar
Sebastien Robin committed
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
                       stepCheckOrderRule \
                       stepCheckOrderLineAggregate \
                       stepCheckOrderSimulation \
                       stepCheckSimulationAggregate \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListIsNotDivergent \
                       stepCheckPackingListLineAggregate \
                       stepCheckToRender_Delivery_viewAggregatedItemList \
                       '
  DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE_AND_SAME_RESOURCE_LINES = DEFAULT_ITEM_WITH_ORDER_SEQUENCE + '\
                       stepCreateItemList \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderSetAggregationList \
                       stepOrderOrder \
                       stepTic \
                       stepConfirmOrder \
                       stepTic \
305 306
                       stepPackingListBuilderAlarm \
                       stepTic \
Sebastien Robin's avatar
Sebastien Robin committed
307 308 309 310 311 312
                       stepCheckOrderSimulation \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListIsNotDivergent \
                       stepCheckOrderPackingList \
                       stepCheckPackingListLineAggregateList \
                       '
313

Jérome Perrin's avatar
Jérome Perrin committed
314
class TestItem(TestItemMixin, ERP5TypeTestCase):
315 316

  quiet = 0
Sebastien Robin's avatar
Sebastien Robin committed
317
  run_all_test= 1
318

319 320 321
  def getTitle(self):
    return "Item"

Sebastien Robin's avatar
Sebastien Robin committed
322
  def beforeTearDown(self):
323
    self.abort()
Sebastien Robin's avatar
Sebastien Robin committed
324 325 326 327 328 329 330 331 332 333
    for module in (self.portal.organisation_module,
                   self.portal.item_module,
                   self.portal.sale_packing_list_module,
                   self.portal.purchase_packing_list_module,
                   self.portal.product_module,
                   self.portal.portal_simulation,):
      module.manage_delObjects(list(module.objectIds()))
    self.tic()


Jérome Perrin's avatar
Jérome Perrin committed
334
  def test_01_ItemSimpleTest(self, quiet=quiet):
335 336 337
    sequence_list = SequenceList()

    # Test with a simply order without cell
338 339 340 341 342 343 344 345 346 347 348 349 350 351
    sequence_string = 'stepCreateOrganisation1 \
                       stepCreateOrganisation2 \
                       stepCreateOrganisation3 \
                       stepCreateItemList \
                       stepCreateOrder \
                       stepSetOrderProfile \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderLineSetAggregationList \
                       stepConfirmOrder \
                       stepTic \
352 353
                       stepPackingListBuilderAlarm \
                       stepTic \
354 355 356 357 358 359
                       stepCheckOrderLineAggregate \
                       stepCheckOrderSimulation \
                       stepCheckSimulationAggregate \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListLineAggregate \
                       stepCheckPackingListIsNotDivergent '
360 361

    sequence_list.addSequenceString(sequence_string)
362 363 364
    sequence_list.play(self, quiet=quiet)


Jérome Perrin's avatar
Jérome Perrin committed
365
  def test_02_ItemWithInvoice(self, quiet=quiet):
366
    sequence_list = SequenceList()
367

368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
    sequence_string = 'stepCreateEntities \
                       stepCreateCurrency \
                       stepCreateItemList \
                       stepCreateSaleInvoiceTransactionRule \
                       stepCreateOrder \
                       stepSetOrderProfile \
                       stepSetOrderPriceCurrency \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderLineSetAggregationList \
                       stepConfirmOrder \
                       stepTic \
383 384
                       stepPackingListBuilderAlarm \
                       stepTic \
385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400
                       stepCheckOrderRule \
                       stepCheckOrderLineAggregate \
                       stepCheckOrderSimulation \
                       stepCheckSimulationAggregate \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListLineAggregate \
                       stepAddPackingListContainer \
                       stepAddPackingListContainerLine \
                       stepSetContainerLineFullQuantity \
                       stepTic \
                       stepCheckPackingListIsPacked \
                       stepSetReadyPackingList \
                       stepTic \
                       stepStartPackingList \
                       stepCheckInvoicingRule \
                       stepTic \
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
401 402
                       stepInvoiceBuilderAlarm \
                       stepTic \
403 404 405 406 407 408 409
                       stepCheckInvoiceBuilding \
                       stepRebuildAndCheckNothingIsCreated \
                       stepCheckInvoicesConsistency \
                       stepCheckInvoiceLineAggregate \
                      ' 

    sequence_list.addSequenceString(sequence_string)
410
    sequence_list.play(self, quiet=quiet)
411 412
    
  
Jérome Perrin's avatar
Jérome Perrin committed
413
  def test_03_CreateItemsFromPackingListLine(self):
414 415 416
    organisation = self.createOrganisation(title='Organisation I')
    self.tic()
    resource = self.createVariatedResource()
417 418
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/1', resource.getRelativeUrl())
419 420
    self.tic()
    packing_list = self.createPackingList(resource=resource,organisation=organisation)
Jérome Perrin's avatar
Jérome Perrin committed
421 422
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
423
    self.tic()
424 425 426 427
    
    # make sure we can render the dialog
    packing_list_line.DeliveryLine_viewItemCreationDialog()

428 429 430 431 432
    # create a listbox 
    listbox = ({ 'listbox_key': '000',
              'title': 'Lot A',
              'reference': '20_05_09_LA',
              'quantity': 20.0,
433
              'line_variation_category_list': 'size/product_module/1/3',
434 435 436 437 438
              },
              { 'listbox_key': '001',
              'title': 'Lot B',
              'reference': '20_05_09_LB',
              'quantity': 10.0,
439
              'line_variation_category_list': 'size/product_module/1/2',
440
              },
Jérome Perrin's avatar
Jérome Perrin committed
441
              { 'listbox_key': '002',
442 443 444
              'title': 'Lot C',
              'reference': '20_05_09_LC',
              'quantity': 15.0,
445
              'line_variation_category_list': 'size/product_module/1/1',
446 447
              },
              )
448

449
    packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
450 451
    self.tic()
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
452 453 454
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot A')]) ,1)
455
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
456 457 458
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot B')]), 1)
459
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
460 461 462
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot C')]), 1)
463 464 465 466 467 468 469 470

    self.assertEquals(packing_list_line.getTotalQuantity(), 45.0)
    self.assertEquals(sorted(packing_list_line.getVariationCategoryList()),
                      sorted(['size/product_module/1/3',
                              'size/product_module/1/2',
                              'size/product_module/1/1']))
    self.assertEquals(packing_list_line.getAggregateTitleList(), [])

471 472
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
    self.assertEquals(3, len(movement_cell_list))

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/1/3', ))
    self.assertEquals(cell.getQuantity(), 20)
    self.assertEquals(['Lot A'], cell.getAggregateTitleList())

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/1/2', ))
    self.assertEquals(cell.getQuantity(), 10)
    self.assertEquals(['Lot B'], cell.getAggregateTitleList())

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/1/1', ))
    self.assertEquals(cell.getQuantity(), 15)
    self.assertEquals(['Lot C'], cell.getAggregateTitleList())
489
    
Jérome Perrin's avatar
Jérome Perrin committed
490
     
Jérome Perrin's avatar
Jérome Perrin committed
491
  def test_04_CreateItemsFromPackingListLineWithVariationDefined(self):
492 493 494
    organisation = self.createOrganisation(title='Organisation II')
    self.tic()
    resource = self.createVariatedResource()
495 496 497
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/2', resource.getRelativeUrl())

498 499 500
    self.tic()
    packing_list = self.createPackingList(resource=resource,organisation=organisation)
   
Jérome Perrin's avatar
Jérome Perrin committed
501 502
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
503 504 505 506 507 508
    self.tic()
    # create a listbox 
    listbox = ({ 'listbox_key': '000',
              'title': 'Lot A2',
              'reference': '25_05_09_LA2',
              'quantity': 20.0,
509
              'line_variation_category_list': 'size/product_module/2/3',
510 511
              },
              )
512
    packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
513 514 515 516
    self.assertEquals(packing_list_line.getVariationCategoryList(),
                      ['size/product_module/2/3'])
    self.assertEquals(packing_list_line.getTotalQuantity(), 20)

517 518 519 520 521
    # create listbox a second time
    listbox = ({ 'listbox_key': '000',
              'title': 'Lot B2',
              'reference': '25_05_09_LB2',
              'quantity': 20.0,
522
              'line_variation_category_list': 'size/product_module/2/1',
523
              },
Jérome Perrin's avatar
Jérome Perrin committed
524
              { 'listbox_key': '001',
525 526 527
              'title': 'Lot C2',
              'reference': '25_05_09_LC2',
              'quantity': 15.0,
528
              'line_variation_category_list': 'size/product_module/2/2',
529 530
              },
              )
Nicolas Delaby's avatar
Nicolas Delaby committed
531
    packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
532
    self.tic()
533 534 535 536 537 538 539

    self.assertEquals(packing_list_line.getTotalQuantity(), 55.0)
    self.assertEquals(sorted(packing_list_line.getVariationCategoryList()),
                      sorted(['size/product_module/2/1',
                              'size/product_module/2/2',
                              'size/product_module/2/3']))

540 541
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
    self.assertEquals(3, len(movement_cell_list))

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/2/3', ))
    self.assertEquals(cell.getQuantity(), 20)
    self.assertEquals(['Lot A2'], cell.getAggregateTitleList())

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/2/1', ))
    self.assertEquals(cell.getQuantity(), 20)
    self.assertEquals(['Lot B2'], cell.getAggregateTitleList())

    cell = packing_list_line.getCell(base_id='movement',
                                     *('size/product_module/2/2', ))
    self.assertEquals(cell.getQuantity(), 15)
    self.assertEquals(['Lot C2'], cell.getAggregateTitleList())
558
 
559

Jérome Perrin's avatar
Jérome Perrin committed
560
  def test_05_CreateItemsFromPackingListLineWithNotVariatedResource(self):
561 562 563 564
    organisation = self.createOrganisation(title='Organisation III')
    self.tic()
    resource = self.createNotVariatedResource()
    self.tic()
Jérome Perrin's avatar
Jérome Perrin committed
565 566
    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation)
567
   
Jérome Perrin's avatar
Jérome Perrin committed
568 569
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
570
    packing_list_line.setQuantity(32)
571 572 573 574 575 576 577 578 579 580 581 582
    self.tic()
    # create a listbox 
    listbox = ({ 'listbox_key': '000',
              'title': 'Lot A3',
              'reference': '25_05_09_LA3',
              'quantity': 10.0,
              },
              { 'listbox_key': '001',
              'title': 'Lot B3',
              'reference': '25_05_09_LB3',
              'quantity': 5.0,
              },
Jérome Perrin's avatar
Jérome Perrin committed
583
              { 'listbox_key': '002',
584 585 586 587 588
              'title': 'Lot C3',
              'reference': '25_05_09_LC3',
              'quantity': 15.0,
              },
              )
589
    packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
590 591
    self.tic()
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
592 593 594
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot A3')]), 1)
595
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
596 597 598
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot B3')]), 1)
599
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
600 601 602
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot C3')]), 1)
603 604
    self.assertEquals(packing_list_line.getQuantity(),30.0)
    
Jérome Perrin's avatar
Jérome Perrin committed
605 606 607
    self.assertEquals(packing_list_line.getVariationCategoryList(), [])
    self.assertEquals(packing_list_line.getAggregateTitleList(),
                      ['Lot A3', 'Lot B3', 'Lot C3'])
608 609 610
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
    self.assertEquals(movement_cell_list,[])
611 612

  @newSimulationExpectedFailure
613 614 615 616 617 618 619 620 621 622 623 624 625 626
  def test_06_VerifyHavingSameItemTwiceOnMovementCausesNoBug(self):
    """
    """
    organisation = self.createOrganisation(title='Organisation VI')
    self.tic()
    resource = self.createVariatedResource()
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/4', resource.getRelativeUrl())

    self.tic()
    packing_list = self.createPackingList(resource=resource,organisation=organisation)
   
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
627
    self.tic()
628 629 630 631 632 633 634 635 636 637
    packing_list_line.DeliveryLine_viewItemCreationDialog()
    # create a listbox 
    listbox = ({ 'listbox_key': '000',
              'title': 'Lot A10',
              'reference': '1070110000015',
              'quantity': 20.0,
              'line_variation_category_list': 'size/product_module/4/3'
              },
              )

638
    packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
639 640 641 642 643 644 645 646 647 648 649 650 651 652
    self.tic()
    item = [x.getObject() for x in self.portal.portal_catalog(
                                    portal_type='Item',
                                    reference = '1070110000015'
                                    )][0]
    packing_list_cell_list = packing_list_line.contentValues(portal_type='Purchase Packing List Cell')
    for packing_list_cell in packing_list_cell_list:
      packing_list_cell.setAggregateValueList(packing_list_cell.getAggregateValueList()+[item])
    self.portal.portal_workflow.doActionFor(packing_list,
               'confirm_action')
    self.assertEquals(packing_list.getSimulationState(),
              'confirmed')
    self.tic()
    self.assertEquals(packing_list.getCausalityState(),'solved')
Jérome Perrin's avatar
Jérome Perrin committed
653

Sebastien Robin's avatar
Sebastien Robin committed
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
  def test_07_WithPackingListChangePackingListQuantityAndAccept(self, quiet=quiet, run=run_all_test):
    """
      Create order and add items, then Change the quantity
      on an delivery line, after that see if the packing list is
      divergent and then split and defer the packing list
    """
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplitted \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  def test_08_ChangePackingListDateAndAccept(self, quiet=quiet, run=run_all_test):
    """
      Create order and add items, then Change the date
      on an delivery line, after that see if the packing list is
      divergent and then accept decision on the packing list
    """
    sequence_list = SequenceList()

    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
                      stepChangePackingListStartDate \
                      stepCheckPackingListIsCalculating \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepUnifyStartDateWithDecision \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckSimulationStartDateUpdated \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

696
  @newSimulationExpectedFailure
Sebastien Robin's avatar
Sebastien Robin committed
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
  def test_09_ChangeOrderDateAndAcceptOnPackingList(self, quiet=quiet, run=run_all_test):
    """
      Create order and add items, then Change the order date
      on an order line, after that see if the packing list is
      divergent and then adopt prevision on the packing list
    """
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
                      stepModifyOneOrderLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepUnifyStartDateWithPrevision \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  def test_10_ChangeOrderQuantityAndAdoptOnPackingList(self, quiet=quiet, run=run_all_test):
    """
      Create order and add items, then Change the quantity
      on an order line, after that see if the packing list is
      divergent and then adopt prevision on the packing list
    """
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
                      stepModifyOrderLinesQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevisionQuantity \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithNewQuantityPrevision \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  def test_11_ChangeOrderQuantityAndAcceptOnPackingList(self, quiet=quiet, run=run_all_test):
    """
      Create order and add items, then Change the quantity
      on an order line, after that see if the packing list is
      divergent and then accept decision on the packing list
    """
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
                      stepModifyOrderLinesQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAcceptDecisionQuantity \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckSimulationQuantityUpdated \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

758
  @newSimulationExpectedFailure
Sebastien Robin's avatar
Sebastien Robin committed
759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
  def test_12_CreteSameResourceDifferentItemOrderLines(self, quiet=quiet, run=run_all_test):
    """
      Create order lines with same resouces and add items into them, then Change the quantity
      on the order lines, after that see if the packing list is
      divergent and then adopt prevision on the packing list
    """
    sequence_list = SequenceList()
    sequence_string = ''
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE_AND_SAME_RESOURCE_LINES + '\
                      stepModifyOrderLinesQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevisionQuantity \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithNewQuantityPrevision \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

780
  @newSimulationExpectedFailure
Sebastien Robin's avatar
Sebastien Robin committed
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
  def test_13_CreateSameResourceDiffrentItemOrderLinesThenChangeTheOrderLinesDate(
           self, quiet=quiet, run=run_all_test):
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE_AND_SAME_RESOURCE_LINES + '\
                      stepModifyOrderLinesDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepUnifyStartDateWithPrevision \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListStartDateAfterStartDateAdopt \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  def test_14_ManuallyAddPackingListWithItem(self, quiet=quiet, run=run_all_test):
    """
    Checks that adding invoice lines and accounting lines to one invoice
    generates correct simulation
    """
    if not quiet:
      self.logMessage('Invoice with Manually Added Movements')
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_PACKING_LIST_SEQUENCE + '\
          stepSetReadyPackingList \
          stepTic \
          stepStartPackingList \
          stepCheckInvoicingRule \
          stepTic \
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
811 812
          stepInvoiceBuilderAlarm \
          stepTic \
Sebastien Robin's avatar
Sebastien Robin committed
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
          stepCheckInvoiceBuilding \
          stepRebuildAndCheckNothingIsCreated \
          stepCheckInvoicesConsistency \
          stepAddInvoiceLines \
          stepTic \
          stepStartInvoice \
          stepTic \
          stepCheckSimulationTrees \
          '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  def test_15_ThreeOrderLines(self, quiet=quiet, run=run_all_test):
    """
    Check that item with three order lines.
    """
    sequence_list = SequenceList()
    sequence_string = self.DEFAULT_ITEM_WITH_ORDER_SEQUENCE + '\
                       stepCreateItemList \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepCreateItemList \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderSetAggregationList \
                       stepTic \
                       stepOrderOrder \
                       stepTic \
                       stepConfirmOrder \
                       stepTic \
845 846
                       stepPackingListBuilderAlarm \
                       stepTic \
Sebastien Robin's avatar
Sebastien Robin committed
847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
                       stepCheckOrderSimulation \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListIsNotDivergent \
                       stepCheckPackingListLineAggregateList \
                       stepCheckOrderPackingList '

    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self, quiet=quiet)

  # Note that: Item with Inventory API tests exsist in
  # testInventoryModule(tested getInventory) and testInventoryAPI(tested getTrackingList).
  #
  # def test_WithInventoryAPI(self):
  #   pass

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
  def test_select_item_dialog_no_variation(self):
    organisation = self.createOrganisation(title='Organisation III')
    resource = self.createNotVariatedResource()
    
    # create one item that is in organisation
    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation)
    packing_list.edit(source_section=None, source=None)
    packing_list_line = self.createPackingListLine(packing_list=packing_list,
                                                   resource=resource)
    item = self.portal.item_module.newContent(
                                    portal_type='Item',
                                    title='Test Item',
                                    reference='TI',
                                    quantity=12)
    packing_list_line.setAggregateValue(item)
    packing_list.confirm()
    packing_list.stop()
    self.assertEquals('stopped', packing_list.getSimulationState())
    self.tic()
    

    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation,
                                          portal_type='Internal Packing List')
    packing_list_line = self.createPackingListLine(
                              packing_list=packing_list,
                              resource=resource,
                              portal_type='Internal Packing List Line')
    packing_list_line.setQuantity(32)
    
    # we can view the dialog
    packing_list_line.DeliveryLine_viewSelectItemListDialog()

    # the listbox contains the items physically in the source of the packing
    # list
    self.assertEquals([item],
                      packing_list_line.DeliveryLine_getSelectableItemList())
    
    packing_list_line.DeliveryLine_selectItemList(
              list_selection_name='select_item_fast_input_selection',
              listbox_uid=(item.getUid(),),
              uids=(item.getUid(),))

    self.assertEquals([item], packing_list_line.getAggregateValueList())
    self.assertEquals(12, packing_list_line.getQuantity())


910
  @newSimulationExpectedFailure
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
  def test_select_item_dialog_variation(self):
    organisation = self.createOrganisation(title='Organisation IV')
    resource = self.createVariatedResource()
    variation_category_list = [ 'size/%s' % variation.getRelativeUrl()
                                 for variation in resource.contentValues() ]
    
    # create one item that is in organisation
    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation)
    packing_list.edit(source_section=None, source=None)
    packing_list_line = self.createPackingListLine(packing_list=packing_list,
                                                   resource=resource)
    packing_list_line.setVariationCategoryList(variation_category_list)

    variation = variation_category_list[0]
    cell = packing_list_line.newCell(base_id='movement',
                                     *(variation,))
    cell.edit(mapped_value_property_list=('quantity,'),
              quantity=1,
              variation_category_list=[variation])

    item = self.portal.item_module.newContent(
                                      portal_type='Item',
                                      title='Test Item %s' % variation,
                                      reference='TI%s' % variation,
                                      quantity=12)
    cell.setAggregateValue(item)

    packing_list.confirm()
    packing_list.stop()
    self.assertEquals('stopped', packing_list.getSimulationState())
    self.tic()
    

    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation,
                                          portal_type='Internal Packing List')
    packing_list_line = self.createPackingListLine(
                              packing_list=packing_list,
                              resource=resource,
                              portal_type='Internal Packing List Line')
    packing_list_line.setQuantity(32)
    
    # we can view the dialog
    packing_list_line.DeliveryLine_viewSelectItemListDialog()

    # the listbox contains the items physically in the source of the packing
    # list, and have matching variations
    self.assertEquals([item],
                      packing_list_line.DeliveryLine_getSelectableItemList())
    
    packing_list_line.DeliveryLine_selectItemList(
              list_selection_name='select_item_fast_input_selection',
              listbox_uid=(item.getUid(),),
              uids=(item.getUid(),))

    self.assertEquals([variation],
                      packing_list_line.getVariationCategoryList())
    self.assertEquals(12, packing_list_line.getTotalQuantity())
    self.assertEquals([], packing_list_line.getAggregateValueList())

    self.assertEquals(1,
        len(packing_list_line.getCellValueList(base_id='movement')))
    
    cell = packing_list_line.getCell(base_id='movement', *(variation, ))
    self.assertEquals(12, cell.getQuantity())
    self.assertEquals([item], cell.getAggregateValueList())


980 981 982 983
class TestItemScripts(ERP5TypeTestCase):
  """Test scripts from erp5_item.
  """
  def getBusinessTemplateList(self):
984
    return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade',
985 986
            'erp5_item', 'erp5_configurator_standard_solver',
            'erp5_simulation_test')
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

  def afterSetUp(self):
    self.validateRules()
    size_category = self.portal.portal_categories.size
    if 'big' not in size_category.objectIds():
      size_category.newContent(portal_type='Category',
                               id='big',
                               title='Big')
    if 'small' not in size_category.objectIds():
      size_category.newContent(portal_type='Category',
                               id='small',
                               title='Small')

    self.node = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Node')
    self.section = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Section')
    self.mirror_node = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Mirror Node')
    self.mirror_section = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Mirror Section')
    self.product = self.portal.product_module.newContent(
                              portal_type='Product',
                              title='Product')
    self.variated_product = self.portal.product_module.newContent(
                              portal_type='Product',
                              title='Variated Product',
                              variation_base_category_list=('size',),
                              variation_category_list=('size/big',
                                                       'size/small'))
    self.item = self.portal.item_module.newContent(
                              portal_type='Item',
                              title='Item')
    self.tic()
  
  def beforeTearDown(self):
1027
    self.abort()
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
    for module in (self.portal.organisation_module,
                   self.portal.item_module,
                   self.portal.sale_packing_list_module,
                   self.portal.purchase_packing_list_module,
                   self.portal.product_module,
                   self.portal.portal_simulation,):
      module.manage_delObjects(list(module.objectIds()))
    self.tic()

  @reindex
  def _makeSalePackingListLine(self):
    packing_list = self.portal.sale_packing_list_module.newContent(
                  portal_type='Sale Packing List',
                  source_value=self.mirror_node,
                  source_section_value=self.mirror_section,
                  destination_value=self.node,
                  destination_section_value=self.section,
                  start_date=DateTime() - 1,)
    line = packing_list.newContent(
                  portal_type='Sale Packing List Line',
                  quantity=1,
                  resource_value=self.product,
                  aggregate_value=self.item,)
    packing_list.confirm()
    packing_list.start()
    packing_list.deliver()
    return line

  # with line
1057
  @newSimulationExpectedFailure
1058 1059 1060 1061
  def test_Item_getResourceValue(self):
    self.assertEquals(None, self.item.Item_getResourceValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.product, self.item.Item_getResourceValue())
1062 1063
    self.assertEquals(None, self.item.Item_getResourceValue(
                                at_date=DateTime() - 2))
1064

1065
  @newSimulationExpectedFailure
1066 1067 1068 1069
  def test_Item_getResourceTitle(self):
    self.assertEquals(None, self.item.Item_getResourceTitle())
    line = self._makeSalePackingListLine()
    self.assertEquals('Product', self.item.Item_getResourceTitle())
1070 1071
    self.assertEquals(None, self.item.Item_getResourceTitle(
                                at_date=DateTime() - 2))
1072

1073
  @newSimulationExpectedFailure
1074 1075 1076 1077
  def test_Item_getCurrentOwnerValue(self):
    self.assertEquals(None, self.item.Item_getCurrentOwnerValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.section, self.item.Item_getCurrentOwnerValue())
1078 1079
    self.assertEquals(None,
        self.item.Item_getCurrentOwnerValue(at_date=DateTime() - 2))
1080

1081
  @newSimulationExpectedFailure
1082 1083 1084 1085
  def test_Item_getCurrentOwnerTitle(self):
    self.assertEquals(None, self.item.Item_getCurrentOwnerTitle())
    line = self._makeSalePackingListLine()
    self.assertEquals('Section', self.item.Item_getCurrentOwnerTitle())
1086 1087
    self.assertEquals(None,
        self.item.Item_getCurrentOwnerTitle(at_date=DateTime() - 2))
1088

1089
  @newSimulationExpectedFailure
1090 1091 1092 1093
  def test_Item_getCurrentSiteValue(self):
    self.assertEquals(None, self.item.Item_getCurrentSiteValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.node, self.item.Item_getCurrentSiteValue())
1094 1095
    self.assertEquals(None, self.item.Item_getCurrentSiteValue(
                                            at_date=DateTime() - 2))
1096

1097
  @newSimulationExpectedFailure
1098 1099 1100 1101
  def test_Item_getCurrentSiteTitle(self):
    self.assertEquals(None, self.item.Item_getCurrentSiteTitle())
    line = self._makeSalePackingListLine()
    self.assertEquals('Node', self.item.Item_getCurrentSiteTitle())
1102 1103
    self.assertEquals(None,
          self.item.Item_getCurrentSiteTitle(at_date=DateTime() - 2))
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

  # with cells
  @reindex
  def _makeSalePackingListCellWithVariation(self):
    packing_list = self.portal.sale_packing_list_module.newContent(
                  portal_type='Sale Packing List',
                  source_value=self.mirror_node,
                  source_section_value=self.mirror_section,
                  destination_value=self.node,
                  destination_section_value=self.section,
                  start_date=DateTime() - 1,)
    line = packing_list.newContent(
                  portal_type='Sale Packing List Line',
                  resource_value=self.variated_product,)
    line.setVariationCategoryList(['size/small'])
    cell = line.newCell(portal_type='Sale Packing List Cell',
                 base_id='movement', *('size/small',))
    cell.edit(mapped_value_property_list=['price','quantity'],
              quantity=1,
              variation_category_list=['size/small'],
              aggregate_value=self.item)
    packing_list.confirm()
    packing_list.start()
    packing_list.deliver()
    return cell

1130
  @newSimulationExpectedFailure
1131 1132 1133 1134
  def test_Item_getVariationCategoryList(self):
    self.assertEquals([], self.item.Item_getVariationCategoryList())
    self._makeSalePackingListCellWithVariation()
    self.assertEquals(['size/small'], self.item.Item_getVariationCategoryList())
1135 1136
    self.assertEquals([],
        self.item.Item_getVariationCategoryList(at_date=DateTime() - 2))
1137

1138
  @newSimulationExpectedFailure
1139 1140 1141 1142 1143 1144
  def test_Item_getVariationRangeCategoryItemList(self):
    self.assertEquals([], self.item.Item_getVariationRangeCategoryItemList())
    self._makeSalePackingListCellWithVariation()
    self.assertEquals([['Big', 'size/big'],
                       ['Small', 'size/small']],
        self.item.Item_getVariationRangeCategoryItemList())
1145 1146 1147
    self.assertEquals([],
        self.item.Item_getVariationRangeCategoryItemList(
                          at_date=DateTime() - 2))
1148

Jérome Perrin's avatar
Jérome Perrin committed
1149
    
1150 1151 1152
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestItem))
1153
  suite.addTest(unittest.makeSuite(TestItemScripts))
1154 1155
  return suite