diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 9e3319caa77..e4cba75bae2 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 40e62f1c93a..a072bd789f2 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 8c23f96074a..211fdcffb16 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 ea6e88dc287..4f205c57032 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 4bf8da0a40f..e411cdf690c 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 7d5e250ba7c..c353b8d9719 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 3623d779326..ea003d84fa4 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 f03fb8f762e..1e99a7671b7 100644 --- a/erpnext/templates/includes/rfq/rfq_items.html +++ b/erpnext/templates/includes/rfq/rfq_items.html @@ -18,12 +18,12 @@