From 93779c21a79dca8a7ac55c753a36c7098d71fd72 Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Wed, 21 Mar 2018 17:52:41 +0530 Subject: [PATCH] [Fix] Project not set in the stock ledger entry (#13357) --- erpnext/controllers/stock_controller.py | 2 +- erpnext/patches.txt | 1 + erpnext/patches/v10_0/update_project_in_sle.py | 15 +++++++++++++++ erpnext/stock/report/stock_ledger/stock_ledger.js | 6 ++++++ erpnext/stock/report/stock_ledger/stock_ledger.py | 7 +++++-- 5 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 erpnext/patches/v10_0/update_project_in_sle.py diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 605881c839..798d8e305d 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -252,7 +252,7 @@ class StockController(AccountsController): "company": self.company, "batch_no": cstr(d.get("batch_no")).strip(), "serial_no": d.get("serial_no"), - "project": d.get("project"), + "project": d.get("project") or self.get('project'), "is_cancelled": self.docstatus==2 and "Yes" or "No" }) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 1df001fc66..36e68ca078 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -497,3 +497,4 @@ erpnext.patches.v10_0.update_warehouse_address_details erpnext.patches.v10_0.update_reserved_qty_for_purchase_order erpnext.patches.v10_0.update_hub_connector_domain erpnext.patches.v10_0.set_student_party_type +erpnext.patches.v10_0.update_project_in_sle \ No newline at end of file diff --git a/erpnext/patches/v10_0/update_project_in_sle.py b/erpnext/patches/v10_0/update_project_in_sle.py new file mode 100644 index 0000000000..15d10e6d98 --- /dev/null +++ b/erpnext/patches/v10_0/update_project_in_sle.py @@ -0,0 +1,15 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + for doctype in ['Sales Invoice', 'Delivery Note', 'Stock Entry']: + frappe.db.sql(""" update + `tabStock Ledger Entry` sle, `tab{0}` parent_doc + set + sle.project = parent_doc.project + where + sle.voucher_no = parent_doc.name and sle.voucher_type = %s and sle.project is null + and parent_doc.project is not null and parent_doc.project != ''""".format(doctype), doctype, debug=1) \ No newline at end of file diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.js b/erpnext/stock/report/stock_ledger/stock_ledger.js index e95f5cab57..d4f5ab5414 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.js +++ b/erpnext/stock/report/stock_ledger/stock_ledger.js @@ -59,6 +59,12 @@ frappe.query_reports["Stock Ledger"] = { "fieldname":"voucher_no", "label": __("Voucher #"), "fieldtype": "Data" + }, + { + "fieldname":"project", + "label": __("Project"), + "fieldtype": "Link", + "options": "Project" } ] } diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index e436132ec8..305702e755 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -24,7 +24,7 @@ def execute(filters=None): item_detail.stock_uom, sle.actual_qty, sle.qty_after_transaction, (sle.incoming_rate if sle.actual_qty > 0 else 0.0), sle.valuation_rate, sle.stock_value, sle.voucher_type, sle.voucher_no, - sle.batch_no, sle.serial_no, sle.company]) + sle.batch_no, sle.serial_no, sle.project, sle.company]) return columns, data @@ -45,6 +45,7 @@ def get_columns(): _("Voucher #") + ":Dynamic Link/" + _("Voucher Type") + ":100", _("Batch") + ":Link/Batch:100", _("Serial #") + ":Link/Serial No:100", + _("Project") + ":Link/Project:100", {"label": _("Company"), "fieldtype": "Link", "width": 110, "options": "company", "fieldname": "company"} ] @@ -54,7 +55,7 @@ def get_columns(): def get_stock_ledger_entries(filters): return frappe.db.sql("""select concat_ws(" ", posting_date, posting_time) as date, item_code, warehouse, actual_qty, qty_after_transaction, incoming_rate, valuation_rate, - stock_value, voucher_type, voucher_no, batch_no, serial_no, company + stock_value, voucher_type, voucher_no, batch_no, serial_no, company, project from `tabStock Ledger Entry` sle where company = %(company)s and posting_date between %(from_date)s and %(to_date)s @@ -96,6 +97,8 @@ def get_sle_conditions(filters): conditions.append("voucher_no=%(voucher_no)s") if filters.get("batch_no"): conditions.append("batch_no=%(batch_no)s") + if filters.get("project"): + conditions.append("project=%(project)s") return "and {}".format(" and ".join(conditions)) if conditions else ""