testInventoryModule.py 26.4 KB
Newer Older
1 2 3 4 5 6
##############################################################################
#
# 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
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
7
# programmers who take the whole responsibility of assessing all potential
8 9
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
10
# guarantees and support are strongly adviced to contract a Free Software
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 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.
#
##############################################################################

Julien Muchembled's avatar
Julien Muchembled committed
29
import unittest
30 31
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DateTime import DateTime
32
from Products.ERP5Type.tests.Sequence import SequenceList
Julien Muchembled's avatar
Julien Muchembled committed
33
from Products.ERP5.tests.testOrder import TestOrderMixin
34

35
class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
36
  """
37
    Test inventory module
38
  """
39
  run_all_test = 1
40 41
  inventory_portal_type = 'Inventory'
  inventory_line_portal_type = 'Inventory Line'
42
  inventory_cell_portal_type = 'Inventory Cell'
43
  item_portal_type = 'Apparel Bath'
44 45 46
  first_date_string = '2005/12/09' # First Inventory
  second_date_string = '2005/12/29' # Next Inventory
  view_stock_date = '2005/12/31' # The day where we are looking for stock
47
  size_list = ['Child/32','Child/34']
48

Sebastien Robin's avatar
Sebastien Robin committed
49 50 51
  def getTitle(self):
    return "Inventory Module"

52 53 54
  def getInventoryModule(self):
    return getattr(self.getPortal(), 'inventory_module',None)

55 56 57 58 59
  def stepCreateInitialMovements(self, sequence=None, **kw):
    """Create movements before this inventory.
    """
    pplm = self.getPortal().purchase_packing_list_module
    splm = self.getPortal().sale_packing_list_module
60
    iplm = self.getPortal().internal_packing_list_module
61 62 63 64 65 66 67 68 69 70 71 72 73

    def deliverPackingList(pl):
      """step through all steps of packing list workflow."""
      pl.confirm()
      pl.setReady()
      pl.start()
      pl.stop()
      pl.deliver()
      self.assertEquals(pl.getSimulationState(), 'delivered')

    # we create content :
    #   1 purchase packing list
    #   1 sale packing list
74
    #   1 internal packing list
75 76 77
    for month in range(1, 11):
      ppl = pplm.newContent(
                      portal_type='Purchase Packing List',
Julien Muchembled's avatar
Julien Muchembled committed
78
                      specialise=self.business_process,
79 80 81 82 83 84 85 86 87 88 89 90
                      source_value = sequence.get('organisation2'),
                      destination_value = sequence.get('organisation1'),
                      start_date=DateTime(2005, month, 1),
                    )
      ppl.newContent( portal_type='Purchase Packing List Line',
                      resource_value=sequence.get('resource'),
                      quantity=month*10) # dummy quantity, it will be
                                         # replaced by inventory
      deliverPackingList(ppl)

      spl = splm.newContent(
                      portal_type='Sale Packing List',
Julien Muchembled's avatar
Julien Muchembled committed
91
                      specialise=self.business_process,
92 93 94 95 96 97 98 99
                      source_value = sequence.get('organisation1'),
                      destination_value = sequence.get('organisation2'),
                      start_date=DateTime(2005, month, 1),
                    )
      spl.newContent( portal_type='Sale Packing List Line',
                      resource_value=sequence.get('resource'),
                      quantity=month*10)
      deliverPackingList(spl)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
100

101 102
      ipl = iplm.newContent(
                      portal_type='Internal Packing List',
Julien Muchembled's avatar
Julien Muchembled committed
103
                      specialise=self.business_process,
104 105 106 107
                      source_value = sequence.get('organisation1'),
                      destination_value = sequence.get('organisation1'),
                      start_date=DateTime(2005, month, 1),
                    )
108
      ipl.newContent( portal_type='Internal Packing List Line',
109 110 111
                      resource_value=sequence.get('resource'),
                      quantity=month*10)
      deliverPackingList(ipl)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
112

113
  def createInventory(self, start_date=None,
114 115 116 117
                                       sequence=None,**kw):
    """
    We will put default values for an inventory
    """
118
    organisation =  sequence.get('organisation1')
119 120 121
    inventory = self.getInventoryModule().newContent()
    inventory.edit(start_date=start_date,
                   destination_value=organisation)
122
    inventory.deliver()
