testItem.py 47.9 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 32
import transaction
from DateTime import DateTime
33
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
34
from Products.ERP5Type.tests.utils import reindex
35
from AccessControl.SecurityManagement import newSecurityManager
36
from Products.ERP5Type.tests.Sequence import SequenceList
37
from Products.ERP5.tests.testInvoice import TestSaleInvoiceMixin
38

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

  def getBusinessTemplateList(self):
    """
44 45 46 47 48 49
    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.
50
    """
51 52
    return TestSaleInvoiceMixin.getBusinessTemplateList(self) + \
         ('erp5_item',) + ('erp5_trade_proxy_field_legacy',)
53
  
Jérome Perrin's avatar
Jérome Perrin committed
54
  def login(self):
55 56 57 58 59
    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
60
  def createOrganisation(self, title=None):
61
    organisation_portal_type = 'Organisation'
Jérome Perrin's avatar
Jérome Perrin committed
62
    organisation_module = self.portal.getDefaultModule(
63
                                   portal_type=organisation_portal_type)
Jérome Perrin's avatar
Jérome Perrin committed
64
    organisation = organisation_module.newContent(
65 66 67 68
                                   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
69 70 71
      organisation.edit(title=title)
    return organisation

72 73 74 75 76
  def createNotVariatedResource(self,title=None):
    """
      Create a resource with no variation
    """
    resource_portal_type = 'Product'
Jérome Perrin's avatar
Jérome Perrin committed
77
    resource_module = self.portal.getDefaultModule(resource_portal_type)
78 79 80 81 82 83 84 85
    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
86
  
87 88
  def createVariatedResource(self,title=None):
    resource_portal_type = 'Product'
Jérome Perrin's avatar
Jérome Perrin committed
89
    resource_module = self.portal.getDefaultModule(resource_portal_type)
90 91 92 93
    resource = resource_module.newContent(portal_type=resource_portal_type)
    resource.edit(
      title = "VariatedResource%s" % resource.getId(),
    )
94
    resource.setIndividualVariationBaseCategoryList(('size',))
95 96 97 98 99 100 101 102 103 104 105 106 107 108
    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
109

110 111 112 113 114 115 116
  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)
117 118
    pac_list.edit(
      title = "PPL%s" % pac_list.getId(),
119 120
      start_date = self.datetime + 20,
      stop_date = self.datetime + 10,
121
    )
122

123 124 125 126 127 128 129 130 131 132 133
    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
134

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

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

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

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

Sebastien Robin's avatar
Sebastien Robin committed
161 162 163 164 165 166 167 168 169 170 171 172 173 174
  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
175
  def stepCheckOrderLineAggregate(self, sequence=None,
176 177 178
                                          sequence_list=None, **kw):
    """ Check items """
    order_line = sequence.get('order_line')
179 180 181 182 183 184
    self.checkAggregate(line=order_line, sequence=sequence)

  def stepCheckSimulationAggregate(self, sequence=None,
                                          sequence_list=None, **kw):
    """ Check items """
    order_line = sequence.get('order_line')
185
    simulation_movement = order_line.getDeliveryRelatedValue()
186
    self.failIf(simulation_movement is None)
187 188 189 190 191 192 193 194
    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
195 196 197 198 199 200 201
  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)


202 203 204 205 206 207 208
  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)
209

Sebastien Robin's avatar
Sebastien Robin committed
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
  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)

252 253 254 255
  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
256
    self.failUnless(item_list[0] in line.getAggregateValueList())
Sebastien Robin's avatar
Sebastien Robin committed
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

  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 \
                       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 \
                       stepCheckOrderSimulation \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListIsNotDivergent \
                       stepCheckOrderPackingList \
                       stepCheckPackingListLineAggregateList \
                       '
308

Jérome Perrin's avatar
Jérome Perrin committed
309
class TestItem(TestItemMixin, ERP5TypeTestCase):
310 311

  quiet = 0
Sebastien Robin's avatar
Sebastien Robin committed
312
  run_all_test= 1
313

314 315 316
  def getTitle(self):
    return "Item"

Sebastien Robin's avatar
Sebastien Robin committed
317 318 319 320 321 322 323 324 325 326 327 328 329
  def beforeTearDown(self):
    transaction.abort()
    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()))
    transaction.commit()
    self.tic()


Jérome Perrin's avatar
Jérome Perrin committed
330
  def test_01_ItemSimpleTest(self, quiet=quiet):
331 332 333
    sequence_list = SequenceList()

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

    sequence_list.addSequenceString(sequence_string)
356 357 358
    sequence_list.play(self, quiet=quiet)


Jérome Perrin's avatar
Jérome Perrin committed
359
  def test_02_ItemWithInvoice(self, quiet=quiet):
