def __call__(self): context = self.context workflow = getToolByName(context, 'portal_workflow') # Collect related data and objects invoice = context.getInvoice() sample = context.getSample() samplePoint = sample.getSamplePoint() reviewState = workflow.getInfoFor(context, 'review_state') # Collection invoice information if invoice: self.invoiceId = invoice.getId() else: self.invoiceId = _('Proforma (Not yet invoiced)') # Collect verified invoice information verified = reviewState in VERIFIED_STATES if verified: self.verifiedBy = context.getVerifier() self.verified = verified self.request['verified'] = verified # Collect published date datePublished = context.getDatePublished() if datePublished is not None: datePublished = self.ulocalized_time( datePublished, long_format=1 ) self.datePublished = datePublished # Collect received date dateReceived = context.getDateReceived() if dateReceived is not None: dateReceived = self.ulocalized_time(dateReceived, long_format=1) self.dateReceived = dateReceived # Collect general information self.reviewState = reviewState contact = context.getContact() self.contact = contact.Title() if contact else "" self.clientOrderNumber = context.getClientOrderNumber() self.clientReference = context.getClientReference() self.clientSampleId = sample.getClientSampleID() self.sampleType = sample.getSampleType().Title() self.samplePoint = samplePoint and samplePoint.Title() self.requestId = context.getRequestID() self.headers = [ {'title': 'Invoice ID', 'value': self.invoiceId}, {'title': 'Client Reference', 'value': self.clientReference }, {'title': 'Sample Type', 'value': self.sampleType}, {'title': 'Request ID', 'value': self.requestId}, {'title': 'Date Received', 'value': self.dateReceived}, ] if not isAttributeHidden('AnalysisRequest', 'ClientOrderNumber'): self.headers.append({'title': 'Client Sample Id', 'value': self.clientOrderNumber}) if not isAttributeHidden('AnalysisRequest', 'SamplePoint'): self.headers.append( {'title': 'Sample Point', 'value': self.samplePoint}) if self.verified: self.headers.append( {'title': 'Verified By', 'value': self.verifiedBy}) if self.datePublished: self.headers.append( {'title': 'datePublished', 'value': self.datePublished}) # <tal:published tal:condition="view/datePublished"> # <th i18n:translate="">Date Published</th> # <td tal:content="view/datePublished"></td> # </tal:published> #</tr> analyses = [] profiles = [] # Retrieve required data from analyses collection all_analyses, all_profiles, analyses_from_profiles = context.getServicesAndProfiles() # Relating category with solo analysis for analysis in all_analyses: service = analysis.getService() categoryName = service.getCategory().Title() # Find the category try: category = ( o for o in analyses if o['name'] == categoryName ).next() except: category = {'name': categoryName, 'analyses': []} analyses.append(category) # Append the analysis to the category category['analyses'].append({ 'title': analysis.Title(), 'price': analysis.getPrice(), 'priceVat': "%.2f" % analysis.getVATAmount(), 'priceTotal': "%.2f" % analysis.getTotalPrice(), }) # Relating analysis services with their profiles # We'll take the analysis contained on each profile for profile in all_profiles: # If profile's checkbox "Use Analysis Profile Price" is enabled, only the profile price will be displayed. # Otherwise each analysis will display its own price. pservices = [] if profile.getUseAnalysisProfilePrice(): # We have to use the profiles price only for pservice in profile.getService(): pservices.append({ 'title': pservice.Title(), 'price': None, 'priceVat': None, 'priceTotal': None, }) profiles.append({'name': profile.title, 'price': profile.getAnalysisProfilePrice(), 'priceVat': profile.getVATAmount(), 'priceTotal': profile.getTotalPrice(), 'analyses': pservices}) else: # We need the analyses prices instead of profile price for pservice in profile.getService(): # We want the analysis instead of the service, because we want the price for the client # (for instance the bulk price) panalysis = self._getAnalysisForProfileService(pservice.getKeyword(), analyses_from_profiles) pservices.append({ 'title': pservice.Title(), 'price': panalysis.getPrice() if panalysis else pservice.getPrice(), 'priceVat': "%.2f" % panalysis.getVATAmount() if panalysis else pservice.getVATAmount(), 'priceTotal': "%.2f" % panalysis.getTotalPrice() if panalysis else pservice.getTotalPrice(), }) profiles.append({'name': profile.title, 'price': None, 'priceVat': None, 'priceTotal': None, 'analyses': pservices}) self.analyses = analyses self.profiles = profiles # Get subtotals self.subtotal = context.getSubtotal() self.subtotalVATAmount = "%.2f" % context.getSubtotalVATAmount() self.subtotalTotalPrice = "%.2f" % context.getSubtotalTotalPrice() # Get totals self.memberDiscount = Decimal(context.getDefaultMemberDiscount()) self.discountAmount = context.getDiscountAmount() self.VATAmount = "%.2f" % context.getVATAmount() self.totalPrice = "%.2f" % context.getTotalPrice() # Render the template return self.template()
def isSamplePointHidden(self): return isAttributeHidden('AnalysisRequest', 'SamplePoint')
def __call__(self): context = self.context workflow = getToolByName(context, 'portal_workflow') # Collect related data and objects invoice = context.getInvoice() sample = context.getSample() samplePoint = sample.getSamplePoint() reviewState = workflow.getInfoFor(context, 'review_state') # Collection invoice information if invoice: self.invoiceId = invoice.getId() else: self.invoiceId = _('Proforma (Not yet invoiced)') # Collect verified invoice information verified = reviewState in VERIFIED_STATES if verified: self.verifiedBy = context.getVerifier() self.verified = verified self.request['verified'] = verified # Collect published date datePublished = context.getDatePublished() if datePublished is not None: datePublished = self.ulocalized_time(datePublished, long_format=1) self.datePublished = datePublished # Collect received date dateReceived = context.getDateReceived() if dateReceived is not None: dateReceived = self.ulocalized_time(dateReceived, long_format=1) self.dateReceived = dateReceived # Collect general information self.reviewState = reviewState contact = context.getContact() self.contact = contact.Title() if contact else "" self.clientOrderNumber = context.getClientOrderNumber() self.clientReference = context.getClientReference() self.clientSampleId = sample.getClientSampleID() self.sampleType = sample.getSampleType().Title() self.samplePoint = samplePoint and samplePoint.Title() self.requestId = context.getRequestID() self.headers = [ { 'title': 'Invoice ID', 'value': self.invoiceId }, { 'title': 'Client Reference', 'value': self.clientReference }, { 'title': 'Sample Type', 'value': self.sampleType }, { 'title': 'Request ID', 'value': self.requestId }, { 'title': 'Date Received', 'value': self.dateReceived }, ] if not isAttributeHidden('AnalysisRequest', 'ClientOrderNumber'): self.headers.append({ 'title': 'Client Sample Id', 'value': self.clientOrderNumber }) if not isAttributeHidden('AnalysisRequest', 'SamplePoint'): self.headers.append({ 'title': 'Sample Point', 'value': self.samplePoint }) if self.verified: self.headers.append({ 'title': 'Verified By', 'value': self.verifiedBy }) if self.datePublished: self.headers.append({ 'title': 'datePublished', 'value': self.datePublished }) # <tal:published tal:condition="view/datePublished"> # <th i18n:translate="">Date Published</th> # <td tal:content="view/datePublished"></td> # </tal:published> #</tr> analyses = [] profiles = [] # Retrieve required data from analyses collection all_analyses, all_profiles, analyses_from_profiles = context.getServicesAndProfiles( ) # Relating category with solo analysis for analysis in all_analyses: service = analysis.getService() categoryName = service.getCategory().Title() # Find the category try: category = (o for o in analyses if o['name'] == categoryName).next() except: category = {'name': categoryName, 'analyses': []} analyses.append(category) # Append the analysis to the category category['analyses'].append({ 'title': analysis.Title(), 'price': analysis.getPrice(), 'priceVat': "%.2f" % analysis.getVATAmount(), 'priceTotal': "%.2f" % analysis.getTotalPrice(), }) # Relating analysis services with their profiles # We'll take the analysis contained on each profile for profile in all_profiles: # If profile's checkbox "Use Analysis Profile Price" is enabled, only the profile price will be displayed. # Otherwise each analysis will display its own price. pservices = [] if profile.getUseAnalysisProfilePrice(): # We have to use the profiles price only for pservice in profile.getService(): pservices.append({ 'title': pservice.Title(), 'price': None, 'priceVat': None, 'priceTotal': None, }) profiles.append({ 'name': profile.title, 'price': profile.getAnalysisProfilePrice(), 'priceVat': profile.getVATAmount(), 'priceTotal': profile.getTotalPrice(), 'analyses': pservices }) else: # We need the analyses prices instead of profile price for pservice in profile.getService(): # We want the analysis instead of the service, because we want the price for the client # (for instance the bulk price) panalysis = self._getAnalysisForProfileService( pservice.getKeyword(), analyses_from_profiles) pservices.append({ 'title': pservice.Title(), 'price': panalysis.getPrice() if panalysis else pservice.getPrice(), 'priceVat': "%.2f" % panalysis.getVATAmount() if panalysis else pservice.getVATAmount(), 'priceTotal': "%.2f" % panalysis.getTotalPrice() if panalysis else pservice.getTotalPrice(), }) profiles.append({ 'name': profile.title, 'price': None, 'priceVat': None, 'priceTotal': None, 'analyses': pservices }) self.analyses = analyses self.profiles = profiles # Get subtotals self.subtotal = context.getSubtotal() self.subtotalVATAmount = "%.2f" % context.getSubtotalVATAmount() self.subtotalTotalPrice = "%.2f" % context.getSubtotalTotalPrice() # Get totals self.memberDiscount = Decimal(context.getDefaultMemberDiscount()) self.discountAmount = context.getDiscountAmount() self.VATAmount = "%.2f" % context.getVATAmount() self.totalPrice = "%.2f" % context.getTotalPrice() # Render the template return self.template()