[12015] | 1 | ## $Id: viewlets.py 12772 2015-03-16 10:02:14Z henrik $ |
---|
[11958] | 2 | ## |
---|
| 3 | ## Copyright (C) 2014 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | |
---|
| 19 | import grok |
---|
[11967] | 20 | from zope.i18n import translate |
---|
| 21 | from zope.interface import Interface |
---|
[12346] | 22 | from zope.component import getUtility |
---|
[11958] | 23 | from waeup.ikoba.interfaces import IIkobaObject |
---|
| 24 | from waeup.ikoba.interfaces import MessageFactory as _ |
---|
| 25 | from waeup.ikoba.browser.viewlets import ( |
---|
| 26 | PrimaryNavTab, ManageActionButton, AddActionButton) |
---|
[11987] | 27 | from waeup.ikoba.browser.layout import default_primary_nav_template |
---|
[11967] | 28 | from waeup.ikoba.customers.interfaces import ( |
---|
[12015] | 29 | ICustomer, ICustomersContainer, |
---|
[12090] | 30 | ICustomerDocumentsContainer, ICustomerDocument, |
---|
[12772] | 31 | IContractsContainer, IContract, ICustomersUtils, |
---|
| 32 | ) |
---|
[11967] | 33 | from waeup.ikoba.customers.browser import ( |
---|
| 34 | CustomersContainerPage, CustomersContainerManagePage, |
---|
[12015] | 35 | CustomerBaseDisplayFormPage, |
---|
[12090] | 36 | DocumentsManageFormPage, DocumentDisplayFormPage, DocumentManageFormPage, |
---|
[12337] | 37 | ContractsFormPage, ContractDisplayFormPage, |
---|
[12500] | 38 | ContractManageFormPage, |
---|
| 39 | ContractOfficialUsePage) |
---|
[12772] | 40 | from waeup.ikoba.payments.payment import get_payments_from_payable_id |
---|
| 41 | from waeup.ikoba.payments.interfaces import STATE_PAID |
---|
[11958] | 42 | |
---|
[11985] | 43 | grok.context(IIkobaObject) # Make IIkobaObject the default context |
---|
[11964] | 44 | grok.templatedir('browser_templates') |
---|
| 45 | |
---|
[11985] | 46 | |
---|
[11958] | 47 | class CustomersTab(PrimaryNavTab): |
---|
| 48 | """Customers tab in primary navigation. |
---|
| 49 | """ |
---|
| 50 | |
---|
| 51 | grok.context(IIkobaObject) |
---|
| 52 | grok.order(4) |
---|
| 53 | grok.require('waeup.viewCustomersTab') |
---|
| 54 | grok.name('customerstab') |
---|
| 55 | |
---|
| 56 | pnav = 4 |
---|
| 57 | tab_title = _(u'Customers') |
---|
| 58 | |
---|
| 59 | @property |
---|
| 60 | def link_target(self): |
---|
[11964] | 61 | return self.view.application_url('customers') |
---|
| 62 | |
---|
[11985] | 63 | |
---|
[11964] | 64 | class PrimaryCustomerNavManager(grok.ViewletManager): |
---|
| 65 | """Viewlet manager for the primary navigation tab. |
---|
| 66 | """ |
---|
| 67 | grok.name('primary_nav_customer') |
---|
| 68 | |
---|
[11985] | 69 | |
---|
[11964] | 70 | class PrimaryCustomerNavTab(grok.Viewlet): |
---|
| 71 | """Base for primary customer nav tabs. |
---|
| 72 | """ |
---|
| 73 | grok.baseclass() |
---|
| 74 | grok.viewletmanager(PrimaryCustomerNavManager) |
---|
| 75 | template = default_primary_nav_template |
---|
| 76 | grok.order(1) |
---|
| 77 | grok.require('waeup.Authenticated') |
---|
| 78 | pnav = 0 |
---|
| 79 | tab_title = u'Some Text' |
---|
| 80 | |
---|
| 81 | @property |
---|
| 82 | def link_target(self): |
---|
| 83 | return self.view.application_url() |
---|
| 84 | |
---|
| 85 | @property |
---|
| 86 | def active(self): |
---|
| 87 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 88 | if view_pnav == self.pnav: |
---|
| 89 | return 'active' |
---|
| 90 | return '' |
---|
| 91 | |
---|
[11985] | 92 | |
---|
[11964] | 93 | class MyCustomerDataTab(PrimaryCustomerNavTab): |
---|
| 94 | """MyData dropdown tab in primary navigation. |
---|
| 95 | """ |
---|
| 96 | grok.order(3) |
---|
| 97 | grok.require('waeup.viewMyCustomerDataTab') |
---|
| 98 | grok.template('mydatadropdowntabs') |
---|
| 99 | grok.name('mycustomerdatatab') |
---|
| 100 | pnav = 4 |
---|
| 101 | tab_title = _(u'My Data') |
---|
| 102 | |
---|
| 103 | @property |
---|
| 104 | def active(self): |
---|
| 105 | view_pnav = getattr(self.view, 'pnav', 0) |
---|
| 106 | if view_pnav == self.pnav: |
---|
| 107 | return 'active dropdown' |
---|
| 108 | return 'dropdown' |
---|
| 109 | |
---|
| 110 | @property |
---|
| 111 | def targets(self): |
---|
| 112 | customer = grok.getSite()['customers'][self.request.principal.id] |
---|
| 113 | customer_url = self.view.url(customer) |
---|
| 114 | targets = [] |
---|
| 115 | targets += [ |
---|
| 116 | {'url':customer_url, 'title':'Base Data'}, |
---|
[12097] | 117 | {'url':customer_url + '/contracts', 'title':_('My Contracts')}, |
---|
[12090] | 118 | {'url':customer_url + '/documents', 'title':_('My Documents')}, |
---|
[11964] | 119 | {'url':customer_url + '/history', 'title':_('History')}, |
---|
| 120 | ] |
---|
[11967] | 121 | return targets |
---|
| 122 | |
---|
[11985] | 123 | |
---|
[11967] | 124 | class CustomerManageSidebar(grok.ViewletManager): |
---|
| 125 | grok.name('left_customermanage') |
---|
| 126 | |
---|
[11985] | 127 | |
---|
[11967] | 128 | class CustomerManageLink(grok.Viewlet): |
---|
| 129 | """A link displayed in the customer box which shows up for CustomerNavigation |
---|
| 130 | objects. |
---|
| 131 | |
---|
| 132 | """ |
---|
| 133 | grok.baseclass() |
---|
| 134 | grok.viewletmanager(CustomerManageSidebar) |
---|
| 135 | grok.view(Interface) |
---|
| 136 | grok.order(5) |
---|
| 137 | grok.require('waeup.viewCustomer') |
---|
| 138 | |
---|
| 139 | link = 'index' |
---|
| 140 | text = _(u'Base Data') |
---|
| 141 | |
---|
| 142 | def render(self): |
---|
| 143 | url = self.view.url(self.context.customer, self.link) |
---|
| 144 | # Here we know that the cookie has been set |
---|
[11979] | 145 | lang = self.request.cookies.get('ikoba.language') |
---|
| 146 | text = translate(self.text, 'waeup.ikoba', |
---|
[11967] | 147 | target_language=lang) |
---|
| 148 | if not self.link: |
---|
| 149 | return '' |
---|
| 150 | return u'<li><a href="%s">%s</a></li>' % ( |
---|
| 151 | url, text) |
---|
| 152 | |
---|
[11985] | 153 | |
---|
[11967] | 154 | class CustomerManageBaseLink(CustomerManageLink): |
---|
| 155 | grok.order(2) |
---|
| 156 | link = 'index' |
---|
| 157 | text = _(u'Base Data') |
---|
| 158 | |
---|
[12090] | 159 | |
---|
[12097] | 160 | class CustomerManageContractsLink(CustomerManageLink): |
---|
[12090] | 161 | grok.order(3) |
---|
[12097] | 162 | link = 'contracts' |
---|
| 163 | text = _(u'Contracts') |
---|
[12090] | 164 | |
---|
| 165 | |
---|
[12015] | 166 | class CustomerManageDocumentsLink(CustomerManageLink): |
---|
[12090] | 167 | grok.order(4) |
---|
[12015] | 168 | link = 'documents' |
---|
| 169 | text = _(u'Documents') |
---|
[11985] | 170 | |
---|
[12762] | 171 | |
---|
[12757] | 172 | class CustomerManagePaymentsLink(CustomerManageLink): |
---|
| 173 | grok.order(5) |
---|
| 174 | link = 'payments' |
---|
| 175 | text = _(u'Payments') |
---|
[12015] | 176 | |
---|
[12757] | 177 | |
---|
[11967] | 178 | class CustomerManageHistoryLink(CustomerManageLink): |
---|
| 179 | grok.order(8) |
---|
| 180 | link = 'history' |
---|
| 181 | text = _(u'History') |
---|
| 182 | |
---|
[11985] | 183 | |
---|
[11967] | 184 | class CustomersContainerManageActionButton(ManageActionButton): |
---|
| 185 | grok.order(1) |
---|
| 186 | grok.context(ICustomersContainer) |
---|
| 187 | grok.view(CustomersContainerPage) |
---|
| 188 | grok.require('waeup.manageCustomer') |
---|
| 189 | text = _('Manage customer section') |
---|
| 190 | |
---|
[11985] | 191 | |
---|
[11967] | 192 | class CustomersContainerAddActionButton(AddActionButton): |
---|
| 193 | grok.order(1) |
---|
| 194 | grok.context(ICustomersContainer) |
---|
| 195 | grok.view(CustomersContainerManagePage) |
---|
| 196 | grok.require('waeup.manageCustomer') |
---|
| 197 | text = _('Add customer') |
---|
| 198 | target = 'addcustomer' |
---|
| 199 | |
---|
[11985] | 200 | |
---|
[11967] | 201 | class ContactActionButton(ManageActionButton): |
---|
| 202 | grok.order(5) |
---|
| 203 | grok.context(ICustomer) |
---|
| 204 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 205 | grok.require('waeup.manageCustomer') |
---|
| 206 | icon = 'actionicon_mail.png' |
---|
| 207 | text = _('Send email') |
---|
| 208 | target = 'contactcustomer' |
---|
| 209 | |
---|
[11985] | 210 | |
---|
[11967] | 211 | class CustomerBaseManageActionButton(ManageActionButton): |
---|
| 212 | grok.order(1) |
---|
| 213 | grok.context(ICustomer) |
---|
| 214 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 215 | grok.require('waeup.manageCustomer') |
---|
| 216 | text = _('Manage') |
---|
| 217 | target = 'manage_base' |
---|
| 218 | |
---|
[11985] | 219 | |
---|
[11967] | 220 | class CustomerTrigTransActionButton(ManageActionButton): |
---|
| 221 | grok.order(2) |
---|
| 222 | grok.context(ICustomer) |
---|
| 223 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 224 | grok.require('waeup.triggerTransition') |
---|
| 225 | icon = 'actionicon_trigtrans.png' |
---|
[12028] | 226 | text = _(u'Transition') |
---|
[11967] | 227 | target = 'trigtrans' |
---|
| 228 | |
---|
[11985] | 229 | |
---|
[11967] | 230 | class CustomerLoginAsActionButton(ManageActionButton): |
---|
| 231 | grok.order(3) |
---|
| 232 | grok.context(ICustomer) |
---|
| 233 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 234 | grok.require('waeup.loginAsCustomer') |
---|
| 235 | icon = 'actionicon_mask.png' |
---|
| 236 | text = _(u'Login as customer') |
---|
| 237 | target = 'loginasstep1' |
---|
| 238 | |
---|
[11985] | 239 | |
---|
[11967] | 240 | class CustomerDeactivateActionButton(ManageActionButton): |
---|
| 241 | grok.order(7) |
---|
| 242 | grok.context(ICustomer) |
---|
| 243 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 244 | grok.require('waeup.manageCustomer') |
---|
| 245 | text = _('Deactivate account') |
---|
| 246 | target = 'deactivate' |
---|
| 247 | icon = 'actionicon_traffic_lights_red.png' |
---|
| 248 | |
---|
| 249 | @property |
---|
| 250 | def target_url(self): |
---|
| 251 | if self.context.suspended: |
---|
| 252 | return '' |
---|
| 253 | return self.view.url(self.view.context, self.target) |
---|
| 254 | |
---|
| 255 | @property |
---|
| 256 | def onclick(self): |
---|
| 257 | return "return window.confirm(%s);" % _( |
---|
| 258 | "'A history message will be added. Are you sure?'") |
---|
| 259 | |
---|
[11985] | 260 | |
---|
[11967] | 261 | class CustomerActivateActionButton(ManageActionButton): |
---|
| 262 | grok.order(7) |
---|
| 263 | grok.context(ICustomer) |
---|
| 264 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 265 | grok.require('waeup.manageCustomer') |
---|
| 266 | text = _('Activate account') |
---|
| 267 | target = 'activate' |
---|
| 268 | icon = 'actionicon_traffic_lights_green.png' |
---|
| 269 | |
---|
| 270 | @property |
---|
| 271 | def target_url(self): |
---|
| 272 | if not self.context.suspended: |
---|
| 273 | return '' |
---|
| 274 | return self.view.url(self.view.context, self.target) |
---|
| 275 | |
---|
| 276 | @property |
---|
| 277 | def onclick(self): |
---|
| 278 | return "return window.confirm(%s);" % _( |
---|
[11977] | 279 | "'A history message will be added. Are you sure?'") |
---|
| 280 | |
---|
[11985] | 281 | |
---|
[11986] | 282 | class CustomerBaseActionButton(ManageActionButton): |
---|
| 283 | grok.order(1) |
---|
| 284 | grok.context(ICustomer) |
---|
| 285 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 286 | grok.require('waeup.handleCustomer') |
---|
| 287 | target = 'edit_base' |
---|
| 288 | |
---|
[12351] | 289 | @property |
---|
| 290 | def text(self): |
---|
| 291 | if self.view.is_requestable: |
---|
| 292 | return _('Edit and request registration') |
---|
| 293 | return _('Edit') |
---|
[12016] | 294 | |
---|
[12351] | 295 | |
---|
[11977] | 296 | class CustomerPasswordActionButton(ManageActionButton): |
---|
| 297 | grok.order(2) |
---|
| 298 | grok.context(ICustomer) |
---|
| 299 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 300 | grok.require('waeup.handleCustomer') |
---|
| 301 | icon = 'actionicon_key.png' |
---|
| 302 | text = _('Change password') |
---|
[11985] | 303 | target = 'changepassword' |
---|
[11986] | 304 | |
---|
[12016] | 305 | |
---|
[11986] | 306 | class CustomerPassportActionButton(ManageActionButton): |
---|
| 307 | grok.order(3) |
---|
| 308 | grok.context(ICustomer) |
---|
| 309 | grok.view(CustomerBaseDisplayFormPage) |
---|
| 310 | grok.require('waeup.handleCustomer') |
---|
[12527] | 311 | icon = 'actionicon_up.png' |
---|
| 312 | text = _('Upload files') |
---|
| 313 | target = 'upload_files' |
---|
[12015] | 314 | |
---|
[12346] | 315 | @property |
---|
| 316 | def target_url(self): |
---|
| 317 | CUSTMANAGE_STATES = getUtility( |
---|
| 318 | ICustomersUtils).CUSTMANAGE_CUSTOMER_STATES |
---|
| 319 | if self.context.state not in CUSTMANAGE_STATES: |
---|
| 320 | return '' |
---|
| 321 | return self.view.url(self.view.context, self.target) |
---|
[12015] | 322 | |
---|
[12346] | 323 | |
---|
[12059] | 324 | # Viewlets for customer documents |
---|
[12015] | 325 | |
---|
[12090] | 326 | class PDFDocumentOverviewActionButton(ManageActionButton): |
---|
[12059] | 327 | grok.order(2) |
---|
| 328 | grok.context(ICustomerDocumentsContainer) |
---|
| 329 | grok.view(DocumentsManageFormPage) |
---|
| 330 | grok.require('waeup.viewCustomer') |
---|
| 331 | icon = 'actionicon_pdf.png' |
---|
| 332 | text = _('Download documents overview') |
---|
[12091] | 333 | target = 'documents_overview_slip.pdf' |
---|
[12059] | 334 | |
---|
| 335 | |
---|
[12016] | 336 | class DocumentManageActionButton(ManageActionButton): |
---|
| 337 | grok.order(1) |
---|
| 338 | grok.context(ICustomerDocument) |
---|
| 339 | grok.view(DocumentDisplayFormPage) |
---|
| 340 | grok.require('waeup.manageCustomer') |
---|
| 341 | text = _('Manage') |
---|
| 342 | target = 'manage' |
---|
| 343 | |
---|
[12166] | 344 | @property |
---|
| 345 | def target_url(self): |
---|
| 346 | if not self.context.is_editable_by_manager: |
---|
| 347 | return '' |
---|
| 348 | return self.view.url(self.view.context, self.target) |
---|
[12018] | 349 | |
---|
[12166] | 350 | |
---|
[12018] | 351 | class DocumentEditActionButton(ManageActionButton): |
---|
| 352 | grok.order(1) |
---|
| 353 | grok.context(ICustomerDocument) |
---|
| 354 | grok.view(DocumentDisplayFormPage) |
---|
| 355 | grok.require('waeup.handleCustomer') |
---|
| 356 | text = _('Edit') |
---|
| 357 | target = 'edit' |
---|
| 358 | |
---|
| 359 | @property |
---|
| 360 | def target_url(self): |
---|
[12166] | 361 | if not self.context.is_editable_by_customer: |
---|
[12018] | 362 | return '' |
---|
| 363 | return self.view.url(self.view.context, self.target) |
---|
| 364 | |
---|
| 365 | |
---|
[12028] | 366 | class DocumentTrigTransActionButton(ManageActionButton): |
---|
| 367 | grok.order(2) |
---|
| 368 | grok.context(ICustomerDocument) |
---|
| 369 | grok.view(DocumentDisplayFormPage) |
---|
| 370 | grok.require('waeup.triggerTransition') |
---|
| 371 | icon = 'actionicon_trigtrans.png' |
---|
| 372 | text = _(u'Transition') |
---|
| 373 | target = 'trigtrans' |
---|
| 374 | |
---|
| 375 | |
---|
[12016] | 376 | class DocumentViewActionButton(ManageActionButton): |
---|
| 377 | grok.order(1) |
---|
| 378 | grok.context(ICustomerDocument) |
---|
| 379 | grok.view(DocumentManageFormPage) |
---|
[12018] | 380 | grok.require('waeup.handleCustomer') |
---|
[12016] | 381 | text = _('View') |
---|
| 382 | target = 'index' |
---|
| 383 | icon = 'actionicon_view.png' |
---|
[12062] | 384 | |
---|
[12090] | 385 | |
---|
| 386 | class PDFDocumentSlipActionButton(ManageActionButton): |
---|
[12062] | 387 | grok.order(3) |
---|
| 388 | grok.context(ICustomerDocument) |
---|
| 389 | grok.view(DocumentDisplayFormPage) |
---|
| 390 | grok.require('waeup.viewCustomer') |
---|
| 391 | icon = 'actionicon_pdf.png' |
---|
| 392 | text = _('Download document slip') |
---|
| 393 | target = 'document_slip.pdf' |
---|
[12090] | 394 | |
---|
[12214] | 395 | |
---|
[12097] | 396 | # Viewlets for customer contracts |
---|
[12090] | 397 | |
---|
[12097] | 398 | class PDFContractOverviewActionButton(ManageActionButton): |
---|
[12090] | 399 | grok.order(2) |
---|
[12097] | 400 | grok.context(IContractsContainer) |
---|
[12337] | 401 | grok.view(ContractsFormPage) |
---|
[12090] | 402 | grok.require('waeup.viewCustomer') |
---|
| 403 | icon = 'actionicon_pdf.png' |
---|
[12097] | 404 | text = _('Download contracts overview') |
---|
| 405 | target = 'contracts_overview_slip.pdf' |
---|
[12090] | 406 | |
---|
| 407 | |
---|
[12097] | 408 | class ContractManageActionButton(ManageActionButton): |
---|
[12090] | 409 | grok.order(1) |
---|
[12097] | 410 | grok.context(IContract) |
---|
| 411 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 412 | grok.require('waeup.manageCustomer') |
---|
| 413 | text = _('Manage') |
---|
| 414 | target = 'manage' |
---|
| 415 | |
---|
| 416 | |
---|
[12500] | 417 | class ContractOUActionButton(ManageActionButton): |
---|
| 418 | grok.order(2) |
---|
| 419 | grok.context(IContract) |
---|
| 420 | grok.view(ContractDisplayFormPage) |
---|
| 421 | grok.require('waeup.manageCustomer') |
---|
| 422 | text = _('Manage official data') |
---|
| 423 | target = 'official_use' |
---|
| 424 | |
---|
| 425 | |
---|
[12097] | 426 | class ContractEditActionButton(ManageActionButton): |
---|
[12090] | 427 | grok.order(1) |
---|
[12097] | 428 | grok.context(IContract) |
---|
| 429 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 430 | grok.require('waeup.handleCustomer') |
---|
| 431 | text = _('Edit') |
---|
| 432 | target = 'edit' |
---|
| 433 | |
---|
| 434 | @property |
---|
| 435 | def target_url(self): |
---|
[12337] | 436 | if not self.context.is_editable: |
---|
[12090] | 437 | return '' |
---|
| 438 | return self.view.url(self.view.context, self.target) |
---|
| 439 | |
---|
| 440 | |
---|
[12097] | 441 | class ContractTrigTransActionButton(ManageActionButton): |
---|
[12500] | 442 | grok.order(3) |
---|
[12097] | 443 | grok.context(IContract) |
---|
| 444 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 445 | grok.require('waeup.triggerTransition') |
---|
| 446 | icon = 'actionicon_trigtrans.png' |
---|
| 447 | text = _(u'Transition') |
---|
| 448 | target = 'trigtrans' |
---|
| 449 | |
---|
| 450 | |
---|
[12097] | 451 | class ContractViewActionButton(ManageActionButton): |
---|
[12090] | 452 | grok.order(1) |
---|
[12097] | 453 | grok.context(IContract) |
---|
| 454 | grok.view(ContractManageFormPage) |
---|
[12090] | 455 | grok.require('waeup.handleCustomer') |
---|
| 456 | text = _('View') |
---|
| 457 | target = 'index' |
---|
| 458 | icon = 'actionicon_view.png' |
---|
| 459 | |
---|
| 460 | |
---|
[12500] | 461 | class ContractViewActionButton2(ContractViewActionButton): |
---|
| 462 | grok.view(ContractOfficialUsePage) |
---|
| 463 | |
---|
| 464 | |
---|
[12097] | 465 | class PDFContractSlipActionButton(ManageActionButton): |
---|
[12500] | 466 | grok.order(4) |
---|
[12097] | 467 | grok.context(IContract) |
---|
| 468 | grok.view(ContractDisplayFormPage) |
---|
[12090] | 469 | grok.require('waeup.viewCustomer') |
---|
| 470 | icon = 'actionicon_pdf.png' |
---|
[12097] | 471 | text = _('Download contract slip') |
---|
| 472 | target = 'contract_slip.pdf' |
---|
[12090] | 473 | |
---|
[12772] | 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 | |
---|