[fix] patch fix
This commit is contained in:
parent
52c2affc9c
commit
ee17e2f277
@ -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.v7_0.update_mins_to_first_response
|
||||||
erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory
|
erpnext.patches.v6_20x.repost_valuation_rate_for_negative_inventory
|
||||||
erpnext.patches.v7_0.re_route #2016-06-27
|
erpnext.patches.v7_0.re_route #2016-06-27
|
||||||
erpnext.patches.v7_0.create_warehouse_nestedset #2016-06-28
|
erpnext.patches.v7_0.create_warehouse_nestedset
|
||||||
erpnext.patches.v7_0.system_settings_setup_complete
|
erpnext.patches.v7_0.system_settings_setup_complete
|
||||||
erpnext.patches.v7_0.merge_account_type_stock_and_warehouse_to_stock
|
erpnext.patches.v7_0.merge_account_type_stock_and_warehouse_to_stock
|
||||||
erpnext.patches.v7_0.set_naming_series_for_timesheet
|
erpnext.patches.v7_0.set_naming_series_for_timesheet
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint
|
from frappe.utils import cint
|
||||||
|
from frappe.utils.nestedset import rebuild_tree
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
frappe.reload_doc("stock", "doctype", "warehouse")
|
frappe.reload_doc("stock", "doctype", "warehouse")
|
||||||
@ -11,36 +12,24 @@ def execute():
|
|||||||
if not frappe.db.get_value("Warehouse", "{0} - {1}".format(_("All Warehouses"), company.abbr)):
|
if not frappe.db.get_value("Warehouse", "{0} - {1}".format(_("All Warehouses"), company.abbr)):
|
||||||
create_default_warehouse_group(company)
|
create_default_warehouse_group(company)
|
||||||
|
|
||||||
for warehouse in frappe.get_all("Warehouse", filters={"company": company.name}, fields=["name", "create_account_under",
|
set_parent_to_warehouse(company)
|
||||||
"parent_warehouse", "is_group"]):
|
|
||||||
set_parent_to_warehouses(warehouse, company)
|
|
||||||
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
||||||
set_parent_to_warehouse_acounts(warehouse, company)
|
set_parent_to_warehouse_acount(company)
|
||||||
|
|
||||||
def set_parent_to_warehouses(warehouse, company):
|
def set_parent_to_warehouse(company):
|
||||||
warehouse = frappe.get_doc("Warehouse", warehouse.name)
|
frappe.db.sql(""" update tabWarehouse set parent_warehouse = %s
|
||||||
warehouse.is_group = warehouse.is_group
|
where (is_group = 0 or is_group is null or is_group = '') and company = %s
|
||||||
|
""",("{0} - {1}".format(_("All Warehouses"), company.abbr), company.name))
|
||||||
|
|
||||||
if not warehouse.parent_warehouse and warehouse.name != "{0} - {1}".format(_("All Warehouses"), company.abbr):
|
rebuild_tree("Warehouse", "parent_warehouse")
|
||||||
warehouse.parent_warehouse = "{0} - {1}".format(_("All Warehouses"), company.abbr)
|
|
||||||
|
|
||||||
warehouse.save(ignore_permissions=True)
|
def set_parent_to_warehouse_acount(company):
|
||||||
|
frappe.db.sql(""" update tabAccount set parent_account = %s
|
||||||
|
where is_group = 0 and account_type = "Warehouse"
|
||||||
|
and (warehouse is not null or warehouse != '') and company = %s
|
||||||
|
""",("{0} - {1}".format(_("All Warehouses"), company.abbr), company.name))
|
||||||
|
|
||||||
def set_parent_to_warehouse_acounts(warehouse, company):
|
rebuild_tree("Account", "parent_account")
|
||||||
account = frappe.db.get_value("Account", {"warehouse": warehouse.name})
|
|
||||||
stock_group = frappe.db.get_value("Account", {"account_type": "Stock",
|
|
||||||
"is_group": 1, "company": company.name})
|
|
||||||
|
|
||||||
if account and account != "{0} - {1}".format(_("All Warehouses"), company.abbr):
|
|
||||||
account = frappe.get_doc("Account", account)
|
|
||||||
|
|
||||||
if warehouse.create_account_under == stock_group or not warehouse.create_account_under:
|
|
||||||
if not warehouse.parent_warehouse:
|
|
||||||
account.parent_account = "{0} - {1}".format(_("All Warehouses"), company.abbr)
|
|
||||||
else:
|
|
||||||
account.parent_account = frappe.db.get_value("Account", warehouse.parent_warehouse)
|
|
||||||
|
|
||||||
account.save(ignore_permissions=True)
|
|
||||||
|
|
||||||
def create_default_warehouse_group(company):
|
def create_default_warehouse_group(company):
|
||||||
frappe.get_doc({
|
frappe.get_doc({
|
||||||
@ -53,14 +42,14 @@ def create_default_warehouse_group(company):
|
|||||||
|
|
||||||
def validate_parent_account_for_warehouse(company):
|
def validate_parent_account_for_warehouse(company):
|
||||||
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
|
||||||
|
|
||||||
parent_account = frappe.db.sql("""select name from tabAccount
|
parent_account = frappe.db.sql("""select name from tabAccount
|
||||||
where account_type='Stock' and company=%s and is_group=1
|
where account_type='Stock' and company=%s and is_group=1
|
||||||
and (warehouse is null or warehouse = '')""", company.name)
|
and (warehouse is null or warehouse = '')""", company.name)
|
||||||
|
|
||||||
if not parent_account:
|
if not parent_account:
|
||||||
current_parent_accounts_for_warehouse = frappe.db.sql("""select parent_account from tabAccount
|
current_parent_accounts_for_warehouse = frappe.db.sql("""select parent_account from tabAccount
|
||||||
where account_type='Warehouse' and (warehouse is not null or warehouse != '') """)
|
where account_type='Warehouse' and (warehouse is not null or warehouse != '') """)
|
||||||
|
|
||||||
if current_parent_accounts_for_warehouse:
|
if current_parent_accounts_for_warehouse:
|
||||||
doc = frappe.get_doc("Account", current_parent_accounts_for_warehouse[0][0])
|
frappe.db.set_value("Account", current_parent_accounts_for_warehouse[0][0], "account_type", "Stock")
|
||||||
doc.account_type = "Stock"
|
|
||||||
doc.warehouse = ""
|
|
||||||
doc.save(ignore_permissions=True)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user