testAmount.py 28.3 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
##############################################################################
#
# Copyright (c) 2005 Nexedi SARL and Contributors. All Rights Reserved.
#          Romain Courteaud <romain@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.
#
##############################################################################

29 30
import unittest
import os
31 32

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
33 34
from AccessControl.SecurityManagement import newSecurityManager
from Products.ERP5Type.tests.Sequence import SequenceList
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59

class TestAmount(ERP5TypeTestCase):

  run_all_test = 1
  resource_portal_type = "Apparel Model"
  amount_portal_type = "Transformation Transformed Resource"
  amount_parent_portal_type = "Transformation"
  # It is important to use property which are not defined on amount.
  variation_property_list = ['composition', 'margin_ratio']
  variation_property_dict = {
    'composition': 'azertyuio', 
    'margin_ratio': 2.4
  }
  failed_variation_property_dict = {
    'composition': 'azertyuio', 
    'margin_ratio': 2.4,
    'sfdvdfbdgbfgbfgbfgbfg': None,
  }

  def getTitle(self):
    return "Amount"

  def getBusinessTemplateList(self):
    """
    """
Romain Courteaud's avatar
Romain Courteaud committed
60
    return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_apparel')
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106

  def login(self, quiet=0, run=run_all_test):
    uf = self.getPortal().acl_users
    uf._doAddUser('rc', '', ['Manager'], [])
    user = uf.getUserById('rc').__of__(uf)
    newSecurityManager(None, user)

  def enableLightInstall(self):
    """
    You can override this. 
    Return if we should do a light install (1) or not (0)
    """
    return 1

  def enableActivityTool(self):
    """
    You can override this.
    Return if we should create (1) or not (0) an activity tool.
    """
    return 1

  def afterSetUp(self, quiet=1, run=run_all_test):
    self.login()

  def stepCreateResource(self, sequence=None, sequence_list=None, **kw):
    """
      Create a resource
    """
    portal = self.getPortal()
    module = portal.getDefaultModule(self.resource_portal_type)
    resource = module.newContent(portal_type=self.resource_portal_type)
    # As the current resource as no variation property, 
    # we will create some for the test.
    resource.setVariationPropertyList(self.variation_property_list)
    sequence.edit(
        resource=resource,
    )

  def stepCreateAmount(self, sequence=None, sequence_list=None, **kw):
    """
      Create a amount to test
    """
    portal = self.getPortal()
    module = portal.getDefaultModule(self.amount_parent_portal_type)
    amount_parent = module.newContent(
                      portal_type=self.amount_parent_portal_type)
107
    amount = amount_parent.newContent(
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
                      portal_type=self.amount_portal_type)
    sequence.edit(
       amount=amount,
    )

  def stepSetAmountResource(self, sequence=None, sequence_list=None, **kw):
    """
      Add a resource to the amount.
    """
    amount = sequence.get('amount')
    resource = sequence.get('resource')
    amount.setResourceValue(resource)
    sequence.edit(
       variation_property_dict= \
           dict([(x, None) for x in self.variation_property_dict])
    )

  def stepCheckEmptyGetVariationPropertyDict(self, sequence=None, 
                                             sequence_list=None, **kw):
    """
      Test the method GetVariationPropertyDict.
    """
    amount = sequence.get('amount')
    vpd = amount.getVariationPropertyDict()
132
    self.assertEqual(vpd, {})
133 134 135 136 137 138 139

  def stepCheckEmptySetVariationPropertyDict(self, sequence=None, 
                                             sequence_list=None, **kw):
    """
      Test the method GetVariationPropertyDict.
    """
    amount = sequence.get('amount')
Jérome Perrin's avatar
Jérome Perrin committed
140 141
    self.assertRaises(KeyError, amount.setVariationPropertyDict,
                      self.variation_property_dict)
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163

  def stepSetVariationPropertyDict(self, sequence=None, 
                                        sequence_list=None, **kw):
    """
      Test the method GetVariationPropertyDict.
    """
    amount = sequence.get('amount')
    amount.setVariationPropertyDict(self.variation_property_dict)
    sequence.edit(
       variation_property_dict=self.variation_property_dict
    )

  def stepCheckGetVariationPropertyDict(self, sequence=None, 
                                        sequence_list=None, **kw):
    """
      Test the method GetVariationPropertyDict.
    """
    amount = sequence.get('amount')
    vpd = amount.getVariationPropertyDict()
    self.failIfDifferentSet(vpd.keys(), 
                            sequence.get('variation_property_dict').keys())
    for key in vpd.keys():
