fix: Postgres Compatibility for Standard Views

Core/User DocType: Add 'group_by' for PostgreSQL

Signed-off-by: Verequies <hamishclaxton@gmail.com>

fix: Postgres Compatibility for Standard Views

Desk/Dashboard DocType: Fix lowercase table name

Signed-off-by: Verequies <hamishclaxton@gmail.com>

Desk/Page/Setup Wizard: Fix data not being commited to database

Signed-off-by: Verequies <hamishclaxton@gmail.com>

Model/db_query: Fix queries with order_by and group_by for PostgreSQL

Signed-off-by: Verequies <hamishclaxton@gmail.com>

Model/db_query: Fix order_by without table name for PostgreSQL

Signed-off-by: Verequies <hamishclaxton@gmail.com>
This commit is contained in:
Verequies 2021-06-22 13:40:41 +10:00 committed by Gavin D'souza
parent 87adfb5ebd
commit 379342d0ca
4 changed files with 18 additions and 7 deletions

View file

@ -36,11 +36,8 @@ class UserType(Document):
if not self.user_doctypes:
return
modules = frappe.get_all("DocType",
fields=["module"],
filters={"name": ("in", [d.document_type for d in self.user_doctypes])},
distinct=True,
)
modules = frappe.get_all('DocType', fields=['distinct module as module'],
filters={'name': ('in', [d.document_type for d in self.user_doctypes])}, group_by='module')
self.set('user_type_modules', [])
for row in modules:

View file

@ -14,7 +14,7 @@ class Dashboard(Document):
if self.is_default:
# make all other dashboards non-default
frappe.db.sql('''update
tabDashboard set is_default = 0 where name != %s''', self.name)
`tabDashboard` set is_default = 0 where name != %s''', self.name)
if frappe.conf.developer_mode and self.is_standard:
export_to_files(record_list=[['Dashboard', self.name, self.module + ' Dashboard']], record_module=self.module)

View file

@ -388,7 +388,6 @@ def make_records(records, debug=False):
# LOG every success and failure
for record in records:
doctype = record.get("doctype")
condition = record.get('__condition')
@ -405,6 +404,7 @@ def make_records(records, debug=False):
try:
doc.insert(ignore_permissions=True)
frappe.db.commit()
except frappe.DuplicateEntryError as e:
# print("Failed to insert duplicate {0} {1}".format(doctype, doc.name))

View file

@ -128,6 +128,20 @@ class DatabaseQuery(object):
args.fields = 'distinct ' + args.fields
args.order_by = '' # TODO: recheck for alternative
if args.order_by and args.group_by:
order_field = args.order_by
for r in (" order by ", " asc", " ASC", " desc", " DESC"):
order_field = order_field.replace(r, "")
if not order_field in args.fields:
order_fieldm = order_field.replace("`", "")
if "." in order_fieldm:
args.fields += ", MAX(" + order_fieldm.split(".")[1] + ") as `" + order_fieldm + "`"
else:
args.fields += ", MAX(" + order_fieldm + ") as `" + order_fieldm + "`"
args.order_by = args.order_by.replace(order_field, "`" + order_fieldm + "`")
query = """select %(fields)s
from %(tables)s
%(conditions)s