From 5ee8fccb1a66b9422bab2aebb8653eba87404815 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Fri, 24 Jun 2016 17:11:15 +0530 Subject: [PATCH 1/8] Item Price update in Price List --- erpnext/stock/get_item_details.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index c42350a421..dcbd3dde5e 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -237,10 +237,10 @@ def insert_item_price(args): if frappe.db.get_value("Price List", args.price_list, "currency") == args.currency \ and cint(frappe.db.get_single_value("Stock Settings", "auto_insert_price_list_rate_if_missing")): if frappe.has_permission("Item Price", "write"): - price_list_rate = args.rate / args.conversion_factor \ if args.get("conversion_factor") else args.rate - + if not price_list_rate: return + item_price = frappe.get_doc({ "doctype": "Item Price", "price_list": args.price_list, @@ -248,9 +248,19 @@ def insert_item_price(args): "currency": args.currency, "price_list_rate": price_list_rate }) - item_price.insert() - frappe.msgprint(_("Item Price added for {0} in Price List {1}").format(args.item_code, - args.price_list)) + + name = frappe.db.get_value('Item Price', {'item_code': args.item_code, 'price_list': args.price_list}, 'name') + + if name: + item_price = frappe.get_doc('Item Price', name) + item_price.price_list_rate = price_list_rate + item_price.save() + frappe.msgprint(_("Item Price updated for {0} in Price List {1}").format(args.item_code, + args.price_list)) + else: + item_price.insert() + frappe.msgprint(_("Item Price added for {0} in Price List {1}").format(args.item_code, + args.price_list)) def get_price_list_rate_for(price_list, item_code): return frappe.db.get_value("Item Price", From 4c0df04db0472aabd11b30b78e6fe0f7a4331f44 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sat, 25 Jun 2016 17:45:16 +0530 Subject: [PATCH 2/8] Retirement Age option in HR Settings --- erpnext/hr/doctype/employee/employee.py | 7 +++- .../hr/doctype/hr_settings/hr_settings.json | 37 ++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index 4919229114..8257ec2664 100755 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -186,7 +186,12 @@ def get_retirement_date(date_of_birth=None): ret = {} if date_of_birth: try: - dt = getdate(date_of_birth) + datetime.timedelta(21915) + retirement_age = frappe.db.get_single_value("HR Settings", "retirement_age") + if retirement_age: + dt = getdate(date_of_birth) + datetime.timedelta(int(retirement_age)*365.2425) + else: + dt = getdate(date_of_birth) + datetime.timedelta(21914.55) + ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')} except ValueError: # invalid date diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json index 561f013eca..599aaccfa9 100644 --- a/erpnext/hr/doctype/hr_settings/hr_settings.json +++ b/erpnext/hr/doctype/hr_settings/hr_settings.json @@ -2,6 +2,7 @@ "allow_copy": 0, "allow_import": 0, "allow_rename": 0, + "beta": 0, "creation": "2013-08-02 13:45:23", "custom": 0, "docstatus": 0, @@ -32,6 +33,33 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "default": "", + "description": "Enter retirement age in years", + "fieldname": "retirement_age", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_list_view": 0, + "label": "Retirement Age", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_on_submit": 0, "bold": 0, @@ -165,13 +193,14 @@ "hide_toolbar": 0, "icon": "icon-cog", "idx": 1, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 0, "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2016-04-26 05:54:32.501880", + "modified": "2016-06-25 17:43:06.643469", "modified_by": "Administrator", "module": "HR", "name": "HR Settings", @@ -191,6 +220,8 @@ "print": 1, "read": 1, "report": 0, + "restrict": 0, + "restricted": 0, "role": "System Manager", "set_user_permissions": 0, "share": 1, @@ -198,7 +229,9 @@ "write": 1 } ], + "quick_entry": 0, "read_only": 0, "read_only_onload": 0, - "sort_order": "ASC" + "sort_order": "ASC", + "track_seen": 0 } \ No newline at end of file From 2ff7d2aade7e18054664e230f5ef470e2cf27947 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sat, 25 Jun 2016 17:54:25 +0530 Subject: [PATCH 3/8] Fixed --- erpnext/stock/get_item_details.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index dcbd3dde5e..f67026ef18 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -239,7 +239,6 @@ def insert_item_price(args): if frappe.has_permission("Item Price", "write"): price_list_rate = args.rate / args.conversion_factor \ if args.get("conversion_factor") else args.rate - if not price_list_rate: return item_price = frappe.get_doc({ "doctype": "Item Price", @@ -249,7 +248,7 @@ def insert_item_price(args): "price_list_rate": price_list_rate }) - name = frappe.db.get_value('Item Price', {'item_code': args.item_code, 'price_list': args.price_list}, 'name') + name = frappe.db.get_value('Item Price', {'item_code': args.item_code, 'price_list': args.price_list, 'currency': args.currency}, 'name') if name: item_price = frappe.get_doc('Item Price', name) From 520fb73676a0f23cc629558a947ea503c43735fe Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sun, 26 Jun 2016 12:09:39 +0530 Subject: [PATCH 4/8] [fix] authorization rule fix for sales order --- erpnext/selling/doctype/sales_order/sales_order.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 060ed621a8..2e0a272ae5 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -153,7 +153,7 @@ class SalesOrder(SellingController): self.check_credit_limit() self.update_reserved_qty() - frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, self.base_grand_total, self) + frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype, self.company, self.base_grand_total, self) self.update_prevdoc_status('submit') From 68f5ae5cbf8d2baa3e2f2780c59121c952b55726 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Sun, 26 Jun 2016 14:10:24 +0530 Subject: [PATCH 5/8] Changes done --- erpnext/hr/doctype/employee/employee.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py index 8257ec2664..578e7b72ac 100755 --- a/erpnext/hr/doctype/employee/employee.py +++ b/erpnext/hr/doctype/employee/employee.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe -from frappe.utils import getdate, validate_email_add, today +from frappe.utils import getdate, validate_email_add, today, add_years from frappe.model.naming import make_autoname from frappe import throw, _ import frappe.permissions @@ -186,12 +186,8 @@ def get_retirement_date(date_of_birth=None): ret = {} if date_of_birth: try: - retirement_age = frappe.db.get_single_value("HR Settings", "retirement_age") - if retirement_age: - dt = getdate(date_of_birth) + datetime.timedelta(int(retirement_age)*365.2425) - else: - dt = getdate(date_of_birth) + datetime.timedelta(21914.55) - + retirement_age = int(frappe.db.get_single_value("HR Settings", "retirement_age") or 60) + dt = add_years(getdate(date_of_birth),retirement_age) ret = {'date_of_retirement': dt.strftime('%Y-%m-%d')} except ValueError: # invalid date From 7fecb503605c41fa2a17bf2ac01226ca76199391 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Fri, 24 Jun 2016 13:11:29 +0530 Subject: [PATCH 6/8] [enhance] rename warehouse account type to stock --- erpnext/accounts/doctype/account/account.js | 2 +- erpnext/accounts/doctype/account/account.json | 7 +++++-- erpnext/accounts/doctype/account/account.py | 15 ++++++++------- erpnext/accounts/general_ledger.py | 2 +- erpnext/accounts/report/cash_flow/cash_flow.py | 2 +- erpnext/accounts/utils.py | 2 +- erpnext/controllers/stock_controller.py | 2 +- erpnext/patches.txt | 1 + ...e_account_type_stock_and_warehouse_to_stock.py | 9 +++++++++ .../stock/doctype/stock_entry/test_stock_entry.py | 10 +++++----- erpnext/stock/doctype/warehouse/warehouse.py | 10 +++++----- erpnext/stock/stock_balance.py | 2 +- 12 files changed, 39 insertions(+), 25 deletions(-) create mode 100644 erpnext/patches/v7_0/merge_account_type_stock_and_warehouse_to_stock.py diff --git a/erpnext/accounts/doctype/account/account.js b/erpnext/accounts/doctype/account/account.js index b2eef20a45..9364b59f95 100644 --- a/erpnext/accounts/doctype/account/account.js +++ b/erpnext/accounts/doctype/account/account.js @@ -41,7 +41,7 @@ cur_frm.add_fetch('parent_account', 'root_type', 'root_type'); cur_frm.cscript.account_type = function(doc, cdt, cdn) { if(doc.is_group==0) { cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax'); - cur_frm.toggle_display('warehouse', doc.account_type=='Warehouse'); + cur_frm.toggle_display('warehouse', doc.account_type=='Stock'); } } diff --git a/erpnext/accounts/doctype/account/account.json b/erpnext/accounts/doctype/account/account.json index 8fc7b55aa9..f11a664b55 100644 --- a/erpnext/accounts/doctype/account/account.json +++ b/erpnext/accounts/doctype/account/account.json @@ -2,6 +2,7 @@ "allow_copy": 1, "allow_import": 1, "allow_rename": 1, + "beta": 0, "creation": "2013-01-30 12:49:46", "custom": 0, "description": "Heads (or groups) against which Accounting Entries are made and balances are maintained.", @@ -282,7 +283,7 @@ "no_copy": 0, "oldfieldname": "account_type", "oldfieldtype": "Select", - "options": "\nAccumulated Depreciation\nBank\nCash\nChargeable\nCost of Goods Sold\nDepreciation\nEquity\nExpense Account\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nTax\nTemporary\nWarehouse", + "options": "\nAccumulated Depreciation\nBank\nCash\nChargeable\nCost of Goods Sold\nDepreciation\nEquity\nExpense Account\nExpenses Included In Valuation\nFixed Asset\nIncome Account\nPayable\nReceivable\nRound Off\nStock\nStock Adjustment\nStock Received But Not Billed\nTax\nTemporary", "permlevel": 0, "print_hide": 0, "print_hide_if_no_value": 0, @@ -475,13 +476,14 @@ "hide_toolbar": 0, "icon": "icon-money", "idx": 1, + "image_view": 0, "in_create": 0, "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-03-31 05:15:51.062604", + "modified": "2016-06-24 13:33:45.504882", "modified_by": "Administrator", "module": "Accounts", "name": "Account", @@ -588,6 +590,7 @@ "write": 1 } ], + "quick_entry": 0, "read_only": 0, "read_only_onload": 0, "search_fields": "", diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py index 83517ce717..95209288dc 100644 --- a/erpnext/accounts/doctype/account/account.py +++ b/erpnext/accounts/doctype/account/account.py @@ -164,20 +164,21 @@ class Account(Document): def validate_warehouse_account(self): if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")): return - - if self.account_type == "Warehouse": + + if self.account_type == "Stock" and not self.is_group: if not self.warehouse: - throw(_("Warehouse is mandatory if account type is Warehouse")) - - old_warehouse = frappe.db.get_value("Account", self.name, "warehouse") - if old_warehouse != self.warehouse: + throw(_("Warehouse is mandatory")) + + old_warehouse = cstr(frappe.db.get_value("Account", self.name, "warehouse")) + if old_warehouse != cstr(self.warehouse): if old_warehouse: self.validate_warehouse(old_warehouse) if self.warehouse: self.validate_warehouse(self.warehouse) + elif self.warehouse: self.warehouse = None - + def validate_warehouse(self, warehouse): lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"]) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index be9a884e6e..21b09c4fc3 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -99,7 +99,7 @@ def validate_account_for_auto_accounting_for_stock(gl_map): if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")) \ and gl_map[0].voucher_type=="Journal Entry": aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount - where account_type = 'Warehouse' and (warehouse != '' and warehouse is not null)""")] + where account_type = 'Stock' and (warehouse != '' and warehouse is not null)""")] for entry in gl_map: if entry.account in aii_accounts: diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py index 681e563b90..3407526516 100644 --- a/erpnext/accounts/report/cash_flow/cash_flow.py +++ b/erpnext/accounts/report/cash_flow/cash_flow.py @@ -19,7 +19,7 @@ def execute(filters=None): {"account_type": "Depreciation", "label": _("Depreciation")}, {"account_type": "Receivable", "label": _("Net Change in Accounts Receivable")}, {"account_type": "Payable", "label": _("Net Change in Accounts Payable")}, - {"account_type": "Warehouse", "label": _("Net Change in Inventory")} + {"account_type": "Stock", "label": _("Net Change in Inventory")} ] } diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index fbead264cf..d2cfb78b5d 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -318,7 +318,7 @@ def get_stock_and_account_difference(account_list=None, posting_date=None): difference = {} account_warehouse = dict(frappe.db.sql("""select name, warehouse from tabAccount - where account_type = 'Warehouse' and (warehouse is not null and warehouse != '') + where account_type = 'Stock' and (warehouse is not null and warehouse != '') and name in (%s)""" % ', '.join(['%s']*len(account_list)), account_list)) for account, warehouse in account_warehouse.items(): diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 1e685e5ca1..e0420d6cb6 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -321,7 +321,7 @@ def get_warehouse_account(): warehouse_account = frappe._dict() for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount - where account_type = 'Warehouse' and (warehouse is not null and warehouse != '' + where account_type = 'Stock' and (warehouse is not null and warehouse != '' and is_group != 1)""", as_dict=1): warehouse_account.setdefault(d.warehouse, d) return warehouse_account diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 23f041c80e..5c1fc2d132 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -275,3 +275,4 @@ erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory erpnext.patches.v7_0.re_route erpnext.patches.v7_0.create_warehouse_nestedset erpnext.patches.v7_0.system_settings_setup_complete +erpnext.patches.v7_0.merge_account_type_stock_and_warehouse_to_stock diff --git a/erpnext/patches/v7_0/merge_account_type_stock_and_warehouse_to_stock.py b/erpnext/patches/v7_0/merge_account_type_stock_and_warehouse_to_stock.py new file mode 100644 index 0000000000..6141792b8f --- /dev/null +++ b/erpnext/patches/v7_0/merge_account_type_stock_and_warehouse_to_stock.py @@ -0,0 +1,9 @@ +import frappe + +def execute(): + frappe.reload_doc("accounts", "doctype", "account") + + frappe.db.sql(""" update tabAccount set account_type = "Stock" + where account_type = "Warehouse" """) + + frappe.db.commit() \ No newline at end of file diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index 24d0546224..30f2a06152 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -127,7 +127,7 @@ class TestStockEntry(unittest.TestCase): mr = make_stock_entry(item_code="_Test Item", target="_Test Warehouse - _TC", qty=50, basic_rate=100, expense_account="Stock Adjustment - _TC") - stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse", + stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Stock", "warehouse": mr.get("items")[0].t_warehouse}) self.check_stock_ledger_entries("Stock Entry", mr.name, @@ -160,7 +160,7 @@ class TestStockEntry(unittest.TestCase): self.check_stock_ledger_entries("Stock Entry", mi.name, [["_Test Item", "_Test Warehouse - _TC", -40.0]]) - stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse", + stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Stock", "warehouse": "_Test Warehouse - _TC"}) stock_value_diff = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Stock Entry", @@ -192,10 +192,10 @@ class TestStockEntry(unittest.TestCase): self.check_stock_ledger_entries("Stock Entry", mtn.name, [["_Test Item", "_Test Warehouse - _TC", -45.0], ["_Test Item", "_Test Warehouse 1 - _TC", 45.0]]) - stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse", + stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Stock", "warehouse": mtn.get("items")[0].s_warehouse}) - fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Warehouse", + fixed_asset_account = frappe.db.get_value("Account", {"account_type": "Stock", "warehouse": mtn.get("items")[0].t_warehouse}) stock_value_diff = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Stock Entry", @@ -260,7 +260,7 @@ class TestStockEntry(unittest.TestCase): repack.insert() repack.submit() - stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Warehouse", + stock_in_hand_account = frappe.db.get_value("Account", {"account_type": "Stock", "warehouse": repack.get("items")[1].t_warehouse}) rm_stock_value_diff = abs(frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Stock Entry", diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 57da471000..cd0954530a 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -18,7 +18,7 @@ class Warehouse(NestedSet): def onload(self): '''load account name for General Ledger Report''' account = frappe.db.get_value("Account", { - "account_type": "Warehouse", "company": self.company, "warehouse": self.name}) + "account_type": "Stock", "company": self.company, "warehouse": self.name, "is_group": 0}) if account: self.set_onload('account', account) @@ -36,7 +36,7 @@ class Warehouse(NestedSet): self.validate_parent_account() warehouse_account = frappe.db.get_value("Account", - {"account_type": "Warehouse", "company": self.company, "warehouse": self.name}, + {"account_type": "Stock", "company": self.company, "warehouse": self.name, "is_group": 0}, ["name", "parent_account"]) if warehouse_account and warehouse_account[1] != self.create_account_under: @@ -61,7 +61,7 @@ class Warehouse(NestedSet): else self.create_account_under, 'is_group': 1 if self.is_group=="Yes" else 0 , 'company':self.company, - "account_type": "Warehouse", + "account_type": "Stock", "warehouse": self.name, "freeze_account": "No" }) @@ -152,8 +152,8 @@ class Warehouse(NestedSet): return get_name_with_abbr(dn, self.company) def get_account(self, warehouse): - return frappe.db.get_value("Account", {"account_type": "Warehouse", - "warehouse": warehouse, "company": self.company}) + return frappe.db.get_value("Account", {"account_type": "Stock", + "warehouse": warehouse, "company": self.company, "is_group": 0}) def after_rename(self, olddn, newdn, merge=False): if merge: diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 7d92813549..61f799b75f 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -231,7 +231,7 @@ def reset_serial_no_status_and_warehouse(serial_nos=None): def repost_all_stock_vouchers(): warehouses_with_account = frappe.db.sql_list("""select master_name from tabAccount - where ifnull(account_type, '') = 'Warehouse'""") + where ifnull(account_type, '') = 'Stock' and (warehouse is not null and warehouse != '') """) vouchers = frappe.db.sql("""select distinct voucher_type, voucher_no from `tabStock Ledger Entry` sle From 78333c7e07485249bfa3c3702f1300a86c2bf90b Mon Sep 17 00:00:00 2001 From: Saurabh Date: Sat, 25 Jun 2016 14:18:28 +0530 Subject: [PATCH 7/8] [fixes] check group condition --- erpnext/accounts/general_ledger.py | 2 +- erpnext/accounts/utils.py | 2 +- erpnext/controllers/stock_controller.py | 2 +- erpnext/stock/stock_balance.py | 3 ++- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 21b09c4fc3..b7fb053bc3 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -99,7 +99,7 @@ def validate_account_for_auto_accounting_for_stock(gl_map): if cint(frappe.db.get_single_value("Accounts Settings", "auto_accounting_for_stock")) \ and gl_map[0].voucher_type=="Journal Entry": aii_accounts = [d[0] for d in frappe.db.sql("""select name from tabAccount - where account_type = 'Stock' and (warehouse != '' and warehouse is not null)""")] + where account_type = 'Stock' and (warehouse != '' and warehouse is not null) and is_group=0""")] for entry in gl_map: if entry.account in aii_accounts: diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index d2cfb78b5d..27389aa441 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -318,7 +318,7 @@ def get_stock_and_account_difference(account_list=None, posting_date=None): difference = {} account_warehouse = dict(frappe.db.sql("""select name, warehouse from tabAccount - where account_type = 'Stock' and (warehouse is not null and warehouse != '') + where account_type = 'Stock' and (warehouse is not null and warehouse != '') and is_group=0 and name in (%s)""" % ', '.join(['%s']*len(account_list)), account_list)) for account, warehouse in account_warehouse.items(): diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index e0420d6cb6..46ed9bc072 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -322,6 +322,6 @@ def get_warehouse_account(): for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount where account_type = 'Stock' and (warehouse is not null and warehouse != '' - and is_group != 1)""", as_dict=1): + and is_group != 1) and is_group=0 """, as_dict=1): warehouse_account.setdefault(d.warehouse, d) return warehouse_account diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 61f799b75f..22fa12a09b 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -231,7 +231,8 @@ def reset_serial_no_status_and_warehouse(serial_nos=None): def repost_all_stock_vouchers(): warehouses_with_account = frappe.db.sql_list("""select master_name from tabAccount - where ifnull(account_type, '') = 'Stock' and (warehouse is not null and warehouse != '') """) + where ifnull(account_type, '') = 'Stock' and (warehouse is not null and warehouse != '') + and is_group=0""") vouchers = frappe.db.sql("""select distinct voucher_type, voucher_no from `tabStock Ledger Entry` sle From d6b734e2e3eefebd699230cfe9ee95c8cb51c9ce Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Sun, 26 Jun 2016 17:43:14 +0530 Subject: [PATCH 8/8] [fix] DuplicateEntryError for Warehouse Account Creation --- erpnext/stock/doctype/warehouse/warehouse.py | 40 ++++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index cd0954530a..ed68065626 100644 --- a/erpnext/stock/doctype/warehouse/warehouse.py +++ b/erpnext/stock/doctype/warehouse/warehouse.py @@ -9,7 +9,7 @@ from frappe.utils.nestedset import NestedSet class Warehouse(NestedSet): nsm_parent_field = 'parent_warehouse' - + def autoname(self): suffix = " - " + frappe.db.get_value("Company", self.company, "abbr") if not self.warehouse_name.endswith(suffix): @@ -53,6 +53,7 @@ class Warehouse(NestedSet): if not self.get_account(self.name): if self.get("__islocal") or not frappe.db.get_value( "Stock Ledger Entry", {"warehouse": self.name}): + self.validate_parent_account() ac_doc = frappe.get_doc({ "doctype": "Account", @@ -66,16 +67,23 @@ class Warehouse(NestedSet): "freeze_account": "No" }) ac_doc.flags.ignore_permissions = True - ac_doc.insert() - msgprint(_("Account head {0} created").format(ac_doc.name)) + + try: + ac_doc.insert() + msgprint(_("Account head {0} created").format(ac_doc.name)) + + except frappe.DuplicateEntryError, e: + if not (e.args and e.args[0]=='Account'): + # if this is not due to creation of Account + raise 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.sql("""select name from tabAccount - where account_type='Stock' and company=%s and is_group=1 + parent_account = frappe.db.sql("""select name from tabAccount + where account_type='Stock' and company=%s and is_group=1 and (warehouse is null or warehouse = '')""", self.company) if parent_account: @@ -86,7 +94,7 @@ class Warehouse(NestedSet): 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 update_nsm_model(self): frappe.utils.nestedset.update_nsm(self) @@ -108,10 +116,10 @@ class Warehouse(NestedSet): if frappe.db.sql("""select name from `tabStock Ledger Entry` where warehouse = %s""", self.name): throw(_("Warehouse can not be deleted as stock ledger entry exists for this warehouse.")) - + if frappe.db.sql("""select name from `tabWarehouse` where parent_warehouse = %s""", self.name): throw(_("Child warehouse exists for this warehouse. You can not delete this warehouse.")) - + self.update_nsm_model() def before_rename(self, olddn, newdn, merge=False): @@ -179,10 +187,10 @@ def get_children(): from erpnext.stock.utils import get_stock_value_on doctype = frappe.local.form_dict.get('doctype') company = frappe.local.form_dict.get('company') - + parent_field = 'parent_' + doctype.lower().replace(' ', '_') parent = frappe.form_dict.get("parent") or "" - + if parent == "Warehouses": parent = "" @@ -193,23 +201,23 @@ def get_children(): and ifnull(`{parent_field}`,'') = %s and `company` = %s order by name""".format(doctype=frappe.db.escape(doctype), parent_field=frappe.db.escape(parent_field)), (parent, company), as_dict=1) - + # return warehouses for wh in warehouses: wh["balance"] = get_stock_value_on(warehouse=wh.value) return warehouses - + @frappe.whitelist() def add_node(): doctype = frappe.form_dict.get('doctype') company = frappe.form_dict.get('company') parent_field = 'parent_' + doctype.lower().replace(' ', '_') name_field = doctype.lower().replace(' ', '_') + '_name' - + doc = frappe.new_doc(doctype) - + parent = frappe.form_dict['parent'] - + if cint(frappe.form_dict['is_root']): parent = None @@ -219,5 +227,5 @@ def add_node(): "is_group": frappe.form_dict['is_group'], "company": company }) - + doc.save()