refactor: improved for readability
This commit is contained in:
parent
e1aa309b87
commit
d93b060f22
1 changed files with 10 additions and 5 deletions
|
|
@ -19,8 +19,6 @@ from frappe.model.utils.user_settings import get_user_settings, update_user_sett
|
|||
from frappe.utils import flt, cint, get_time, make_filter_tuple, get_filter, add_to_date, cstr, nowdate
|
||||
from frappe.model.meta import get_table_columns
|
||||
|
||||
MYSQL_METHODS = ('COUNT(', 'AVG(', 'SUM')
|
||||
|
||||
class DatabaseQuery(object):
|
||||
def __init__(self, doctype, user=None):
|
||||
self.doctype = doctype
|
||||
|
|
@ -286,10 +284,17 @@ class DatabaseQuery(object):
|
|||
def set_field_tables(self):
|
||||
'''If there are more than one table, the fieldname must not be ambiguous.
|
||||
If the fieldname is not explicitly mentioned, set the default table'''
|
||||
def _in_standard_sql_methods(field):
|
||||
methods = ('COUNT(', 'AVG(', 'SUM(')
|
||||
for method in methods:
|
||||
if method in field.upper():
|
||||
return True
|
||||
return False
|
||||
|
||||
if len(self.tables) > 1:
|
||||
for i, f in enumerate(self.fields):
|
||||
if '.' not in f and not sum([int(method in f.upper()) for method in MYSQL_METHODS]):
|
||||
self.fields[i] = '{0}.{1}'.format(self.tables[0], f)
|
||||
for idx, field in enumerate(self.fields):
|
||||
if '.' not in field and not _in_standard_sql_methods(field):
|
||||
self.fields[idx] = '{0}.{1}'.format(self.tables[0], field)
|
||||
|
||||
def set_optional_columns(self):
|
||||
"""Removes optional columns like `_user_tags`, `_comments` etc. if not in table"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue