mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-12 19:35:09 +00:00
fix: use qb for functions
This commit is contained in:
committed by
Akhil Narang
parent
ec4d4a0d6c
commit
d40e660a52
@@ -14,6 +14,7 @@ import openpyxl
|
||||
from frappe import _
|
||||
from frappe.core.doctype.data_import.data_import import DataImport
|
||||
from frappe.core.doctype.data_import.importer import Importer, ImportFile
|
||||
from frappe.query_builder.functions import Count
|
||||
from frappe.utils.background_jobs import enqueue
|
||||
from frappe.utils.file_manager import get_file, save_file
|
||||
from frappe.utils.xlsxutils import ILLEGAL_CHARACTERS_RE, handle_html
|
||||
@@ -371,7 +372,7 @@ def get_import_status(docname):
|
||||
|
||||
logs = frappe.get_all(
|
||||
"Data Import Log",
|
||||
fields=["count(*) as count", "success"],
|
||||
fields=[{"COUNT": "*", "as": "count"}, "success"],
|
||||
filters={"data_import": docname},
|
||||
group_by="success",
|
||||
)
|
||||
|
||||
@@ -71,7 +71,7 @@ class OpeningInvoiceCreationTool(Document):
|
||||
max_count = {}
|
||||
fields = [
|
||||
"company",
|
||||
"count(name) as total_invoices",
|
||||
{"COUNT": "*", "as": "total_invoices"},
|
||||
"sum(outstanding_amount) as outstanding_amount",
|
||||
]
|
||||
companies = frappe.get_all("Company", fields=["name as company", "default_currency as currency"])
|
||||
|
||||
@@ -74,7 +74,7 @@ class OpportunitySummaryBySalesStage:
|
||||
}[self.filters.get("based_on")]
|
||||
|
||||
data_based_on = {
|
||||
"Number": "count(name) as count",
|
||||
"Number": {"COUNT": "*", "as": "count"},
|
||||
"Amount": "opportunity_amount as amount",
|
||||
}[self.filters.get("data_based_on")]
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class SalesPipelineAnalytics:
|
||||
]
|
||||
|
||||
self.data_based_on = {
|
||||
"Number": "count(name) as count",
|
||||
"Number": {"COUNT": "*", "as": "count"},
|
||||
"Amount": "opportunity_amount as amount",
|
||||
}[self.filters.get("based_on")]
|
||||
|
||||
|
||||
@@ -10,6 +10,8 @@ import frappe
|
||||
from frappe import _, bold
|
||||
from frappe.core.doctype.version.version import get_diff
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from frappe.query_builder import Field
|
||||
from frappe.query_builder.functions import Count, IfNull, Sum
|
||||
from frappe.utils import cint, cstr, flt, get_link_to_form, parse_json, today
|
||||
from frappe.website.website_generator import WebsiteGenerator
|
||||
|
||||
@@ -1191,7 +1193,6 @@ def get_valuation_rate(data):
|
||||
2) If no value, get last valuation rate from SLE
|
||||
3) If no value, get valuation rate from Item
|
||||
"""
|
||||
from frappe.query_builder.functions import Count, IfNull, Sum
|
||||
from pypika import Case
|
||||
|
||||
item_code, company = data.get("item_code"), data.get("company")
|
||||
@@ -1482,7 +1483,10 @@ def add_non_stock_items_cost(stock_entry, work_order, expense_account, job_card=
|
||||
non_stock_items = frappe.get_all(
|
||||
"Item",
|
||||
fields="name",
|
||||
filters={"name": ("in", list(items.keys())), "ifnull(is_stock_item, 0)": 0},
|
||||
filters=[
|
||||
["name", "in", list(items.keys())],
|
||||
[IfNull(Field("is_stock_item"), 0), "=", 0],
|
||||
],
|
||||
as_list=1,
|
||||
)
|
||||
|
||||
@@ -1601,8 +1605,6 @@ def add_operations_cost(stock_entry, work_order=None, expense_account=None, job_
|
||||
)
|
||||
|
||||
def get_max_operation_quantity():
|
||||
from frappe.query_builder.functions import Sum
|
||||
|
||||
table = frappe.qb.DocType("Job Card")
|
||||
query = (
|
||||
frappe.qb.from_(table)
|
||||
@@ -1617,8 +1619,6 @@ def add_operations_cost(stock_entry, work_order=None, expense_account=None, job_
|
||||
return min([d.qty for d in query.run(as_dict=True)], default=0)
|
||||
|
||||
def get_utilised_corrective_cost():
|
||||
from frappe.query_builder.functions import Sum
|
||||
|
||||
table = frappe.qb.DocType("Stock Entry")
|
||||
subquery = (
|
||||
frappe.qb.from_(table)
|
||||
@@ -1728,7 +1728,10 @@ def item_query(doctype, txt, searchfield, start, page_len, filters):
|
||||
if not searchfields:
|
||||
searchfields = ["name"]
|
||||
|
||||
query_filters = {"disabled": 0, "ifnull(end_of_life, '3099-12-31')": (">", today())}
|
||||
query_filters = [
|
||||
["disabled", "=", 0],
|
||||
[IfNull(Field("end_of_life"), "3099-12-31"), ">", today()],
|
||||
]
|
||||
|
||||
or_cond_filters = {}
|
||||
if txt:
|
||||
|
||||
@@ -80,7 +80,7 @@ def get_filtered_data(filters):
|
||||
def get_bom_count(bom_data):
|
||||
data = frappe.get_all(
|
||||
"BOM Item",
|
||||
fields=["count(name) as count", "bom_no"],
|
||||
fields=[{"COUNT": "*", "as": "count"}, "bom_no"],
|
||||
filters={"bom_no": ("in", bom_data)},
|
||||
group_by="bom_no",
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ import frappe
|
||||
def execute():
|
||||
warehouse_perm = frappe.get_all(
|
||||
"User Permission",
|
||||
fields=["count(*) as p_count", "is_default", "user"],
|
||||
fields=[{"COUNT": "*", "as": "p_count"}, "is_default", "user"],
|
||||
filters={"allow": "Warehouse"},
|
||||
group_by="user",
|
||||
)
|
||||
|
||||
@@ -799,7 +799,7 @@ class EmailDigest(Document):
|
||||
"status": ["not in", ("Cancelled")],
|
||||
"company": self.company,
|
||||
},
|
||||
fields=["count(*) as count", "sum(grand_total) as grand_total"],
|
||||
fields=[{"COUNT": "*", "as": "count"}, "sum(grand_total) as grand_total"],
|
||||
)
|
||||
|
||||
def get_from_to_date(self):
|
||||
|
||||
@@ -7,6 +7,8 @@ import json
|
||||
import frappe
|
||||
from frappe import _, throw
|
||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||
from frappe.query_builder import Field
|
||||
from frappe.query_builder.functions import IfNull
|
||||
from frappe.utils import cint
|
||||
from frappe.utils.caching import request_cache
|
||||
from frappe.utils.nestedset import NestedSet
|
||||
@@ -197,10 +199,12 @@ def get_children(doctype, parent=None, company=None, is_root=False, include_disa
|
||||
include_disabled = json.loads(include_disabled)
|
||||
|
||||
fields = ["name as value", "is_group as expandable"]
|
||||
|
||||
filters = [
|
||||
["ifnull(`parent_warehouse`, '')", "=", parent],
|
||||
[IfNull(Field("parent_warehouse"), ""), "=", parent],
|
||||
["company", "in", (company, None, "")],
|
||||
]
|
||||
|
||||
if frappe.db.has_column(doctype, "disabled") and not include_disabled:
|
||||
filters.append(["disabled", "=", False])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user