changes for the default cost center
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 7dc9a89..9487963 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -883,13 +883,13 @@
frappe.throw(
_("Default Unit of Measure for Item {0} cannot be changed directly because you have already made some transaction(s) with another UOM. You will need to create a new Item to use a different Default UOM.").format(item))
-def get_item_details(item, company):
+def get_item_defaults(item, company):
return frappe.db.sql('''
select
- i.item_name, i.description, i.stock_uom, i.name, i.is_stock_item, i.item_code
- id.expense_account, id.buying_cost_center, id.warehouse
+ i.item_name, i.description, i.stock_uom, i.name, i.is_stock_item, i.item_code, i.item_group,
+ id.expense_account, id.buying_cost_center, id.default_warehouse, id.selling_cost_center
from
`tabItem` i, `tabItem Default` id
where
i.name = id.parent and i.name = %s and id.company = %s
- ''', (item, company), as_dict=1)
\ No newline at end of file
+ ''', (item, company), as_dict=1)[0]
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/test_item.py b/erpnext/stock/doctype/item/test_item.py
index ee2ca98..1c915ee 100644
--- a/erpnext/stock/doctype/item/test_item.py
+++ b/erpnext/stock/doctype/item/test_item.py
@@ -36,7 +36,7 @@
if item.is_stock_item:
- for item_default in [doc for doc in item.item_defaults if not doc.default_warehouse]
+ for item_default in [doc for doc in item.item_defaults if not doc.default_warehouse]:
item_default.default_warehouse = "_Test Warehouse - _TC"
item.insert()
@@ -205,7 +205,7 @@
"default_warehouse": "_Test Warehouse - _TC",
"company": "_Test Company"
}
- ]
+ ],
"has_variants": 1
})
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 49a278c..5a6384a 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -10,7 +10,7 @@
from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError, get_valuation_rate
from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor
from erpnext.stock.doctype.batch.batch import get_batch_no, set_batch_nos, get_batch_qty
-from erpnext.stock.doctype.item.item import get_item_details
+from erpnext.stock.doctype.item.item import get_item_defaults
from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
from erpnext.stock.utils import get_bin
import json
@@ -563,14 +563,14 @@
pro_doc.run_method("update_planned_qty")
def get_item_details(self, args=None, for_update=False):
- item = frappe.db.sql("""select stock_uom, description, image, item_name,
- expense_account, buying_cost_center, item_group, has_serial_no,
- has_batch_no, sample_quantity
- from `tabItem`
- where name = %s
- and disabled=0
- and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""",
- (args.get('item_code'), nowdate()), as_dict = 1)
+ item = frappe.db.sql("""select i.stock_uom, i.description, i.image, i.item_name, i.item_group,
+ i.has_batch_no, i.sample_quantity, i.has_serial_no,
+ id.expense_account, id.buying_cost_center
+ from `tabItem`, `tabItem Default` id
+ where i.name=%s and i.name=id.parent and id.company=%s
+ and i.disabled=0
+ and (i.end_of_life is null or i.end_of_life='0000-00-00' or i.end_of_life > %s)""",
+ (args.get('item_code'), self.company, nowdate()), as_dict = 1)
if not item:
frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code")))
@@ -717,7 +717,7 @@
item_code = frappe.db.get_value("BOM", self.bom_no, "item")
to_warehouse = self.to_warehouse
- item = get_item_details(item_code, self.company)
+ item = get_item_defaults(item_code, self.company)
if not self.work_order and not to_warehouse:
# in case of BOM
@@ -783,7 +783,7 @@
for item in wo_items:
qty = item.required_qty
- item_account_details = get_item_details(item.item_code, self.company)
+ item_account_details = get_item_defaults(item.item_code, self.company)
# Take into account consumption if there are any.
if self.purpose == 'Manufacture':
req_qty_each = flt(item.required_qty / wo.qty)
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 0351364..bbbe860 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -11,7 +11,7 @@
from frappe.model.meta import get_field_precision
from erpnext.stock.doctype.batch.batch import get_batch_no
from erpnext import get_company_currency
-from erpnext.stock.doctype.item.item import get_item_details
+from erpnext.stock.doctype.item.item import get_item_defaults
from six import string_types, iteritems
@@ -206,9 +206,8 @@
user_default_warehouse = user_default_warehouse_list[0] \
if len(user_default_warehouse_list) == 1 else ""
- item_default_warehouse = [default.default_warehouse for default in item.item_defaults if default.company == args.company]
- item_default_warehouse = item_default_warehouse[0] if item_default_warehouse else None
- warehouse = user_default_warehouse or item_default_warehouse or args.warehouse
+ item_defaults = get_item_defaults(item.name, args.company)
+ warehouse = user_default_warehouse or item_defaults.default_warehouse or args.warehouse
material_request_type = ''
if args.get('doctype') == "Material Request":
@@ -231,9 +230,9 @@
"description": cstr(item.description).strip(),
"image": cstr(item.image).strip(),
"warehouse": warehouse,
- "income_account": get_default_income_account(args, item),
- "expense_account": get_default_expense_account(args, item),
- "cost_center": get_default_cost_center(args, item),
+ "income_account": get_default_income_account(args, item_defaults),
+ "expense_account": get_default_expense_account(args, item_defaults),
+ "cost_center": get_default_cost_center(args, item_defaults),
'has_serial_no': item.has_serial_no,
'has_batch_no': item.has_batch_no,
"batch_no": None,
@@ -682,7 +681,7 @@
return bom
def get_valuation_rate(item_code, company, warehouse=None):
- item = get_item_details(item_code, company)
+ item = get_item_defaults(item_code, company)
# item = frappe.get_doc("Item", item_code)
if item.is_stock_item:
if not warehouse: