refactor: change print format type html to custom

This commit is contained in:
khushi8112
2025-10-10 15:50:50 +05:30
parent 50eb6786bf
commit 12ebab1657
9 changed files with 76 additions and 722 deletions

View File

@@ -282,6 +282,8 @@ class SalesInvoice(SellingController):
def before_print(self, settings=None):
from frappe.contacts.doctype.address.address import get_address_display_list
super().before_print(settings)
company_details = frappe.get_value(
"Company", self.company, ["company_logo", "website", "phone_no", "email"], as_dict=True
)
@@ -298,6 +300,14 @@ class SalesInvoice(SellingController):
]
if not all(required_fields):
if not frappe.has_permission("Company", "write", throw=False):
frappe.msgprint(
_(
"Some required Company details are missing. You don't have permission to update them. Please contact your System Manager."
)
)
return
frappe.publish_realtime(
"sales_invoice_before_print",
{

View File

@@ -1,330 +0,0 @@
{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead, footer, print_settings=None,
print_heading_template=None) -%}
{% if letter_head and not no_letterhead %}
<div class="letter-head">{{ letter_head }}</div>
{% endif %}
{% if print_heading_template %}
{{ frappe.render_template(print_heading_template, {"doc":doc}) }}
{% endif %}
{%- endmacro -%}
{% for page in layout %}
<div class="page-break invoice-page">
<div {% if print_settings.repeat_header_footer %} id="header-html" class="hidden-pdf" {% endif %}>
{{ add_header(loop.index, layout|len, doc, letter_head, no_letterhead, footer, print_settings) }}
</div>
<style>
.letter-head {
padding-top: 12px !important;
padding-bottom: 12px !important;
}
.invoice-page {
font-family: Inter, sans-serif;
color: #171717;
}
.print-format-body {
padding: 30px 12px 12px 12px !important;
}
.title {
color: #7c7c7c !important;
}
.text-muted {
color: #7c7c7c !important;
}
.text-dark {
color: #171717 !important;
}
.small-text {
font-size: 11px;
color: #666;
}
.text-left {
text-align: left;
}
.text-center {
text-align: center;
}
.text-right {
text-align: right;
}
.text-bold {
font-weight: 700;
}
.mt-15 {
margin-top: 15px;
}
.mt-16 {
margin-top: 16px;
}
.mt-40 {
margin-top: 40px;
}
.mw-400 {
max-width: 400px;
}
.items-table,
.tax-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
border-radius: 10px;
overflow: hidden;
}
.items-table td,
.tax-table td {
border-bottom: 1px solid #ededed;
padding: 8px;
}
.items-table thead td,
.tax-table thead td {
color: #7c7c7c !important;
}
.items-table thead tr:first-of-type td,
.tax-table thead tr:first-of-type td {
border-bottom: none;
}
.items-table thead tr:first-child td:first-child,
.tax-table thead tr:first-child td:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.items-table thead tr:first-child td:last-child,
.tax-table thead tr:first-child td:last-child {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
.in-words {
color: #171717 !important;
max-width: 400px;
word-wrap: break-word;
line-height: 1.5;
font-size: 12px;
}
.row-divider {
border-bottom: 1px solid #e9e9e9;
}
.highlight-bg {
background: #f8f8f8;
}
.info-card {
margin-top: 40px;
color: #7c7c7c;
}
.info-text {
margin-bottom: 12px;
}
.print-format {
color: #171717;
font-size: 14px;
font-style: normal;
font-weight: 420;
line-height: 21px;
padding: 0px !important;
margin-left: 0mm !important;
margin-right: 0mm !important;
}
.letter-head-footer {
margin-top: 0px !important;
}
.print-format-body td {
padding: 8px 8px !important;
}
.tax-table td,
.items-table td {
height: auto !important;
}
.tax-table thead td,
.items-table thead td {
height: 32px;
}
.item-img td {
border: none !important;
padding: 0px !important;
}
</style>
<div class="print-format-body">
<table class="info-table col-xs-12" style="width: 100%; margin-left: 12px">
<tr>
<td class="col-xs-6" style="padding: 0 !important">
<div class="title col-xs-5 p-0">
<div class="info-text">Customer Name:</div>
<div class="info-text">Bill to:</div>
</div>
<div class="col-xs-7">
<div class="info-text">{{ doc.customer_name }}</div>
<div class="info-text">
{% if doc.customer_address %}
{% set customer_address = frappe.get_doc("Address", doc.customer_address) %}
{{ customer_address.address_line1 or "" }}<br>
{% if customer_address.address_line2 %}{{ customer_address.address_line2 }}<br>{% endif %}
{{ customer_address.city or "" }} {{ customer_address.state or "" }} {{ customer_address.pincode or "" }} {{ customer_address.country or "" }}<br>
{% endif %}
</div>
</div>
</td>
<td class="col-xs-6" style="padding: 0 !important">
<div class="title col-xs-5 p-0">
<div class="info-text">Invoice Number:</div>
</div>
<div class="col-xs-7">
<div class="info-text">{{ doc.name }}</div>
</div>
<div class="title col-xs-5 p-0">
<div class="info-text">Invoice Date:</div>
</div>
<div class="col-xs-7">
<div class="info-text">{{ frappe.utils.format_date(doc.posting_date) }}</div>
</div>
<div class="title col-xs-5 p-0">
<div class="info-text">Payment Due Date:</div>
</div>
<div class="col-xs-7">
<div class="info-text">{{ frappe.utils.format_date(doc.due_date) }}</div>
</div>
</td>
</tr>
</table>
<!-- Items Table -->
{% set item_naming_by = frappe.db.get_single_value("Stock Settings", "item_naming_by") %}
<table class="items-table mt-15">
<thead class="highlight-bg">
<tr>
<td class=" text-center">{{ _("No") }}</td>
<td class="text-left">{{ _("Item") }}</td>
{% if item_naming_by != "Item Code" %}
<td class="text-left">{{ _("Item Code") }}</td>
{% endif %}
<td class="text-right">{{ _("Quantity") }}</td>
<td class="text-right">{{ _("Rate") }}</td>
<td class="text-right">{{ _("Amount") }}</td>
</tr>
</thead>
<tbody>
{% for item in doc.items %}
<tr>
<td class="text-center">{{ loop.index }}</td>
<td class="text-left">
<table class="item-img" style="border-collapse: collapse">
<tr>
{% if item.image %}
<td class="no-style" style="border-radius: 6px; vertical-align: middle">
<img
src="{{ item.image }}"
alt="{{ item.item_name }}"
style="
border-radius: 6px;
height: 24px;
width: 24px !important;
margin-right: 8px;
vertical-align: middle;
"
/>
</td>
{% endif %}
<td
class="no-style"
style="vertical-align: middle !important; padding: 0 !important"
>
{{ item.item_name }}
</td>
</tr>
</table>
</td>
{% if item_naming_by != "Item Code" %}
<td class="text-left">{{ item.item_code }}</td>
{% endif %}
<td class="text-right">{{ item.get_formatted("qty", 0) }} {{ item.uom }}</td>
<td class="text-right">{{ item.get_formatted("net_rate", doc) }}</td>
<td class="text-right">{{ item.get_formatted("net_amount", doc) }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<div class="test" style="float: right; margin-top: 15px; margin-bottom: 5px;">
<table style="width: 100%; border-collapse: collapse">
<tr class="row-divider">
<td class="text-right text-muted" style="padding-right: 30px !important;">{{ _("Sub Total:") }}</td>
<td class="text-right">{{ doc.get_formatted("total", doc) }}</td>
</tr>
{%- if doc.apply_discount_on == "Net Total" -%}
<tr class="row-divider">
<td class="text-right text-muted" style="padding-right: 30px !important;">
{{ _("Discount") }} ({{ doc.additional_discount_percentage }}%):
</td>
<td class="text-right">{{ doc.get_formatted("discount_amount", doc) }}</td>
</tr>
{%- endif -%}
{%- for tax in doc.taxes -%}
{%- if (tax.tax_amount or print_settings.print_taxes_with_zero_amount) and (not tax.included_in_print_rate or doc.flags.show_inclusive_tax_in_print) -%}
<tr class="row-divider">
<td class="text-right text-muted" style="padding-right: 30px !important;">{{ tax.get_formatted("description") }} ({{ tax.get_formatted("rate") }}%):</td>
<td class="text-right">{{ tax.get_formatted("tax_amount") }}</td>
</tr>
{%- endif -%}
{%- endfor -%}
{%- if doc.apply_discount_on == "Grand Total" -%}
<tr class="row-divider">
<td class="text-right text-muted" style="padding-right: 30px !important;">
{{ _("Discount") }} ({{ doc.additional_discount_percentage }}%):
</td>
<td class="text-right">{{ doc.get_formatted("discount_amount", doc) }}</td>
</tr>
{%- endif -%}
</table>
</div>
<div style="border-bottom: 1px solid #ededed;">
<table class="highlight-bg" style="width: 100%; border-collapse: collapse; border-radius: 12px; margin-bottom: 10px;">
<tr>
<td class="text-left mw-400">
<div class="text-capitalize">
<span class="title"> {{ _("In Words: ") }}</span>{{ doc.in_words }}
</div>
</td>
<td class="text-right"><b>{{ _("Grand Total:") }}</b></td>
<td class="text-right">
<span style="font-weight: 700">
{{ doc.get_formatted("grand_total", doc) }}
</span>
</td>
</tr>
</table>
</div>
<!-- Terms -->
{% if doc.terms %}
<div class="info-card">
<div class="title">{{ _("Terms and Conditions") }}</div>
{{ doc.terms}}
</div>
{% endif %}
</div>
</div>
{% endfor %}

View File

@@ -1,32 +0,0 @@
{
"absolute_value": 0,
"align_labels_right": 0,
"creation": "2025-09-15 16:31:00.732539",
"custom_format": 0,
"default_print_language": "en",
"disabled": 0,
"doc_type": "Sales Invoice",
"docstatus": 0,
"doctype": "Print Format",
"font_size": 14,
"idx": 0,
"line_breaks": 0,
"margin_bottom": 15.0,
"margin_left": 15.0,
"margin_right": 15.0,
"margin_top": 15.0,
"modified": "2025-09-15 16:31:00.732539",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Print Format Sales Invoice",
"owner": "Administrator",
"page_number": "Hide",
"pdf_generator": "wkhtmltopdf",
"print_format_builder": 0,
"print_format_builder_beta": 0,
"print_format_for": "DocType",
"print_format_type": "Jinja",
"raw_printing": 0,
"show_section_headings": 0,
"standard": "Yes"
}

View File

@@ -1,328 +0,0 @@
{%- macro add_header(page_num, max_pages, doc, letter_head, no_letterhead, footer, print_settings=None,
print_heading_template=None) -%}
{% if letter_head and not no_letterhead %}
<div class="letter-head">{{ letter_head }}</div>
{% endif %}
{% if print_heading_template %}
{{ frappe.render_template(print_heading_template, {"doc":doc}) }}
{% else %}
{% endif %}
{%- if doc.meta.is_submittable and doc.docstatus==2-%}
<div class="text-center" document-status="cancelled">
<h4 style="margin: 0px">{{ _("CANCELLED") }}</h4>
</div>
{%- endif -%}
{%- endmacro -%} {% for page in layout %}
<div class="page-break invoice-wrapper">
<div {% if print_settings.repeat_header_footer %} id="header-html" class="hidden-pdf" {% endif %}>
{{ add_header(loop.index, layout|len, doc, letter_head, no_letterhead, footer, print_settings) }}
</div>
<style>
.letter-head {
margin-top: 12px !important;
}
.invoice-wrapper {
font-family: "Inter", sans-serif;
color: var(--black-overlay-700);
}
.print-format-body {
padding: 30px 12px 12px 12px !important;
}
body {
margin-bottom: 0mm !important;
padding: 0px !important;
}
table.info-table,
table.items-table,
table.tax-table {
border-collapse: separate;
border-spacing: 0;
border: 1px solid #ededed;
border-radius: 10px;
overflow: hidden;
}
table.info-table td {
border-bottom: 1px solid #ededed;
padding: 8px 10px !important;
}
table.items-table td,
table.tax-table td {
border-bottom: 1px solid #ededed;
padding: 8px;
}
table.info-table td:not(:first-of-type),
table.items-table td:not(:first-of-type),
table.tax-table td:not(:first-of-type) {
border-left: 1px solid #ededed;
}
table.info-table tbody tr:last-of-type td,
table.items-table tbody tr:last-of-type td,
table.tax-table tbody tr:last-of-type td {
border-bottom: none;
}
thead.table-header {
background: #f8f8f8;
}
thead.table-header td {
color: #7c7c7c;
}
.text-center {
text-align: center;
}
.text-left {
text-align: left;
}
.text-right {
text-align: right;
}
.text-muted {
color: #7c7c7c;
}
.text-dark {
color: #525252;
}
.text-bold {
font-weight: bold;
}
.small-text {
color: #666;
}
.mt-10 {
margin-top: 10px;
}
.mt-15 {
margin-top: 15px;
}
.mt-20 {
margin-top: 20px;
}
.mt-40 {
margin-top: 40px;
}
.mt-80 {
margin-top: 80px;
}
.mb-20 {
margin-bottom: 20px;
}
.pb-8 {
padding-bottom: 8px;
}
.amount-width {
width: 110px;
}
.totals-table {
border-radius: 5px;
width: 100%;
}
.totals-table td {
padding: 4px 8px;
}
.totals-table tr {
border-bottom: 1px solid #ededed;
position: relative;
}
.totals-table tr td {
position: relative;
}
.totals-table tr td div {
width: 12%;
height: 14px;
background-color: white;
position: absolute;
bottom: -6px;
left: 0%;
color: white;
}
.totals-table tr:last-child {
border-bottom: none;
}
.totals-table .grand-total td {
padding: 6px 8px;
font-weight: bold;
}
.words-box {
background: #f8f8f8;
border-radius: 8px;
padding: 8px;
line-height: 21px;
letter-spacing: 0.21px;
font-size: small;
}
.info-card {
color: #7c7c7c;
}
.title {
color: #7c7c7c !important;
}
.heading {
color: #525252 !important;
font-weight: 300;
}
.print-format {
color: #171717;
font-size: 14px;
font-style: normal;
font-weight: 420;
line-height: 21px;
padding: 0px;
letter-spacing: 0.14px;
margin-left: 0mm !important;
margin-right: 0mm !important;
}
.letter-head-footer {
margin-top: 0px !important;
}
.print-heading {
margin-top: 0px !important;
margin-bottom: 0px !important;
padding-bottom: 0px !important;
}
</style>
<div class="print-format-body">
<table class="info-table mb-20" style="width: 100%">
<tr>
<td style="width: 50%">
<span class="heading">{{ _("Customer Name") }}:</span> {{doc.customer_name }}
</td>
<td style="width: 50%">
<span class="heading">{{ _("Payment Due Date") }}:</span> {{
frappe.utils.format_date(doc.due_date) }}
</td>
</tr>
<tr>
<td><span class="heading">{{ _("Invoice Number") }}:</span> {{ doc.name }}</td>
<td>
<span class="heading">{{ _("Invoice Date") }}:</span> {{
frappe.utils.format_date(doc.posting_date) }}
</td>
</tr>
<tr>
<td><span class="heading">{{ _("Bill From") }}:</span><br />
{% if doc.customer_address %}
{% set customer_address = frappe.get_doc("Address", doc.customer_address) %}
{{ doc.customer_name }}<br>
{{ customer_address.address_line1 or "" }}<br>
{% if customer_address.address_line2 %}{{ customer_address.address_line2 }}<br>{% endif %}
{{ customer_address.city or "" }} {{ customer_address.state or "" }} {{ customer_address.pincode or "" }} {{ customer_address.country or "" }}<br>
{% endif %}
</td>
<td><span class="heading">{{ _("Bill To") }}:</span><br />
{% if doc.company_address %}
{% set company_address_display = frappe.get_doc("Address", doc.company_address) %}
{{ doc.company }}<br>
{{ company_address_display.address_line1 or "" }}<br>
{% if company_address_display.address_line2 %}{{ company_address_display.address_line2 }}<br>{% endif %}
{{ company_address_display.city or "" }} {{ company_address_display.state or "" }} {{ company_address_display.pincode or "" }} {{ company_address_display.country or "" }}<br>
{% endif %}
</td>
</tr>
</table>
<!-- Items Table -->
{% set item_naming_by = frappe.db.get_single_value("Stock Settings", "item_naming_by") %}
<table class="items-table mt-15" style="width: 100%">
<thead class="table-header">
<tr>
<td class="text-center">{{ _("No") }}</td>
<td class="text-left">{{ _("Item") }}</td>
{% if item_naming_by != "Item Code" %}
<td class="text-left">{{ _("Item Code") }}</td>
{% endif %}
<td class="text-right">{{ _("Quantity") }}</td>
<td class="text-right">{{ _("Rate") }}</td>
<td class="text-right">{{ _("Amount") }}</td>
</tr>
</thead>
<tbody>
{% for item in doc.items %}
<tr>
<td class="text-center text-dark">{{ loop.index }}</td>
<td>{{ item.item_name }}</td>
{% if item_naming_by != "Item Code" %}
<td class="text-left">{{ item.item_code }}</td>
{% endif %}
<td class="text-right text-dark">{{ item.get_formatted("qty", 0) }} {{ item.uom }}</td>
<td class="text-right text-dark">{{ item.get_formatted("net_rate", doc) }}</td>
<td class="text-right" style="color: #171717">
{{ item.get_formatted("net_amount", doc) }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
<!-- Totals Section -->
<table style="width:100%; margin-top: 15px">
<td style="vertical-align: bottom !important; width: 60%;">
<p class="title">{{ _("Total in words") }}</p>
<div class="words-box text-uppercase">{{ doc.in_words }}</div>
</td>
<td>
&nbsp;
</td>
<td style="width: 38%;">
<table class="totals-table">
<tr>
<td class="text-right text-muted"><div></div>{{ _("Sub Total:") }}</td>
<td class="text-right amount-width">{{ doc.get_formatted("total", doc) }}</td>
</tr>
{%- if doc.apply_discount_on == "Net Total" -%}
<tr>
<td class="text-right text-muted">
<div></div>{{ _("Discount") }} ({{ doc.additional_discount_percentage }}%):
</td>
<td class="text-right amount-width">{{ doc.get_formatted("discount_amount", doc) }}</td>
</tr>
{%- endif -%}
{%- for tax in doc.taxes -%}
{%- if (tax.tax_amount or print_settings.print_taxes_with_zero_amount) and (not tax.included_in_print_rate or doc.flags.show_inclusive_tax_in_print) -%}
<tr>
<td class="text-right text-muted"><div></div>{{ tax.get_formatted("description") }} ({{ tax.get_formatted("rate") }}%):</td>
<td class="text-right amount-width">{{ tax.get_formatted("tax_amount") }}</td>
</tr>
{%- endif -%}
{%- endfor -%}
{%- if doc.apply_discount_on == "Grand Total" -%}
<tr>
<td class="text-right text-muted">
<div></div>{{ _("Discount") }} ({{ doc.additional_discount_percentage }}%):
</td>
<td class="text-right amount-width">{{ doc.get_formatted("discount_amount", doc) }}</td>
</tr>
{%- endif -%}
<tr class="grand-total">
<td class="text-right">{{ _("Grand Total:") }}</td>
<td class="text-right amount-width">{{ doc.get_formatted("grand_total", doc) }}</td>
</tr>
</table>
</td>
</table>
<!-- Terms -->
<div class="terms-section">
{% if doc.terms %}
<div class="info-card mt-40">
<div>{{ _("Terms and Conditions") }}</div>
{{ doc.terms}}
</div>
{% endif %}
</div>
</div>
{% endfor %}

View File

@@ -1,32 +0,0 @@
{
"absolute_value": 0,
"align_labels_right": 0,
"creation": "2025-08-28 04:03:36.284420",
"custom_format": 0,
"default_print_language": "en",
"disabled": 0,
"doc_type": "Sales Invoice",
"docstatus": 0,
"doctype": "Print Format",
"font_size": 14,
"idx": 0,
"line_breaks": 0,
"margin_bottom": 15.0,
"margin_left": 15.0,
"margin_right": 15.0,
"margin_top": 15.0,
"modified": "2025-10-08 22:18:52.241069",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Print Format",
"owner": "Administrator",
"page_number": "Hide",
"pdf_generator": "wkhtmltopdf",
"print_format_builder": 0,
"print_format_builder_beta": 0,
"print_format_for": "DocType",
"print_format_type": "Jinja",
"raw_printing": 0,
"show_section_headings": 0,
"standard": "Yes"
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long