chore: seperate function to apply filter for warehouse in case of QB
This commit is contained in:
parent
6381e75fa5
commit
2481574a28
@ -9,6 +9,7 @@ from frappe import _, throw
|
|||||||
from frappe.contacts.address_and_contact import load_address_and_contact
|
from frappe.contacts.address_and_contact import load_address_and_contact
|
||||||
from frappe.utils import cint, flt
|
from frappe.utils import cint, flt
|
||||||
from frappe.utils.nestedset import NestedSet
|
from frappe.utils.nestedset import NestedSet
|
||||||
|
from pypika.terms import ExistsCriterion
|
||||||
|
|
||||||
from erpnext.stock import get_warehouse_account
|
from erpnext.stock import get_warehouse_account
|
||||||
|
|
||||||
@ -266,3 +267,23 @@ def get_warehouses_based_on_account(account, company=None):
|
|||||||
frappe.throw(_("Warehouse not found against the account {0}").format(account))
|
frappe.throw(_("Warehouse not found against the account {0}").format(account))
|
||||||
|
|
||||||
return warehouses
|
return warehouses
|
||||||
|
|
||||||
|
|
||||||
|
# Will be use for frappe.qb
|
||||||
|
def apply_warehouse_filter(query, sle, filters):
|
||||||
|
if warehouse := filters.get("warehouse"):
|
||||||
|
warehouse_table = frappe.qb.DocType("Warehouse")
|
||||||
|
|
||||||
|
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
||||||
|
chilren_subquery = (
|
||||||
|
frappe.qb.from_(warehouse_table)
|
||||||
|
.select(warehouse_table.name)
|
||||||
|
.where(
|
||||||
|
(warehouse_table.lft >= lft)
|
||||||
|
& (warehouse_table.rgt <= rgt)
|
||||||
|
& (warehouse_table.name == sle.warehouse)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
query = query.where(ExistsCriterion(chilren_subquery))
|
||||||
|
|
||||||
|
return query
|
||||||
|
@ -6,7 +6,8 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.utils import cint, flt, getdate
|
from frappe.utils import cint, flt, getdate
|
||||||
from pypika import functions as fn
|
from pypika import functions as fn
|
||||||
from pypika.terms import ExistsCriterion
|
|
||||||
|
from erpnext.stock.doctype.warehouse.warehouse import apply_warehouse_filter
|
||||||
|
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
@ -104,25 +105,6 @@ def get_stock_ledger_entries(filters):
|
|||||||
return query.run(as_dict=True)
|
return query.run(as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
def apply_warehouse_filter(query, sle, filters):
|
|
||||||
if warehouse := filters.get("warehouse"):
|
|
||||||
warehouse_table = frappe.qb.DocType("Warehouse")
|
|
||||||
|
|
||||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
|
||||||
chilren_subquery = (
|
|
||||||
frappe.qb.from_(warehouse_table)
|
|
||||||
.select(warehouse_table.name)
|
|
||||||
.where(
|
|
||||||
(warehouse_table.lft >= lft)
|
|
||||||
& (warehouse_table.rgt <= rgt)
|
|
||||||
& (warehouse_table.name == sle.warehouse)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
query = query.where(ExistsCriterion(chilren_subquery))
|
|
||||||
|
|
||||||
return query
|
|
||||||
|
|
||||||
|
|
||||||
def get_item_warehouse_batch_map(filters, float_precision):
|
def get_item_warehouse_batch_map(filters, float_precision):
|
||||||
sle = get_stock_ledger_entries(filters)
|
sle = get_stock_ledger_entries(filters)
|
||||||
iwb_map = {}
|
iwb_map = {}
|
||||||
|
@ -10,10 +10,10 @@ from frappe import _
|
|||||||
from frappe.query_builder.functions import CombineDatetime
|
from frappe.query_builder.functions import CombineDatetime
|
||||||
from frappe.utils import cint, date_diff, flt, getdate
|
from frappe.utils import cint, date_diff, flt, getdate
|
||||||
from frappe.utils.nestedset import get_descendants_of
|
from frappe.utils.nestedset import get_descendants_of
|
||||||
from pypika.terms import ExistsCriterion
|
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
|
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
|
||||||
|
from erpnext.stock.doctype.warehouse.warehouse import apply_warehouse_filter
|
||||||
from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots, get_average_age
|
from erpnext.stock.report.stock_ageing.stock_ageing import FIFOSlots, get_average_age
|
||||||
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
|
||||||
|
|
||||||
@ -270,18 +270,8 @@ def apply_conditions(query, filters):
|
|||||||
if company := filters.get("company"):
|
if company := filters.get("company"):
|
||||||
query = query.where(sle.company == company)
|
query = query.where(sle.company == company)
|
||||||
|
|
||||||
if warehouse := filters.get("warehouse"):
|
if filters.get("warehouse"):
|
||||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
query = apply_warehouse_filter(query, sle, filters)
|
||||||
chilren_subquery = (
|
|
||||||
frappe.qb.from_(warehouse_table)
|
|
||||||
.select(warehouse_table.name)
|
|
||||||
.where(
|
|
||||||
(warehouse_table.lft >= lft)
|
|
||||||
& (warehouse_table.rgt <= rgt)
|
|
||||||
& (warehouse_table.name == sle.warehouse)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
query = query.where(ExistsCriterion(chilren_subquery))
|
|
||||||
elif warehouse_type := filters.get("warehouse_type"):
|
elif warehouse_type := filters.get("warehouse_type"):
|
||||||
query = (
|
query = (
|
||||||
query.join(warehouse_table)
|
query.join(warehouse_table)
|
||||||
|
@ -6,11 +6,11 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.query_builder.functions import CombineDatetime
|
from frappe.query_builder.functions import CombineDatetime
|
||||||
from frappe.utils import cint, flt
|
from frappe.utils import cint, flt
|
||||||
from pypika.terms import ExistsCriterion
|
|
||||||
|
|
||||||
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
|
from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
|
||||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
|
||||||
from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import get_stock_balance_for
|
from erpnext.stock.doctype.stock_reconciliation.stock_reconciliation import get_stock_balance_for
|
||||||
|
from erpnext.stock.doctype.warehouse.warehouse import apply_warehouse_filter
|
||||||
from erpnext.stock.utils import (
|
from erpnext.stock.utils import (
|
||||||
is_reposting_item_valuation_in_progress,
|
is_reposting_item_valuation_in_progress,
|
||||||
update_included_uom_in_report,
|
update_included_uom_in_report,
|
||||||
@ -295,20 +295,7 @@ def get_stock_ledger_entries(filters, items):
|
|||||||
if filters.get(field):
|
if filters.get(field):
|
||||||
query = query.where(sle[field] == filters.get(field))
|
query = query.where(sle[field] == filters.get(field))
|
||||||
|
|
||||||
if warehouse := filters.get("warehouse"):
|
query = apply_warehouse_filter(query, sle, filters)
|
||||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
|
||||||
|
|
||||||
warehouse_table = frappe.qb.DocType("Warehouse")
|
|
||||||
chilren_subquery = (
|
|
||||||
frappe.qb.from_(warehouse_table)
|
|
||||||
.select(warehouse_table.name)
|
|
||||||
.where(
|
|
||||||
(warehouse_table.lft >= lft)
|
|
||||||
& (warehouse_table.rgt <= rgt)
|
|
||||||
& (warehouse_table.name == sle.warehouse)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
query = query.where(ExistsCriterion(chilren_subquery))
|
|
||||||
|
|
||||||
return query.run(as_dict=True)
|
return query.run(as_dict=True)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user