def createInvoice(self, client_uid, items): """ Creates and invoice for a client and a set of items """ invoice_id = self.generateUniqueId('Invoice') invoice = _createObjectByType("Invoice", self, invoice_id) invoice.edit( Client=client_uid, InvoiceDate=DateTime(), ) invoice.processForm() invoice.invoice_lineitems = [] for item in items: lineitem = InvoiceLineItem() if item.portal_type == 'AnalysisRequest': lineitem['ItemDate'] = item.getDatePublished() lineitem['OrderNumber'] = item.getRequestID() lineitem['AnalysisRequest'] = item description = get_invoice_item_description(item) lineitem['ItemDescription'] = description elif item.portal_type == 'SupplyOrder': lineitem['ItemDate'] = item.getDateDispatched() lineitem['OrderNumber'] = item.getOrderNumber() description = get_invoice_item_description(item) lineitem['ItemDescription'] = description lineitem['Subtotal'] = item.getSubtotal() lineitem['VATAmount'] = item.getVATAmount() lineitem['Total'] = item.getTotal() invoice.invoice_lineitems.append(lineitem) invoice.reindexObject() return invoice
def createInvoice(self, client_title, items): """ Creates and invoice for a client and a set of items """ plone_view = self.restrictedTraverse('@@plone') invoice_id = self.generateUniqueId('Invoice') invoice = _createObjectByType("Invoice", self, invoice_id) pc = getToolByName(self, "portal_catalog") client = pc(portal_type="Client", getName=client_title)[0].getObject() invoice.edit( Client=client, InvoiceDate=DateTime(), ) invoice.processForm() invoice.invoice_lineitems = [] for item in items: lineitem = InvoiceLineItem() if item.portal_type == 'AnalysisRequest': lineitem['ItemDate'] = plone_view.toLocalizedTime( getTransitionDate(item, 'publish'), long_format=1) lineitem['OrderNumber'] = item.getRequestID() lineitem['AnalysisRequest'] = item lineitem['SupplyOrder'] = '' description = get_invoice_item_description(item) lineitem['ItemDescription'] = description elif item.portal_type == 'SupplyOrder': lineitem['ItemDate'] = item.getDateDispatched() lineitem['OrderNumber'] = item.getOrderNumber() lineitem['AnalysisRequest'] = '' lineitem['SupplyOrder'] = item description = get_invoice_item_description(item) lineitem['ItemDescription'] = description lineitem['Subtotal'] = item.getSubtotal() lineitem['VATAmount'] = item.getVATAmount() lineitem['Total'] = item.getTotal() invoice.invoice_lineitems.append(lineitem) invoice.reindexObject() return invoice
def _create_lineitem(obj, service, message='', start='', end='', sub_total=0.0, vat=0.0, total=0.0): lineitem = InvoiceLineItem() if service in ('Kit', 'Storage'): lineitem['ItemDate'] = start lineitem['OrderNumber'] = obj.getId() lineitem['AnalysisRequest'] = '' lineitem['SupplyOrder'] = '' lineitem['Project'] = obj lineitem['ItemDescription'] = message.format( start.strftime('%Y-%m-%d'), end.strftime('%Y-%m-%d')) elif service == 'LabProduct': lineitem['ItemDate'] = obj.getDateDispatched() lineitem['OrderNumber'] = obj.getOrderNumber() lineitem['AnalysisRequest'] = '' lineitem['SupplyOrder'] = obj description = get_invoice_item_description(obj) lineitem['ItemDescription'] = description elif service == 'AnalysisRequest': lineitem['ItemDate'] = obj.getDatePublished() lineitem['OrderNumber'] = obj.getRequestID() lineitem['AnalysisRequest'] = obj lineitem['SupplyOrder'] = '' description = get_invoice_item_description(obj) lineitem['ItemDescription'] = description lineitem['Subtotal'] = sub_total lineitem['VATAmount'] = vat lineitem['Total'] = total return lineitem