From 79a8be363338ea2eb8fae386d2a2f252e26109b6 Mon Sep 17 00:00:00 2001 From: Achilles Rasquinha Date: Mon, 11 Dec 2017 15:10:32 +0530 Subject: [PATCH 1/4] [HOTFIX] Currency Format on Print (#4584) * [HOTFIX] fix currency issue on print * [HOTFIX] fix currency issue on print * added value check for format * added value check for format * fix codacy --- frappe/utils/data.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 168e0430c0..9eb5140b24 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -371,12 +371,17 @@ def fmt_money(amount, precision=None, currency=None): # 40,000 -> 40,000.00 # 40,000.00000 -> 40,000.00 # 40,000.23000 -> 40,000.23 + if decimal_str: parts = str(amount).split(decimal_str) decimals = parts[1] if len(parts) > 1 else '' if precision > 2: if len(decimals) < 3: - precision = 2 + if currency: + fraction = frappe.db.get_value("Currency", currency, "fraction_units") or 100 + precision = len(cstr(fraction)) - 1 + else: + precision = 2 elif len(decimals) < precision: precision = len(decimals) @@ -781,7 +786,7 @@ def make_filter_tuple(doctype, key, value): return [doctype, key, value[0], value[1]] else: return [doctype, key, "=", value] - + def scrub_urls(html): html = expand_relative_urls(html) # encoding should be responsibility of the composer From 8592d49c07a43f05534a3f23aecfdb50184d4226 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 12 Dec 2017 11:41:08 +0530 Subject: [PATCH 2/4] [fix] test for image files (#4602) --- frappe/public/js/frappe/misc/utils.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/public/js/frappe/misc/utils.js b/frappe/public/js/frappe/misc/utils.js index cfdbd16ee0..0b055ae6f5 100644 --- a/frappe/public/js/frappe/misc/utils.js +++ b/frappe/public/js/frappe/misc/utils.js @@ -537,6 +537,8 @@ frappe.utils = { }, is_image_file: function(filename) { + // url can have query params + filename = filename.split('?')[0]; return (/\.(gif|jpg|jpeg|tiff|png|svg)$/i).test(filename); }, @@ -635,4 +637,4 @@ if (!Array.prototype.uniqBy) { }) } }) -} \ No newline at end of file +} From 49b63d76802dfc82b5b272d9954c46f733829a56 Mon Sep 17 00:00:00 2001 From: Faris Ansari Date: Tue, 12 Dec 2017 19:04:38 +0530 Subject: [PATCH 3/4] Add is_image util (#4605) --- frappe/templates/print_formats/standard_macros.html | 2 +- frappe/utils/data.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/frappe/templates/print_formats/standard_macros.html b/frappe/templates/print_formats/standard_macros.html index a720b404f0..2257ac8d49 100644 --- a/frappe/templates/print_formats/standard_macros.html +++ b/frappe/templates/print_formats/standard_macros.html @@ -112,7 +112,7 @@ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}" {% elif df.fieldtype in ("Attach", "Attach Image") and doc[df.fieldname] - and (guess_mimetype(doc[df.fieldname])[0] or "").startswith("image/") %} + and frappe.utils.is_image(doc[df.fieldname]) %} {% elif df.fieldtype=="HTML" %} diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 9eb5140b24..6bf0cb8880 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -516,6 +516,13 @@ def is_html(text): break return out +def is_image(filepath): + from mimetypes import guess_type + + # filepath can be https://example.com/bed.jpg?v=129 + filepath = filepath.split('?')[0] + return (guess_type(filepath)[0] or "").startswith("image/") + # from Jinja2 code _striptags_re = re.compile(r'(|<[^>]*>)') From f8936c724e3a62d437446ef20d481d2b30136526 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 12 Dec 2017 19:35:50 +0600 Subject: [PATCH 4/4] bumped to version 9.2.23 --- frappe/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index edadfe4c74..a0fdf7c6c8 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -14,7 +14,7 @@ import os, sys, importlib, inspect, json from .exceptions import * from .utils.jinja import get_jenv, get_template, render_template, get_email_from_template -__version__ = '9.2.22' +__version__ = '9.2.23' __title__ = "Frappe Framework" local = Local()