Changeset 12772 for main/waeup.ikoba/trunk
- Timestamp:
- 16 Mar 2015, 10:02:14 (10 years ago)
- 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 43 43 from waeup.ikoba.payments.payment import ( 44 44 get_payments_from_payer_id, 45 get_payments_from_payable_id, 45 46 find_payable_from_payable_id, 46 47 get_payment_providers … … 1732 1733 return search_payments( 1733 1734 query=self.context.customer_id, searchtype='payer_id') 1735 1736 1737 class 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 50 50 from waeup.ikoba.products.productoptions import ProductOption 51 51 from waeup.ikoba.customers.interfaces import CurrencyMismatch 52 from waeup.ikoba.payments.payment import Payment 53 from waeup.ikoba.payments.interfaces import IPayer, IPayable, STATE_PAID 52 54 53 55 PH_LEN = 15911 # Length of placeholder file … … 1291 1293 'Select payment method (final submission)') 1292 1294 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 1293 1303 def add_product_option(self, contract): 1294 1304 prodoption = ProductOption() … … 1565 1575 print "Sample contract_slip.pdf written to %s" % path 1566 1576 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 1567 1595 def test_contract_approval(self): 1568 1596 # This is not a UI test. It's just a functional test. -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/utils.py
r12663 r12772 43 43 from waeup.ikoba.browser.interfaces import IPDFCreator 44 44 from 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, 46 46 get_signature_tables, get_qrcode) 47 from waeup.ikoba.payments.interfaces import STATE_PAID 47 48 48 49 RE_CUSTID_NON_NUM = re.compile('[^\d]+') … … 384 385 # Insert widgets 385 386 if view.form_fields: 386 if view.__name__ == 'contract_slip.pdf':387 if view.__name__.startswith('contract'): 387 388 data_header = trans(_('Contract Data'), portal_language) 388 389 data.append(Paragraph(data_header, HEADING_STYLE)) … … 392 393 separators=separators) 393 394 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 394 405 395 406 # Insert scanned docs -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/viewlets.py
r12762 r12772 29 29 ICustomer, ICustomersContainer, 30 30 ICustomerDocumentsContainer, ICustomerDocument, 31 IContractsContainer, IContract, ICustomersUtils) 31 IContractsContainer, IContract, ICustomersUtils, 32 ) 32 33 from waeup.ikoba.customers.browser import ( 33 34 CustomersContainerPage, CustomersContainerManagePage, … … 37 38 ContractManageFormPage, 38 39 ContractOfficialUsePage) 40 from waeup.ikoba.payments.payment import get_payments_from_payable_id 41 from waeup.ikoba.payments.interfaces import STATE_PAID 39 42 40 43 grok.context(IIkobaObject) # Make IIkobaObject the default context … … 469 472 target = 'contract_slip.pdf' 470 473 474 class 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 56 56 return None 57 57 58 58 59 def get_payments_from_payer_id(payer_id): 59 60 """Get payments by payer id. … … 64 65 result_set = [x for x in cat.searchResults( 65 66 payer_id=(payer_id, payer_id))] 67 if len(result_set): 68 return result_set 69 return None 70 71 72 def 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))] 66 80 if len(result_set): 67 81 return result_set -
main/waeup.ikoba/trunk/src/waeup/ikoba/payments/tests/test_payment.py
r12753 r12772 36 36 Payment, get_payment_providers, PaymentItem, format_payment_item_values, 37 37 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, 39 39 ) 40 40 from waeup.ikoba.testing import (FunctionalLayer, FunctionalTestCase) … … 169 169 self.assertTrue(result[0] is p1) 170 170 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) 171 183 172 184 def test_find_payable_from_payable_id(self):
Note: See TracChangeset for help on using the changeset viewer.