From c1f65dd863cd39222b50eeab4e9d80a22cea0298 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Tue, 29 Jul 2014 16:59:20 +0530 Subject: [PATCH 1/6] Validation: Account must belong to the same company --- erpnext/accounts/doctype/account/account.py | 25 +++++++++++--------- erpnext/setup/doctype/company/company.py | 17 +++++++++++-- erpnext/stock/doctype/warehouse/warehouse.py | 23 ++++++++++++++---- 3 files changed, 47 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 014dde51e9..5b034f8b23 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -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 diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py index f8e043a927..bd623e6ad6 100644 --- a/erpnext/setup/doctype/company/company.py +++ b/erpnext/setup/doctype/company/company.py @@ -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 = [ diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 2b6892890a..0095bbb4e5 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -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 From 0ad677045ae18fac064c0b3384680f3678687a67 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Tue, 29 Jul 2014 17:47:02 +0530 Subject: [PATCH 2/6] Test record fixed for warehouse --- erpnext/accounts/general_ledger.py | 3 ++- erpnext/stock/doctype/warehouse/test_records.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 3fbbe39e2c..673149577d 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -15,7 +15,8 @@ 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: + save_entries(gl_map, adv_adj, update_outstanding) else: delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding) diff --git a/erpnext/stock/doctype/warehouse/test_records.json b/erpnext/stock/doctype/warehouse/test_records.json index e0941af26c..72071f88ca 100644 --- a/erpnext/stock/doctype/warehouse/test_records.json +++ b/erpnext/stock/doctype/warehouse/test_records.json @@ -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" }, From c34329284b8759f0a48498c8d49e7a6724cd2451 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Tue, 29 Jul 2014 18:06:18 +0530 Subject: [PATCH 3/6] Post gl entries only if there are atleast 2 distinct account head --- erpnext/accounts/general_ledger.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 673149577d..a98d6d08f2 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -15,8 +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) - if gl_map: + if gl_map and len(gl_map) > 1: save_entries(gl_map, adv_adj, update_outstanding) + else: + frappe.throw(_("No general ledger entries. You might have selected wrong account head")) else: delete_gl_entries(gl_map, adv_adj=adv_adj, update_outstanding=update_outstanding) From 4859b48c4302796ff26e4506b3329105f7294d18 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Wed, 30 Jul 2014 14:28:24 +0530 Subject: [PATCH 4/6] message fix --- erpnext/accounts/general_ledger.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index a98d6d08f2..211476822f 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -18,7 +18,7 @@ def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, if gl_map and len(gl_map) > 1: save_entries(gl_map, adv_adj, update_outstanding) else: - frappe.throw(_("No general ledger entries. You might have selected wrong account head")) + 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) From d6ff58daa10707eb2878dcd3104a4262fd7b1bec Mon Sep 17 00:00:00 2001 From: nabinhait Date: Wed, 30 Jul 2014 14:40:57 +0530 Subject: [PATCH 5/6] Minor fix in customer issue --- erpnext/support/doctype/customer_issue/customer_issue.py | 1 - 1 file changed, 1 deletion(-) diff --git a/erpnext/support/doctype/customer_issue/customer_issue.py b/erpnext/support/doctype/customer_issue/customer_issue.py index d6d65966fe..6f368a8b04 100644 --- a/erpnext/support/doctype/customer_issue/customer_issue.py +++ b/erpnext/support/doctype/customer_issue/customer_issue.py @@ -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 From 8dbd295c9ba451a207e1155c60862c3494f4e2c0 Mon Sep 17 00:00:00 2001 From: nabinhait Date: Thu, 31 Jul 2014 11:40:21 +0530 Subject: [PATCH 6/6] bom operations on_delete_row function --- erpnext/manufacturing/doctype/bom/bom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 6af63d9633..d73ac9a11e 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -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); }