From 70972b5b7abfdf6515b58de39f41604225fdf243 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 8 Sep 2021 19:28:30 +0530 Subject: [PATCH] fix: added delivery date filters to get sales orders in production plan (#27367) (cherry picked from commit 295020451f54c83e711d598a67f72ecbc94fcae2) # Conflicts: # erpnext/manufacturing/doctype/production_plan/production_plan.json # erpnext/manufacturing/doctype/production_plan/production_plan.py --- .../production_plan/production_plan.json | 4 ++ .../production_plan/production_plan.py | 41 +++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.json b/erpnext/manufacturing/doctype/production_plan/production_plan.json index 23b32379413..725687609db 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.json +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.json @@ -378,7 +378,11 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2022-03-25 09:15:25.017664", +======= + "modified": "2021-09-06 18:35:59.642232", +>>>>>>> 295020451f (fix: added delivery date filters to get sales orders in production plan (#27367)) "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Plan", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py index 173c730bb31..36b94bd7c57 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -1016,6 +1016,7 @@ def get_material_request_items( def get_sales_orders(self): +<<<<<<< HEAD bom = frappe.qb.DocType("BOM") pi = frappe.qb.DocType("Packed Item") so = frappe.qb.DocType("Sales Order") @@ -1079,6 +1080,46 @@ def get_sales_orders(self): open_so = open_so_query.run(as_dict=True) +======= + so_filter = item_filter = "" + bom_item = "bom.item = so_item.item_code" + + date_field_mapper = { + 'from_date': ('>=', 'so.transaction_date'), + 'to_date': ('<=', 'so.transaction_date'), + 'from_delivery_date': ('>=', 'so_item.delivery_date'), + 'to_delivery_date': ('<=', 'so_item.delivery_date') + } + + for field, value in date_field_mapper.items(): + if self.get(field): + so_filter += f" and {value[1]} {value[0]} %({field})s" + + for field in ['customer', 'project', 'sales_order_status']: + if self.get(field): + so_field = 'status' if field == 'sales_order_status' else field + so_filter += f" and so.{so_field} = %({field})s" + + if self.item_code and frappe.db.exists('Item', self.item_code): + bom_item = self.get_bom_item() or bom_item + item_filter += " and so_item.item_code = %(item_code)s" + + open_so = frappe.db.sql(f""" + select distinct so.name, so.transaction_date, so.customer, so.base_grand_total + from `tabSales Order` so, `tabSales Order Item` so_item + where so_item.parent = so.name + and so.docstatus = 1 and so.status not in ("Stopped", "Closed") + and so.company = %(company)s + and so_item.qty > so_item.work_order_qty {so_filter} {item_filter} + and (exists (select name from `tabBOM` bom where {bom_item} + and bom.is_active = 1) + or exists (select name from `tabPacked Item` pi + where pi.parent = so.name and pi.parent_item = so_item.item_code + and exists (select name from `tabBOM` bom where bom.item=pi.item_code + and bom.is_active = 1))) + """, self.as_dict(), as_dict=1) + +>>>>>>> 295020451f (fix: added delivery date filters to get sales orders in production plan (#27367)) return open_so