123 124 125 126 127 128 129 130 131 132 133 134
    inventory_list = sequence.get('inventory_list',[])
    inventory_list.append(inventory)
    sequence.edit(inventory_list=inventory_list)
    return inventory

  def createNotVariatedInventoryLine(self, quantity=None,
                                       sequence=None,**kw):
    """
    We will put default values for an inventory
    """
    inventory = sequence.get('inventory_list')[-1]
    resource = sequence.get('resource_list')[-1]
135 136 137
    inventory_line = inventory.newContent(
           portal_type=self.inventory_line_portal_type)
    inventory_line.edit(inventory=quantity,
138
                        resource_value = resource)
139 140
    return inventory

141 142
  def stepCreateFirstNotVariatedInventory(self, sequence=None,
                                          sequence_list=None, **kw):
143 144 145 146 147
    """
    We will put default values for an inventory
    """
    date = DateTime(self.first_date_string)
    quantity=self.default_quantity
148 149
    self.createInventory(start_date=date,sequence=sequence)
    self.createNotVariatedInventoryLine(sequence=sequence,
150 151
                                    quantity=quantity)

152 153
  def stepCreateSecondNotVariatedInventory(self, sequence=None,
                                           sequence_list=None, **kw):
154 155 156 157 158
    """
    We will put default values for an inventory
    """
    date = DateTime(self.second_date_string)
    quantity=self.default_quantity - 2
159
    self.createInventory(start_date=date,sequence=sequence)
160
    self.second_inventory = self.createNotVariatedInventoryLine(sequence=sequence,
161 162
                                    quantity=quantity)

163 164 165 166 167 168 169 170 171

  def stepModifySecondNotVariatedInventory(self, sequence=None,
                                           sequence_list=None, **kw):
    """
    Modify the quantity to have a tmp line with null quantity
    """
    quantity=self.default_quantity
    inventory_line = self.second_inventory.objectValues()[0]
    inventory_line.edit(inventory=quantity)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
172

173

174 175
  def stepCheckFirstNotVariatedInventory(self, start_date=None,quantity=None,
                                             sequence=None,**kw):
176
    node_uid = sequence.get('organisation1').getUid()
177 178 179 180
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
181
                        to_date=date,simulation_state='delivered')
182 183 184
    self.assertEquals(self.default_quantity,quantity)

  def stepCheckSecondNotVariatedInventory(self, start_date=None,quantity=None,
185
                                             sequence=None, **kw):
186
    node_uid = sequence.get('organisation1').getUid()
187 188 189 190
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
191
                        to_date=date,simulation_state='delivered')
192 193
    self.assertEquals(self.default_quantity-2,quantity)

194 195 196 197 198 199 200 201 202 203 204
  def stepCheckSecondNotVariatedInventoryModified(self, start_date=None,quantity=None,
                                             sequence=None,**kw):
    node_uid = sequence.get('organisation1').getUid()
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date,simulation_state='delivered')
    self.assertEquals(self.default_quantity,quantity)


205
  def test_01_NotVariatedInventory(self, quiet=0, run=run_all_test):
206 207 208 209 210 211 212
    """
    We will create an inventory with the default quantity for
    a particular resource. Then we will check if the is correct.
    Then we create another inventory and see if we have the new
    stock value
    """
    if not run: return
213 214
    self.logMessage('Test Not Variated Inventory')

215 216
    sequence_list = SequenceList()

217
    # Test with a simple inventory without cell
218 219 220 221 222 223 224 225 226
    sequence_string = 'stepCreateNotVariatedResource \
                       stepCreateOrganisation1 \
                       stepCreateInitialMovements \
                       stepTic \
                       stepCreateFirstNotVariatedInventory \
                       stepTic \
                       stepCheckFirstNotVariatedInventory \
                       stepCreateSecondNotVariatedInventory \
                       stepTic \
227 228 229 230
                       stepCheckSecondNotVariatedInventory \
                       stepModifySecondNotVariatedInventory \
                       stepTic \
                       stepCheckSecondNotVariatedInventoryModified'
231 232 233 234
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
235
  def createVariatedInventoryLine(self, sequence=None, sequence_list=None,
236
                                 start_date=None, quantity=None, item_list=None,
237
                                 **kw):
238 239 240
    """
    We will put default values for an inventory
    """
241 242 243 244 245
    inventory = sequence.get('inventory_list')[-1]
    resource = sequence.get('resource_list')[-1]
    inventory_line = inventory.newContent(
           portal_type=self.inventory_line_portal_type)
    inventory_line.edit(resource_value = resource)
