[fix] check for parent account with type stock in patch if not exists get parent account from existing warehouse accounts

This commit is contained in:
Saurabh 2016-06-28 14:41:48 +05:30
parent 4803376da8
commit 52c2affc9c
4 changed files with 25 additions and 7 deletions

View File

@ -27,13 +27,13 @@ frappe.treeview_settings["Account"] = {
{fieldtype:'Select', fieldname:'root_type', label:__('Root Type'),
options: ['Asset', 'Liability', 'Equity', 'Income', 'Expense'].join('\n')},
{fieldtype:'Select', fieldname:'account_type', label:__('Account Type'),
options: ['', 'Bank', 'Cash', 'Warehouse', 'Tax', 'Chargeable'].join('\n'),
options: ['', 'Bank', 'Cash', 'Stock', 'Tax', 'Chargeable'].join('\n'),
description: __("Optional. This setting will be used to filter in various transactions."),
depends_on: 'eval:doc.is_group==1'},
{fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate'),
depends_on: 'eval:doc.is_group==1&&doc.account_type=="Tax"'},
{fieldtype:'Link', fieldname:'warehouse', label:__('Warehouse'), options:"Warehouse",
depends_on: 'eval:(doc.is_group==1&&doc.account_type=="Warehouse")'},
depends_on: 'eval:(!doc.is_group&&doc.account_type=="Warehouse")'},
{fieldtype:'Link', fieldname:'account_currency', label:__('Currency'), options:"Currency",
description: __("Optional. Sets company's default currency, if not specified.")}
],

View File

@ -273,7 +273,7 @@ execute:frappe.rename_doc("DocType", "Payments", "Sales Invoice Payment", force=
erpnext.patches.v7_0.update_mins_to_first_response
erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory
erpnext.patches.v7_0.re_route #2016-06-27
erpnext.patches.v7_0.create_warehouse_nestedset
erpnext.patches.v7_0.create_warehouse_nestedset #2016-06-28
erpnext.patches.v7_0.system_settings_setup_complete
erpnext.patches.v7_0.merge_account_type_stock_and_warehouse_to_stock
erpnext.patches.v7_0.set_naming_series_for_timesheet

View File

@ -1,17 +1,21 @@
import frappe
from frappe import _
from frappe.utils import cint
def execute():
frappe.reload_doc("stock", "doctype", "warehouse")
for company in frappe.get_all("Company", fields=["name", "abbr"]):
validate_parent_account_for_warehouse(company)
if not frappe.db.get_value("Warehouse", "{0} - {1}".format(_("All Warehouses"), company.abbr)):
create_default_warehouse_group(company)
for warehouse in frappe.get_all("Warehouse", filters={"company": company.name}, fields=["name", "create_account_under",
"parent_warehouse", "is_group"]):
set_parent_to_warehouses(warehouse, company)
set_parent_to_warehouse_acounts(warehouse, company)
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
set_parent_to_warehouse_acounts(warehouse, company)
def set_parent_to_warehouses(warehouse, company):
warehouse = frappe.get_doc("Warehouse", warehouse.name)
@ -45,4 +49,18 @@ def create_default_warehouse_group(company):
"is_group": 1,
"company": company.name,
"parent_warehouse": ""
}).insert(ignore_permissions=True)
}).insert(ignore_permissions=True)
def validate_parent_account_for_warehouse(company):
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
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 = '')""", company.name)
if not parent_account:
current_parent_accounts_for_warehouse = frappe.db.sql("""select parent_account from tabAccount
where account_type='Warehouse' and (warehouse is not null or warehouse != '') """)
if current_parent_accounts_for_warehouse:
doc = frappe.get_doc("Account", current_parent_accounts_for_warehouse[0][0])
doc.account_type = "Stock"
doc.warehouse = ""
doc.save(ignore_permissions=True)

View File

@ -113,7 +113,7 @@ class Warehouse(NestedSet):
if warehouse_account:
frappe.delete_doc("Account", warehouse_account)
if self.check_sle_exists():
if self.check_if_sle_exists():
throw(_("Warehouse can not be deleted as stock ledger entry exists for this warehouse."))
if self.check_if_child_exists():