[usability] [issue] webnotes/erpnext#606 - disable default currency after a transaction is created for a company

This commit is contained in:
Anand Doshi 2013-08-01 18:58:35 +05:30
parent c4a54fe24e
commit 5cd58dc387
2 changed files with 24 additions and 0 deletions

View File

@ -17,6 +17,10 @@
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(doc.abbr && !doc.__islocal)
cur_frm.set_df_property("abbr", "read_only", 1)
if(!doc.__islocal) {
cur_frm.toggle_enable("default_currency", !cur_frm.doc.__transactions_exist);
}
}
cur_frm.cscript.has_special_chars = function(t) {

View File

@ -29,11 +29,31 @@ class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
def onload(self):
self.doc.fields["__transactions_exist"] = self.check_if_transactions_exist()
def check_if_transactions_exist(self):
exists = False
for doctype in ["Sales Invoice", "Delivery Note", "Sales Order", "Quotation",
"Purchase Invoice", "Purchase Receipt", "Purchase Order", "Supplier Quotation"]:
if webnotes.conn.sql("""select name from `tab%s` where company=%s and docstatus=1
limit 1""" % (doctype, "%s"), self.doc.name):
exists = True
break
return exists
def validate(self):
if self.doc.fields.get('__islocal') and len(self.doc.abbr) > 5:
webnotes.msgprint("Abbreviation cannot have more than 5 characters",
raise_exception=1)
self.previous_default_currency = webnotes.conn.get_value("Company", self.doc.name, "default_currency")
if self.doc.default_currency and self.previous_default_currency and \
self.doc.default_currency != self.previous_default_currency and \
self.check_if_transactions_exist():
msgprint(_("Sorry! You cannot change company's default currency, because there are existing transactions against it. You will need to cancel those transactions if you want to change the default currency."), raise_exception=True)
def on_update(self):
if not webnotes.conn.sql("""select name from tabAccount
where company=%s and docstatus<2 limit 1""", self.doc.name):