Created
January 19, 2023 09:31
-
-
Save itsyosefali/36af0ec25de133b1b1d39e2e940d5baf to your computer and use it in GitHub Desktop.
the balance of sponge shape
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sql_item_code_cond_filter = "" | |
| if filters.get("item_code"): | |
| escaped_input = frappe.db.escape(filters.get("item_code")) | |
| sql_item_code_cond_filter = f"AND `tabStock Ledger Entry`.item_code = {escaped_input}" | |
| sql_sponge_shape="" | |
| if filters.get("sponge_shape"): | |
| escaped_input = frappe.db.escape(filters.get("sponge_shape")) | |
| sql_item_code_cond_filter = f"AND `tabStock Ledger Entry`.sponge_shape = {escaped_input}" | |
| sql_warehouse_cond_filter = "" | |
| if filters.get("warehouse"): | |
| escaped_input = frappe.db.escape(filters.get("warehouse")) | |
| sql_warehouse_cond_filter = f"Having`tabStock Ledger Entry`.warehouse = {escaped_input}" | |
| sql_date_cond = "" | |
| if filters.get("date_to"): | |
| date_to = frappe.db.escape(filters.get("date_to")) | |
| sql_date_cond = f""" and `tabStock Ledger Entry`.posting_date between '2022-12-30' AND {date_to} """ | |
| res = frappe.db.sql(f"""SELECT `tabStock Ledger Entry`.item_code, | |
| `tabStock Ledger Entry`.warehouse, | |
| `tabStock Ledger Entry`.sponge_shape, | |
| `tabStock Ledger Entry`.posting_date, | |
| `tabSponge Shape`.shape_related_factor, | |
| sum(`tabStock Ledger Entry`.actual_qty) As 'qty' | |
| FROM `tabStock Ledger Entry` | |
| INNER JOIN `tabSponge Shape` | |
| ON `tabStock Ledger Entry`.sponge_shape = `tabSponge Shape`.name | |
| Where `tabStock Ledger Entry`.is_cancelled = 0 | |
| and `tabStock Ledger Entry`.posting_date between '2022-12-30' AND CURDATE() | |
| {sql_item_code_cond_filter} | |
| {sql_date_cond} | |
| Group By | |
| `tabStock Ledger Entry`.sponge_shape | |
| {sql_warehouse_cond_filter} | |
| """, as_dict=True) | |
| for item in res: | |
| if item.shape_related_factor and item.qty: | |
| div_res = float(item.qty) / float(item.shape_related_factor) | |
| item.sponge = div_res | |
| result = res | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment