Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added condition to query for postgre #394

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions erpnext/stock/reorder_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ def get_items_for_reorder() -> dict[str, list]:
reorder_table = frappe.qb.DocType("Item Reorder")
item_table = frappe.qb.DocType("Item")

# handling error of date range in postgres
if frappe.db.db_type == "mariadb":
end_of_life_condition = item_table.end_of_life == "0000-00-00"
elif frappe.db.db_type == "postgres":
end_of_life_condition = item_table.end_of_life == "1900-01-01"

query = (
frappe.qb.from_(reorder_table)
.inner_join(item_table)
Expand All @@ -136,7 +142,7 @@ def get_items_for_reorder() -> dict[str, list]:
& (
(item_table.end_of_life.isnull())
| (item_table.end_of_life > nowdate())
| (item_table.end_of_life == "0000-00-00")
| end_of_life_condition
)
)
)
Expand All @@ -154,6 +160,12 @@ def get_items_for_reorder() -> dict[str, list]:
def get_reorder_levels_for_variants(itemwise_reorder):
item_table = frappe.qb.DocType("Item")

# handling error of date range in postgres
if frappe.db.db_type == "mariadb":
end_of_life_condition = item_table.end_of_life == "0000-00-00"
elif frappe.db.db_type == "postgres":
end_of_life_condition = item_table.end_of_life == "1900-01-01"

query = (
frappe.qb.from_(item_table)
.select(
Expand All @@ -166,7 +178,7 @@ def get_reorder_levels_for_variants(itemwise_reorder):
& (
(item_table.end_of_life.isnull())
| (item_table.end_of_life > nowdate())
| (item_table.end_of_life == "0000-00-00")
| end_of_life_condition
)
& (item_table.variant_of.notnull())
)
Expand Down
Loading