360
    sequence_list = SequenceList()
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
    sequence_string = 'stepCreateEntities \
                       stepCreateCurrency \
                       stepCreateItemList \
                       stepCreateSaleInvoiceTransactionRule \
                       stepCreateOrder \
                       stepSetOrderProfile \
                       stepSetOrderPriceCurrency \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepCreateOrderLine \
                       stepSetOrderLineResource \
                       stepSetOrderLineDefaultValues \
                       stepOrderLineSetAggregationList \
                       stepConfirmOrder \
                       stepTic \
                       stepCheckOrderRule \
                       stepCheckOrderLineAggregate \
                       stepCheckOrderSimulation \
                       stepCheckSimulationAggregate \
                       stepCheckDeliveryBuilding \
                       stepCheckPackingListLineAggregate \
                       stepAddPackingListContainer \
                       stepAddPackingListContainerLine \
                       stepSetContainerLineFullQuantity \
                       stepTic \
                       stepCheckPackingListIsPacked \
                       stepSetReadyPackingList \
                       stepTic \
                       stepStartPackingList \
                       stepCheckInvoicingRule \
                       stepTic \
                       stepCheckInvoiceBuilding \
                       stepRebuildAndCheckNothingIsCreated \
                       stepCheckInvoicesConsistency \
                       stepCheckInvoiceLineAggregate \
                      ' 

    sequence_list.addSequenceString(sequence_string)
400
    sequence_list.play(self, quiet=quiet)
401 402
    
  
Jérome Perrin's avatar
Jérome Perrin committed
403
  def test_03_CreateItemsFromPackingListLine(self):
404
    organisation = self.createOrganisation(title='Organisation I')
Jérome Perrin's avatar
Jérome Perrin committed
405
    transaction.commit()
406 407
    self.tic()
    resource = self.createVariatedResource()
408 409
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/1', resource.getRelativeUrl())
Jérome Perrin's avatar
Jérome Perrin committed
410
    transaction.commit()
411 412
    self.tic()
    packing_list = self.createPackingList(resource=resource,organisation=organisation)
Jérome Perrin's avatar
Jérome Perrin committed
413 414
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
Jérome Perrin's avatar
Jérome Perrin committed
415
    transaction.commit()
416
    self.tic()
417 418 419 420
    
    # make sure we can render the dialog
    packing_list_line.DeliveryLine_viewItemCreationDialog()

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

    self.portal.REQUEST.set('type', 'Item')
443
    packing_list_line.DeliveryLine_createItemList(listbox=listbox)
Jérome Perrin's avatar
Jérome Perrin committed
444
    transaction.commit()
445 446
    self.tic()
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
447 448 449
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot A')]) ,1)
450
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
451 452 453
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot B')]), 1)
454
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
455 456 457
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot C')]), 1)
458 459 460 461 462 463 464 465

    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(), [])

466 467
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
    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())
484
    
Jérome Perrin's avatar
Jérome Perrin committed
485
     
Jérome Perrin's avatar
Jérome Perrin committed
486
  def test_04_CreateItemsFromPackingListLineWithVariationDefined(self):
487
    organisation = self.createOrganisation(title='Organisation II')
Jérome Perrin's avatar
Jérome Perrin committed
488
    transaction.commit()
489 490
    self.tic()
    resource = self.createVariatedResource()
491 492 493
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/2', resource.getRelativeUrl())

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

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

    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']))

541 542
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558
    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())
559
 
560

Jérome Perrin's avatar
Jérome Perrin committed
561
  def test_05_CreateItemsFromPackingListLineWithNotVariatedResource(self):
562
    organisation = self.createOrganisation(title='Organisation III')
Jérome Perrin's avatar
Jérome Perrin committed
563
    transaction.commit()
564 565
    self.tic()
    resource = self.createNotVariatedResource()
Jérome Perrin's avatar
Jérome Perrin committed
566
    transaction.commit()
567
    self.tic()
Jérome Perrin's avatar
Jérome Perrin committed
568 569
    packing_list = self.createPackingList(resource=resource,
                                          organisation=organisation)
570
   
Jérome Perrin's avatar
Jérome Perrin committed
571 572
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
573
    packing_list_line.setQuantity(32)
Jérome Perrin's avatar
Jérome Perrin committed
574
    transaction.commit()
575 576 577 578 579 580 581 582 583 584 585 586
    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
587
              { 'listbox_key': '002',
588 589 590 591 592
              'title': 'Lot C3',
              'reference': '25_05_09_LC3',
              'quantity': 15.0,
              },
              )
593
    self.portal.REQUEST.set('type', 'Item')
594
    packing_list_line.DeliveryLine_createItemList(listbox=listbox)
Jérome Perrin's avatar
Jérome Perrin committed
595
    transaction.commit()
596 597
    self.tic()
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
598 599 600
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot A3')]), 1)
601
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
602 603 604
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot B3')]), 1)
605
    self.assertEquals(
Jérome Perrin's avatar
Jérome Perrin committed
606 607 608
           len([x.getObject() for x in self.portal.portal_catalog(
                                          portal_type='Item',
                                          title='Lot C3')]), 1)
