From 62fea0374b1ef640b9ae7fbafbb13eecc9ca23fc Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 30 Mar 2016 13:24:42 +0530 Subject: [PATCH] [Enhancement] Added currency symbol on RFQ form of supplier portal, currency validation for party --- erpnext/accounts/party.py | 6 ++++ .../request_for_quotation.js | 9 ++++++ .../request_for_quotation.py | 17 ++++++----- .../test_request_for_quotation.py | 5 ++-- .../controllers/website_list_for_contact.py | 4 +++ erpnext/shopping_cart/cart.py | 2 +- erpnext/templates/includes/rfq.js | 7 +++-- erpnext/templates/includes/rfq/rfq_items.html | 4 +-- erpnext/templates/pages/rfq.html | 2 +- erpnext/templates/pages/rfq.py | 30 +++++++++++++------ 10 files changed, 60 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 9e3319caa7..e4cba75bae 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -227,10 +227,16 @@ def validate_party_accounts(doc): party_account_currency = frappe.db.get_value("Account", account.account, "account_currency") existing_gle_currency = get_party_gle_currency(doc.doctype, doc.name, account.company) + company_default_currency = frappe.db.get_value("Company", + frappe.db.get_default("Company"), "default_currency", cache=True) if existing_gle_currency and party_account_currency != existing_gle_currency: frappe.throw(_("Accounting entries have already been made in currency {0} for company {1}. Please select a receivable or payable account with currency {0}.").format(existing_gle_currency, account.company)) + if doc.default_currency and party_account_currency and company_default_currency: + if doc.default_currency != party_account_currency and doc.default_currency != company_default_currency: + frappe.throw(_("Billing currency must be equal to either default comapany's currency or party's payble account currency")) + @frappe.whitelist() def get_due_date(posting_date, party_type, party, company): """Set Due Date = Posting Date + Credit Days""" diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 40e62f1c93..a072bd789f 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -32,6 +32,7 @@ frappe.ui.form.on("Request for Quotation",{ frm.add_custom_button(__("Send Supplier Emails"), function() { frappe.call({ method: 'erpnext.buying.doctype.request_for_quotation.request_for_quotation.send_supplier_emails', + freeze: true, args: { rfq_name: frm.doc.name } @@ -78,6 +79,14 @@ frappe.ui.form.on("Request for Quotation",{ } }) +frappe.ui.form.on("Request for Quotation Supplier",{ + supplier: function(frm, cdt, cdn){ + var d = locals[cdt][cdn] + frappe.model.set_value(cdt, cdn, 'contact', '') + frappe.model.set_value(cdt, cdn, 'email_id', '') + } +}) + erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.extend({ refresh: function() { this._super(); diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py index 8c23f96074..211fdcffb1 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py @@ -5,9 +5,10 @@ from __future__ import unicode_literals import frappe, json from frappe import _ +from frappe.model.mapper import get_mapped_doc from frappe.utils import get_url, random_string from frappe.utils.user import get_user_fullname -from frappe.model.mapper import get_mapped_doc +from erpnext.accounts.party import get_party_account_currency, get_party_details from erpnext.stock.doctype.material_request.material_request import set_missing_values from erpnext.controllers.buying_controller import BuyingController @@ -98,7 +99,6 @@ class RequestforQuotation(BuyingController): frappe.sendmail(recipients=data.email_id, sender=sender, subject=subject, message=frappe.get_template(template).render(args), attachments = [frappe.attach_print('Request for Quotation', self.name)],as_bulk=True) - frappe.msgprint(_("Email sent to supplier {0}").format(data.supplier)) @frappe.whitelist() @@ -119,6 +119,9 @@ def get_list_context(context=None): def make_supplier_quotation(source_name, for_supplier, target_doc=None): def postprocess(source, target_doc): target_doc.supplier = for_supplier + args = get_party_details(for_supplier, party_type="Supplier", ignore_permissions=True) + target_doc.currency = args.currency + target_doc.buying_price_list = args.buying_price_list or frappe.db.get_value('Buying Settings', None, 'buying_price_list') set_missing_values(source, target_doc) doclist = get_mapped_doc("Request for Quotation", source_name, { @@ -146,18 +149,16 @@ def create_supplier_quotation(doc): if isinstance(doc, basestring): doc = json.loads(doc) - supplier = frappe.get_doc('Supplier', doc.get('supplier')) - try: sq_doc = frappe.get_doc({ "doctype": "Supplier Quotation", - "supplier": supplier.name, + "supplier": doc.get('supplier'), "terms": doc.get("terms"), "company": doc.get("company"), - "currency": supplier.default_currency, - "buying_price_list": supplier.default_price_list or frappe.db.get_value('Buying Settings', None, 'buying_price_list') + "currency": doc.get('currency') or get_party_account_currency('Supplier', doc.get('supplier'), doc.get('company')), + "buying_price_list": doc.get('buying_price_list') or frappe.db.get_value('Buying Settings', None, 'buying_price_list') }) - add_items(sq_doc, supplier, doc.get('items')) + add_items(sq_doc, doc.get('supplier'), doc.get('items')) sq_doc.flags.ignore_permissions = True sq_doc.run_method("set_missing_values") sq_doc.save() diff --git a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py index ea6e88dc28..4f205c5703 100644 --- a/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py +++ b/erpnext/buying/doctype/request_for_quotation/test_request_for_quotation.py @@ -50,8 +50,7 @@ def make_request_for_quotation(): rfq.transaction_date = nowdate() rfq.status = 'Draft' rfq.company = '_Test Company' - rfq.response = 'Test Data' - rfq.message_for_supplier = "Please supply the specified items at the best possible rates" + rfq.message_for_supplier = 'Please supply the specified items at the best possible rates.' for data in supplier_data: rfq.append('suppliers', data) @@ -77,4 +76,4 @@ def get_supplier_data(): { "supplier": "_Test Supplier 1", "supplier_name": "_Test Supplier 1" - }] \ No newline at end of file + }] diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py index 4bf8da0a40..e411cdf690 100644 --- a/erpnext/controllers/website_list_for_contact.py +++ b/erpnext/controllers/website_list_for_contact.py @@ -93,6 +93,7 @@ def post_process(doctype, data): return result def get_customers_suppliers(doctype, user): + from erpnext.shopping_cart.cart import get_customer meta = frappe.get_meta(doctype) contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"], filters={"email_id": user}) @@ -100,6 +101,9 @@ def get_customers_suppliers(doctype, user): 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 + if not customers and not suppliers: + return [get_customer().name], None + return customers, suppliers def has_website_permission(doc, ptype, user, verbose=False): diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py index 7d5e250ba7..c353b8d971 100644 --- a/erpnext/shopping_cart/cart.py +++ b/erpnext/shopping_cart/cart.py @@ -351,7 +351,7 @@ def get_debtors_account(cart_settings): def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None): if not party: - party = get_customer() + return address_docs = frappe.db.sql("""select * from `tabAddress` where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(), diff --git a/erpnext/templates/includes/rfq.js b/erpnext/templates/includes/rfq.js index 3623d77932..ea003d84fa 100644 --- a/erpnext/templates/includes/rfq.js +++ b/erpnext/templates/includes/rfq.js @@ -6,6 +6,9 @@ window.doc={{ doc.as_json() }}; $(document).ready(function() { new rfq(); doc.supplier = "{{ doc.supplier }}" + doc.currency = "{{ doc.currency }}" + doc.number_format = "{{ doc.number_format }}" + doc.buying_price_list = "{{ doc.buying_price_list }}" }); rfq = Class.extend({ @@ -57,11 +60,11 @@ rfq = Class.extend({ data.qty = me.qty; data.rate = me.rate; data.amount = (me.rate * me.qty) || 0.0; - $(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(data.amount.toFixed(2)); + $(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(format_number(data.amount, doc.number_format, 2)); } doc.grand_total += flt(data.amount); - $('.tax-grand-total').text(doc.grand_total.toFixed(2)); + $('.tax-grand-total').text(format_number(doc.grand_total, doc.number_format, 2)); }) }, diff --git a/erpnext/templates/includes/rfq/rfq_items.html b/erpnext/templates/includes/rfq/rfq_items.html index f03fb8f762..1e99a7671b 100644 --- a/erpnext/templates/includes/rfq/rfq_items.html +++ b/erpnext/templates/includes/rfq/rfq_items.html @@ -18,12 +18,12 @@

-
- 0.00 + {{doc.currency_symbol}} 0.00
diff --git a/erpnext/templates/pages/rfq.html b/erpnext/templates/pages/rfq.html index 8009819557..dfbbbc9d65 100644 --- a/erpnext/templates/pages/rfq.html +++ b/erpnext/templates/pages/rfq.html @@ -64,7 +64,7 @@
{{ _("Grand Total") }}
- 0.0 + {{doc.currency_symbol}} 0.0
{% endif %} diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py index aefa3151d6..181cf73c89 100644 --- a/erpnext/templates/pages/rfq.py +++ b/erpnext/templates/pages/rfq.py @@ -4,24 +4,24 @@ from __future__ import unicode_literals import frappe from frappe import _ +from erpnext.controllers.website_list_for_contact import get_customers_suppliers, \ + get_party_details def get_context(context): context.no_cache = 1 context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name) context.parents = frappe.form_dict.parents context.doc.supplier = get_supplier() - unauthrized_user(context.doc.supplier) + update_supplier_details(context) + unauthorized_user(context.doc.supplier) context["title"] = frappe.form_dict.name -def unauthrized_user(supplier): - status = check_supplier_has_docname_access(supplier) - if status == False: - frappe.throw(_("Not Permitted"), frappe.PermissionError) - def get_supplier(): - from erpnext.shopping_cart.utils import check_customer_or_supplier - key, parties = check_customer_or_supplier() - return parties[0] if key == 'Supplier' else '' + doctype = frappe.form_dict.doctype + parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype + customers, suppliers = get_customers_suppliers(parties_doctype, frappe.session.user) + key, parties = get_party_details(customers, suppliers) + return parties[0] if key == 'supplier' else '' def check_supplier_has_docname_access(supplier): status = True @@ -29,3 +29,15 @@ def check_supplier_has_docname_access(supplier): where supplier = '{supplier}'""".format(supplier=supplier)): status = False return status + +def unauthorized_user(supplier): + status = check_supplier_has_docname_access(supplier) + if status == False: + frappe.throw(_("Not Permitted"), frappe.PermissionError) + +def update_supplier_details(context): + supplier_doc = frappe.get_doc("Supplier", context.doc.supplier) + context.doc.currency = supplier_doc.default_currency + 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.buying_price_list = supplier_doc.default_price_list \ No newline at end of file