refactor: use db agnostic CombineDatetime

This commit is contained in:
Ankush Menat 2022-04-21 20:01:48 +05:30
parent 4ffea617ef
commit e1c1687661
2 changed files with 7 additions and 9 deletions

View File

@ -8,9 +8,8 @@ from typing import Optional, Set, Tuple
import frappe
from frappe import _
from frappe.model.meta import get_field_precision
from frappe.query_builder.functions import Sum
from frappe.query_builder.functions import CombineDatetime, Sum
from frappe.utils import cint, cstr, flt, get_link_to_form, getdate, now, nowdate
from pypika import CustomFunction
import erpnext
from erpnext.stock.doctype.bin.bin import update_qty as update_bin_qty
@ -1158,16 +1157,15 @@ def get_batch_incoming_rate(
item_code, warehouse, batch_no, posting_date, posting_time, creation=None
):
Timestamp = CustomFunction("timestamp", ["date", "time"])
sle = frappe.qb.DocType("Stock Ledger Entry")
timestamp_condition = Timestamp(sle.posting_date, sle.posting_time) < Timestamp(
timestamp_condition = CombineDatetime(sle.posting_date, sle.posting_time) < CombineDatetime(
posting_date, posting_time
)
if creation:
timestamp_condition |= (
Timestamp(sle.posting_date, sle.posting_time) == Timestamp(posting_date, posting_time)
CombineDatetime(sle.posting_date, sle.posting_time)
== CombineDatetime(posting_date, posting_time)
) & (sle.creation < creation)
batch_details = (

View File

@ -7,6 +7,7 @@ from typing import Dict, Optional
import frappe
from frappe import _
from frappe.query_builder.functions import CombineDatetime
from frappe.utils import cstr, flt, get_link_to_form, nowdate, nowtime
import erpnext
@ -143,12 +144,10 @@ def get_stock_balance(
def get_serial_nos_data_after_transactions(args):
from pypika import CustomFunction
serial_nos = set()
args = frappe._dict(args)
sle = frappe.qb.DocType("Stock Ledger Entry")
Timestamp = CustomFunction("timestamp", ["date", "time"])
stock_ledger_entries = (
frappe.qb.from_(sle)
@ -157,7 +156,8 @@ def get_serial_nos_data_after_transactions(args):
(sle.item_code == args.item_code)
& (sle.warehouse == args.warehouse)
& (
Timestamp(sle.posting_date, sle.posting_time) < Timestamp(args.posting_date, args.posting_time)
CombineDatetime(sle.posting_date, sle.posting_time)
< CombineDatetime(args.posting_date, args.posting_time)
)
& (sle.is_cancelled == 0)
)