""" Create custom Print Format for Sales Invoice — Gigafibre/TARGO style. Inspired by Cogeco layout: summary page 1, details page 2, envelope window address. Run inside erpnext-backend-1: /home/frappe/frappe-bench/env/bin/python /home/frappe/frappe-bench/setup_invoice_print_format.py """ import os, sys os.chdir("/home/frappe/frappe-bench/sites") import frappe frappe.init(site="erp.gigafibre.ca", sites_path=".") frappe.connect() print("Connected:", frappe.local.site) # ── Update Print Settings to Letter size ── from frappe.installer import update_site_config frappe.db.set_single_value("Print Settings", "pdf_page_size", "Letter") frappe.db.commit() print(" PDF page size set to Letter") # ── Register the logo file if not exists ── if not frappe.db.exists("File", {"file_url": "/files/targo-logo-green.svg"}): f = frappe.get_doc({ "doctype": "File", "file_name": "targo-logo-green.svg", "file_url": "/files/targo-logo-green.svg", "is_private": 0, }) f.insert(ignore_permissions=True) frappe.db.commit() print(" Registered logo file") PRINT_FORMAT_NAME = "Facture TARGO" html_template = r""" {%- set company_name = "TARGO Communications" -%} {%- set company_addr = "123 rue Principale" -%} {%- set company_city = "Victoriaville QC G6P 1A1" -%} {%- set company_tel = "(819) 758-1555" -%} {%- set company_web = "gigafibre.ca" -%} {%- set tps_no = "TPS: #819304698RT0001" -%} {%- set tvq_no = "TVQ: #1215640113TQ0001" -%} {%- set brand_green = "#019547" -%} {%- set brand_light = "#e8f5ee" -%} {%- set is_credit = doc.is_return == 1 -%} {%- set mois_fr = {"January":"janvier","February":"février","March":"mars","April":"avril","May":"mai","June":"juin","July":"juillet","August":"août","September":"septembre","October":"octobre","November":"novembre","December":"décembre"} -%} {%- macro date_fr(d) -%} {%- if d -%} {%- set dt = frappe.utils.getdate(d) -%} {{ dt.day }} {{ mois_fr.get(dt.strftime("%B"), dt.strftime("%B")) }} {{ dt.year }} {%- else -%}—{%- endif -%} {%- endmacro -%} {%- macro date_short(d) -%} {%- if d -%} {%- set dt = frappe.utils.getdate(d) -%} {{ "%02d/%02d/%04d" | format(dt.day, dt.month, dt.year) }} {%- else -%}—{%- endif -%} {%- endmacro -%} {# Decode HTML entities in item names #} {%- macro clean(s) -%}{{ s | replace("'", "'") | replace("&", "&") | replace("<", "<") | replace(">", ">") | replace(""", '"') if s else "" }}{%- endmacro -%} {# Get customer address from Service Location or address_display #} {%- set cust_addr = doc.address_display or "" -%} {%- if not cust_addr and doc.customer_address -%} {%- set addr_doc = frappe.get_doc("Address", doc.customer_address) -%} {%- set cust_addr = (addr_doc.address_line1 or "") + "\n" + (addr_doc.city or "") + " " + (addr_doc.state or "") + " " + (addr_doc.pincode or "") -%} {%- endif -%}
| {% if is_credit %}NOTE DE CRÉDIT{% else %}FACTURE{% endif %} |
|
Services fournis à
{{ doc.customer_name or doc.customer }}
{% if cust_addr %}
{{ cust_addr | striptags | replace("\n","
{% endif %}
") }} |
|
| {% if is_credit %}MONTANT CRÉDITÉ{% else %}MONTANT TOTAL DÛ{% endif %} | {{ frappe.utils.fmt_money(doc.grand_total | abs, currency=doc.currency) }} |
| Solde antérieur | {{ frappe.utils.fmt_money((doc.outstanding_amount or 0) - (doc.grand_total or 0), currency=doc.currency) }} |
| Frais du mois courant | |
| {{ group }} | {{ frappe.utils.fmt_money(amount, currency=doc.currency) }} |
| Sous-total avant taxes | {{ frappe.utils.fmt_money(doc.net_total, currency=doc.currency) }} |
| {{ "TPS" if "TPS" in (tax.description or tax.account_head or "") else "TVQ" }} ({{ tax.rate }}%) | {{ frappe.utils.fmt_money(tax.tax_amount, currency=doc.currency) }} |
| Total du mois courant | {{ frappe.utils.fmt_money(doc.grand_total, currency=doc.currency) }} |
|
Contactez-nous {{ company_tel }} {{ company_web }} |
Service à la clientèle Lun-Ven 8h-17h info@gigafibre.ca |
QR |
Payez en ligne Scannez le code QR ou visitez {{ company_web }}/payer |
Montant versé ________ |
Nº de compte {{ doc.customer }} |
Date d'échéance {{ date_short(doc.due_date) }} |
Montant à payer {{ frappe.utils.fmt_money(doc.grand_total | abs, currency=doc.currency) }} |
|
Nº de facture: {{ doc.name }} Nº de compte: {{ doc.customer }} Date: {{ date_fr(doc.posting_date) }} |
| Description | Qté | Prix unit. | Montant |
|---|---|---|---|
| {{ clean(item.item_name or item.item_code) }} | {{ item.qty | int if item.qty == (item.qty | int) else item.qty }} | {{ frappe.utils.fmt_money(item.rate, currency=doc.currency) }} | {{ frappe.utils.fmt_money(item.amount, currency=doc.currency) }} |
| Sous-total avant taxes | {{ frappe.utils.fmt_money(doc.net_total, currency=doc.currency) }} | ||
| {{ "TPS" if "TPS" in (tax.description or tax.account_head or "") else "TVQ" }} ({{ tax.rate }}%) | {{ frappe.utils.fmt_money(tax.tax_amount, currency=doc.currency) }} | ||
| TOTAL | {{ frappe.utils.fmt_money(doc.grand_total, currency=doc.currency) }} | ||