From 361df8993f50a46b6a78e6ce152e3e7c5da85f82 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Fri, 18 Sep 2015 12:59:51 +0530 Subject: [PATCH] [fix] no default party currency --- erpnext/accounts/party.py | 59 +++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 34 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index a589a694dd..75322ce590 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -20,7 +20,7 @@ def get_party_details(party=None, account=None, party_type="Customer", company=N if not party: return {} - + if not frappe.db.exists(party_type, party): frappe.throw(_("{0}: {1} does not exists").format(party_type, party)) @@ -29,7 +29,7 @@ def get_party_details(party=None, account=None, party_type="Customer", company=N def _get_party_details(party=None, account=None, party_type="Customer", company=None, posting_date=None, price_list=None, currency=None, doctype=None, ignore_permissions=False): - + out = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, doctype)) party = out[party_type.lower()] @@ -145,20 +145,11 @@ def set_account_and_due_date(party, account, party_type, company, posting_date, "due_date": get_due_date(posting_date, party_type, party, company) } return out - + def validate_accounting_currency(party): - company_currency = get_company_currency() - - # set party account currency - if not party.party_account_currency: - if party.default_currency: - party.party_account_currency = party.default_currency - elif len(set(company_currency.values())) == 1: - party.party_account_currency = company_currency.values()[0] - party_account_currency_in_db = frappe.db.get_value(party.doctype, party.name, "party_account_currency") if party_account_currency_in_db != party.party_account_currency: - existing_gle = frappe.db.get_value("GL Entry", {"party_type": party.doctype, + existing_gle = frappe.db.get_value("GL Entry", {"party_type": party.doctype, "party": party.name}, ["name", "account_currency"], as_dict=1) if existing_gle: if party_account_currency_in_db: @@ -166,8 +157,8 @@ def validate_accounting_currency(party): .format(party.doctype), InvalidCurrency) else: party.party_account_currency = existing_gle.account_currency - - + + def validate_party_account(party): company_currency = get_company_currency() if party.party_account_currency: @@ -175,31 +166,31 @@ def validate_party_account(party): for company, currency in company_currency.items(): if currency != party.party_account_currency: companies_with_different_currency.append(company) - + for d in party.get("accounts"): if d.company in companies_with_different_currency: companies_with_different_currency.remove(d.company) - + selected_account_currency = frappe.db.get_value("Account", d.account, "account_currency") if selected_account_currency != party.party_account_currency: frappe.throw(_("Account {0} is invalid, account currency must be {1}") .format(d.account, selected_account_currency), InvalidAccountCurrency) - + if companies_with_different_currency: frappe.msgprint(_("Please mention Default {0} Account for the following companies, as accounting currency is different from company's default currency: {1}") .format( - "Receivable" if party.doctype=="Customer" else "Payable", + "Receivable" if party.doctype=="Customer" else "Payable", "\n" + "\n".join(companies_with_different_currency) ) ) - + def get_company_currency(): company_currency = frappe._dict() for d in frappe.get_all("Company", fields=["name", "default_currency"]): company_currency.setdefault(d.name, d.default_currency) - + return company_currency - + @frappe.whitelist() def get_party_account(company, party, party_type): """Returns the account for the given `party`. @@ -241,7 +232,7 @@ def get_due_date(posting_date, party_type, party, company): credit_days = get_credit_days(party_type, party, company) if credit_days: due_date = add_days(posting_date, credit_days) - + return due_date def get_credit_days(party_type, party, company): @@ -249,21 +240,21 @@ def get_credit_days(party_type, party, company): if party_type == "Customer": credit_days_based_on, credit_days, customer_group = \ frappe.db.get_value(party_type, party, ["credit_days_based_on", "credit_days", "customer_group"]) - + if not credit_days_based_on: credit_days_based_on, credit_days = \ frappe.db.get_value("Customer Group", customer_group, ["credit_days_based_on", "credit_days"]) \ or frappe.db.get_value("Company", company, ["credit_days_based_on", "credit_days"]) - + return credit_days_based_on, credit_days else: credit_days, supplier_type = frappe.db.get_value(party_type, party, ["credit_days", "supplier_type"]) if not credit_days: credit_days = frappe.db.get_value("Supplier Type", supplier_type, "credit_days") \ or frappe.db.get_value("Company", company, "credit_days") - + return credit_days - + def validate_due_date(posting_date, due_date, party_type, party, company): if getdate(due_date) < getdate(posting_date): frappe.throw(_("Due Date cannot be before Posting Date")) @@ -276,9 +267,9 @@ def validate_due_date(posting_date, due_date, party_type, party, company): .format(date_diff(due_date, default_due_date))) else: frappe.throw(_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date))) - + @frappe.whitelist() -def set_taxes(party, party_type, posting_date, company, customer_group=None, supplier_type=None, +def set_taxes(party, party_type, posting_date, company, customer_group=None, supplier_type=None, billing_address=None, shipping_address=None, use_for_shopping_cart=None): from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details args = { @@ -287,19 +278,19 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup "supplier_type": supplier_type, "company": company } - + if billing_address or shipping_address: args.update(get_party_details(party, party_type, {"billing_address": billing_address, \ "shipping_address": shipping_address })) else: args.update(get_party_details(party, party_type)) - + if party_type=="Customer": args.update({"tax_type": "Sales"}) else: args.update({"tax_type": "Purchase"}) - + if use_for_shopping_cart: args.update({"use_for_shopping_cart": use_for_shopping_cart}) - - return get_tax_template(posting_date, args) \ No newline at end of file + + return get_tax_template(posting_date, args)