refactor: simplify get_items_and_warehouses
Also remove dead code related to stock reconciliation_json.
This commit is contained in:
parent
c56d07dee3
commit
e6ab8df8f2
@ -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)
|
|
||||||
|
|
||||||
if self.doctype == "Stock Entry":
|
warehouses = set()
|
||||||
if d.get("s_warehouse") and d.s_warehouse not in warehouses:
|
for d in item_rows:
|
||||||
warehouses.append(d.s_warehouse)
|
if d.get("warehouse"):
|
||||||
if d.get("t_warehouse") and d.t_warehouse not in warehouses:
|
warehouses.add(d.warehouse)
|
||||||
warehouses.append(d.t_warehouse)
|
|
||||||
|
|
||||||
return items, warehouses
|
if self.doctype == "Stock Entry":
|
||||||
|
if d.get("s_warehouse"):
|
||||||
|
warehouses.add(d.s_warehouse)
|
||||||
|
if d.get("t_warehouse"):
|
||||||
|
warehouses.add(d.t_warehouse)
|
||||||
|
|
||||||
|
return list(items), list(warehouses)
|
||||||
|
|
||||||
def get_stock_ledger_details(self):
|
def get_stock_ledger_details(self):
|
||||||
stock_ledger = {}
|
stock_ledger = {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user