refactor: simplify get_items_and_warehouses

Also remove dead code related to stock reconciliation_json.
This commit is contained in:
Ankush Menat 2022-02-06 13:02:34 +05:30 committed by Ankush Menat
parent c56d07dee3
commit e6ab8df8f2

View File

@ -3,6 +3,7 @@
import json import json
from collections import defaultdict from collections import defaultdict
from typing import List, Tuple
import frappe import frappe
from frappe import _ from frappe import _
@ -181,33 +182,28 @@ class StockController(AccountsController):
return details return details
def get_items_and_warehouses(self): def get_items_and_warehouses(self) -> Tuple[List[str], List[str]]:
items, warehouses = [], [] """Get list of items and warehouses affected by a transaction"""
if hasattr(self, "items") or hasattr(self, "packed_items"): if not (hasattr(self, "items") or hasattr(self, "packed_items")):
item_doclist = (self.get("items") or []) + (self.get("packed_items") or []) return [], []
elif self.doctype == "Stock Reconciliation":
item_doclist = []
data = json.loads(self.reconciliation_json)
for row in data[data.index(self.head_row)+1:]:
d = frappe._dict(zip(["item_code", "warehouse", "qty", "valuation_rate"], row))
item_doclist.append(d)
if item_doclist: item_rows = (self.get("items") or []) + (self.get("packed_items") or [])
for d in item_doclist:
if d.item_code and d.item_code not in items:
items.append(d.item_code)
if d.get("warehouse") and d.warehouse not in warehouses: items = {d.item_code for d in item_rows if d.item_code}
warehouses.append(d.warehouse)
warehouses = set()
for d in item_rows:
if d.get("warehouse"):
warehouses.add(d.warehouse)
if self.doctype == "Stock Entry": if self.doctype == "Stock Entry":
if d.get("s_warehouse") and d.s_warehouse not in warehouses: if d.get("s_warehouse"):
warehouses.append(d.s_warehouse) warehouses.add(d.s_warehouse)
if d.get("t_warehouse") and d.t_warehouse not in warehouses: if d.get("t_warehouse"):
warehouses.append(d.t_warehouse) warehouses.add(d.t_warehouse)
return items, warehouses return list(items), list(warehouses)
def get_stock_ledger_details(self): def get_stock_ledger_details(self):
stock_ledger = {} stock_ledger = {}