164
      self.assertEqual(vpd[key], sequence.get('variation_property_dict')[key])
165 166 167 168 169 170 171

  def stepSetWrongVariationPropertyDict(self, sequence=None, 
                                        sequence_list=None, **kw):
    """
      Test the method GetVariationPropertyDict.
    """
    amount = sequence.get('amount')
Jérome Perrin's avatar
Jérome Perrin committed
172 173
    self.assertRaises(KeyError, amount.setVariationPropertyDict,
                      self.failed_variation_property_dict)
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227

  def stepCheckEdit(self, sequence=None, sequence_list=None, **kw):
    """
      Test edit method on amount.
    """
    amount = sequence.get('amount')
    # If edit doesn't raise a error, it's ok.
    amount.edit(**self.variation_property_dict)
    sequence.edit(
       variation_property_dict=self.variation_property_dict
    )

  def test_01_variationProperty(self, quiet=0, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()
    # Test setVariationPropertyDict and
    # getVariationPropertyDict without
    # resource on Amount.
    sequence_string = '\
              CreateAmount \
              CheckEmptyGetVariationPropertyDict \
              CheckEmptySetVariationPropertyDict \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test setVariationPropertyDict and
    # getVariationPropertyDict
    sequence_string = '\
              CreateResource \
              CreateAmount \
              SetAmountResource \
              CheckGetVariationPropertyDict \
              SetVariationPropertyDict \
              CheckGetVariationPropertyDict \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test setVariationPropertyDict with a wrong property
    sequence_string = '\
              CreateResource \
              CreateAmount \
              SetAmountResource \
              SetWrongVariationPropertyDict \
              '
    sequence_list.addSequenceString(sequence_string)
    # Test edit method on amount
    sequence_string = '\
              CreateResource \
              CreateAmount \
              SetAmountResource \
              CheckEdit \
              CheckGetVariationPropertyDict \
              '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

228

229 230 231 232 233 234 235
class TestMovement(ERP5TypeTestCase):
  """Tests for Movement class
  """
  def afterSetUp(self):
    self.login()
    self.portal = self.getPortal()

236 237 238 239 240 241 242 243 244 245 246 247 248
    if getattr(self.portal, 'dummy_delivery_module', None) is None:
      types_tool = self.portal.portal_types
      types_tool.newContent(id="My Movement",
                            type_class="Movement")
      types_tool.newContent(id="My Delivery",
                            type_class="Delivery",
                            type_allowed_content_type_list=("My Movement",))
      types_tool.newContent(id="My Delivery Module",
                            type_class="Folder",
                            type_allowed_content_type_list=("My Delivery",))

      self.portal.newContent(id="dummy_delivery_module",
                             portal_type="My Delivery Module")
249
      self.commit()
250 251
    self.delivery_module = self.portal.dummy_delivery_module

252 253 254 255 256 257
  def getPortalName(self):
    forced_portal_id = os.environ.get('erp5_tests_portal_id')
    if forced_portal_id:
      return str(forced_portal_id)
    return 'movement_test'

258 259 260 261
  def _makeOne(self, **kw):
    # returns a Movement inside of a delivery
    delivery = self.delivery_module.newContent()
    return delivery.newContent(**kw)
262 263

  def testQuantity(self):
264
    mvt = self._makeOne()
265
    mvt.setQuantity(10)
266 267
    self.assertEqual(10, mvt.getQuantity())
    self.assertEqual(0, mvt.getTotalPrice())
268
    mvt.edit(quantity=20)
269
    self.assertEqual(20, mvt.getQuantity())
270 271
  
  def testPrice(self):
272
    mvt = self._makeOne()
273
    self.assertEqual(None, mvt.getPrice())
274
    mvt.setPrice(10)
275 276
    self.assertEqual(10, mvt.getPrice())
    self.assertEqual(0, mvt.getTotalPrice())
277
    mvt.setQuantity(1)
278
    self.assertEqual(10, mvt.getTotalPrice())
279 280
    
  def testSourceDebit(self):
281
    mvt = self._makeOne()
282
    mvt.setSourceDebit(10)
283 284 285
    self.assertEqual(10, mvt.getSourceDebit())
    self.assertEqual(0, mvt.getSourceCredit())
    self.assertEqual(-10, mvt.getQuantity())
286 287

    mvt.edit(source_debit=20)
288 289 290
    self.assertEqual(20, mvt.getSourceDebit())
    self.assertEqual(0, mvt.getSourceCredit())
    self.assertEqual(-20, mvt.getQuantity())
291 292
  
  def testSourceCredit(self):
293
    mvt = self._makeOne()
294
    mvt.setSourceCredit(10)
295 296 297
    self.assertEqual(0, mvt.getSourceDebit())
    self.assertEqual(10, mvt.getSourceCredit())
    self.assertEqual(10, mvt.getQuantity())
298 299

    mvt.edit(source_credit=20)
300 301 302
    self.assertEqual(0, mvt.getSourceDebit())
    self.assertEqual(20, mvt.getSourceCredit())
    self.assertEqual(20, mvt.getQuantity())
303 304
  
  def testSourceDebitCredit(self):
305
    mvt = self._makeOne()
306 307
    mvt.setSourceCredit(10)
    mvt.edit(source_credit=0, source_debit=10)
308 309 310
    self.assertEqual(10, mvt.getSourceDebit())
    self.assertEqual(0, mvt.getSourceCredit())
    self.assertEqual(-10, mvt.getQuantity())
311 312

  def testDestinationDebit(self):
313
    mvt = self._makeOne()
314
    mvt.setDestinationDebit(10)
315 316 317
    self.assertEqual(10, mvt.getDestinationDebit())
    self.assertEqual(0, mvt.getDestinationCredit())
    self.assertEqual(10, mvt.getQuantity())
318 319

    mvt.edit(destination_debit=20)
320 321 322
    self.assertEqual(20, mvt.getDestinationDebit())
    self.assertEqual(0, mvt.getDestinationCredit())
    self.assertEqual(20, mvt.getQuantity())
323 324
  
  def testDestinationCredit(self):
325
    mvt = self._makeOne()
326
    mvt.setDestinationCredit(10)
327 328 329
    self.assertEqual(0, mvt.getDestinationDebit())
    self.assertEqual(10, mvt.getDestinationCredit())
    self.assertEqual(-10, mvt.getQuantity())
330 331

    mvt.edit(destination_credit=20)
332 333 334
    self.assertEqual(0, mvt.getDestinationDebit())
    self.assertEqual(20, mvt.getDestinationCredit())
    self.assertEqual(-20, mvt.getQuantity())
335 336
  
  def testDestinationDebitCredit(self):
337
    mvt = self._makeOne()
338 339
    mvt.setDestinationCredit(10)
    mvt.edit(destination_credit=0, destination_debit=10)
340 341 342
    self.assertEqual(10, mvt.getDestinationDebit())
    self.assertEqual(0, mvt.getDestinationCredit())
    self.assertEqual(10, mvt.getQuantity())
343
  
344
  def testSourceAssetCredit(self):
345
    mvt = self._makeOne()
346
    mvt.edit(source_asset_credit=100)
347 348 349 350 351
    self.assertEqual(100, mvt.getSourceAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetPrice())
352 353
    # reset and set quantity instead
    mvt.edit(source_asset_credit=None, source_credit=200)
354 355
    self.assertEqual(0.0, mvt.getSourceAssetCredit())
    self.assertEqual(200, mvt.getSourceCredit())
356 357

  def testSourceAssetDebit(self):
358
    mvt = self._makeOne()
359
    mvt.edit(source_asset_debit=100)
360 361 362 363 364
    self.assertEqual(100, mvt.getSourceAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetPrice())
365 366
    # reset and set quantity instead
    mvt.edit(source_asset_debit=None, source_debit=200)
367 368
    self.assertEqual(0.0, mvt.getSourceAssetDebit())
    self.assertEqual(200, mvt.getSourceDebit())
369

370
  def testEditSourceAssetDebitAndCredit(self):
371
    mvt = self._makeOne()
372
    mvt.edit(source_asset_debit=100, source_asset_credit=None)
373
    self.assertEqual(100, mvt.getSourceAssetDebit())
374
    mvt.edit(source_asset_debit=None, source_asset_credit=100)
375
    self.assertEqual(100, mvt.getSourceAssetCredit())
376
    mvt.edit(source_asset_debit=100, source_asset_credit='')
377
    self.assertEqual(100, mvt.getSourceAssetDebit())
378
    mvt.edit(source_asset_debit='', source_asset_credit=100)
379
    self.assertEqual(100, mvt.getSourceAssetCredit())
380

381
  def testDestinationAssetCredit(self):
382
    mvt = self._makeOne()
383
    mvt.edit(destination_asset_credit=100)
384 385 386 387 388
    self.assertEqual(100, mvt.getDestinationAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetPrice())
389 390
    # reset and set quantity instead
    mvt.edit(destination_asset_credit=None, destination_credit=200)
391 392
    self.assertEqual(0.0, mvt.getDestinationAssetCredit())
    self.assertEqual(200, mvt.getDestinationCredit())
393 394

  def testDestinationAssetDebit(self):
395
    mvt = self._makeOne()
396
    mvt.edit(destination_asset_debit=100)
397 398 399 400 401
    self.assertEqual(100, mvt.getDestinationAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetPrice())
402 403
    # reset and set quantity instead
    mvt.edit(destination_asset_debit=None, destination_debit=200)
404 405
    self.assertEqual(0.0, mvt.getDestinationAssetDebit())
    self.assertEqual(200, mvt.getDestinationDebit())
406
  
407
  def testEditDestinationAssetDebitAndCredit(self):
408
    mvt = self._makeOne()
409
    mvt.edit(destination_asset_debit=100, destination_asset_credit=None)
410
    self.assertEqual(100, mvt.getDestinationAssetDebit())
411
    mvt.edit(destination_asset_debit=None, destination_asset_credit=100)
412
    self.assertEqual(100, mvt.getDestinationAssetCredit())
413
    mvt.edit(destination_asset_debit=100, destination_asset_credit='')
414
    self.assertEqual(100, mvt.getDestinationAssetDebit())
415
    mvt.edit(destination_asset_debit='', destination_asset_credit=100)
416
    self.assertEqual(100, mvt.getDestinationAssetCredit())
417

418
  def testCancellationAmountGetDestinationCredit(self):
419
    mvt = self._makeOne()
420 421
    mvt.setCancellationAmount(True)
    mvt.setQuantity(10)
422 423 424
    self.assertEqual(mvt.getQuantity(), 10)
    self.assertEqual(mvt.getDestinationDebit(), 0)
    self.assertEqual(mvt.getDestinationCredit(), -10)
425 426

  def testCancellationAmountGetDestinationDebit(self):
427
    mvt = self._makeOne()
428 429
    mvt.setCancellationAmount(True)
    mvt.setQuantity(-10)
430 431 432
    self.assertEqual(mvt.getQuantity(), -10)
    self.assertEqual(mvt.getDestinationDebit(), -10)
    self.assertEqual(mvt.getDestinationCredit(), 0)
433 434

  def testCancellationAmountGetSourceCredit(self):
435
    mvt = self._makeOne()
436 437
    mvt.setCancellationAmount(True)
    mvt.setQuantity(-10)
438 439 440
    self.assertEqual(mvt.getQuantity(), -10)
    self.assertEqual(mvt.getSourceDebit(), 0)
    self.assertEqual(mvt.getSourceCredit(), -10)
441 442

  def testCancellationAmountGetSourceDebit(self):
443
    mvt = self._makeOne()
444 445
    mvt.setCancellationAmount(True)
    mvt.setQuantity(10)
446 447 448
    self.assertEqual(mvt.getQuantity(), 10)
    self.assertEqual(mvt.getSourceDebit(), -10)
    self.assertEqual(mvt.getSourceCredit(), 0)
449 450

  def testCancellationAmountSetDestinationCredit(self):
451
    mvt = self._makeOne()
452 453
    mvt.setDestinationCredit(-10)
    self.assertTrue(mvt.isCancellationAmount())
454 455
    self.assertEqual(mvt.getDestinationDebit(), 0)
    self.assertEqual(mvt.getDestinationCredit(), -10)
456 457 458

    mvt.setDestinationCredit(10)
    self.assertFalse(mvt.isCancellationAmount())
459 460
    self.assertEqual(mvt.getDestinationDebit(), 0)
    self.assertEqual(mvt.getDestinationCredit(), 10)
461 462

  def testCancellationAmountSetDestinationDebit(self):
463
    mvt = self._makeOne()
464 465
    mvt.setDestinationDebit(-10)
    self.assertTrue(mvt.isCancellationAmount())
466 467
    self.assertEqual(mvt.getDestinationDebit(), -10)
    self.assertEqual(mvt.getDestinationCredit(), 0)
468 469 470

    mvt.setDestinationDebit(10)
    self.assertFalse(mvt.isCancellationAmount())
471 472
    self.assertEqual(mvt.getDestinationDebit(), 10)
    self.assertEqual(mvt.getDestinationCredit(), 0)
473 474

  def testCancellationAmountSetDestinationDebitCredit(self):
475
    mvt = self._makeOne()
476 477
    mvt.edit(destination_debit=-10, destination_credit=0)
    self.assertTrue(mvt.isCancellationAmount())
478 479
    self.assertEqual(mvt.getDestinationDebit(), -10)
    self.assertEqual(mvt.getDestinationCredit(), 0)
480 481 482

    mvt.edit(destination_debit=-10, destination_credit=None)
    self.assertTrue(mvt.isCancellationAmount())
483 484
    self.assertEqual(mvt.getDestinationDebit(), -10)
    self.assertEqual(mvt.getDestinationCredit(), 0)
485 486

  def testCancellationAmountSetSourceCredit(self):
487
    mvt = self._makeOne()
488 489
    mvt.setSourceCredit(-10)
    self.assertTrue(mvt.isCancellationAmount())
490 491
    self.assertEqual(mvt.getSourceDebit(), 0)
    self.assertEqual(mvt.getSourceCredit(), -10)
492 493 494

    mvt.setSourceCredit(10)
    self.assertFalse(mvt.isCancellationAmount())
495 496
    self.assertEqual(mvt.getSourceDebit(), 0)
    self.assertEqual(mvt.getSourceCredit(), 10)
497 498

  def testCancellationAmountSetSourceDebit(self):
499
    mvt = self._makeOne()
500 501
    mvt.setSourceDebit(-10)
    self.assertTrue(mvt.isCancellationAmount())
502 503
    self.assertEqual(mvt.getSourceDebit(), -10)
    self.assertEqual(mvt.getSourceCredit(), 0)
504 505 506

    mvt.setSourceDebit(10)
    self.assertFalse(mvt.isCancellationAmount())
507 508
    self.assertEqual(mvt.getSourceDebit(), 10)
    self.assertEqual(mvt.getSourceCredit(), 0)
509 510

  def testCancellationAmountSetSourceDebitCredit(self):
511
    mvt = self._makeOne()
512 513
    mvt.edit(source_debit=-10, source_credit=0)
    self.assertTrue(mvt.isCancellationAmount())
514 515
    self.assertEqual(mvt.getSourceDebit(), -10)
    self.assertEqual(mvt.getSourceCredit(), 0)
516 517 518

    mvt.edit(source_debit=-10, source_credit=None)
    self.assertTrue(mvt.isCancellationAmount())
519 520
    self.assertEqual(mvt.getSourceDebit(), -10)
    self.assertEqual(mvt.getSourceCredit(), 0)
521

522

523 524 525 526
class TestAccountingTransactionLine(TestMovement):
  """Tests for Accounting Transaction Line class, which have an overloaded
  'edit' method.
  """
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541
  def afterSetUp(self):
    self.login()
    self.portal = self.getPortal()

    if getattr(self.portal, 'accounting_transaction_line_module', None) is None:
      types_tool = self.portal.portal_types
      types_tool.newContent(id="My Accounting Transaction Line",
                            type_class="AccountingTransactionLine")
      types_tool.newContent(
          id="My Accounting Transaction Line Module",
          type_class="Folder",
          type_allowed_content_type_list=("My Accounting Transaction Line",))

      self.portal.newContent(id="accounting_transaction_line_module",
                             portal_type="My Accounting Transaction Line Module")
542
      self.commit()
543 544 545 546
    self.atl_module = self.portal.accounting_transaction_line_module

  def _makeOne(self, **kw):
    return self.atl_module.newContent(**kw)
547 548 549

  def testPrice(self):
    # price is always 1 for accounting transactions lines
550
    mvt = self._makeOne()
551
    self.assertEqual(1, mvt.getPrice())
552 553
  
  def testQuantity(self):
554
    mvt = self._makeOne()
555
    mvt.setQuantity(10)
556 557
    self.assertEqual(10, mvt.getQuantity())
    # self.assertEqual(None, mvt.getTotalPrice()) 
558 559
    # ... not with Accounting Transaction Lines, because price is 1
    mvt.edit(quantity=20)
560
    self.assertEqual(20, mvt.getQuantity())
561 562

  def testDefautSourceTotalAssetDebit(self):
563
    mvt = self._makeOne()
564
    mvt.edit(source_debit=100)
565 566 567 568 569 570 571
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetPrice())
    self.assertEqual(None, mvt.getSourceTotalAssetPrice())
    self.assertEqual(None, mvt.getDestinationTotalAssetPrice())
    self.assertEqual(0.0, mvt.getSourceAssetDebit())
    self.assertEqual(0.0, mvt.getSourceAssetCredit())
