Merge pull request #2001 from nabinhait/hotfix

Validation: Account must belong to the same company
This commit is contained in:
Anand Doshi 2014-07-31 11:55:56 +05:30
commit c2371af779
7 changed files with 53 additions and 22 deletions

View File

@ -41,21 +41,24 @@ class Account(Document):
throw(_("Invalid Master Name"))
def validate_parent(self):
"""Fetch Parent Details and validation for account not to be created under ledger"""
"""Fetch Parent Details and validate parent account"""
if self.parent_account:
par = frappe.db.get_value("Account", self.parent_account,
["name", "group_or_ledger", "report_type", "root_type"], as_dict=1)
["name", "group_or_ledger", "report_type", "root_type", "company"], as_dict=1)
if not par:
throw(_("Parent account does not exist"))
elif par["name"] == self.name:
throw(_("You can not assign itself as parent account"))
elif par["group_or_ledger"] != 'Group':
throw(_("Parent account can not be a ledger"))
throw(_("Account {0}: Parent account {1} does not exist").format(self.name, self.parent_account))
elif par.name == self.name:
throw(_("Account {0}: You can not assign itself as parent account").format(self.name))
elif par.group_or_ledger != 'Group':
throw(_("Account {0}: Parent account {1} can not be a ledger").format(self.name, self.parent_account))
elif par.company != self.company:
throw(_("Account {0}: Parent account {1} does not belong to company: {2}")
.format(self.name, self.parent_account, self.company))
if par["report_type"]:
self.report_type = par["report_type"]
if par["root_type"]:
self.root_type = par["root_type"]
if par.report_type:
self.report_type = par.report_type
if par.root_type:
self.root_type = par.root_type
def validate_root_details(self):
#does not exists parent

View File

@ -15,7 +15,10 @@ def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True,
if gl_map:
if not cancel:
gl_map = process_gl_map(gl_map, merge_entries)
save_entries(gl_map, adv_adj, update_outstanding)
if gl_map and len(gl_map) > 1:
save_entries(gl_map, adv_adj, update_outstanding)
else:
frappe.throw(_("Incorrect number of General Ledger Entries found. You might have selected a wrong Account in the transaction."))
else:
delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding)

View File

@ -53,7 +53,7 @@ erpnext.bom.set_operation_no = function(doc) {
refresh_field("bom_materials");
}
cur_frm.fields_dict["bom_operations"].grid.on_row_delete = function(cdt, cdn){
cur_frm.cscript.bom_operations_remove = function(){
erpnext.bom.set_operation_no(doc);
}

View File

@ -35,6 +35,18 @@ class Company(Document):
self.default_currency != self.previous_default_currency and \
self.check_if_transactions_exist():
frappe.throw(_("Cannot change company's default currency, because there are existing transactions. Transactions must be cancelled to change the default currency."))
self.validate_default_accounts()
def validate_default_accounts(self):
for field in ["default_bank_account", "default_cash_account", "receivables_group", "payables_group",
"default_expense_account", "default_income_account", "stock_received_but_not_billed",
"stock_adjustment_account", "expenses_included_in_valuation"]:
if self.get(field):
for_company = frappe.db.get_value("Account", self.get(field), "company")
if for_company != self.name:
frappe.throw(_("Account {0} does not belong to company: {1}")
.format(self.get(field), self.name))
def on_update(self):
if not frappe.db.sql("""select name from tabAccount
@ -60,7 +72,7 @@ class Company(Document):
for whname in (_("Stores"), _("Work In Progress"), _("Finished Goods")):
if not frappe.db.exists("Warehouse", whname + " - " + self.abbr):
stock_group = frappe.db.get_value("Account", {"account_type": "Stock",
"group_or_ledger": "Group"})
"group_or_ledger": "Group", "company": self.name})
if stock_group:
frappe.get_doc({
"doctype":"Warehouse",
@ -115,7 +127,8 @@ class Company(Document):
_set_default_account("expenses_included_in_valuation", "Expenses Included In Valuation")
if not self.default_income_account:
self.db_set("default_income_account", frappe.db.get_value("Account", {"account_name": _("Sales")}))
self.db_set("default_income_account", frappe.db.get_value("Account",
{"account_name": _("Sales"), "company": self.name}))
def create_default_cost_center(self):
cc_list = [

View File

@ -13,7 +13,7 @@
},
{
"company": "_Test Company 1",
"create_account_under": "Stock Assets - _TC",
"create_account_under": "Stock Assets - _TC1",
"doctype": "Warehouse",
"warehouse_name": "_Test Warehouse 2"
},

View File

@ -22,11 +22,16 @@ class Warehouse(Document):
self.update_parent_account()
def update_parent_account(self):
if not getattr(self, "__islocal", None) and (self.create_account_under !=
frappe.db.get_value("Warehouse", self.name, "create_account_under")):
warehouse_account = frappe.db.get_value("Account",
{"account_type": "Warehouse", "company": self.company,
"master_name": self.name}, ["name", "parent_account"])
if not getattr(self, "__islocal", None) \
and (self.create_account_under != frappe.db.get_value("Warehouse", self.name, "create_account_under")):
self.validate_parent_account()
warehouse_account = frappe.db.get_value("Account",
{"account_type": "Warehouse", "company": self.company, "master_name": self.name},
["name", "parent_account"])
if warehouse_account and warehouse_account[1] != self.create_account_under:
acc_doc = frappe.get_doc("Account", warehouse_account[0])
acc_doc.parent_account = self.create_account_under
@ -57,13 +62,21 @@ class Warehouse(Document):
msgprint(_("Account head {0} created").format(ac_doc.name))
def validate_parent_account(self):
if not self.company:
frappe.throw(_("Warehouse {0}: Company is mandatory").format(self.name))
if not self.create_account_under:
parent_account = frappe.db.get_value("Account",
{"account_name": "Stock Assets", "company": self.company})
if parent_account:
self.create_account_under = parent_account
else:
frappe.throw(_("Please enter parent account group for warehouse account"))
elif frappe.db.get_value("Account", self.create_account_under, "company") != self.company:
frappe.throw(_("Warehouse {0}: Parent account {1} does not bolong to the company {2}")
.format(self.name, self.create_account_under, self.company))
def on_trash(self):
# delete bin

View File

@ -20,7 +20,6 @@ class CustomerIssue(TransactionBase):
if self.status=="Closed" and \
frappe.db.get_value("Customer Issue", self.name, "status")!="Closed":
self.resolution_date = today()
self.resolved_by = frappe.session.user
def on_cancel(self):
lst = frappe.db.sql("""select t1.name