refactor: add filter type info
This commit is contained in:
parent
e6aa28ea14
commit
64ac22af82
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
|
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
|
from typing import Optional, TypedDict
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
@ -14,7 +15,20 @@ from erpnext.stock.report.stock_ledger.stock_ledger import get_item_group_condit
|
|||||||
from erpnext.stock.utils import add_additional_uom_columns, is_reposting_item_valuation_in_progress
|
from erpnext.stock.utils import add_additional_uom_columns, is_reposting_item_valuation_in_progress
|
||||||
|
|
||||||
|
|
||||||
def execute(filters=None):
|
class StockBalanceFilter(TypedDict):
|
||||||
|
company: Optional[str]
|
||||||
|
from_date: str
|
||||||
|
to_date: str
|
||||||
|
item_group: Optional[str]
|
||||||
|
item: Optional[str]
|
||||||
|
warehouse: Optional[str]
|
||||||
|
warehouse_type: Optional[str]
|
||||||
|
include_uom: Optional[str] # include extra info in converted UOM
|
||||||
|
show_stock_ageing_data: bool
|
||||||
|
show_variant_attributes: bool
|
||||||
|
|
||||||
|
|
||||||
|
def execute(filters: Optional[StockBalanceFilter] = None):
|
||||||
is_reposting_item_valuation_in_progress()
|
is_reposting_item_valuation_in_progress()
|
||||||
if not filters:
|
if not filters:
|
||||||
filters = {}
|
filters = {}
|
||||||
@ -92,7 +106,7 @@ def execute(filters=None):
|
|||||||
return columns, data
|
return columns, data
|
||||||
|
|
||||||
|
|
||||||
def get_columns(filters):
|
def get_columns(filters: StockBalanceFilter):
|
||||||
"""return columns"""
|
"""return columns"""
|
||||||
columns = [
|
columns = [
|
||||||
{
|
{
|
||||||
@ -215,7 +229,7 @@ def get_columns(filters):
|
|||||||
return columns
|
return columns
|
||||||
|
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_conditions(filters: StockBalanceFilter):
|
||||||
conditions = ""
|
conditions = ""
|
||||||
if not filters.get("from_date"):
|
if not filters.get("from_date"):
|
||||||
frappe.throw(_("'From Date' is required"))
|
frappe.throw(_("'From Date' is required"))
|
||||||
@ -249,7 +263,7 @@ def get_conditions(filters):
|
|||||||
return conditions
|
return conditions
|
||||||
|
|
||||||
|
|
||||||
def get_stock_ledger_entries(filters, items):
|
def get_stock_ledger_entries(filters: StockBalanceFilter, items):
|
||||||
item_conditions_sql = ""
|
item_conditions_sql = ""
|
||||||
if items:
|
if items:
|
||||||
item_conditions_sql = " and sle.item_code in ({})".format(
|
item_conditions_sql = " and sle.item_code in ({})".format(
|
||||||
@ -274,7 +288,7 @@ def get_stock_ledger_entries(filters, items):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_item_warehouse_map(filters, sle):
|
def get_item_warehouse_map(filters: StockBalanceFilter, sle):
|
||||||
iwb_map = {}
|
iwb_map = {}
|
||||||
from_date = getdate(filters.get("from_date"))
|
from_date = getdate(filters.get("from_date"))
|
||||||
to_date = getdate(filters.get("to_date"))
|
to_date = getdate(filters.get("to_date"))
|
||||||
@ -349,7 +363,7 @@ def filter_items_with_no_transactions(iwb_map, float_precision):
|
|||||||
return iwb_map
|
return iwb_map
|
||||||
|
|
||||||
|
|
||||||
def get_items(filters):
|
def get_items(filters: StockBalanceFilter):
|
||||||
"Get items based on item code, item group or brand."
|
"Get items based on item code, item group or brand."
|
||||||
conditions = []
|
conditions = []
|
||||||
if filters.get("item_code"):
|
if filters.get("item_code"):
|
||||||
@ -368,7 +382,7 @@ def get_items(filters):
|
|||||||
return items
|
return items
|
||||||
|
|
||||||
|
|
||||||
def get_item_details(items, sle, filters):
|
def get_item_details(items, sle, filters: StockBalanceFilter):
|
||||||
item_details = {}
|
item_details = {}
|
||||||
if not items:
|
if not items:
|
||||||
items = list(set(d.item_code for d in sle))
|
items = list(set(d.item_code for d in sle))
|
||||||
|
Loading…
Reference in New Issue
Block a user