572 573
    
  def testDefautSourceTotalAssetCredit(self):
574
    mvt = self._makeOne()
575
    mvt.edit(source_credit=100)
576 577 578 579 580 581 582
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetPrice())
    self.assertEqual(None, mvt.getSourceTotalAssetPrice())
    self.assertEqual(None, mvt.getDestinationTotalAssetPrice())
    self.assertEqual(0.0, mvt.getSourceAssetDebit())
    self.assertEqual(0.0, mvt.getSourceAssetCredit())
583
 
584
  def testDefautDestinationTotalAssetDebit(self):
585
    mvt = self._makeOne()
586
    mvt.edit(destination_debit=100)
587 588 589 590 591 592 593
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetPrice())
    self.assertEqual(None, mvt.getSourceTotalAssetPrice())
    self.assertEqual(None, mvt.getDestinationTotalAssetPrice())
    self.assertEqual(0.0, mvt.getDestinationAssetDebit())
    self.assertEqual(0.0, mvt.getDestinationAssetCredit())
594 595
    
  def testDefautDestinationTotalAssetCredit(self):
596
    mvt = self._makeOne()
597
    mvt.edit(destination_credit=100)
598 599 600 601 602 603 604
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetPrice())
    self.assertEqual(None, mvt.getSourceTotalAssetPrice())
    self.assertEqual(None, mvt.getDestinationTotalAssetPrice())
    self.assertEqual(0.0, mvt.getDestinationAssetDebit())
    self.assertEqual(0.0, mvt.getDestinationAssetCredit())