609 610
    self.assertEquals(packing_list_line.getQuantity(),30.0)
    
Jérome Perrin's avatar
Jérome Perrin committed
611 612 613
    self.assertEquals(packing_list_line.getVariationCategoryList(), [])
    self.assertEquals(packing_list_line.getAggregateTitleList(),
                      ['Lot A3', 'Lot B3', 'Lot C3'])
614 615 616 617
    movement_cell_list = packing_list_line.contentValues(
                                    portal_type='Purchase Packing List Cell')
    self.assertEquals(movement_cell_list,[])
    
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
  def test_06_VerifyHavingSameItemTwiceOnMovementCausesNoBug(self):
    """
    """
    organisation = self.createOrganisation(title='Organisation VI')
    transaction.commit()
    self.tic()
    resource = self.createVariatedResource()
    # XXX this tests depends on the relative url of the resource
    self.assertEquals('product_module/4', resource.getRelativeUrl())

    transaction.commit()
    self.tic()
    packing_list = self.createPackingList(resource=resource,organisation=organisation)
   
    packing_list_line= self.createPackingListLine(packing_list=packing_list,
                                                  resource=resource)
    transaction.commit()
    self.tic()				      
    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'
              },
              )

    self.portal.REQUEST.set('type', 'Item')
    packing_list_line.DeliveryLine_createItemList(listbox=listbox)
    transaction.commit()
    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')
    transaction.commit()
    self.tic()
    self.assertEquals(packing_list.getCausalityState(),'solved')
Jérome Perrin's avatar
Jérome Perrin committed
664

Sebastien Robin's avatar
Sebastien Robin committed
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
  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)

  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)

  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)

  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 \
          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 \
                       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

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
  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())
    transaction.commit()
    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())


  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())
    transaction.commit()
    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())


985 986 987 988
class TestItemScripts(ERP5TypeTestCase):
  """Test scripts from erp5_item.
  """
  def getBusinessTemplateList(self):
989 990
    return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade',
            'erp5_item', 'erp5_simulation_test')
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

  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')
    transaction.commit()
    self.tic()
  
  def beforeTearDown(self):
    transaction.abort()
    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()))
    transaction.commit()
    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
  def test_Item_getResourceValue(self):
    self.assertEquals(None, self.item.Item_getResourceValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.product, self.item.Item_getResourceValue())
1067 1068
    self.assertEquals(None, self.item.Item_getResourceValue(
                                at_date=DateTime() - 2))
1069 1070 1071 1072 1073

  def test_Item_getResourceTitle(self):
    self.assertEquals(None, self.item.Item_getResourceTitle())
    line = self._makeSalePackingListLine()
    self.assertEquals('Product', self.item.Item_getResourceTitle())
1074 1075
    self.assertEquals(None, self.item.Item_getResourceTitle(
                                at_date=DateTime() - 2))
1076 1077 1078 1079 1080

  def test_Item_getCurrentOwnerValue(self):
    self.assertEquals(None, self.item.Item_getCurrentOwnerValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.section, self.item.Item_getCurrentOwnerValue())
1081 1082
    self.assertEquals(None,
        self.item.Item_getCurrentOwnerValue(at_date=DateTime() - 2))
1083 1084 1085 1086 1087

  def test_Item_getCurrentOwnerTitle(self):
    self.assertEquals(None, self.item.Item_getCurrentOwnerTitle())
    line = self._makeSalePackingListLine()
    self.assertEquals('Section', self.item.Item_getCurrentOwnerTitle())
1088 1089
    self.assertEquals(None,
        self.item.Item_getCurrentOwnerTitle(at_date=DateTime() - 2))
1090 1091 1092 1093 1094

  def test_Item_getCurrentSiteValue(self):
    self.assertEquals(None, self.item.Item_getCurrentSiteValue())
    line = self._makeSalePackingListLine()
    self.assertEquals(self.node, self.item.Item_getCurrentSiteValue())
1095 1096
    self.assertEquals(None, self.item.Item_getCurrentSiteValue(
                                            at_date=DateTime() - 2))
1097 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 1130 1131 1132 1133

  # 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

  def test_Item_getVariationCategoryList(self):
    self.assertEquals([], self.item.Item_getVariationCategoryList())
    self._makeSalePackingListCellWithVariation()
    self.assertEquals(['size/small'], self.item.Item_getVariationCategoryList())
1134 1135
    self.assertEquals([],
        self.item.Item_getVariationCategoryList(at_date=DateTime() - 2))
1136 1137 1138 1139 1140 1141 1142

  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())
1143 1144 1145
    self.assertEquals([],
        self.item.Item_getVariationRangeCategoryItemList(
                          at_date=DateTime() - 2))
1146

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