246
    resource_vcl = list(resource.getVariationCategoryList(
247
        omit_individual_variation=1, omit_optional_variation=1))
248
    resource_vcl.sort()
249 250
    self.assertEquals(len(resource_vcl),2)
    inventory_line.setVariationCategoryList(resource_vcl)
251
    base_id = 'movement'
252
    cell_key_list = list(inventory_line.getCellKeyList(base_id=base_id))
253 254 255
    cell_key_list.sort()
    price = 100
    for cell_key in cell_key_list:
256 257 258
      cell = inventory_line.newCell(base_id=base_id,
                                portal_type=self.inventory_cell_portal_type,
                                *cell_key)
259 260
      cell.edit(mapped_value_property_list=['price','inventory'],
                price=price, inventory=quantity,
261
                predicate_category_list=cell_key,
262 263 264
                variation_category_list=cell_key,)
      if item_list is not None:
        cell.setAggregateValueList(item_list)
265 266 267
      price += 1
      quantity += 1

268
  def stepCreateFirstVariatedInventory(self, sequence=None, sequence_list=None, \
269 270 271 272 273
                                 **kw):
    """
    We will put default values for an inventory
    """
    date = DateTime(self.first_date_string)
274 275
    inventory = self.createInventory(start_date=date,sequence=sequence)
    quantity = self.default_quantity
