[fix] no default party currency
This commit is contained in:
parent
5532a14938
commit
361df8993f
@ -20,7 +20,7 @@ def get_party_details(party=None, account=None, party_type="Customer", company=N
|
|||||||
|
|
||||||
if not party:
|
if not party:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
if not frappe.db.exists(party_type, party):
|
if not frappe.db.exists(party_type, party):
|
||||||
frappe.throw(_("{0}: {1} does not exists").format(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,
|
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):
|
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))
|
out = frappe._dict(set_account_and_due_date(party, account, party_type, company, posting_date, doctype))
|
||||||
|
|
||||||
party = out[party_type.lower()]
|
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)
|
"due_date": get_due_date(posting_date, party_type, party, company)
|
||||||
}
|
}
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def validate_accounting_currency(party):
|
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")
|
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:
|
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)
|
"party": party.name}, ["name", "account_currency"], as_dict=1)
|
||||||
if existing_gle:
|
if existing_gle:
|
||||||
if party_account_currency_in_db:
|
if party_account_currency_in_db:
|
||||||
@ -166,8 +157,8 @@ def validate_accounting_currency(party):
|
|||||||
.format(party.doctype), InvalidCurrency)
|
.format(party.doctype), InvalidCurrency)
|
||||||
else:
|
else:
|
||||||
party.party_account_currency = existing_gle.account_currency
|
party.party_account_currency = existing_gle.account_currency
|
||||||
|
|
||||||
|
|
||||||
def validate_party_account(party):
|
def validate_party_account(party):
|
||||||
company_currency = get_company_currency()
|
company_currency = get_company_currency()
|
||||||
if party.party_account_currency:
|
if party.party_account_currency:
|
||||||
@ -175,31 +166,31 @@ def validate_party_account(party):
|
|||||||
for company, currency in company_currency.items():
|
for company, currency in company_currency.items():
|
||||||
if currency != party.party_account_currency:
|
if currency != party.party_account_currency:
|
||||||
companies_with_different_currency.append(company)
|
companies_with_different_currency.append(company)
|
||||||
|
|
||||||
for d in party.get("accounts"):
|
for d in party.get("accounts"):
|
||||||
if d.company in companies_with_different_currency:
|
if d.company in companies_with_different_currency:
|
||||||
companies_with_different_currency.remove(d.company)
|
companies_with_different_currency.remove(d.company)
|
||||||
|
|
||||||
selected_account_currency = frappe.db.get_value("Account", d.account, "account_currency")
|
selected_account_currency = frappe.db.get_value("Account", d.account, "account_currency")
|
||||||
if selected_account_currency != party.party_account_currency:
|
if selected_account_currency != party.party_account_currency:
|
||||||
frappe.throw(_("Account {0} is invalid, account currency must be {1}")
|
frappe.throw(_("Account {0} is invalid, account currency must be {1}")
|
||||||
.format(d.account, selected_account_currency), InvalidAccountCurrency)
|
.format(d.account, selected_account_currency), InvalidAccountCurrency)
|
||||||
|
|
||||||
if companies_with_different_currency:
|
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}")
|
frappe.msgprint(_("Please mention Default {0} Account for the following companies, as accounting currency is different from company's default currency: {1}")
|
||||||
.format(
|
.format(
|
||||||
"Receivable" if party.doctype=="Customer" else "Payable",
|
"Receivable" if party.doctype=="Customer" else "Payable",
|
||||||
"\n" + "\n".join(companies_with_different_currency)
|
"\n" + "\n".join(companies_with_different_currency)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_company_currency():
|
def get_company_currency():
|
||||||
company_currency = frappe._dict()
|
company_currency = frappe._dict()
|
||||||
for d in frappe.get_all("Company", fields=["name", "default_currency"]):
|
for d in frappe.get_all("Company", fields=["name", "default_currency"]):
|
||||||
company_currency.setdefault(d.name, d.default_currency)
|
company_currency.setdefault(d.name, d.default_currency)
|
||||||
|
|
||||||
return company_currency
|
return company_currency
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_party_account(company, party, party_type):
|
def get_party_account(company, party, party_type):
|
||||||
"""Returns the account for the given `party`.
|
"""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)
|
credit_days = get_credit_days(party_type, party, company)
|
||||||
if credit_days:
|
if credit_days:
|
||||||
due_date = add_days(posting_date, credit_days)
|
due_date = add_days(posting_date, credit_days)
|
||||||
|
|
||||||
return due_date
|
return due_date
|
||||||
|
|
||||||
def get_credit_days(party_type, party, company):
|
def get_credit_days(party_type, party, company):
|
||||||
@ -249,21 +240,21 @@ def get_credit_days(party_type, party, company):
|
|||||||
if party_type == "Customer":
|
if party_type == "Customer":
|
||||||
credit_days_based_on, credit_days, customer_group = \
|
credit_days_based_on, credit_days, customer_group = \
|
||||||
frappe.db.get_value(party_type, party, ["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:
|
if not credit_days_based_on:
|
||||||
credit_days_based_on, credit_days = \
|
credit_days_based_on, credit_days = \
|
||||||
frappe.db.get_value("Customer Group", customer_group, ["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"])
|
or frappe.db.get_value("Company", company, ["credit_days_based_on", "credit_days"])
|
||||||
|
|
||||||
return credit_days_based_on, credit_days
|
return credit_days_based_on, credit_days
|
||||||
else:
|
else:
|
||||||
credit_days, supplier_type = frappe.db.get_value(party_type, party, ["credit_days", "supplier_type"])
|
credit_days, supplier_type = frappe.db.get_value(party_type, party, ["credit_days", "supplier_type"])
|
||||||
if not credit_days:
|
if not credit_days:
|
||||||
credit_days = frappe.db.get_value("Supplier Type", supplier_type, "credit_days") \
|
credit_days = frappe.db.get_value("Supplier Type", supplier_type, "credit_days") \
|
||||||
or frappe.db.get_value("Company", company, "credit_days")
|
or frappe.db.get_value("Company", company, "credit_days")
|
||||||
|
|
||||||
return credit_days
|
return credit_days
|
||||||
|
|
||||||
def validate_due_date(posting_date, due_date, party_type, party, company):
|
def validate_due_date(posting_date, due_date, party_type, party, company):
|
||||||
if getdate(due_date) < getdate(posting_date):
|
if getdate(due_date) < getdate(posting_date):
|
||||||
frappe.throw(_("Due Date cannot be before 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)))
|
.format(date_diff(due_date, default_due_date)))
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date)))
|
frappe.throw(_("Due / Reference Date cannot be after {0}").format(formatdate(default_due_date)))
|
||||||
|
|
||||||
@frappe.whitelist()
|
@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):
|
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
|
from erpnext.accounts.doctype.tax_rule.tax_rule import get_tax_template, get_party_details
|
||||||
args = {
|
args = {
|
||||||
@ -287,19 +278,19 @@ def set_taxes(party, party_type, posting_date, company, customer_group=None, sup
|
|||||||
"supplier_type": supplier_type,
|
"supplier_type": supplier_type,
|
||||||
"company": company
|
"company": company
|
||||||
}
|
}
|
||||||
|
|
||||||
if billing_address or shipping_address:
|
if billing_address or shipping_address:
|
||||||
args.update(get_party_details(party, party_type, {"billing_address": billing_address, \
|
args.update(get_party_details(party, party_type, {"billing_address": billing_address, \
|
||||||
"shipping_address": shipping_address }))
|
"shipping_address": shipping_address }))
|
||||||
else:
|
else:
|
||||||
args.update(get_party_details(party, party_type))
|
args.update(get_party_details(party, party_type))
|
||||||
|
|
||||||
if party_type=="Customer":
|
if party_type=="Customer":
|
||||||
args.update({"tax_type": "Sales"})
|
args.update({"tax_type": "Sales"})
|
||||||
else:
|
else:
|
||||||
args.update({"tax_type": "Purchase"})
|
args.update({"tax_type": "Purchase"})
|
||||||
|
|
||||||
if use_for_shopping_cart:
|
if use_for_shopping_cart:
|
||||||
args.update({"use_for_shopping_cart": use_for_shopping_cart})
|
args.update({"use_for_shopping_cart": use_for_shopping_cart})
|
||||||
|
|
||||||
return get_tax_template(posting_date, args)
|
return get_tax_template(posting_date, args)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user