def folderitems(self, full_objects=False): currency = currency_format(self.context, 'en') self.show_all = True self.contentsMethod = self.getInvoices items = BikaListingView.folderitems(self, full_objects) for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % ( item['url'], obj.getId() ) item['replace']['id'] = number_link if obj.getClient(): item['client'] = obj.getClient().Title() item['replace']['client'] = "<a href='%s'>%s</a>" % ( obj.getClient().absolute_url(), obj.getClient().Title() ) item['email'] = obj.getClient().getEmailAddress() item['replace']['email'] = "<a href='%s'>%s</a>" % ( 'mailto:%s' % obj.getClient().getEmailAddress(), obj.getClient().getEmailAddress() ) item['phone'] = obj.getClient().getPhone() else: item['client'] = '' item['email'] = '' item['phone'] = '' item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['startdate'] = self.ulocalized_time(obj.getBatchStartDate()) item['enddate'] = self.ulocalized_time(obj.getBatchEndDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return items
def folderitem(self, obj, item, idx): """ Replace or add the required/wanted fields for each invoice in the item dictionary :param obj: the instance of the class to be foldered. In our case, an Invoice :param item: dict containing the properties of the object to be used by the template :return: dictionary with the updated fields of the invoice being processed """ currency = currency_format(self.context, 'en') item['replace']['id'] = get_link(api.get_url(obj), obj.getId()) client = obj.getClient() if client: item['client'] = client.Title() item['replace']['client'] = get_link(client.absolute_url(), item['client']) item['email'] = client.getEmailAddress() item['replace']['email'] = get_email_link(client.getEmailAddress()) item['phone'] = client.getPhone() else: item['client'] = '' item['email'] = '' item['phone'] = '' item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['startdate'] = self.ulocalized_time(obj.getBatchStartDate()) item['enddate'] = self.ulocalized_time(obj.getBatchEndDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return item
def folderitems(self, full_objects=False): currency = currency_format(self.context, 'en') self.show_all = True self.contentsMethod = self.getInvoices items = BikaListingView.folderitems(self, full_objects) for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % (item['url'], obj.getId()) item['replace']['id'] = number_link if obj.getClient(): item['client'] = obj.getClient().Title() item['replace']['client'] = "<a href='%s'>%s</a>" % ( obj.getClient().absolute_url(), obj.getClient().Title()) item['email'] = obj.getClient().getEmailAddress() item['replace']['email'] = "<a href='%s'>%s</a>" % ( 'mailto:%s' % obj.getClient().getEmailAddress(), obj.getClient().getEmailAddress()) item['phone'] = obj.getClient().getPhone() else: item['client'] = '' item['email'] = '' item['phone'] = '' item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['startdate'] = self.ulocalized_time(obj.getBatchStartDate()) item['enddate'] = self.ulocalized_time(obj.getBatchEndDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return items
def folderitem(self, obj, item, index): obj = api.get_object(obj) currency = currency_format(self.context, 'en') item['replace']['id'] = get_link(item["url"], api.get_id(obj)) item['client'] = obj.getClient().Title() item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return item
def folderitems(self): currency = currency_format(self.context, 'en') self.contentsMethod = self.getInvoices items = BikaListingView.folderitems(self) for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % (item['url'], obj.getId()) item['replace']['id'] = number_link item['client'] = obj.getClient().Title() item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return items
def folderitems(self): currency = currency_format(self.context, 'en') self.contentsMethod = self.getInvoices items = BikaListingView.folderitems(self) for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % ( item['url'], obj.getId() ) item['replace']['id'] = number_link item['client'] = obj.getClient().Title() item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) return items
def folderitems(self, full_objects=False): """ :return: All the invoices related with the Insurance Company's clients. """ currency = currency_format(self.context, 'en') self.show_all = True items = BikaListingView.folderitems(self, full_objects) l = [] for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % (item['url'], obj.getId()) item['replace']['id'] = number_link item['client'] = obj.getClient().Title() item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) l.append(item) return l
def folderitems(self, full_objects=False): """ :return: All the invoices related with the Insurance Company's clients. """ currency = currency_format(self.context, 'en') self.show_all = True items = BikaListingView.folderitems(self, full_objects) l = [] for item in items: obj = item['obj'] number_link = "<a href='%s'>%s</a>" % ( item['url'], obj.getId() ) item['replace']['id'] = number_link item['client'] = obj.getClient().Title() item['invoicedate'] = self.ulocalized_time(obj.getInvoiceDate()) item['subtotal'] = currency(obj.getSubtotal()) item['vatamount'] = currency(obj.getVATAmount()) item['total'] = currency(obj.getTotal()) l.append(item) return l
def __call__(self, REQUEST, RESPONSE): """Export invoice batch into csv format. Writes the csv file into the response to allow the file to be streamed to the user. Nothing gets returned. """ delimiter = ',' filename = 'invoice_batch.txt' # Getting the invoice batch container = self.context assert container container.plone_log("Exporting InvoiceBatch to CSV format for PASTEL") # Getting the invoice batch's invoices invoices = self.getInvoices({}) if not len(invoices): container.plone_log("InvoiceBatch contains no entries") csv_rows = [['Invoice Batch']] # Invoice batch header csv_rows.append(['ID', container.getId()]) csv_rows.append(['Invoice Batch Title', container.title]) csv_rows.append( ['Start Date', container.getBatchStartDate().strftime('%Y-%m-%d')]) csv_rows.append( ['End Date', container.getBatchEndDate().strftime('%Y-%m-%d')]) csv_rows.append([]) # Building the invoice field header csv_rows.append(['Invoices']) csv_rows.append([ 'Invoice ID', 'Client ID', 'Client Name', 'Account Num.', 'Phone', 'Date', 'Total Price' ]) invoices_items_rows = [] currency = currency_format(self.context, 'en') for invoice in invoices: # Building the invoice field header invoice_info_header = [ invoice.getId(), invoice.getClient().getId(), invoice.getClient().getName(), invoice.getClient().getAccountNumber(), invoice.getClient().getPhone(), invoice.getInvoiceDate().strftime('%Y-%m-%d'), currency(invoice.getTotal()), ] csv_rows.append(invoice_info_header) # Obtaining and sorting all analysis items. # These analysis are saved inside a list to add later items = invoice.invoice_lineitems mixed = [(item.get('OrderNumber', ''), item) for item in items] mixed.sort() # Defining each analysis row for line in mixed: invoice_analysis = [ line[1].get('ItemDate', ''), line[1].get('ItemDescription', ''), line[1].get('OrderNumber', ''), line[1].get('Subtotal', ''), line[1].get('VATAmount', ''), line[1].get('Total', ''), ] invoices_items_rows.append(invoice_analysis) csv_rows.append([]) # Creating analysis items header csv_rows.append(['Invoices items']) csv_rows.append([ 'Date', 'Description', 'Order', 'Amount', 'VAT', 'Amount incl. VAT' ]) # Adding all invoices items for item_row in invoices_items_rows: csv_rows.append(item_row) # convert lists to csv string ramdisk = StringIO() writer = csv.writer(ramdisk, delimiter=delimiter) assert writer writer.writerows(csv_rows) result = ramdisk.getvalue() ramdisk.close() # stream file to browser setheader = RESPONSE.setHeader setheader('Content-Length', len(result)) setheader('Content-Type', 'text/x-comma-separated-values') setheader('Content-Disposition', 'inline; filename=%s' % filename) RESPONSE.write(result)
def __call__(self, REQUEST, RESPONSE): """Export invoice batch into csv format. Writes the csv file into the response to allow the file to be streamed to the user. Nothing gets returned. """ delimiter = ',' filename = 'invoice_batch.txt' # Getting the invoice batch container = self.context assert container container.plone_log("Exporting InvoiceBatch to CSV format for PASTEL") # Getting the invoice batch's invoices invoices = self.getInvoices({}) if not len(invoices): container.plone_log("InvoiceBatch contains no entries") csv_rows = [['Invoice Batch']] # Invoice batch header csv_rows.append( ['ID', container.getId()]) csv_rows.append( ['Invoice Batch Title', container.title]) csv_rows.append( ['Start Date', container.getBatchStartDate().strftime('%Y-%m-%d')]) csv_rows.append( ['End Date', container.getBatchEndDate().strftime('%Y-%m-%d')]) csv_rows.append([]) # Building the invoice field header csv_rows.append(['Invoices']) csv_rows.append([ 'Invoice ID', 'Client ID', 'Client Name', 'Account Num.', 'Phone', 'Date', 'Total Price' ]) invoices_items_rows = [] currency = currency_format(self.context, 'en') for invoice in invoices: # Building the invoice field header invoice_info_header = [ invoice.getId(), invoice.getClient().getId(), invoice.getClient().getName(), invoice.getClient().getAccountNumber(), invoice.getClient().getPhone(), invoice.getInvoiceDate().strftime('%Y-%m-%d'), currency(invoice.getTotal()), ] csv_rows.append(invoice_info_header) # Obtaining and sorting all analysis items. # These analysis are saved inside a list to add later items = invoice.invoice_lineitems mixed = [(item.get('OrderNumber', ''), item) for item in items] mixed.sort() # Defining each analysis row for line in mixed: invoice_analysis = [ line[1].get('ItemDate', ''), line[1].get('ItemDescription', ''), line[1].get('OrderNumber', ''), line[1].get('Subtotal', ''), line[1].get('VATAmount', ''), line[1].get('Total', ''), ] invoices_items_rows.append(invoice_analysis) csv_rows.append([]) # Creating analysis items header csv_rows.append(['Invoices items']) csv_rows.append(['Date', 'Description', 'Order', 'Amount', 'VAT', 'Amount incl. VAT']) # Adding all invoices items for item_row in invoices_items_rows: csv_rows.append(item_row) # convert lists to csv string ramdisk = StringIO() writer = csv.writer(ramdisk, delimiter=delimiter) assert writer writer.writerows(csv_rows) result = ramdisk.getvalue() ramdisk.close() # stream file to browser setheader = RESPONSE.setHeader setheader('Content-Length', len(result)) setheader('Content-Type', 'text/x-comma-separated-values') setheader('Content-Disposition', 'inline; filename=%s' % filename) RESPONSE.write(result)