fix: default cost center in item master not set in stock entry (#23877)

Co-authored-by: Marica <maricadsouza221197@gmail.com>
This commit is contained in:
rohitwaghchaure 2020-11-15 09:40:44 +05:30 committed by GitHub
parent 8ff0d0cff6
commit 1c8c1d78e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 6 deletions

View File

@ -443,6 +443,11 @@ class TestWorkOrder(unittest.TestCase):
ste1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1)) ste1 = frappe.get_doc(make_stock_entry(wo.name, "Manufacture", 1))
self.assertEqual(len(ste1.items), 3) self.assertEqual(len(ste1.items), 3)
def test_cost_center_for_manufacture(self):
wo_order = make_wo_order_test_record()
ste = make_stock_entry(wo_order.name, "Material Transfer for Manufacture", wo_order.qty)
self.assertEquals(ste.get("items")[0].get("cost_center"), "_Test Cost Center - _TC")
def test_operation_time_with_batch_size(self): def test_operation_time_with_batch_size(self):
fg_item = "Test Batch Size Item For BOM" fg_item = "Test Batch Size Item For BOM"
rm1 = "Test Batch Size Item RM 1 For BOM" rm1 = "Test Batch Size Item RM 1 For BOM"

View File

@ -1227,8 +1227,6 @@ class StockEntry(StockController):
return item_dict return item_dict
def add_to_stock_entry_detail(self, item_dict, bom_no=None): def add_to_stock_entry_detail(self, item_dict, bom_no=None):
cost_center = frappe.db.get_value("Company", self.company, 'cost_center')
for d in item_dict: for d in item_dict:
stock_uom = item_dict[d].get("stock_uom") or frappe.db.get_value("Item", d, "stock_uom") stock_uom = item_dict[d].get("stock_uom") or frappe.db.get_value("Item", d, "stock_uom")
@ -1239,9 +1237,10 @@ class StockEntry(StockController):
se_child.uom = item_dict[d]["uom"] if item_dict[d].get("uom") else stock_uom se_child.uom = item_dict[d]["uom"] if item_dict[d].get("uom") else stock_uom
se_child.stock_uom = stock_uom se_child.stock_uom = stock_uom
se_child.qty = flt(item_dict[d]["qty"], se_child.precision("qty")) se_child.qty = flt(item_dict[d]["qty"], se_child.precision("qty"))
se_child.cost_center = item_dict[d].get("cost_center") or cost_center
se_child.allow_alternative_item = item_dict[d].get("allow_alternative_item", 0) se_child.allow_alternative_item = item_dict[d].get("allow_alternative_item", 0)
se_child.subcontracted_item = item_dict[d].get("main_item_code") se_child.subcontracted_item = item_dict[d].get("main_item_code")
se_child.cost_center = (item_dict[d].get("cost_center") or
get_default_cost_center(item_dict[d], company = self.company))
for field in ["idx", "po_detail", "original_item", for field in ["idx", "po_detail", "original_item",
"expense_account", "description", "item_name"]: "expense_account", "description", "item_name"]:

View File

@ -559,23 +559,40 @@ def get_default_deferred_account(args, item, fieldname=None):
else: else:
return None return None
def get_default_cost_center(args, item, item_group, brand, company=None): def get_default_cost_center(args, item=None, item_group=None, brand=None, company=None):
cost_center = None cost_center = None
if not company and args.get("company"):
company = args.get("company")
if args.get('project'): if args.get('project'):
cost_center = frappe.db.get_value("Project", args.get("project"), "cost_center", cache=True) cost_center = frappe.db.get_value("Project", args.get("project"), "cost_center", cache=True)
if not cost_center: if not cost_center and (item and item_group and brand):
if args.get('customer'): if args.get('customer'):
cost_center = item.get('selling_cost_center') or item_group.get('selling_cost_center') or brand.get('selling_cost_center') cost_center = item.get('selling_cost_center') or item_group.get('selling_cost_center') or brand.get('selling_cost_center')
else: else:
cost_center = item.get('buying_cost_center') or item_group.get('buying_cost_center') or brand.get('buying_cost_center') cost_center = item.get('buying_cost_center') or item_group.get('buying_cost_center') or brand.get('buying_cost_center')
cost_center = cost_center or args.get("cost_center") elif not cost_center and args.get("item_code") and company:
for method in ["get_item_defaults", "get_item_group_defaults", "get_brand_defaults"]:
path = "erpnext.stock.get_item_details.{0}".format(method)
data = frappe.get_attr(path)(args.get("item_code"), company)
if data and (data.selling_cost_center or data.buying_cost_center):
return data.selling_cost_center or data.buying_cost_center
if not cost_center and args.get("cost_center"):
cost_center = args.get("cost_center")
if (company and cost_center if (company and cost_center
and frappe.get_cached_value("Cost Center", cost_center, "company") != company): and frappe.get_cached_value("Cost Center", cost_center, "company") != company):
return None return None
if not cost_center and company:
cost_center = frappe.get_cached_value("Company",
company, "cost_center")
return cost_center return cost_center
def get_default_supplier(args, item, item_group, brand): def get_default_supplier(args, item, item_group, brand):