def picking_list(production_order_shipment): '''create a picking_list for a production_order''' production_order = production_order_shipment.production_order production_order_items = production_order.productionorderitem_set.all() document = SuzysDocument() document.add_title('Picking List {}'.format(production_order_shipment)) document.add_invoice_delivery_headers( production_order.invoice_to.printing_address_newlines().replace( '\n', '<br></br>'), production_order.ship_to.own_address.printing_address_newlines(). replace('\n', '<br></br>')) table_data = [['sku', 'ean_code', 'qty']] [ table_data.append([prod.product.sku, prod.product.ean_code, prod.qty]) for prod in production_order_items ] document.add_table(table_data, [0.33] * 3) return document.print_document()
def production_order_report(production_order): doc = SuzysDocument() doc.add_text( 'Production Order for {}'.format( production_order.production_location.own_address.company_name), 'Title') delivery_date = production_order.est_delivery or 'Unconfirmed' po_info = [ 'Our Reference: PR{}'.format(production_order.id), 'Delivery Date {}'.format(delivery_date), ] table_widths = [0.5, 0.5] doc.add_table([po_info], table_widths, bold_header_row=False, line_under_header_row=False, box_line=True) address_format = '''{company.company_name} {company.address1} {company.address2} {company.postcode} {company.city} {company.country} VAT: {company.vat} '''.replace('\n', '<br></br>') invoice_to = address_format.format(company=production_order.invoice_to) deliver_to = address_format.format( company=production_order.ship_to.own_address) doc.add_invoice_delivery_headers(invoice_to, deliver_to) doc.add_text('Items requested', 'Heading2') items_requested = [['Name', 'sku', 'Quantity']] for item in production_order.productionorderitem_set.all(): items_requested.append([ item.product.name, item.product.sku, item.qty, ]) doc.add_table(items_requested, [0.4, 0.3, 0.3]) doc.add_vertical_space(10) doc.add_text( 'Thank you for swift confirmation, communication and delivery.', 'BodyTextCenter') return doc.print_document()
def customs_invoice(sales_order_shipment): ''' create a picking_list for a sales_order. Loosly based on: http://www.dhl.co.uk/content/dam/downloads/g0/express/ customs_regulations_russia/export_import_guidelines_to_russia.pdf ''' sales_order = sales_order_shipment.sales_order sample_shipment = sales_order.sample_order sales_order_shipment_items = sales_order_shipment.salesorderdeliveryitem_set.all( ) document = SuzysDocument() # 3 copies needed for i in range(0, 3): ## Title if not sample_shipment: document.add_title('Commercial Invoice') else: document.add_title('Proforma Invoice') ## Invoice info if not sample_shipment: payment_terms = sales_order.payment_terms else: payment_terms = 'Samples Free of charge' table_data = [[ u'Invoice number: {} {}'.format( sales_order.invoice_number, sales_order_shipment._shipment_reference()), u'Invoice date: {}'.format( sales_order.created_at.strftime('%d/%m/%Y')), u'Delivery terms: DAP {}'.format(sales_order.ship_to.city), u'Payment terms: {}'.format(payment_terms), ]] document.add_table(table_data, [1.0 / len(table_data[0])] * len(table_data[0]), bold_header_row=False, line_under_header_row=False, box_line=True) ## Invoice and delivery addresses document.add_invoice_delivery_headers( sales_order.client.printing_address_newlines().replace( '\n', '<br></br>'), sales_order.ship_to.printing_address_newlines( include_phone=True).replace('\n', '<br></br>')) ## Product table table_data = [[ 'Product', 'Country of Origin', 'Qty (pieces)', 'HS Code', 'Unit Price (EUR)', 'Total Price (EUR)' ]] table_columns_width = [0.3, 0.2, 0.1, 0.25, 0.15] total_shipment_value = 0.0 for prod in sales_order_shipment_items: product_name = u'{}, pet {}, art: {}, {}'.format( prod.product.name, prod.product.product_model.umbrella_product_model. get_product_type_display(), prod.product.sku, prod.product.umbrella_product.export_composition_description) sold_item = prod.sales_order_delivery.sales_order.salesorderproduct_set.get( price_list_item__product=prod.product) table_data.append([product_name, prod.product.umbrella_product.country_of_origin,\ prod.qty, prod.product.umbrella_product.export_hs_code, sold_item.unit_price, \ prod.qty * sold_item.unit_price]) total_shipment_value += prod.qty * sold_item.unit_price table_data.append(['', '', '', '', '', '']) table_data.append( ['<b>Total price EUR</b>', total_shipment_value, '', '', '', '']) table_data.append([ '<b>Freight cost EUR</b>', sales_order.transport_cost, '', '', '', '' ]) if not sample_shipment: table_data.append([ '<b>Total for payment EUR</b>', total_shipment_value + sales_order.transport_cost, '', '', '', '' ]) else: table_data.append( ['<b>Total for payment EUR</b>', 0.0, '', '', '', '']) # table_data.append(['', '', '', '', '', '']) # table_data.append(['<b>Gross Weight</b>', '', '', '', '', '']) document.add_table(table_data, table_columns_width) if sample_shipment: document.add_heading( 'FREE OF CHARGE DELIVERY - SAMPLES FOR MARKETING') document.add_page_break() return document.print_document()
def picking_list(sales_order_shipment): '''create a picking_list for a sales_order, and include tracking-urls of available''' sales_order = sales_order_shipment.sales_order sales_order_shipment_items = sales_order_shipment.salesorderdeliveryitem_set.all( ) document = SuzysDocument() document.add_title(u'Picking List {}'.format(sales_order_shipment)) document.add_invoice_delivery_headers( sales_order.client.printing_address_newlines().replace( '\n', '<br></br>'), sales_order.ship_to.printing_address_newlines().replace( '\n', '<br></br>')) document.add_heading('Items') table_data = [['sku', 'ean_code', 'qty']] for prod in sales_order_shipment_items: sold_item = prod.sales_order_delivery.sales_order.salesorderproduct_set.get( price_list_item__product=prod.product) table_data.append([prod.product.sku, prod.product.ean_code, prod.qty]) document.add_table(table_data, [0.33] * 3) try: tracking_ids_raw = sales_order_shipment.request_sprintpack_order_status[ 'TrackIDs']['Package'] tracking_ids = set() try: for t_id in tracking_ids_raw: tracking_ids.add((t_id['TrackAndTraceURL'], t_id['TrackID'])) except TypeError: tracking_ids.add((tracking_ids_raw['TrackAndTraceURL'], tracking_ids_raw['TrackID'])) if len(tracking_ids) > 0: document.add_vertical_space(10) document.add_heading('Tracking information') for t_id in tracking_ids: if t_id[0] is not None: document.add_paragraph('''Tracking ID: {id} <link href="{link}">{link}</link>'''.format( id=t_id[1], link=t_id[0])) except (TypeError, KeyError): pass ## No tracking data known return document.print_document()
def commission_report(agent, commission_items, sales_total, commission_total, report_date): ''' return pdf with commission report ''' report = SuzysDocument() agent_name = u'{} {}'.format(agent.contact_first_name, agent.contact_name) ## title and instructions report.add_title(u'Commission report {} {}'.format( agent_name, report_date.strftime('%d/%m/%Y'))) ## Commission details report.add_heading(u'Commission Detail') table_headers = [ u'Order #', u'Client Name', u'Date Ordered', u'Date Paid', u'Order Amount' ] col_widths = [0.12, 0.33, 0.18, 0.18, 0.19] table_data = [] table_data.append(table_headers) for order in commission_items: table_data.append([ order[u'order #'], order[u'client name'], order[u'order data'], order[u'date paid'], order[u'sale total'], ]) report.add_table(table_data, col_widths) sales_total = 0 for s in commission_items: sales_total += s[u'sale total'] report.add_paragraph(u'''Sales total payments received: {} Commission owed: {} Please send your commission-note to S-Company ltd with this document attached''' .format(sales_total, commission_total)) # report.add_paragraph(u'Commission total: {}'.format(commission_total)) # report.add_paragraph(u'Please send your commission-note to S-Company ltd with this document attached') report.add_heading(u'Below our agreed percentages for your information:') for tier in agent.agentcommission_set.all(): report.add_text( u'{}% for sales greater then {}'.format(tier.percentage, tier.from_amount), 'Bullet') return report.print_document()
def production_notes_for_umbrella_product(umbrella_product, language='EN'): ''' function that returns a pdf-file with all production documentation for a collection It contains: - Collection name and number - Model name and number - Pictures - Extra production notes - Materials used, with name, type and sku - Available sizes ''' document = SuzysDocument() ## data base_sku = umbrella_product.base_sku collection = umbrella_product.collection collection_number = umbrella_product.collection.number model_type = umbrella_product.umbrella_product_model.get_product_type_display() model_number = umbrella_product.umbrella_product_model.number model_name = umbrella_product.umbrella_product_model.name ## styles title = 'Title' heading = 'Heading2' heading2 = 'Heading3' bullet = 'Bullet' text = 'BodyText' if language == 'EN': document.add_text(u'Production notes for {}'.format(base_sku), title) elif language == 'CZ': document.add_text(u'Poznámky k výrobě {}'.format(base_sku), title) document.add_text('{}'.format(datetime.date.today().strftime("%d %B, %Y")), title) if language == 'EN': document.add_text(u'Product details', heading) elif language == 'CZ': document.add_text(u'Detaily produkty', heading) if language == 'EN': document.add_text(u'Collection: {} {}'.format(collection, collection_number), bullet) elif language == 'CZ': document.add_text(u'Kolekce: {} {}'.format(collection, collection_number), bullet) if language == 'EN': document.add_text(u'Model type: {}'.format(model_type), bullet) elif language == 'CZ': document.add_text(u'Typ modelu: {}'.format(model_type), bullet) if language == 'EN': document.add_text(u'Model number: {} ({})'.format(model_number, model_name), bullet) elif language == 'CZ': document.add_text(u'Modelové číslo: {} ({})'.format(model_number, model_name), bullet) umbrella_product_images = umbrella_product.umbrellaproductimage_set.all() if len(umbrella_product_images) > 0: if language == 'EN': document.add_text('Product Images', heading) elif language == 'CZ': document.add_text(u'Obrázky výrobků', heading) for img in umbrella_product_images: path = img.image.path aspect_ratio = img.image.height / float(img.image.width) document.add_image(path, 0.4, aspect_ratio) ## FIXME: Below code renders blank images # number_of_columns = 4 # image_table_data = ImageTable(number_of_columns=number_of_columns, page_width=document.doc.width) # for img in umbrella_product.umbrellaproductimage_set.all(): # path = img.image.path # aspect_ratio = img.image.height / float(img.image.width) # image_table_data.add_image(path, aspect_ratio) # document.add_table(image_table_data.return_table_data(), # [document.doc.width / number_of_columns] * number_of_columns, # bold_header_row=False, # line_under_header_row=False) if language == 'EN': document.add_text(u'Available sizes', heading) elif language == 'CZ': document.add_text(u'Dostupné velikosti', heading) for model in umbrella_product.umbrella_product_model.productmodel_set.all(): size = '{} ({})'.format(model.size.short_size, model.size.full_size) document.add_text(size, bullet) if language == 'EN': document.add_text('Production notes', heading) elif language == 'CZ': document.add_text(u'Poznámky k výrobě', heading) for note in umbrella_product.umbrellaproductmodelproductionnote_set.all(): if language == 'EN': document.add_text(note.name_en, heading2) document.add_text(note.note_en, bullet) elif language == 'CZ': document.add_text(note.name_cz or note.name_en, heading2) document.add_text(note.note_cz or note.note_en, bullet) if note.image: aspect_ratio = note.image_optimised.height / float(note.image_optimised.width) document.add_image(note.image_optimised.path, 0.25, aspect_ratio) for note in umbrella_product.umbrella_product_model.umbrellaproductmodelproductionnote_set.all(): if language == 'EN': document.add_text(note.name_en, heading2) document.add_text(note.note_en, bullet) elif language == 'CZ': document.add_text(note.name_cz or note.name_en, heading2) document.add_text(note.note_cz or note.note_en, bullet) if note.image: aspect_ratio = note.image_optimised.height / float(note.image_optimised.width) document.add_image(note.image_optimised.path, 0.25, aspect_ratio) if language == 'EN': if umbrella_product.production_remark_en or umbrella_product.umbrella_product_model.production_remark_en: document.add_text('Important remark', heading) if umbrella_product.production_remark_en: document.add_text(umbrella_product.production_remark_en, text) if umbrella_product.umbrella_product_model.production_remark_en: document.add_text(umbrella_product.umbrella_product_model.production_remark_en, text) elif language == 'CZ': if umbrella_product.production_remark_en or umbrella_product.umbrella_product_model.production_remark_en: document.add_text(u'Důležité informace', heading) if umbrella_product.production_remark_en: document.add_text(umbrella_product.production_remark_cz or umbrella_product.production_remark_en, text) if umbrella_product.umbrella_product_model.production_remark_en: document.add_text(umbrella_product.umbrella_product_model.production_remark_cz or umbrella_product.umbrella_product_model.production_remark_en, text) if language == 'EN': document.add_text('Bill Of Materials', heading) elif language == 'CZ': document.add_text(u'Seznam materiálů', heading) table_widths = [0.5, 0.3, 0.2] if language == 'EN': table_data = [[ 'Material', 'SKU', 'Material Type', ]] elif language == 'CZ': table_data = [[ 'Material', 'SKU', 'Material Type', ]] for bom in umbrella_product.umbrellaproductbillofmaterial_set.all(): table_data.append([ bom.material, bom.material.sku, bom.material.get_mat_type_display(), ]) document.add_table(table_data, table_widths) if language == 'EN': document.add_text('List Of Patterns', heading) elif language == 'CZ': document.add_text(u'Seznam střihů', heading) table_widths = [0.1, 0.45, 0.25, 0.2] if language == 'EN': table_data = [[ 'Size', 'Pattern name', 'Type', 'Times to use', ]] elif language == 'CZ': table_data = [[ 'Size', 'Pattern name', 'Type', 'Times to use', ]] for product in umbrella_product.product_set.all(): for pattern in product.product_model.productmodelpattern_set.all(): if pattern.times_to_use > 0: table_data.append([ product.product_model.size.short_size, pattern.name, pattern.get_pattern_type_display(), pattern.times_to_use, ]) document.add_table(table_data, table_widths) if len(umbrella_product.umbrellaproductmodelproductionissue_set.all()) > 0 or\ len(umbrella_product.umbrella_product_model.umbrellaproductmodelproductionissue_set.all()) > 0: document.add_text('Known production issues', heading) for remark in umbrella_product.umbrellaproductmodelproductionissue_set.all(): if language == 'EN': document.add_text(remark.name_en, heading2) document.add_text(remark.note_en, bullet) elif language == 'CZ': document.add_text(remark.name_cz or remark.name_en, heading2) document.add_text(remark.note_cz or remark.note_en, bullet) if remark.image: aspect_ratio = remark.image_optimised.height / float(remark.image_optimised.width) document.add_image(remark.image_optimised.path, 0.25, aspect_ratio) for remark in umbrella_product.umbrella_product_model.umbrellaproductmodelproductionissue_set.all(): if language == 'EN': document.add_text(remark.name_en, heading2) document.add_text(remark.note_en, bullet) elif language == 'CZ': document.add_text(remark.name_cz or remark.name_en, heading2) document.add_text(remark.note_cz or remark.note_en, bullet) if remark.image: aspect_ratio = remark.image_optimised.height / float(remark.image_optimised.width) document.add_image(remark.image_optimised.path, 0.25, aspect_ratio) document.add_vertical_space(10) if language == 'EN': document.add_text('In case of questions, doubts or suggestions please contact Sascha ([email protected])', 'BodyTextCenter') elif language == 'CZ': document.add_text(u'V případě dotazů, pochybností nebo návrhů prosím kontaktujte [email protected]', 'BodyTextCenter') if language == 'CZ': glossary_items = [ u'Accessories - Doplňky', u'Barcode - Čárový kód', u'Bag – Kapsa, sáček uvnitř tašky/nosiče', u'Carrier - Taška, nosič', u'Cotton - Bavlna', u'Cushion - Polštář', u'Fabrics - Tkaniny', u'Foams - Pěny', u'Filling - Náplň', u'Fur - Kožešina, srst', u"Golden Suzy's Plaque - Zlata značka/deska Suzy's", u"Golden Suzy's plaque bottom attachments - Zlata značka/deska Suzy's - spodní přílohy", u"Hollow Fibres, wadding - Duté vlákno", u"Leather faux - Umělé kůže", u"PVC plate - PVC deska", u'Ribbon - Paska', u'Small Materials - Malé materiály', u'Wash label - Mycí štítek', u'Work Pramont - Práce Pramont', u'Zipper - Zip', ] document.add_text(u'Glosář', heading) [document.add_text(i, text) for i in glossary_items] return document.print_document()
def purchase_order_report(purchase_order): doc = SuzysDocument() doc.add_text( u'Purchase Order for {}'.format(purchase_order.supplier.business_name), 'Title') delivery_date = purchase_order.est_delivery or 'Unconfirmed' po_info = [ u'Our Reference: PO{}'.format(purchase_order.id), u'Delivery Date {}'.format(delivery_date), ] table_widths = [0.5, 0.5] doc.add_table([po_info], table_widths, bold_header_row=False, line_under_header_row=False, box_line=True) address_format = u'''{company.company_name} {company.address1} {company.address2} {company.postcode} {company.city} {company.country} VAT: {company.vat} ''' invoice_to = address_format.format( company=purchase_order.invoice_to).replace('\n', '<br></br>') deliver_to = address_format.format( company=purchase_order.ship_to.own_address).replace('\n', '<br></br>') doc.add_invoice_delivery_headers(invoice_to, deliver_to) doc.add_text('Items requested', 'Heading2') items_requested = [['Name', 'SKU', 'Quantity', 'Unit']] for item in purchase_order.purchaseorderitem_set.all(): items_requested.append([ item.material.name, item.material.sku_supplier, item.qty, item.material.get_unit_usage_display(), ]) doc.add_table(items_requested, [0.35, 0.35, 0.15, 0.15]) doc.add_vertical_space(10) doc.add_text( 'Thank you for swift confirmation, communication and delivery.', 'BodyTextCenter') return doc.print_document()
def export_pricelist_pdf(pricelist, include_stock=False, active_only=True): ''' export a pricelist to pdf ''' # Create the HttpResponse object with the appropriate PDF headers. document = SuzysDocument() if include_stock: document.add_title('Price- and Stocklist {} {}'.format( pricelist.name, datetime.date.today().strftime('%d/%m/%Y'))) else: document.add_title('Pricelist {} {}'.format( pricelist.name, datetime.date.today().strftime('%d/%m/%Y'))) document.add_heading('Products available') table_data_dict = get_pricelist_price_data(pricelist, include_stock=include_stock, active_only=active_only) table_data = [] table_data.append(table_data_dict[0].keys()) logger.debug('header looks like {}'.format(table_data)) [table_data.append(i.values()) for i in table_data_dict] logger.debug('full table_data looks like {}'.format(table_data)) if include_stock: table_columns_width = [0.2, 0.35, 0.10, 0.10, 0.10, 0.10, 0.10] else: table_columns_width = [0.2, 0.47, 0.11, 0.11, 0.11, 0.11] document.add_table(table_data, table_columns_width) document.add_paragraph( '''If the item you wish is not on stock, please consult us for delivery times.'''.strip().replace('\n', '')) # document.add_heading('Shipping prices') # table_data = get_transport_costs() # document.add_table(table_data, [0.33]*3) return document.print_document()