Changeset 12774 for main/waeup.ikoba/trunk
- Timestamp:
- 16 Mar 2015, 12:27:21 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba/payments
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/payment.py
r12772 r12774 186 186 grok.provides(IPayment) 187 187 188 @property 189 def amount(self): 190 """Total amount. 191 192 Sum of all contained payment items. 193 """ 194 amounts = [item.amount for item in self.payment_items] 195 return sum(amounts, decimal.Decimal("0.00")) 196 188 197 def __init__(self, payer, payable, payee=None): 189 198 super(Payment, self).__init__() 190 item_amounts = [decimal.Decimal("0.00"), ] 191 item_amounts += [item.amount for item in payable.payment_items] 192 self.amount = sum(item_amounts) 199 items = tuple([x for x in payable.payment_items]) 200 self.payment_items = items 193 201 self.payer_id = payer.payer_id 194 202 self.payable_id = payable.payable_id -
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_payment.py
r12772 r12774 61 61 62 62 payable_id = u'id1' 63 items = (64 (u'item 1', decimal.Decimal("1.00")),65 (u'item 2', decimal.Decimal("2.12")),66 )67 63 68 64 def __init__(self, payable_id=u'PAYABLE_01', title=u'title', … … 340 336 self.assertEqual(p1.amount, decimal.Decimal("0.00")) 341 337 338 def test_amount_changed_after_init(self): 339 # amount is dynamic: changes to payment items are reflected 340 payable = FakePayable(payment_items=()) 341 p1 = Payment(self.payer, payable) 342 assert p1.amount == decimal.Decimal("0.00") 343 p1.payment_items = (PaymentItem(amount=decimal.Decimal("5.55")), ) 344 assert p1.amount == decimal.Decimal("5.55") 345 p1.payment_items = ( 346 PaymentItem(amount=decimal.Decimal("5.55")), 347 PaymentItem(amount=decimal.Decimal("1.11")), 348 ) 349 assert p1.amount == decimal.Decimal("6.66") 350 351 def test_payment_items(self): 352 # we can get payment items from a payment 353 payable = FakePayable(payment_items=FAKE_PAYMENT_ITEMS) 354 p1 = Payment(self.payer, payable) 355 assert isinstance(p1.payment_items, tuple) 356 357 def test_payment_items_number(self): 358 # payment item values are respected 359 payable = FakePayable() 360 item = PaymentItem(amount=decimal.Decimal("9.99")) 361 payable.payment_items = [item, ] 362 payment = Payment(self.payer, payable) 363 assert len(payment.payment_items) == 1 364 assert payment.payment_items[0] is item 365 342 366 343 367 class PaymentItemTests(unittest.TestCase):
Note: See TracChangeset for help on using the changeset viewer.