mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
fix: Filters for portal quotation list (#18704)
* fix: Filters for portal quotation list * fix: Remove unwanted import
This commit is contained in:
@@ -21,42 +21,45 @@ def get_list_context(context=None):
|
|||||||
|
|
||||||
def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_page_length=20, order_by="modified"):
|
def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_page_length=20, order_by="modified"):
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
key = None
|
ignore_permissions = False
|
||||||
|
|
||||||
if not filters: filters = []
|
if not filters: filters = []
|
||||||
|
|
||||||
if doctype == 'Supplier Quotation':
|
if doctype == 'Supplier Quotation':
|
||||||
filters.append((doctype, "docstatus", "<", 2))
|
filters.append((doctype, 'docstatus', '<', 2))
|
||||||
else:
|
else:
|
||||||
filters.append((doctype, "docstatus", "=", 1))
|
filters.append((doctype, 'docstatus', '=', 1))
|
||||||
|
|
||||||
if (user != "Guest" and is_website_user()) or doctype == 'Request for Quotation':
|
if (user != 'Guest' and is_website_user()) or doctype == 'Request for Quotation':
|
||||||
parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
|
parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
|
||||||
# find party for this contact
|
# find party for this contact
|
||||||
customers, suppliers = get_customers_suppliers(parties_doctype, user)
|
customers, suppliers = get_customers_suppliers(parties_doctype, user)
|
||||||
|
|
||||||
if not customers and not suppliers: return []
|
if customers:
|
||||||
|
if doctype == 'Quotation':
|
||||||
key, parties = get_party_details(customers, suppliers)
|
filters.append(('quotation_to', '=', 'Customer'))
|
||||||
|
filters.append(('party_name', 'in', customers))
|
||||||
if doctype == 'Request for Quotation':
|
else:
|
||||||
return rfq_transaction_list(parties_doctype, doctype, parties, limit_start, limit_page_length)
|
filters.append(('customer', 'in', customers))
|
||||||
|
elif suppliers:
|
||||||
filters.append((doctype, key, "in", parties))
|
filters.append(('supplier', 'in', suppliers))
|
||||||
|
|
||||||
if key:
|
|
||||||
return post_process(doctype, get_list_for_transactions(doctype, txt,
|
|
||||||
filters=filters, fields="name",limit_start=limit_start,
|
|
||||||
limit_page_length=limit_page_length,ignore_permissions=True,
|
|
||||||
order_by="modified desc"))
|
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
|
|
||||||
return post_process(doctype, get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_length,
|
if doctype == 'Request for Quotation':
|
||||||
fields="name", order_by="modified desc"))
|
parties = customers or suppliers
|
||||||
|
return rfq_transaction_list(parties_doctype, doctype, parties, limit_start, limit_page_length)
|
||||||
|
|
||||||
|
# Since customers and supplier do not have direct access to internal doctypes
|
||||||
|
ignore_permissions = True
|
||||||
|
|
||||||
|
transactions = get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_length,
|
||||||
|
fields='name', ignore_permissions=ignore_permissions, order_by='modified desc')
|
||||||
|
|
||||||
|
return post_process(doctype, transactions)
|
||||||
|
|
||||||
def get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_length=20,
|
def get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_length=20,
|
||||||
ignore_permissions=False,fields=None, order_by=None):
|
ignore_permissions=False, fields=None, order_by=None):
|
||||||
""" Get List of transactions like Invoices, Orders """
|
""" Get List of transactions like Invoices, Orders """
|
||||||
from frappe.www.list import get_list
|
from frappe.www.list import get_list
|
||||||
meta = frappe.get_meta(doctype)
|
meta = frappe.get_meta(doctype)
|
||||||
@@ -83,16 +86,6 @@ def get_list_for_transactions(doctype, txt, filters, limit_start, limit_page_len
|
|||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_party_details(customers, suppliers):
|
|
||||||
if customers:
|
|
||||||
key, parties = "customer", customers
|
|
||||||
elif suppliers:
|
|
||||||
key, parties = "supplier", suppliers
|
|
||||||
else:
|
|
||||||
key, parties = "customer", []
|
|
||||||
|
|
||||||
return key, parties
|
|
||||||
|
|
||||||
def rfq_transaction_list(parties_doctype, doctype, parties, limit_start, limit_page_length):
|
def rfq_transaction_list(parties_doctype, doctype, parties, limit_start, limit_page_length):
|
||||||
data = frappe.db.sql("""select distinct parent as name, supplier from `tab{doctype}`
|
data = frappe.db.sql("""select distinct parent as name, supplier from `tab{doctype}`
|
||||||
where supplier = '{supplier}' and docstatus=1 order by modified desc limit {start}, {len}""".
|
where supplier = '{supplier}' and docstatus=1 order by modified desc limit {start}, {len}""".
|
||||||
@@ -159,7 +152,7 @@ def has_website_permission(doc, ptype, user, verbose=False):
|
|||||||
doctype = doc.doctype
|
doctype = doc.doctype
|
||||||
customers, suppliers = get_customers_suppliers(doctype, user)
|
customers, suppliers = get_customers_suppliers(doctype, user)
|
||||||
if customers:
|
if customers:
|
||||||
return frappe.db.exists(doctype, filters=get_customer_filter(doc, customers))
|
return frappe.db.exists(doctype, get_customer_filter(doc, customers))
|
||||||
elif suppliers:
|
elif suppliers:
|
||||||
fieldname = 'suppliers' if doctype == 'Request for Quotation' else 'supplier'
|
fieldname = 'suppliers' if doctype == 'Request for Quotation' else 'supplier'
|
||||||
return frappe.db.exists(doctype, filters={
|
return frappe.db.exists(doctype, filters={
|
||||||
@@ -175,7 +168,7 @@ def get_customer_filter(doc, customers):
|
|||||||
filters.name = doc.name
|
filters.name = doc.name
|
||||||
filters[get_customer_field_name(doctype)] = ['in', customers]
|
filters[get_customer_field_name(doctype)] = ['in', customers]
|
||||||
if doctype == 'Quotation':
|
if doctype == 'Quotation':
|
||||||
filters.party_type = 'Customer'
|
filters.quotation_to = 'Customer'
|
||||||
return filters
|
return filters
|
||||||
|
|
||||||
def get_customer_field_name(doctype):
|
def get_customer_field_name(doctype):
|
||||||
|
|||||||
@@ -5,8 +5,7 @@ from __future__ import unicode_literals
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import formatdate
|
from frappe.utils import formatdate
|
||||||
from erpnext.controllers.website_list_for_contact import (get_customers_suppliers,
|
from erpnext.controllers.website_list_for_contact import get_customers_suppliers
|
||||||
get_party_details)
|
|
||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
@@ -23,8 +22,8 @@ def get_supplier():
|
|||||||
doctype = frappe.form_dict.doctype
|
doctype = frappe.form_dict.doctype
|
||||||
parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
|
parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
|
||||||
customers, suppliers = get_customers_suppliers(parties_doctype, frappe.session.user)
|
customers, suppliers = get_customers_suppliers(parties_doctype, frappe.session.user)
|
||||||
key, parties = get_party_details(customers, suppliers)
|
|
||||||
return parties[0] if key == 'supplier' else ''
|
return suppliers[0] if suppliers else ''
|
||||||
|
|
||||||
def check_supplier_has_docname_access(supplier):
|
def check_supplier_has_docname_access(supplier):
|
||||||
status = True
|
status = True
|
||||||
|
|||||||
Reference in New Issue
Block a user