Sales Invoice Print Issue

Hi…when I take print of sales invoice, the following error is showing:

Traceback (most recent call last):
File “apps/frappe/frappe/website/serve.py”, line 18, in get_response
response = renderer_instance.render()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 78, in render
html = self.get_html()
File “apps/frappe/frappe/website/utils.py”, line 510, in cache_html_decorator
html = func(*args, **kwargs)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 89, in get_html
self.update_context()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 157, in update_context
data = self.run_pymodule_method(“get_context”)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 219, in run_pymodule_method
return method(self.context)
File “apps/frappe/frappe/www/printview.py”, line 51, in get_context
body = get_rendered_template(
File “apps/frappe/frappe/www/printview.py”, line 153, in get_rendered_template
format_data_map[df.get(“fieldname”)] = df
AttributeError: ‘str’ object has no attribute ‘get’

When I download PDF, the following error shows there:
Traceback (most recent call last):
File “apps/frappe/frappe/website/serve.py”, line 18, in get_response
response = renderer_instance.render()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 78, in render
html = self.get_html()
File “apps/frappe/frappe/website/utils.py”, line 510, in cache_html_decorator
html = func(*args, **kwargs)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 89, in get_html
self.update_context()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 157, in update_context
data = self.run_pymodule_method(“get_context”)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 219, in run_pymodule_method
return method(self.context)
File “apps/frappe/frappe/www/printview.py”, line 51, in get_context
body = get_rendered_template(
File “apps/frappe/frappe/www/printview.py”, line 153, in get_rendered_template
format_data_map[df.get(“fieldname”)] = df
AttributeError: ‘str’ object has no attribute ‘get’

Please guide, how to fixit. Thanks

Hi @Naveed1
If you are not using the standard format of sales invoice. Please find the format which is Standard = Yes and Custom Format = 1. Maybe the problem is with your html code in that format.

Hi @Safvan_Ph Hope you are fine. Actually in Standard Sales Invoice print and PDF both are OK. Actually I have created another print format Standard Modified, in this print format system throws an error.

Kindly suggest me how to fix it. Thanks

Hi @Naveed1
Kindly share both html and css code. then we can review the code.

PRINT STYLE: REDESIGN CSS:

.print-format {
font-size: 13px;
background: white;
}

.print-heading {
border-bottom: 1px solid #f4f5f6;
padding-bottom: 5px;
margin-bottom: 10px;
}

.print-heading h2 {
font-size: 24px;
}

.print-heading h2 div {
font-weight: 600;
}

.print-heading small {
font-size: 13px !important;
font-weight: normal;
line-height: 2.5;
color: #4c5a67;
}

.print-format .letter-head {
margin-bottom: 30px;
}

.print-format label {
font-weight: normal;
font-size: 13px;
color: #4C5A67;
margin-bottom: 0;
}

.print-format .data-field {
margin-top: 0;
margin-bottom: 0;
}

.print-format .value {
color: #192734;
line-height: 1.8;
}

.print-format .section-break:not(:last-child) {
margin-bottom: 0;
}

.print-format .row:not(.section-break) {
line-height: 1.6;
margin-top: 15px !important;
}

.print-format .important .value {
font-size: 13px;
font-weight: 600;
}

.print-format th {
color: #74808b;
font-weight: normal;
border-bottom-width: 1px !important;
}

.print-format .table-bordered td, .print-format .table-bordered th {
border: 1px solid #f4f5f6;
}

.print-format .table-bordered {
border: 1px solid #f4f5f6;
}

.print-format td, .print-format th {
padding: 10px !important;
}

.print-format .primary.compact-item {
font-weight: normal;
}

.print-format table td .value {
font-size: 12px;
line-height: 1.8;
}

PRINT ERROR:

Traceback (most recent call last):
File “apps/frappe/frappe/website/serve.py”, line 18, in get_response
response = renderer_instance.render()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 78, in render
html = self.get_html()
File “apps/frappe/frappe/website/utils.py”, line 510, in cache_html_decorator
html = func(*args, **kwargs)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 89, in get_html
self.update_context()
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 157, in update_context
data = self.run_pymodule_method(“get_context”)
File “apps/frappe/frappe/website/page_renderers/template_page.py”, line 219, in run_pymodule_method
return method(self.context)
File “apps/frappe/frappe/www/printview.py”, line 51, in get_context
body = get_rendered_template(
File “apps/frappe/frappe/www/printview.py”, line 153, in get_rendered_template
format_data_map[df.get(“fieldname”)] = df
AttributeError: ‘str’ object has no attribute ‘get’

Hi @Naveed1
Did you add any jinja code in the format?. Please check using Edit Format Button

No. I have not used jinja. When I click at edit format and then click show preview the following error shows

Traceback (most recent call last):
File “apps/frappe/frappe/utils/weasyprint.py”, line 241, in import_weasyprint
from weasyprint import CSS, HTML
File “env/lib/python3.10/site-packages/weasyprint/init.py”, line 469, in
from .css import preprocess_stylesheet # noqa isort:skip
File “env/lib/python3.10/site-packages/weasyprint/css/init.py”, line 27, in
from . import computed_values, counters, media_queries
File “env/lib/python3.10/site-packages/weasyprint/css/computed_values.py”, line 15, in
from … import text
File “env/lib/python3.10/site-packages/weasyprint/text.py”, line 11, in
import cairocffi as cairo
File “env/lib/python3.10/site-packages/cairocffi/init.py”, line 48, in
cairo = dlopen(
File “env/lib/python3.10/site-packages/cairocffi/init.py”, line 45, in dlopen
raise OSError(error_message) # pragma: no cover
OSError: no library called “cairo” was found
no library called “libcairo-2” was found
cannot load library ‘libcairo.so.2’: libcairo.so.2: cannot open shared object file: No such file or directory
cannot load library ‘libcairo.2.dylib’: libcairo.2.dylib: cannot open shared object file: No such file or directory
cannot load library ‘libcairo-2.dll’: libcairo-2.dll: cannot open shared object file: No such file or directory

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “apps/frappe/frappe/app.py”, line 69, in application
response = frappe.api.handle()
File “apps/frappe/frappe/api.py”, line 54, in handle
return frappe.handler.handle()
File “apps/frappe/frappe/handler.py”, line 45, in handle
data = execute_cmd(cmd)
File “apps/frappe/frappe/handler.py”, line 83, in execute_cmd
return frappe.call(method, **frappe.form_dict)
File “apps/frappe/frappe/init.py”, line 1598, in call
return fn(*args, **newargs)
File “apps/frappe/frappe/utils/weasyprint.py”, line 13, in download_pdf
pdf = generator.render_pdf()
File “apps/frappe/frappe/utils/weasyprint.py”, line 105, in render_pdf
HTML, CSS = import_weasyprint()
File “apps/frappe/frappe/utils/weasyprint.py”, line 253, in import_weasyprint
frappe.throw(message)
File “apps/frappe/frappe/init.py”, line 523, in throw
msgprint(
File “apps/frappe/frappe/init.py”, line 491, in msgprint
_raise_exception()
File “apps/frappe/frappe/init.py”, line 443, in _raise_exception
raise raise_exception(msg)
frappe.exceptions.ValidationError: WeasyPrint depdends on additional system dependencies.
Follow instructions specific to your operating system:
https://doc.courtbouillon.org/weasyprint/stable/first_steps.html