2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-06-15 05:39:27 +00:00
|
|
|
import frappe
|
|
|
|
|
2012-04-05 12:57:56 +00:00
|
|
|
install_docs = [
|
2015-07-13 09:36:12 +00:00
|
|
|
{"doctype":"Role", "role_name":"Stock Manager", "name":"Stock Manager"},
|
|
|
|
{"doctype":"Role", "role_name":"Item Manager", "name":"Item Manager"},
|
|
|
|
{"doctype":"Role", "role_name":"Stock User", "name":"Stock User"},
|
2012-04-17 06:15:35 +00:00
|
|
|
{"doctype":"Role", "role_name":"Quality Manager", "name":"Quality Manager"},
|
2016-07-14 08:33:19 +00:00
|
|
|
{"doctype":"Item Group", "item_group_name":"All Item Groups", "is_group": 1},
|
2013-01-16 12:18:17 +00:00
|
|
|
{"doctype":"Item Group", "item_group_name":"Default",
|
2016-07-14 08:33:19 +00:00
|
|
|
"parent_item_group":"All Item Groups", "is_group": 0},
|
2012-04-05 12:57:56 +00:00
|
|
|
]
|
2017-06-15 05:39:27 +00:00
|
|
|
|
|
|
|
def get_warehouse_account_map():
|
|
|
|
if not frappe.flags.warehouse_account_map or frappe.flags.in_test:
|
|
|
|
warehouse_account = frappe._dict()
|
|
|
|
|
2018-04-02 05:00:17 +00:00
|
|
|
for d in frappe.get_all('Warehouse',
|
|
|
|
fields = ["name", "account", "parent_warehouse", "company"],
|
|
|
|
order_by="lft, rgt"):
|
2017-06-15 05:39:27 +00:00
|
|
|
if not d.account:
|
2018-04-02 05:00:17 +00:00
|
|
|
d.account = get_warehouse_account(d, warehouse_account)
|
2017-06-15 05:39:27 +00:00
|
|
|
|
|
|
|
if d.account:
|
2018-04-02 05:00:17 +00:00
|
|
|
d.account_currency = frappe.db.get_value('Account', d.account, 'account_currency', cache=True)
|
2017-06-15 05:39:27 +00:00
|
|
|
warehouse_account.setdefault(d.name, d)
|
2018-04-02 05:00:17 +00:00
|
|
|
|
2017-06-15 05:39:27 +00:00
|
|
|
frappe.flags.warehouse_account_map = warehouse_account
|
2018-04-02 05:00:17 +00:00
|
|
|
|
2017-06-15 05:39:27 +00:00
|
|
|
return frappe.flags.warehouse_account_map
|
|
|
|
|
2018-04-02 05:00:17 +00:00
|
|
|
def get_warehouse_account(warehouse, warehouse_account=None):
|
|
|
|
account = warehouse.account
|
|
|
|
if not account and warehouse.parent_warehouse:
|
|
|
|
if warehouse_account:
|
|
|
|
account = warehouse_account.get(warehouse.parent_warehouse).account
|
|
|
|
else:
|
|
|
|
account = frappe.db.sql("""
|
|
|
|
select
|
|
|
|
account from `tabWarehouse`
|
|
|
|
where
|
|
|
|
lft <= %s and rgt >= %s and company = %s
|
|
|
|
and account is not null and ifnull(account, '') !=''
|
|
|
|
order by lft desc limit 1""", (warehouse.lft, warehouse.rgt, warehouse.company), as_list=1)
|
|
|
|
|
|
|
|
account = account[0][0] if account else None
|
|
|
|
|
2018-08-16 08:28:44 +00:00
|
|
|
if not account and warehouse.company:
|
2018-04-02 05:00:17 +00:00
|
|
|
account = get_company_default_inventory_account(warehouse.company)
|
|
|
|
|
2017-06-15 05:39:27 +00:00
|
|
|
return account
|
|
|
|
|
|
|
|
def get_company_default_inventory_account(company):
|
2018-08-16 08:28:44 +00:00
|
|
|
return frappe.get_cached_value('Company', company, 'default_inventory_account')
|