Skip to content

Commit

Permalink
fix: posting_date to posting_datetime in stock related queries
Browse files Browse the repository at this point in the history
(cherry picked from commit e61ab48)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Jan 30, 2025
1 parent 20d5a79 commit cd5174e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ def get_stock_ledger_entries_for_batch_bundle(filters):
sle = frappe.qb.DocType("Stock Ledger Entry")
batch_package = frappe.qb.DocType("Serial and Batch Entry")

to_date = get_datetime(filters.to_date + " 23:59:59")

query = (
frappe.qb.from_(sle)
.inner_join(batch_package)
Expand All @@ -166,7 +168,7 @@ def get_stock_ledger_entries_for_batch_bundle(filters):
(sle.docstatus < 2)
& (sle.is_cancelled == 0)
& (sle.has_batch_no == 1)
& (sle.posting_date <= filters["to_date"])
& (sle.posting_datetime <= to_date)
)
.groupby(sle.voucher_no, batch_package.batch_no, batch_package.warehouse)
.orderby(sle.item_code, sle.warehouse)
Expand Down
7 changes: 4 additions & 3 deletions erpnext/stock/report/stock_ageing/stock_ageing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import frappe
from frappe import _
from frappe.utils import cint, date_diff, flt
from frappe.utils import cint, date_diff, flt, get_datetime

from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos

Expand Down Expand Up @@ -424,6 +424,7 @@ def __aggregate_details_by_item(self, wh_wise_data: dict) -> dict:
def __get_stock_ledger_entries(self) -> Iterator[dict]:
sle = frappe.qb.DocType("Stock Ledger Entry")
item = self.__get_item_query() # used as derived table in sle query
to_date = get_datetime(self.filters.get("to_date") + " 23:59:59")

sle_query = (
frappe.qb.from_(sle)
Expand All @@ -450,7 +451,7 @@ def __get_stock_ledger_entries(self) -> Iterator[dict]:
.where(
(sle.item_code == item.name)
& (sle.company == self.filters.get("company"))
& (sle.posting_date <= self.filters.get("to_date"))
& (sle.posting_datetime <= to_date)
& (sle.is_cancelled != 1)
)
)
Expand All @@ -467,7 +468,7 @@ def __get_stock_ledger_entries(self) -> Iterator[dict]:
if warehouses:
sle_query = sle_query.where(sle.warehouse.isin(warehouses))

sle_query = sle_query.orderby(sle.posting_date, sle.posting_time, sle.creation, sle.actual_qty)
sle_query = sle_query.orderby(sle.posting_datetime, sle.creation)

return sle_query.run(as_dict=True, as_iterator=True)

Expand Down
13 changes: 6 additions & 7 deletions erpnext/stock/report/stock_ledger/stock_ledger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import frappe
from frappe import _
from frappe.query_builder.functions import CombineDatetime, Sum
from frappe.utils import cint, flt
from frappe.utils import cint, flt, get_datetime

from erpnext.stock.doctype.inventory_dimension.inventory_dimension import get_inventory_dimensions
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
Expand Down Expand Up @@ -367,6 +367,9 @@ def get_columns(filters):


def get_stock_ledger_entries(filters, items):
from_date = get_datetime(filters.from_date + " 00:00:00")
to_date = get_datetime(filters.to_date + " 23:59:59")

sle = frappe.qb.DocType("Stock Ledger Entry")
query = (
frappe.qb.from_(sle)
Expand All @@ -390,12 +393,8 @@ def get_stock_ledger_entries(filters, items):
sle.serial_no,
sle.project,
)
.where(
(sle.docstatus < 2)
& (sle.is_cancelled == 0)
& (sle.posting_date[filters.from_date : filters.to_date])
)
.orderby(CombineDatetime(sle.posting_date, sle.posting_time))
.where((sle.docstatus < 2) & (sle.is_cancelled == 0) & (sle.posting_datetime[from_date:to_date]))
.orderby(sle.posting_datetime)
.orderby(sle.creation)
)

Expand Down

0 comments on commit cd5174e

Please sign in to comment.