mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-14 01:20:41 +00:00
refactor(postgres): port POS Profile doctype queries to the query builder
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -118,14 +118,21 @@ class POSProfile(Document):
|
|||||||
|
|
||||||
def validate_default_profile(self):
|
def validate_default_profile(self):
|
||||||
for row in self.applicable_for_users:
|
for row in self.applicable_for_users:
|
||||||
res = frappe.db.sql(
|
pfu = frappe.qb.DocType("POS Profile User")
|
||||||
"""select pf.name
|
pf = frappe.qb.DocType("POS Profile")
|
||||||
from
|
res = (
|
||||||
`tabPOS Profile User` pfu, `tabPOS Profile` pf
|
frappe.qb.from_(pfu)
|
||||||
where
|
.inner_join(pf)
|
||||||
pf.name = pfu.parent and pfu.user = %s and pf.name != %s and pf.company = %s
|
.on(pf.name == pfu.parent)
|
||||||
and pfu.default=1 and pf.disabled = 0""",
|
.select(pf.name)
|
||||||
(row.user, self.name, self.company),
|
.where(
|
||||||
|
(pfu.user == row.user)
|
||||||
|
& (pf.name != self.name)
|
||||||
|
& (pf.company == self.company)
|
||||||
|
& (pfu.default == 1)
|
||||||
|
& (pf.disabled == 0)
|
||||||
|
)
|
||||||
|
.run()
|
||||||
)
|
)
|
||||||
|
|
||||||
if row.default and res:
|
if row.default and res:
|
||||||
@@ -265,10 +272,11 @@ def get_permitted_nodes(group_type):
|
|||||||
|
|
||||||
def get_child_nodes(group_type, root):
|
def get_child_nodes(group_type, root):
|
||||||
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
lft, rgt = frappe.db.get_value(group_type, root, ["lft", "rgt"])
|
||||||
return frappe.db.sql(
|
return frappe.get_all(
|
||||||
f""" Select name, lft, rgt from `tab{group_type}` where
|
group_type,
|
||||||
lft >= {lft} and rgt <= {rgt} order by lft""",
|
filters={"lft": [">=", lft], "rgt": ["<=", rgt]},
|
||||||
as_dict=1,
|
fields=["name", "lft", "rgt"],
|
||||||
|
order_by="lft",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -278,40 +286,33 @@ def pos_profile_query(doctype: str, txt: str, searchfield: str, start: int, page
|
|||||||
user = frappe.session["user"]
|
user = frappe.session["user"]
|
||||||
company = filters.get("company") or frappe.defaults.get_user_default("company")
|
company = filters.get("company") or frappe.defaults.get_user_default("company")
|
||||||
|
|
||||||
args = {
|
pf = frappe.qb.DocType("POS Profile")
|
||||||
"user": user,
|
pfu = frappe.qb.DocType("POS Profile User")
|
||||||
"start": start,
|
|
||||||
"company": company,
|
|
||||||
"page_len": page_len,
|
|
||||||
"txt": "%%%s%%" % txt,
|
|
||||||
}
|
|
||||||
|
|
||||||
pos_profile = frappe.db.sql(
|
pos_profile = (
|
||||||
"""select pf.name
|
frappe.qb.from_(pf)
|
||||||
from
|
.inner_join(pfu)
|
||||||
`tabPOS Profile` pf, `tabPOS Profile User` pfu
|
.on(pfu.parent == pf.name)
|
||||||
where
|
.select(pf.name)
|
||||||
pfu.parent = pf.name and pfu.user = %(user)s and pf.company = %(company)s
|
.where((pfu.user == user) & (pf.company == company) & pf.name.like(f"%{txt}%") & (pf.disabled == 0))
|
||||||
and (pf.name like %(txt)s)
|
.limit(page_len)
|
||||||
and pf.disabled = 0 limit %(page_len)s offset %(start)s""",
|
.offset(start)
|
||||||
args,
|
.run()
|
||||||
)
|
)
|
||||||
|
|
||||||
if not pos_profile:
|
if not pos_profile:
|
||||||
del args["user"]
|
pos_profile = (
|
||||||
|
frappe.qb.from_(pf)
|
||||||
pos_profile = frappe.db.sql(
|
.left_join(pfu)
|
||||||
"""select pf.name
|
.on(pf.name == pfu.parent)
|
||||||
from
|
.select(pf.name)
|
||||||
`tabPOS Profile` pf left join `tabPOS Profile User` pfu
|
.where(
|
||||||
on
|
(pfu.user.isnull() | (pfu.user == ""))
|
||||||
pf.name = pfu.parent
|
& (pf.company == company)
|
||||||
where
|
& pf.name.like(f"%{txt}%")
|
||||||
ifnull(pfu.user, '') = ''
|
& (pf.disabled == 0)
|
||||||
and pf.company = %(company)s
|
)
|
||||||
and pf.name like %(txt)s
|
.run()
|
||||||
and pf.disabled = 0""",
|
|
||||||
args,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return pos_profile
|
return pos_profile
|
||||||
|
|||||||
Reference in New Issue
Block a user