Ignore:
Timestamp:
9 Mar 2015, 01:51:12 (10 years ago)
Author:
uli
Message:

Add adapter to turn IContract into IPayer

Location:
main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/contracts.py

    r12683 r12697  
    3232    IContractSelectProduct, ICustomersUtils, ISampleContract,
    3333    ISampleContractProcess, ISampleContractEdit, ISampleContractOfficialUse)
    34 from waeup.ikoba.payments.interfaces import IPaymentItem
     34from waeup.ikoba.payments.interfaces import IPayer
    3535from waeup.ikoba.payments.payment import PaymentItem
    3636from waeup.ikoba.utils.helpers import attrs_to_fields
     
    7171        result.append(item)
    7272    return result
     73
     74
     75class ContractPayer(grok.Adapter):
     76    """Adapter to turn contracts into IPayers.
     77    """
     78    grok.implements(IPayer)
     79    grok.context(IContract)
     80
     81    def __init__(self, context):
     82        self.context = context
     83
     84    @property
     85    def _customer(self):
     86        # XXX: contracts have no `customer` in interface.
     87        return self.context.customer
     88
     89    @property
     90    def first_name(self):
     91        return getattr(self._customer, 'firstname', None)
     92
     93    @property
     94    def last_name(self):
     95        return getattr(self._customer, 'lastname', None)
     96
     97    @property
     98    def payer_id(self):
     99        return getattr(self._customer, 'customer_id', None)
    73100
    74101
  • main/waeup.ikoba/branches/uli-payments/src/waeup/ikoba/customers/tests/test_contract.py

    r12683 r12697  
    2828from waeup.ikoba.customers.contracts import (
    2929    ContractsContainer, SampleContract, payment_items_from_contract,
     30    ContractPayer,
    3031    )
    31 from waeup.ikoba.payments.interfaces import IPaymentItem
     32from waeup.ikoba.customers.customer import Customer
     33from waeup.ikoba.payments.interfaces import IPaymentItem, IPayer
    3234from waeup.ikoba.products.productoptions import ProductOption
    3335from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    122124        payment_items = payment_items_from_contract(contract)
    123125        assert payment_items == []
     126
     127    def test_payer_adapter(self):
     128        # we can adapt IContract to IPayer (i.e. create a payer)
     129        customer = Customer()
     130        customer.firstname, customer.lastname = u'Anna', u'Tester'
     131        contract = createObject(u'waeup.SampleContract')
     132        customer['contracts'] = ContractsContainer()
     133        customer['contracts'].addContract(contract)
     134        result = IPayer(contract)
     135        self.assertTrue(isinstance(result, ContractPayer))
     136        verifyObject(IPayer, result)
     137        self.assertEqual(result.first_name, u'Anna')
     138        self.assertEqual(result.last_name, u'Tester')
     139        self.assertEqual(result.payer_id, customer.customer_id)
Note: See TracChangeset for help on using the changeset viewer.