Ignore:
Timestamp:
16 Mar 2015, 10:02:14 (10 years ago)
Author:
Henrik Bettermann
Message:

Prepare contract payment receipt.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12762 r12772  
    4343from waeup.ikoba.payments.payment import (
    4444    get_payments_from_payer_id,
     45    get_payments_from_payable_id,
    4546    find_payable_from_payable_id,
    4647    get_payment_providers
     
    17321733        return search_payments(
    17331734            query=self.context.customer_id, searchtype='payer_id')
     1735
     1736
     1737class PDFContractReceiptPage(UtilityView, grok.View):
     1738    """Deliver pdf file including metadata.
     1739    """
     1740    grok.context(IContract)
     1741    grok.name('contract_payment_receipt.pdf')
     1742    grok.require('waeup.viewCustomer')
     1743    prefix = 'form'
     1744
     1745    omit_fields = ('suspended', 'sex',
     1746                   'suspended_comment',)
     1747
     1748    @property
     1749    def form_fields(self):
     1750        return grok.AutoFields(self.context.form_fields_interface)
     1751
     1752    @property
     1753    def label(self):
     1754        return 'Payment Receipt: %s' % (
     1755            self.context.title)
     1756
     1757    @property
     1758    def payment(self):
     1759        return get_payments_from_payable_id(self.context.contract_id)
     1760
     1761    def render(self):
     1762        customerview = CustomerBasePDFFormPage(self.context.customer,
     1763            self.request, self.omit_fields)
     1764        customers_utils = getUtility(ICustomersUtils)
     1765        return customers_utils.renderPDF(
     1766            self, 'contract_payment_receipt.pdf',
     1767            self.context.customer, customerview,
     1768            omit_fields=self.omit_fields,
     1769            show_history=False)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12770 r12772  
    5050from waeup.ikoba.products.productoptions import ProductOption
    5151from waeup.ikoba.customers.interfaces import CurrencyMismatch
     52from waeup.ikoba.payments.payment import Payment
     53from waeup.ikoba.payments.interfaces import IPayer, IPayable, STATE_PAID
    5254
    5355PH_LEN = 15911  # Length of placeholder file
     
    12911293        'Select payment method (final submission)')
    12921294
     1295    def setup_payment(self):
     1296        payer = IPayer(self.customer)
     1297        payable = IPayable(self.contract)
     1298        self.payment = Payment(payer, payable)
     1299        self.payment.gateway_service = 'demo_creditcard'
     1300        self.payment.state = STATE_PAID
     1301        self.app['payments'][self.payment.payment_id] = self.payment
     1302
    12931303    def add_product_option(self, contract):
    12941304        prodoption = ProductOption()
     
    15651575        print "Sample contract_slip.pdf written to %s" % path
    15661576
     1577    def test_view_receipt(self):
     1578        self.add_product_option(self.contract)
     1579        self.setup_payment()
     1580        IWorkflowState(self.document).setState(SUBMITTED)
     1581        self.contract.document_object = self.document
     1582        self.contract.product_object = self.product
     1583        self.contract.title = u'Contract Title'
     1584        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
     1585        # Officers can open the receipt
     1586        self.browser.open(self.customer_path + '/contracts/CON1')
     1587        self.browser.getLink("Download payment receipt").click()
     1588        self.assertEqual(self.browser.headers['Status'], '200 Ok')
     1589        self.assertEqual(
     1590            self.browser.headers['Content-Type'], 'application/pdf')
     1591        path = os.path.join(samples_dir(), 'contract_payment_receipt.pdf')
     1592        open(path, 'wb').write(self.browser.contents)
     1593        print "Sample contract_payment_receipt.pdf written to %s" % path
     1594
    15671595    def test_contract_approval(self):
    15681596        # This is not a UI test. It's just a functional test.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py

    r12663 r12772  
    4343from waeup.ikoba.browser.interfaces import IPDFCreator
    4444from waeup.ikoba.browser.pdf import (
    45     ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
     45    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE, HEADLINE1_STYLE,
    4646    get_signature_tables, get_qrcode)
     47from waeup.ikoba.payments.interfaces import STATE_PAID
    4748
    4849RE_CUSTID_NON_NUM = re.compile('[^\d]+')
     
    384385        # Insert widgets
    385386        if view.form_fields:
    386             if view.__name__ == 'contract_slip.pdf':
     387            if view.__name__.startswith('contract'):
    387388                data_header = trans(_('Contract Data'), portal_language)
    388389                data.append(Paragraph(data_header, HEADING_STYLE))
     
    392393                separators=separators)
    393394            data.append(table)
     395
     396        # Insert payment data
     397        if getattr(view, 'payment', None) is not None:
     398            data_header = trans(_('Payment Data'), portal_language)
     399            data.append(Paragraph(data_header, HEADING_STYLE))
     400            for payment in getattr(view, 'payment', None):
     401                if payment.state != STATE_PAID:
     402                    continue
     403                data.append(Paragraph('Payment', HEADLINE1_STYLE))
     404                # XXX: Collect and render payment data
    394405
    395406        # Insert scanned docs
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py

    r12762 r12772  
    2929    ICustomer, ICustomersContainer,
    3030    ICustomerDocumentsContainer, ICustomerDocument,
    31     IContractsContainer, IContract, ICustomersUtils)
     31    IContractsContainer, IContract, ICustomersUtils,
     32    )
    3233from waeup.ikoba.customers.browser import (
    3334    CustomersContainerPage, CustomersContainerManagePage,
     
    3738    ContractManageFormPage,
    3839    ContractOfficialUsePage)
     40from waeup.ikoba.payments.payment import get_payments_from_payable_id
     41from waeup.ikoba.payments.interfaces import STATE_PAID
    3942
    4043grok.context(IIkobaObject)  # Make IIkobaObject the default context
     
    469472    target = 'contract_slip.pdf'
    470473
     474class PDFContractReceiptActionButton(ManageActionButton):
     475    grok.order(5)
     476    grok.context(IContract)
     477    grok.view(ContractDisplayFormPage)
     478    grok.require('waeup.viewCustomer')
     479    icon = 'actionicon_pdf.png'
     480    text = _('Download payment receipt')
     481    target = 'contract_payment_receipt.pdf'
     482
     483    @property
     484    def target_url(self):
     485        payments = get_payments_from_payable_id(self.context.contract_id)
     486        if payments is not None:
     487            for payment in payments:
     488                if payment.state == STATE_PAID:
     489                     return self.view.url(self.view.context, self.target)
     490        return ''
     491       
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/payment.py

    r12766 r12772  
    5656    return None
    5757
     58
    5859def get_payments_from_payer_id(payer_id):
    5960    """Get payments by payer id.
     
    6465    result_set = [x for x in cat.searchResults(
    6566        payer_id=(payer_id, payer_id))]
     67    if len(result_set):
     68        return result_set
     69    return None
     70
     71
     72def get_payments_from_payable_id(payable_id):
     73    """Get payments by payer id.
     74
     75    If no such payment can be found in catalog, return none.
     76    """
     77    cat = getUtility(ICatalog, name='payments_catalog')
     78    result_set = [x for x in cat.searchResults(
     79        payable_id=(payable_id, payable_id))]
    6680    if len(result_set):
    6781        return result_set
  • main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_payment.py

    r12753 r12772  
    3636    Payment, get_payment_providers, PaymentItem, format_payment_item_values,
    3737    get_payment, get_payments_from_payer_id, find_payable_from_payable_id,
    38     find_payer_from_payer_id, format_amount,
     38    find_payer_from_payer_id, get_payments_from_payable_id, format_amount,
    3939    )
    4040from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase)
     
    169169        self.assertTrue(result[0] is p1)
    170170        self.assertTrue(get_payments_from_payer_id('not-valid') is None)
     171
     172    def test_get_payments_from_payable_id(self):
     173        # we can lookup payments.
     174        self.getRootFolder()['app'] = Company()
     175        app = self.getRootFolder()['app']
     176        setSite(app)
     177        p1 = Payment(FakePayer(), FakePayable())
     178        app['payments']['1'] = p1
     179        p_id = p1.payment_id
     180        result = get_payments_from_payable_id('PAYABLE_01')
     181        self.assertTrue(result[0] is p1)
     182        self.assertTrue(get_payments_from_payable_id('not-valid') is None)
    171183
    172184    def test_find_payable_from_payable_id(self):
Note: See TracChangeset for help on using the changeset viewer.