added multiple fixes to report generating
This commit is contained in:
+34
-23
@@ -361,50 +361,61 @@ Generate at end of processing and save as a file:
|
||||
|
||||
## **PDF Report Generation**
|
||||
|
||||
After completing Step 3, generate a professional PDF report using `reportlab`. The PDF serves as the primary deliverable for the traffic team to review and act on. Install with `pip install reportlab --break-system-packages` if not available.
|
||||
After completing Step 3, generate the PDF report by running **`generate_report.py`** (in this same skill folder). This script contains all layout, branding, classification logic, and table formatting. Do NOT write PDF generation code from scratch — always use this script.
|
||||
|
||||
### PDF Structure
|
||||
```bash
|
||||
python generate_report.py <orders_json> <hubspot_tickets_json> <output_pdf> [--date "DD Month YYYY"]
|
||||
```
|
||||
|
||||
The report has three main sections, each starting on a new page:
|
||||
**Example:**
|
||||
```bash
|
||||
python generate_report.py s3_today.json hs_tickets.json delay-list-step3-report-2026-04-10.pdf --date "10 April 2026"
|
||||
```
|
||||
|
||||
The script requires two input JSON files:
|
||||
- **orders_json** — the Step 3 filtered orders (output of the delay list API filtering in Step 3 above). List of order objects with keys: `id_order_detail`, `id_order`, `supplier_name`, `product_tid`, `despatch_date_target`, `supplier_order_number`, `carriername`.
|
||||
- **hubspot_tickets_json** — merged HubSpot ticket search results from the mandatory 3-step search. List of ticket objects with nested `properties` containing: `hs_ticket_id`, `hp_order_line_id`, `subject`, `content`, `createdate`.
|
||||
|
||||
The script handles all classification (HubSpot 5-category split, Flyeralarm/Probo/Masterprint separation, Probo delay email detection, outreach grouping) and generates the branded PDF automatically.
|
||||
|
||||
> **Styling reference:** All colours, fonts, layout specs, table column widths, and section structure are also documented in **`REPORT-STYLE.md`** (in this same skill folder) for reference. The script implements these specs. If you need to modify the visual design, update both the script and REPORT-STYLE.md.
|
||||
|
||||
### PDF Structure & Content
|
||||
|
||||
The report has three main sections, each starting on a new page. The exact visual design (colours, fonts, column widths, spacing) is specified in `REPORT-STYLE.md`. Below is the content specification:
|
||||
|
||||
**Page 1 — Cover & Summary**
|
||||
- Title block with dark background: "Delay List Report — Step 3: Supplier Outreach Analysis" + date
|
||||
- Summary stat cards in a grid layout showing: Total Orders, HubSpot Hits, Need Outreach, Internal Issues, Masterprint (Skipped), Flyeralarm (Manual), Probo (Manual), Suppliers to Contact
|
||||
- Title block: "Delay List Report" + "Step 3: Supplier Outreach Analysis" + date
|
||||
- Summary stat cards (2×4 grid): Total Orders, HubSpot Hits, Need Outreach, Internal Issues, Masterprint (Skipped), Flyeralarm (Manual), Probo (Manual), Suppliers to Contact
|
||||
- Caveat note about HubSpot search scope limitations
|
||||
|
||||
**Section 1 — HubSpot Analysis**
|
||||
Colour-coded tables categorising orders with existing communication:
|
||||
- **1.1 Internal Issues** (red header) — orders blocked by artwork errors, API failures, retry limits, price disputes. These need Helloprint action, not supplier outreach.
|
||||
- **1.2 In Production / On Track / Reprints** (green header) — orders confirmed in production or with reprints underway. No outreach needed.
|
||||
- **1.3 Other Statuses** (blue header) — shipped, awaiting approval, customer issues, unclear status.
|
||||
- **1.4 HubSpot Tickets Found — Review Needed** (orange header) — tickets exist but need manual review to determine action.
|
||||
- **1.1 Internal Issues** — orders blocked by artwork errors, API failures, retry limits, price disputes. These need Helloprint action, not supplier outreach.
|
||||
- **1.2 In Production / On Track** — orders confirmed in production with delay reason, reprints underway. No outreach needed.
|
||||
- **1.3 Shipped** — orders where tracking/shipping confirmation was found.
|
||||
- **1.4 Other Statuses** — awaiting approval, customer issues, unclear status.
|
||||
- **1.5 HubSpot Tickets Found — Review Needed** — tickets exist but need manual review to determine action.
|
||||
|
||||
Each table has 4 columns: **Ticket ID** (the real HubSpot `hs_ticket_id`), **Order Detail ID** (`id_order_detail`), **Order ID** (`id_order`), **Details** (summary of the issue/status). The Ticket ID must be the actual HubSpot ticket identifier — do NOT use the `id_order_detail` as Ticket ID. When performing the HubSpot search, always store the returned `hs_ticket_id` alongside the matched `hp_order_line_id` / `hp_order_id` so they can be rendered correctly in the report. Use Paragraph flowables for the Details column to allow text wrapping.
|
||||
|
||||
**Section 2 — Manual Action Required**
|
||||
- **Flyeralarm** — order table with note that portal case creation is required
|
||||
- **Probo** — order table with note to verify in Probo portal
|
||||
- **Flyeralarm** — order table with instruction text, columns: Order Detail ID, Order ID, Supplier, Product, Target Dispatch
|
||||
- **Probo** — order table with instruction text, columns: Order Detail ID, Order ID, Product, Target Dispatch, **Delay Email?** (Yes/No — whether a Probo delay email was found in HubSpot)
|
||||
- **Masterprint** — count + note that tracking is automated
|
||||
|
||||
**Section 3 — Supplier Outreach Emails**
|
||||
For each supplier (sorted by order count descending):
|
||||
- Supplier heading with order count
|
||||
- Supplier heading with order count (format: "Supplier Name — N order(s)")
|
||||
- Draft email using the standard email template (see Email Template section above)
|
||||
- Embedded order table within the email block
|
||||
|
||||
### PDF Styling
|
||||
### Implementation Notes
|
||||
|
||||
Use these design principles for a clean, professional look:
|
||||
These notes apply if you ever need to modify `generate_report.py`:
|
||||
|
||||
- **Colours**: Dark navy (#1a1a2e) for title block, blue (#0f3460) for section headers, red (#e94560) for internal issues, green (#27ae60) for on-track, orange (#f39c12) for review-needed, blue (#2980b9) for other statuses
|
||||
- **Fonts**: Helvetica family (Bold for headers, Regular for body)
|
||||
- **Tables**: Dark header row with white text, alternating row backgrounds, thin grid lines (#bdc3c7), compact padding (2-3pt)
|
||||
- **Page**: A4, 18mm left/right margins, header line with "Helloprint | Delay List Step 3 Report | [date]", footer with "Confidential - Helloprint Operations" and page number
|
||||
- **Email blocks**: Separated by horizontal rules (blue #2980b9), not wrapped in a single table cell (large supplier email blocks with many orders must be able to split across pages)
|
||||
|
||||
### Implementation Note
|
||||
|
||||
Do NOT wrap email blocks in a single-cell Table flowable — suppliers with many orders (e.g. Yurchak with 40+ orders) will overflow a single page and cause a LayoutError. Instead, use individual flowables (Paragraph, Table, Spacer) separated by HRFlowable dividers. This allows reportlab to split content naturally across page breaks.
|
||||
- Do NOT wrap email blocks in a single-cell Table flowable — suppliers with many orders will overflow a single page and cause a LayoutError. Use individual flowables separated by HRFlowable dividers. `KeepTogether` only for supplier blocks with ≤5 orders.
|
||||
- All table cell values must be wrapped in `Paragraph` flowables (via the `w()` helper) to enable automatic line-breaking. Plain strings will overflow their columns.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user