fix: SQL error on fetching RM in production plan (bp #26592)
* fix: SQL error on fetching RM in production plan * refactor: avoid passing by reference and mutations
This commit is contained in:
parent
49c5cd66f3
commit
5b32fa5ccd
@ -747,9 +747,8 @@ def get_bin_details(row, company, for_warehouse=None, all_warehouse=False):
|
|||||||
group by item_code, warehouse
|
group by item_code, warehouse
|
||||||
""".format(conditions=conditions), { "item_code": row['item_code'] }, as_dict=1)
|
""".format(conditions=conditions), { "item_code": row['item_code'] }, as_dict=1)
|
||||||
|
|
||||||
def get_warehouse_list(warehouses, warehouse_list=None):
|
def get_warehouse_list(warehouses):
|
||||||
if not warehouse_list:
|
warehouse_list = []
|
||||||
warehouse_list = []
|
|
||||||
|
|
||||||
if isinstance(warehouses, str):
|
if isinstance(warehouses, str):
|
||||||
warehouses = json.loads(warehouses)
|
warehouses = json.loads(warehouses)
|
||||||
@ -761,23 +760,19 @@ def get_warehouse_list(warehouses, warehouse_list=None):
|
|||||||
else:
|
else:
|
||||||
warehouse_list.append(row.get("warehouse"))
|
warehouse_list.append(row.get("warehouse"))
|
||||||
|
|
||||||
|
return warehouse_list
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_data=None):
|
def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_data=None):
|
||||||
if isinstance(doc, str):
|
if isinstance(doc, str):
|
||||||
doc = frappe._dict(json.loads(doc))
|
doc = frappe._dict(json.loads(doc))
|
||||||
|
|
||||||
warehouse_list = []
|
|
||||||
if warehouses:
|
if warehouses:
|
||||||
get_warehouse_list(warehouses, warehouse_list)
|
warehouses = list(set(get_warehouse_list(warehouses)))
|
||||||
|
|
||||||
if warehouse_list:
|
|
||||||
warehouses = list(set(warehouse_list))
|
|
||||||
|
|
||||||
if doc.get("for_warehouse") and not get_parent_warehouse_data and doc.get("for_warehouse") in warehouses:
|
if doc.get("for_warehouse") and not get_parent_warehouse_data and doc.get("for_warehouse") in warehouses:
|
||||||
warehouses.remove(doc.get("for_warehouse"))
|
warehouses.remove(doc.get("for_warehouse"))
|
||||||
|
|
||||||
warehouse_list = None
|
|
||||||
|
|
||||||
doc['mr_items'] = []
|
doc['mr_items'] = []
|
||||||
|
|
||||||
po_items = doc.get('po_items') if doc.get('po_items') else doc.get('items')
|
po_items = doc.get('po_items') if doc.get('po_items') else doc.get('items')
|
||||||
|
@ -10,7 +10,7 @@ from erpnext.stock.doctype.item.test_item import create_item
|
|||||||
from erpnext.manufacturing.doctype.production_plan.production_plan import get_sales_orders
|
from erpnext.manufacturing.doctype.production_plan.production_plan import get_sales_orders
|
||||||
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation
|
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation import create_stock_reconciliation
|
||||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
|
||||||
from erpnext.manufacturing.doctype.production_plan.production_plan import get_items_for_material_requests
|
from erpnext.manufacturing.doctype.production_plan.production_plan import get_items_for_material_requests, get_warehouse_list
|
||||||
|
|
||||||
class TestProductionPlan(unittest.TestCase):
|
class TestProductionPlan(unittest.TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
@ -251,6 +251,27 @@ class TestProductionPlan(unittest.TestCase):
|
|||||||
pln.cancel()
|
pln.cancel()
|
||||||
frappe.delete_doc("Production Plan", pln.name)
|
frappe.delete_doc("Production Plan", pln.name)
|
||||||
|
|
||||||
|
def test_get_warehouse_list_group(self):
|
||||||
|
"""Check if required warehouses are returned"""
|
||||||
|
warehouse_json = '[{\"warehouse\":\"_Test Warehouse Group - _TC\"}]'
|
||||||
|
|
||||||
|
warehouses = set(get_warehouse_list(warehouse_json))
|
||||||
|
expected_warehouses = {"_Test Warehouse Group-C1 - _TC", "_Test Warehouse Group-C2 - _TC"}
|
||||||
|
|
||||||
|
missing_warehouse = expected_warehouses - warehouses
|
||||||
|
|
||||||
|
self.assertTrue(len(missing_warehouse) == 0,
|
||||||
|
msg=f"Following warehouses were expected {', '.join(missing_warehouse)}")
|
||||||
|
|
||||||
|
def test_get_warehouse_list_single(self):
|
||||||
|
warehouse_json = '[{\"warehouse\":\"_Test Scrap Warehouse - _TC\"}]'
|
||||||
|
|
||||||
|
warehouses = set(get_warehouse_list(warehouse_json))
|
||||||
|
expected_warehouses = {"_Test Scrap Warehouse - _TC", }
|
||||||
|
|
||||||
|
self.assertEqual(warehouses, expected_warehouses)
|
||||||
|
|
||||||
|
|
||||||
def create_production_plan(**args):
|
def create_production_plan(**args):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user