605
  
606
  def testSourceAssetCredit(self):
607
    mvt = self._makeOne()
608
    mvt.edit(source_asset_credit=100)
609 610 611 612 613
    self.assertEqual(100, mvt.getSourceAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetPrice())
614 615
    # reset and set quantity instead
    mvt.edit(source_asset_credit=None, source_credit=200)
616 617
    self.assertEqual(0.0, mvt.getSourceAssetCredit())
    self.assertEqual(200, mvt.getSourceCredit())
618
    # this is only true for Accounting Transaction Line:
619 620 621
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(200, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(-200, mvt.getSourceInventoriatedTotalAssetPrice())
622

623
  def testSourceAssetDebit(self):
624
    mvt = self._makeOne()
625
    mvt.edit(source_asset_debit=100)
626 627 628 629 630
    self.assertEqual(100, mvt.getSourceAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetPrice())
631 632
    # reset and set quantity instead
    mvt.edit(source_asset_debit=None, source_debit=200)
633 634
    self.assertEqual(0.0, mvt.getSourceAssetDebit())
    self.assertEqual(200, mvt.getSourceDebit())
635
    # this is only true for Accounting Transaction Line:
636 637 638
    self.assertEqual(200, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(200, mvt.getSourceInventoriatedTotalAssetPrice())
639 640

  def testDestinationAssetCredit(self):
641
    mvt = self._makeOne()
642
    mvt.edit(destination_asset_credit=100)
643 644 645 646 647
    self.assertEqual(100, mvt.getDestinationAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetPrice())
648 649
    # reset and set quantity instead
    mvt.edit(destination_asset_credit=None, destination_credit=200)
650 651
    self.assertEqual(0.0, mvt.getDestinationAssetCredit())
    self.assertEqual(200, mvt.getDestinationCredit())
652
    # this is only true for Accounting Transaction Line:
653 654 655
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(200, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(-200, mvt.getDestinationInventoriatedTotalAssetPrice())
656 657

  def testDestinationAssetDebit(self):
658
    mvt = self._makeOne()
659
    mvt.edit(destination_asset_debit=100)
660 661 662 663 664
    self.assertEqual(100, mvt.getDestinationAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetPrice())
665 666
    # reset and set quantity instead
    mvt.edit(destination_asset_debit=None, destination_debit=200)
667 668
    self.assertEqual(0.0, mvt.getDestinationAssetDebit())
    self.assertEqual(200, mvt.getDestinationDebit())
669
    # this is only true for Accounting Transaction Line:
670 671 672
    self.assertEqual(200, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(200, mvt.getDestinationInventoriatedTotalAssetPrice())
673

674
  def testDestinationAssetDebitCancellation(self):
675
    mvt = self._makeOne()
676 677
    mvt.edit(destination_asset_debit=-100)
    self.assertTrue(mvt.isCancellationAmount())
678 679 680 681 682
    self.assertEqual(-100, mvt.getDestinationAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetPrice())
683 684

  def testDestinationAssetCreditCancellation(self):
685
    mvt = self._makeOne()
686 687
    mvt.edit(destination_asset_credit=-100)
    self.assertTrue(mvt.isCancellationAmount())
688 689 690 691 692
    self.assertEqual(-100, mvt.getDestinationAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(-100, mvt.getDestinationInventoriatedTotalAssetCredit())
    self.assertEqual(0, mvt.getDestinationInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getDestinationInventoriatedTotalAssetPrice())
693 694

  def testSourceAssetDebitCancellation(self):
695
    mvt = self._makeOne()
696 697
    mvt.edit(source_asset_debit=-100)
    self.assertTrue(mvt.isCancellationAmount())
698 699 700 701 702
    self.assertEqual(-100, mvt.getSourceAssetDebit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetPrice())
703 704

  def testSourceAssetCreditCancellation(self):
705
    mvt = self._makeOne()
706 707
    mvt.edit(source_asset_credit=-100)
    self.assertTrue(mvt.isCancellationAmount())
708 709 710 711 712
    self.assertEqual(-100, mvt.getSourceAssetCredit())
    self.assertEqual(0, mvt.getQuantity())
    self.assertEqual(-100, mvt.getSourceInventoriatedTotalAssetCredit())
    self.assertEqual(0, mvt.getSourceInventoriatedTotalAssetDebit())
    self.assertEqual(100, mvt.getSourceInventoriatedTotalAssetPrice())
713 714


715 716 717 718 719 720
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestAmount))
  suite.addTest(unittest.makeSuite(TestMovement))
  suite.addTest(unittest.makeSuite(TestAccountingTransactionLine))
  return suite