mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-01 19:29:10 +00:00
Merge pull request #5133 from rohitwaghchaure/new_rfq
[Fixes]Portal, Supplier can view their addresses, default buying price list …
This commit is contained in:
@@ -31,6 +31,9 @@ def get_transaction_list(doctype, txt=None, filters=None, limit_start=0, limit_p
|
|||||||
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 []
|
||||||
|
|
||||||
key, parties = get_party_details(customers, suppliers)
|
key, parties = get_party_details(customers, suppliers)
|
||||||
|
|
||||||
if doctype == 'Request for Quotation':
|
if doctype == 'Request for Quotation':
|
||||||
@@ -93,7 +96,6 @@ def post_process(doctype, data):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
def get_customers_suppliers(doctype, user):
|
def get_customers_suppliers(doctype, user):
|
||||||
from erpnext.shopping_cart.cart import get_customer
|
|
||||||
meta = frappe.get_meta(doctype)
|
meta = frappe.get_meta(doctype)
|
||||||
contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"],
|
contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"],
|
||||||
filters={"email_id": user})
|
filters={"email_id": user})
|
||||||
@@ -101,9 +103,6 @@ def get_customers_suppliers(doctype, user):
|
|||||||
customers = [c.customer for c in contacts if c.customer] if meta.get_field("customer") else None
|
customers = [c.customer for c in contacts if c.customer] if meta.get_field("customer") else None
|
||||||
suppliers = [c.supplier for c in contacts if c.supplier] if meta.get_field("supplier") else None
|
suppliers = [c.supplier for c in contacts if c.supplier] if meta.get_field("supplier") else None
|
||||||
|
|
||||||
if not customers and not suppliers:
|
|
||||||
return [get_customer().name], None
|
|
||||||
|
|
||||||
return customers, suppliers
|
return customers, suppliers
|
||||||
|
|
||||||
def has_website_permission(doc, ptype, user, verbose=False):
|
def has_website_permission(doc, ptype, user, verbose=False):
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ def set_cart_count(quotation=None):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_cart_quotation(doc=None):
|
def get_cart_quotation(doc=None):
|
||||||
party = get_customer()
|
party = get_party()
|
||||||
|
|
||||||
if not doc:
|
if not doc:
|
||||||
quotation = _get_cart_quotation(party)
|
quotation = _get_cart_quotation(party)
|
||||||
@@ -150,7 +150,7 @@ def decorate_quotation_doc(doc):
|
|||||||
|
|
||||||
def _get_cart_quotation(party=None):
|
def _get_cart_quotation(party=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_customer()
|
party = get_party()
|
||||||
|
|
||||||
quotation = frappe.get_all("Quotation", fields=["name"], filters=
|
quotation = frappe.get_all("Quotation", fields=["name"], filters=
|
||||||
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0},
|
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0},
|
||||||
@@ -182,7 +182,7 @@ def _get_cart_quotation(party=None):
|
|||||||
return qdoc
|
return qdoc
|
||||||
|
|
||||||
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
||||||
party = get_customer()
|
party = get_party()
|
||||||
|
|
||||||
party.customer_name = company_name or fullname
|
party.customer_name = company_name or fullname
|
||||||
party.customer_type == "Company" if company_name else "Individual"
|
party.customer_type == "Company" if company_name else "Individual"
|
||||||
@@ -211,7 +211,7 @@ def update_party(fullname, company_name=None, mobile_no=None, phone=None):
|
|||||||
|
|
||||||
def apply_cart_settings(party=None, quotation=None):
|
def apply_cart_settings(party=None, quotation=None):
|
||||||
if not party:
|
if not party:
|
||||||
party = get_customer()
|
party = get_party()
|
||||||
if not quotation:
|
if not quotation:
|
||||||
quotation = _get_cart_quotation(party)
|
quotation = _get_cart_quotation(party)
|
||||||
|
|
||||||
@@ -276,20 +276,24 @@ def set_taxes(quotation, cart_settings):
|
|||||||
# # append taxes
|
# # append taxes
|
||||||
quotation.append_taxes_from_master()
|
quotation.append_taxes_from_master()
|
||||||
|
|
||||||
def get_customer(user=None):
|
def get_party(user=None):
|
||||||
if not user:
|
if not user:
|
||||||
user = frappe.session.user
|
user = frappe.session.user
|
||||||
|
|
||||||
customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
|
party = frappe.db.get_value("Contact", {"email_id": user}, ["customer", "supplier"], as_dict=1)
|
||||||
|
if party:
|
||||||
|
party_doctype = 'Customer' if party.customer else 'Supplier'
|
||||||
|
party = party.customer or party.supplier
|
||||||
|
|
||||||
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
cart_settings = frappe.get_doc("Shopping Cart Settings")
|
||||||
|
|
||||||
debtors_account = ''
|
debtors_account = ''
|
||||||
|
|
||||||
if cart_settings.enable_checkout:
|
if cart_settings.enable_checkout:
|
||||||
debtors_account = get_debtors_account(cart_settings)
|
debtors_account = get_debtors_account(cart_settings)
|
||||||
|
|
||||||
if customer:
|
if party:
|
||||||
return frappe.get_doc("Customer", customer)
|
return frappe.get_doc(party_doctype, party)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
customer = frappe.new_doc("Customer")
|
customer = frappe.new_doc("Customer")
|
||||||
@@ -300,7 +304,7 @@ def get_customer(user=None):
|
|||||||
"customer_group": get_shopping_cart_settings().default_customer_group,
|
"customer_group": get_shopping_cart_settings().default_customer_group,
|
||||||
"territory": get_root_of("Territory")
|
"territory": get_root_of("Territory")
|
||||||
})
|
})
|
||||||
|
|
||||||
if debtors_account:
|
if debtors_account:
|
||||||
customer.update({
|
customer.update({
|
||||||
"accounts": [{
|
"accounts": [{
|
||||||
@@ -308,7 +312,7 @@ def get_customer(user=None):
|
|||||||
"account": debtors_account
|
"account": debtors_account
|
||||||
}]
|
}]
|
||||||
})
|
})
|
||||||
|
|
||||||
customer.flags.ignore_mandatory = True
|
customer.flags.ignore_mandatory = True
|
||||||
customer.insert(ignore_permissions=True)
|
customer.insert(ignore_permissions=True)
|
||||||
|
|
||||||
@@ -326,12 +330,12 @@ def get_customer(user=None):
|
|||||||
def get_debtors_account(cart_settings):
|
def get_debtors_account(cart_settings):
|
||||||
payment_gateway_account_currency = \
|
payment_gateway_account_currency = \
|
||||||
frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency
|
frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency
|
||||||
|
|
||||||
account_name = _("Debtors ({0})".format(payment_gateway_account_currency))
|
account_name = _("Debtors ({0})".format(payment_gateway_account_currency))
|
||||||
|
|
||||||
debtors_account_name = get_account_name("Receivable", "Asset", is_group=0,\
|
debtors_account_name = get_account_name("Receivable", "Asset", is_group=0,\
|
||||||
account_currency=payment_gateway_account_currency, company=cart_settings.company)
|
account_currency=payment_gateway_account_currency, company=cart_settings.company)
|
||||||
|
|
||||||
if not debtors_account_name:
|
if not debtors_account_name:
|
||||||
debtors_account = frappe.get_doc({
|
debtors_account = frappe.get_doc({
|
||||||
"doctype": "Account",
|
"doctype": "Account",
|
||||||
@@ -340,18 +344,18 @@ def get_debtors_account(cart_settings):
|
|||||||
"is_group": 0,
|
"is_group": 0,
|
||||||
"parent_account": get_account_name(root_type="Asset", is_group=1, company=cart_settings.company),
|
"parent_account": get_account_name(root_type="Asset", is_group=1, company=cart_settings.company),
|
||||||
"account_name": account_name,
|
"account_name": account_name,
|
||||||
"currency": payment_gateway_account_currency
|
"currency": payment_gateway_account_currency
|
||||||
}).insert(ignore_permissions=True)
|
}).insert(ignore_permissions=True)
|
||||||
|
|
||||||
return debtors_account.name
|
return debtors_account.name
|
||||||
|
|
||||||
else:
|
else:
|
||||||
return debtors_account_name
|
return debtors_account_name
|
||||||
|
|
||||||
|
|
||||||
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
|
||||||
if not party:
|
if not party:
|
||||||
return
|
party = get_party()
|
||||||
|
|
||||||
address_docs = frappe.db.sql("""select * from `tabAddress`
|
address_docs = frappe.db.sql("""select * from `tabAddress`
|
||||||
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
|
||||||
@@ -371,7 +375,7 @@ def set_customer_in_address(doc, method=None):
|
|||||||
|
|
||||||
if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
|
if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
|
||||||
# creates a customer if one does not exist
|
# creates a customer if one does not exist
|
||||||
get_customer()
|
get_party()
|
||||||
doc.link_address()
|
doc.link_address()
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
@@ -439,4 +443,4 @@ def get_address_territory(address_name):
|
|||||||
return territory
|
return territory
|
||||||
|
|
||||||
def show_terms(doc):
|
def show_terms(doc):
|
||||||
return doc.tc_name
|
return doc.tc_name
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import unittest
|
import unittest
|
||||||
import frappe
|
import frappe
|
||||||
from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_customer
|
from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_party
|
||||||
|
|
||||||
class TestShoppingCart(unittest.TestCase):
|
class TestShoppingCart(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
@@ -118,7 +118,7 @@ class TestShoppingCart(unittest.TestCase):
|
|||||||
"doctype": "Quotation",
|
"doctype": "Quotation",
|
||||||
"quotation_to": "Customer",
|
"quotation_to": "Customer",
|
||||||
"order_type": "Shopping Cart",
|
"order_type": "Shopping Cart",
|
||||||
"customer": get_customer(frappe.session.user).name,
|
"customer": get_party(frappe.session.user).name,
|
||||||
"docstatus": 0,
|
"docstatus": 0,
|
||||||
"contact_email": frappe.session.user,
|
"contact_email": frappe.session.user,
|
||||||
"selling_price_list": "_Test Price List Rest of the World",
|
"selling_price_list": "_Test Price List Rest of the World",
|
||||||
|
|||||||
@@ -64,7 +64,7 @@
|
|||||||
<div class="row grand-total-row">
|
<div class="row grand-total-row">
|
||||||
<div class="col-xs-10 text-right">{{ _("Grand Total") }}</div>
|
<div class="col-xs-10 text-right">{{ _("Grand Total") }}</div>
|
||||||
<div class="col-xs-2 text-right">
|
<div class="col-xs-2 text-right">
|
||||||
{{doc.currency_symbol}} <span class="tax-grand-total">0.0</span>
|
{{doc.currency_symbol}} <span class="tax-grand-total">0.0</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -4,16 +4,16 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
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
|
get_party_details)
|
||||||
|
|
||||||
def get_context(context):
|
def get_context(context):
|
||||||
context.no_cache = 1
|
context.no_cache = 1
|
||||||
context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
|
||||||
context.parents = frappe.form_dict.parents
|
context.parents = frappe.form_dict.parents
|
||||||
context.doc.supplier = get_supplier()
|
context.doc.supplier = get_supplier()
|
||||||
update_supplier_details(context)
|
|
||||||
unauthorized_user(context.doc.supplier)
|
unauthorized_user(context.doc.supplier)
|
||||||
|
update_supplier_details(context)
|
||||||
context["title"] = frappe.form_dict.name
|
context["title"] = frappe.form_dict.name
|
||||||
|
|
||||||
def get_supplier():
|
def get_supplier():
|
||||||
@@ -31,13 +31,13 @@ def check_supplier_has_docname_access(supplier):
|
|||||||
return status
|
return status
|
||||||
|
|
||||||
def unauthorized_user(supplier):
|
def unauthorized_user(supplier):
|
||||||
status = check_supplier_has_docname_access(supplier)
|
status = check_supplier_has_docname_access(supplier) or False
|
||||||
if status == False:
|
if status == False:
|
||||||
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
frappe.throw(_("Not Permitted"), frappe.PermissionError)
|
||||||
|
|
||||||
def update_supplier_details(context):
|
def update_supplier_details(context):
|
||||||
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
|
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
|
||||||
context.doc.currency = supplier_doc.default_currency
|
context.doc.currency = supplier_doc.default_currency or frappe.db.get_value("Company", context.doc.company, "default_currency")
|
||||||
context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol")
|
context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol")
|
||||||
context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format")
|
context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format")
|
||||||
context.doc.buying_price_list = supplier_doc.default_price_list
|
context.doc.buying_price_list = supplier_doc.default_price_list or ''
|
||||||
Reference in New Issue
Block a user