276
    self.createVariatedInventoryLine(start_date=date,
277 278 279 280 281 282 283 284 285 286
                  sequence=sequence, quantity=quantity)

  def stepCreateSecondVariatedInventory(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
    We will put default values for an inventory
    """
    date = DateTime(self.second_date_string)
    inventory = self.createInventory(start_date=date,sequence=sequence)
    quantity = self.default_quantity - 10
287
    self.createVariatedInventoryLine(start_date=date,
288
                  sequence=sequence, quantity=quantity)
289 290 291 292 293 294

  def createVariatedInventory(self, start_date=None,quantity=None,
                                       sequence=None,**kw):
    """
    We will put default values for an inventory
    """
295 296
    inventory = self.createNotVariatedInventory(sequence=sequence,
                                                start_date=start_date)
297
    resource = sequence.get('resource_list')[0]
298
    organisation =  sequence.get('organisation1')
299 300 301 302 303 304 305 306 307
    inventory = self.getInventoryModule().newContent()
    inventory.edit(start_date=start_date,
                   destination_value=organisation)
    inventory_line = inventory.newContent(
           portal_type=self.inventory_line_portal_type)
    inventory_line.edit(inventory=quantity,
                        resource_value = resource,
                        destination_value=organisation)

308 309
  def stepCheckFirstVariatedInventory(self, start_date=None,quantity=None,
                                             sequence=None,**kw):
310
    node_uid = sequence.get('organisation1').getUid()
311 312 313 314 315 316 317 318 319 320 321 322
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    total_quantity = 99 + 100
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date)
    self.assertEquals(total_quantity,quantity)
    variation_text = 'size/Child/32'
    total_quantity = 99
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        variation_text=variation_text,
323
                        to_date=date,simulation_state='delivered')
324 325 326 327
    self.assertEquals(total_quantity,quantity)

  def stepCheckSecondVariatedInventory(self, start_date=None,quantity=None,
                                             sequence=None,**kw):
328
    node_uid = sequence.get('organisation1').getUid()
329 330 331 332 333 334 335 336 337 338 339 340
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    total_quantity = 89 + 90
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date)
    self.assertEquals(total_quantity,quantity)
    variation_text = 'size/Child/32'
    total_quantity = 89
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        variation_text=variation_text,
341
                        to_date=date,simulation_state='delivered')
342 343
    self.assertEquals(total_quantity,quantity)

344
  def test_02_VariatedInventory(self, run=run_all_test):
345 346 347 348
    """
    Same thing as test_01 with variation
    """
    if not run: return
349 350
    self.logMessage('Test Variated Inventory')

351 352
    sequence_list = SequenceList()

353
    # Test with a variated inventory
354 355 356 357 358 359 360 361 362 363
    sequence_string = 'stepCreateVariatedResource \
                       stepCreateOrganisation1 \
                       stepCreateInitialMovements \
                       stepTic \
                       stepCreateFirstVariatedInventory \
                       stepTic \
                       stepCheckFirstVariatedInventory \
                       stepCreateSecondVariatedInventory \
                       stepTic \
                       stepCheckSecondVariatedInventory'
364 365 366 367
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

368 369 370 371 372 373 374 375 376 377 378 379 380 381
  def stepCreateItem(self, start_date=None,quantity=None,
                                             sequence=None,**kw):
    """
    Create an Apparel Bath
    """
    portal = self.getPortal()
    item_list = sequence.get('item_list',[])
    item_module = portal.getDefaultModule(self.item_portal_type)
    item = item_module.newContent(portal_type=self.item_portal_type)
    item_list.append(item)
    sequence.edit(item_list=item_list)

  def stepCreateFirstVariatedAggregatedInventory(self, sequence=None, sequence_list=None, \
                                 **kw):
382
    """
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
    We will put default values for an inventory
    - size/Child/32 99
    - size/Child/34 100
    - size/Child/32 99    item1,item2
    - size/Child/34 100   item1,item2
    """
    date = DateTime(self.first_date_string)
    inventory = self.createInventory(start_date=date,sequence=sequence)
    quantity = self.default_quantity
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity)
    item_list = sequence.get('item_list')
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity,
                  item_list=item_list)

  def getAggregateRelativeUrlText(self,item_list):
    relative_url_list = ['aggregate/%s' % x.getRelativeUrl() for x in item_list]
    relative_url_list.sort()
    relative_url_text = '\n'.join(relative_url_list)
    return relative_url_text

405 406
  def stepCheckFirstVariatedAggregatedInventory(self, start_date=None,
                                quantity=None, sequence=None, **kw):
407
    node_uid = sequence.get('organisation1').getUid()
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    total_quantity = (99 + 100) * 2
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date)
    self.assertEquals(total_quantity,quantity)
    variation_text = 'size/Child/32'
    total_quantity = (99) * 2
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        variation_text=variation_text,
                        to_date=date)
    self.assertEquals(total_quantity,quantity)
    # Also check when we look stock for a particular aggregate
423
    sub_variation_text = self.getAggregateRelativeUrlText(
424 425 426 427 428 429 430 431
                                            sequence.get('item_list'))
    total_quantity = 99
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        variation_text=variation_text,
                        to_date=date,
                        sub_variation_text=sub_variation_text)
    self.assertEquals(total_quantity,quantity)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
432

433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450
  def stepCheckExplanationTextInInventoryList(self, start_date=None,
                                quantity=None, sequence=None, **kw):
    """Tests getExplanationText from InventoryBrain
    """
    # this is rather a test for InventoryBrain
    node_uid = sequence.get('organisation1').getUid()
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    for inventory_brain in self.getSimulationTool().getInventoryList(
                        node_uid=node_uid,
                        resource=resource_url,
                        to_date=date):
      self.assertNotEquals(inventory_brain.getExplanationText(),
                           'Unknown')
      self.assertNotEquals(inventory_brain.getListItemUrl(
                                'getExplanationText',
                                0,
                                'dummy_selection_name'), '')
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
451

452 453
  def stepCreateSecondVariatedAggregatedInventory(self, sequence=None,
                                      sequence_list=None, **kw):
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471
    """
    We will put default values for an inventory
    - size/Child/32 89    item1,item2
    - size/Child/34 90    item1,item2
    - size/Child/32 89    item1
    - size/Child/34 90    item1
    """
    date = DateTime(self.second_date_string)
    inventory = self.createInventory(start_date=date,sequence=sequence)
    quantity = self.default_quantity - 10
    item_list = sequence.get('item_list')
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity)
    item_list = sequence.get('item_list')[:1]
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity,
                  item_list=item_list)

472 473
  def stepCheckSecondVariatedAggregatedInventory(self, start_date=None,
                                quantity=None, sequence=None, **kw):
474
    node_uid = sequence.get('organisation1').getUid()
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    total_quantity = (89 + 90) * 2
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date)
    self.assertEquals(total_quantity,quantity)
    variation_text = 'size/Child/32'
    total_quantity = (89) * 2
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        variation_text=variation_text,
                        to_date=date,simulation_state='delivered')
    self.assertEquals(total_quantity,quantity)
    # Also check when we look stock for a particular aggregate
490 491
    sub_variation_text = self.getAggregateRelativeUrlText(
                                                sequence.get('item_list'))
492 493 494 495 496 497 498
    total_quantity = 0
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                        resource=resource_url,
                        to_date=date,
                        sub_variation_text=sub_variation_text,
                        simulation_state='delivered')
    self.assertEquals(total_quantity,quantity)
499 500
    sub_variation_text = self.getAggregateRelativeUrlText(
                                    sequence.get('item_list')[:1])
501 502 503 504

  def test_03_VariatedAggregatedInventory(self, run=run_all_test):
    """
    Same thing as test_01 with variation and aggregate
505 506
    """
    if not run: return
507 508
    self.logMessage('Test Variated Aggregated Inventory')

509 510
    sequence_list = SequenceList()

511
    # Test with a variated inventory with some aggregate
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
    sequence_string = 'stepCreateVariatedResource \
                       stepCreateOrganisation1 \
                       stepCreateInitialMovements \
                       stepTic \
                       stepCreateItem \
                       stepCreateItem \
                       stepCreateFirstVariatedAggregatedInventory \
                       stepTic \
                       stepCheckFirstVariatedAggregatedInventory \
                       stepCreateSecondVariatedAggregatedInventory \
                       stepTic \
                       stepCheckSecondVariatedAggregatedInventory'
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

  def test_04_VariatedAggregatedInventoryGetInventoryList(self, run=run_all_test):
    """
    Same thing as test_03 with testing getInventoryList columns
    """
    if not run: return
    self.logMessage('Test getInventoryList and Variated Aggregated Inventory')

    sequence_list = SequenceList()

    # Test with a variated inventory with some aggregate
    sequence_string = 'stepCreateVariatedResource \
                       stepCreateOrganisation1 \
                       stepCreateInitialMovements \
                       stepTic \
                       stepCreateItem \
                       stepCreateItem \
                       stepCreateFirstVariatedAggregatedInventory \
                       stepTic \
                       stepCheckFirstVariatedAggregatedInventory \
                       stepCheckExplanationTextInInventoryList \
                       stepCreateSecondVariatedAggregatedInventory \
                       stepTic \
                       stepCheckSecondVariatedAggregatedInventory \
                       stepCheckExplanationTextInInventoryList'
552 553 554
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)
Julien Muchembled's avatar
Julien Muchembled committed
555

556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  def stepCreateFirstVariatedMultipleQuantityUnitResourceInventory(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
    We will put default values for an inventory
    - size/Child/32 99 drum
    - size/Child/34 100 drum
    - size/Child/32 99 kilogram
    - size/Child/34 100 kiligram
    """
    date = DateTime(self.first_date_string)
    inventory = self.createInventory(start_date=date,sequence=sequence)
    quantity = self.default_quantity
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity)
    inventory_line = inventory.objectValues(portal_type='Inventory Line')[0]
    inventory_line.setQuantityUnitValue(self.portal.portal_categories.quantity_unit.unit.drum)
    self.createVariatedInventoryLine(start_date=date,
                  sequence=sequence, quantity=quantity)

  def stepCheckFirstVariatedMultipleQuantityUnitResourceInventory(self, sequence=None, sequence_list=None, \
                                 **kw):
    node_uid = sequence.get('organisation1').getUid()
    resource_url = sequence.get('resource').getRelativeUrl()
    date = DateTime(self.view_stock_date)
    inventory = sequence.get('inventory_list')[-1]
    total_quantity = sum([inventory_movement.getInventoriatedQuantity() for inventory_movement in inventory.getMovementList()])
    self.assertEqual(total_quantity, (99*100 + 100*100 + 99 + 100))
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                                                     resource=resource_url,
                                                     to_date=date)
    self.assertEquals(total_quantity, quantity)
    variation_text = 'size/Child/32'
    total_quantity = (99*100 + 99)
    quantity = self.getSimulationTool().getInventory(node_uid=node_uid,
                                                     resource=resource_url,
                                                     variation_text=variation_text,
                                                     to_date=date)
    self.assertEquals(total_quantity,quantity)

  def test_05_VariatedMultipleQuantityUnitResourceInventory(self, run=run_all_test):
    """
    Input inventory for resource which has variation and multiple quantity units
    and make sure that inventory stores correct data.
    """
    if not run: return
    self.logMessage('Test inventory with variated multiple quantity units resource')

    sequence_list = SequenceList()

    sequence_string = 'stepCreateVariatedMultipleQuantityUnitResource \
                       stepCreateOrganisation1 \
                       stepTic \
                       stepCreateFirstVariatedMultipleQuantityUnitResourceInventory \
                       stepTic \
                       stepCheckFirstVariatedMultipleQuantityUnitResourceInventory'
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

Julien Muchembled's avatar
Julien Muchembled committed
615 616 617 618 619

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestInventoryModule))
  return suite