mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-16 05:15:10 +00:00
fix: add doctype fieldname in condition
(cherry picked from commit e2d63e4c32)
# Conflicts:
# erpnext/accounts/utils.py
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
# License: GNU General Public License v3. See license.txt
|
# License: GNU General Public License v3. See license.txt
|
||||||
|
|
||||||
|
|
||||||
|
from collections import defaultdict
|
||||||
from json import loads
|
from json import loads
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
@@ -2195,25 +2196,37 @@ def run_ledger_health_checks():
|
|||||||
doc.save()
|
doc.save()
|
||||||
|
|
||||||
|
|
||||||
|
def get_link_fields_grouped_by_option(doctype):
|
||||||
|
meta = frappe.get_meta(doctype)
|
||||||
|
link_fields_map = defaultdict(list)
|
||||||
|
|
||||||
|
for df in meta.fields:
|
||||||
|
if df.fieldtype == "Link" and df.options and not df.ignore_user_permissions:
|
||||||
|
link_fields_map[df.options].append(df.fieldname)
|
||||||
|
|
||||||
|
return link_fields_map
|
||||||
|
|
||||||
|
|
||||||
def build_qb_match_conditions(doctype, user=None) -> list:
|
def build_qb_match_conditions(doctype, user=None) -> list:
|
||||||
match_filters = build_match_conditions(doctype, user, False)
|
match_filters = build_match_conditions(doctype, user, False)
|
||||||
|
link_fields_map = get_link_fields_grouped_by_option(doctype)
|
||||||
criterion = []
|
criterion = []
|
||||||
apply_strict_user_permissions = frappe.get_system_settings("apply_strict_user_permissions")
|
apply_strict_user_permissions = frappe.get_system_settings("apply_strict_user_permissions")
|
||||||
|
|
||||||
if match_filters:
|
if match_filters:
|
||||||
from frappe import qb
|
|
||||||
|
|
||||||
_dt = qb.DocType(doctype)
|
_dt = qb.DocType(doctype)
|
||||||
|
|
||||||
for filter in match_filters:
|
for filter in match_filters:
|
||||||
for d, names in filter.items():
|
for link_option, allowed_values in filter.items():
|
||||||
fieldname = d.lower().replace(" ", "_")
|
fieldnames = link_fields_map.get(link_option, [])
|
||||||
field = _dt[fieldname]
|
|
||||||
|
|
||||||
cond = field.isin(names)
|
for fieldname in fieldnames:
|
||||||
if not apply_strict_user_permissions:
|
field = _dt[fieldname]
|
||||||
cond = (Coalesce(field, "") == "") | field.isin(names)
|
cond = field.isin(allowed_values)
|
||||||
|
|
||||||
criterion.append(cond)
|
if not apply_strict_user_permissions:
|
||||||
|
cond = (Coalesce(field, "") == "") | cond
|
||||||
|
|
||||||
|
criterion.append(cond)
|
||||||
|
|
||||||
return criterion
|
return criterion
|
||||||
|
|||||||
Reference in New Issue
Block a user