From 097b32fe673e406e8094d9b0dcf5401526a9d536 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 26 Oct 2020 15:27:37 +0530 Subject: [PATCH 1/5] feat: Close Production Plan --- .../production_plan/production_plan.js | 30 +++++++++++++++++-- .../production_plan/production_plan.json | 5 ++-- .../production_plan/production_plan.py | 9 +++++- .../production_plan/production_plan_list.js | 5 ++-- ...ction_plan_material_request_warehouse.json | 20 ++++--------- 5 files changed, 46 insertions(+), 23 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index 1a64bc5e248..b29fd4cf434 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -56,23 +56,35 @@ frappe.ui.form.on('Production Plan', { refresh: function(frm) { if (frm.doc.docstatus === 1) { frm.trigger("show_progress"); + + if (frm.doc.status === "Closed") { + frm.add_custom_button(__("Re-open"), function() { + frm.events.close_open_production_plan(frm, false); + }, __("Status")); + } else { + frm.add_custom_button(__("Close"), function() { + frm.events.close_open_production_plan(frm, true); + }, __("Status")); + } } if (frm.doc.docstatus === 1 && frm.doc.po_items - && frm.doc.status != 'Completed') { + && !in_list(['Closed', 'Completed'], frm.doc.status)) { frm.add_custom_button(__("Work Order"), ()=> { frm.trigger("make_work_order"); }, __('Create')); } if (frm.doc.docstatus === 1 && frm.doc.mr_items - && !in_list(['Material Requested', 'Completed'], frm.doc.status)) { + && !in_list(['Material Requested', 'Completed', 'Closed'], frm.doc.status)) { frm.add_custom_button(__("Material Request"), ()=> { frm.trigger("make_material_request"); }, __('Create')); } - frm.page.set_inner_btn_group_as_primary(__('Create')); + if (frm.doc.status !== "Closed") { + frm.page.set_inner_btn_group_as_primary(__('Create')); + } frm.trigger("material_requirement"); const projected_qty_formula = ` @@ -121,6 +133,18 @@ frappe.ui.form.on('Production Plan', { set_field_options("projected_qty_formula", projected_qty_formula); }, + close_open_production_plan: (frm, close=false) => { + frappe.call({ + method: "set_status", + freeze: true, + doc: frm.doc, + args: {close : close}, + callback: function() { + frm.reload_doc(); + } + }); + }, + make_work_order: function(frm) { frappe.call({ method: "make_work_order", diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.json b/erpnext/manufacturing/doctype/production_plan/production_plan.json index 90e8b22ed91..850d5aeff8c 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.json +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.json @@ -275,7 +275,7 @@ "fieldtype": "Select", "label": "Status", "no_copy": 1, - "options": "\nDraft\nSubmitted\nNot Started\nIn Process\nCompleted\nStopped\nCancelled\nMaterial Requested", + "options": "\nDraft\nSubmitted\nNot Started\nIn Process\nCompleted\nClosed\nCancelled\nMaterial Requested", "print_hide": 1, "read_only": 1 }, @@ -304,9 +304,10 @@ } ], "icon": "fa fa-calendar", + "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], - "modified": "2020-02-03 00:25:25.934202", + "modified": "2020-10-26 13:00:54.335319", "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 b6552d5d6b1..4cf798d3e25 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.py +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py @@ -219,13 +219,17 @@ class ProductionPlan(Document): filters = {'docstatus': 0, 'production_plan': ("=", self.name)}): frappe.delete_doc('Work Order', d.name) - def set_status(self): + def set_status(self, close=None): self.status = { 0: 'Draft', 1: 'Submitted', 2: 'Cancelled' }.get(self.docstatus) + if close: + self.db_set('status', 'Closed') + return + if self.total_produced_qty > 0: self.status = "In Process" if self.total_produced_qty == self.total_planned_qty: @@ -235,6 +239,9 @@ class ProductionPlan(Document): self.update_ordered_status() self.update_requested_status() + if close is not None: + self.db_set('status', self.status) + def update_ordered_status(self): update_status = False for d in self.po_items: diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan_list.js b/erpnext/manufacturing/doctype/production_plan/production_plan_list.js index d377ef0af76..165b66ff5d6 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan_list.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan_list.js @@ -1,6 +1,6 @@ frappe.listview_settings['Production Plan'] = { add_fields: ["status"], - filters: [["status", "!=", "Stopped"]], + filters: [["status", "!=", "Closed"]], get_indicator: function(doc) { if(doc.status==="Submitted") { return [__("Not Started"), "orange", "status,=,Submitted"]; @@ -10,7 +10,8 @@ frappe.listview_settings['Production Plan'] = { "In Process": "orange", "Completed": "green", "Material Requested": "darkgrey", - "Cancelled": "darkgrey" + "Cancelled": "darkgrey", + "Closed": "grey" }[doc.status], "status,=," + doc.status]; } } diff --git a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json index 53e33c02657..e72f48943c8 100644 --- a/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json +++ b/erpnext/manufacturing/doctype/production_plan_material_request_warehouse/production_plan_material_request_warehouse.json @@ -11,30 +11,20 @@ { "fieldname": "warehouse", "fieldtype": "Link", + "in_list_view": 1, "label": "Warehouse", "options": "Warehouse" } ], + "index_web_pages_for_search": 1, + "istable": 1, "links": [], - "modified": "2020-02-02 10:37:16.650836", + "modified": "2020-10-26 12:55:00.778201", "modified_by": "Administrator", "module": "Manufacturing", "name": "Production Plan Material Request Warehouse", "owner": "Administrator", - "permissions": [ - { - "create": 1, - "delete": 1, - "email": 1, - "export": 1, - "print": 1, - "read": 1, - "report": 1, - "role": "System Manager", - "share": 1, - "write": 1 - } - ], + "permissions": [], "quick_entry": 1, "sort_field": "modified", "sort_order": "DESC", From 689b77d1ed39027c2a13b415a1f86a69cafeee07 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 26 Oct 2020 16:28:39 +0530 Subject: [PATCH 2/5] fix: Don't show buttons if status is Completed --- .../production_plan/production_plan.js | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.js b/erpnext/manufacturing/doctype/production_plan/production_plan.js index b29fd4cf434..b723387a091 100644 --- a/erpnext/manufacturing/doctype/production_plan/production_plan.js +++ b/erpnext/manufacturing/doctype/production_plan/production_plan.js @@ -57,31 +57,31 @@ frappe.ui.form.on('Production Plan', { if (frm.doc.docstatus === 1) { frm.trigger("show_progress"); - if (frm.doc.status === "Closed") { - frm.add_custom_button(__("Re-open"), function() { - frm.events.close_open_production_plan(frm, false); - }, __("Status")); - } else { - frm.add_custom_button(__("Close"), function() { - frm.events.close_open_production_plan(frm, true); - }, __("Status")); + if (frm.doc.status !== "Completed") { + if (frm.doc.po_items && frm.doc.status !== "Closed") { + frm.add_custom_button(__("Work Order"), ()=> { + frm.trigger("make_work_order"); + }, __('Create')); + } + + if (frm.doc.mr_items && !in_list(['Material Requested', 'Closed'], frm.doc.status)) { + frm.add_custom_button(__("Material Request"), ()=> { + frm.trigger("make_material_request"); + }, __('Create')); + } + + if (frm.doc.status === "Closed") { + frm.add_custom_button(__("Re-open"), function() { + frm.events.close_open_production_plan(frm, false); + }, __("Status")); + } else { + frm.add_custom_button(__("Close"), function() { + frm.events.close_open_production_plan(frm, true); + }, __("Status")); + } } } - if (frm.doc.docstatus === 1 && frm.doc.po_items - && !in_list(['Closed', 'Completed'], frm.doc.status)) { - frm.add_custom_button(__("Work Order"), ()=> { - frm.trigger("make_work_order"); - }, __('Create')); - } - - if (frm.doc.docstatus === 1 && frm.doc.mr_items - && !in_list(['Material Requested', 'Completed', 'Closed'], frm.doc.status)) { - frm.add_custom_button(__("Material Request"), ()=> { - frm.trigger("make_material_request"); - }, __('Create')); - } - if (frm.doc.status !== "Closed") { frm.page.set_inner_btn_group_as_primary(__('Create')); } From 71913c36a7d97a93111887a751729378ab488ca1 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 30 Oct 2020 02:47:39 +0530 Subject: [PATCH 3/5] fix: po_detail field has no value for subcontracted stock entry --- .../buying/doctype/purchase_order/test_purchase_order.py | 6 +++++- erpnext/controllers/buying_controller.py | 6 +++--- erpnext/stock/doctype/stock_entry/stock_entry.py | 9 +++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py index 0181ae78b4e..d568ef1ceda 100644 --- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py @@ -876,7 +876,7 @@ class TestPurchaseOrder(unittest.TestCase): }, { "item_code":item_code,"rm_item_code":"Sub Contracted Raw Material 4","item_name":"_Test Item", - "qty":250,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos", "name": po.supplied_items[1].name + "qty":250,"warehouse":"_Test Warehouse - _TC", "stock_uom":"Nos" }, ] @@ -885,6 +885,10 @@ class TestPurchaseOrder(unittest.TestCase): se = frappe.get_doc(make_subcontract_transfer_entry(po.name, rm_item_string)) se.submit() + # Test po_detail field has value or not + for item_row in se.items: + self.assertEqual(item_row.po_detail, po.supplied_items[item_row.idx - 1].name) + po_doc = frappe.get_doc("Purchase Order", po.name) for row in po_doc.supplied_items: # Valid that whether transferred quantity is matching with supplied qty or not in the purchase order diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index f376836f7b8..9ee83e34816 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -301,7 +301,7 @@ class BuyingController(StockController): # backflushed_batch_qty_map = get_backflushed_batch_qty_map(item.purchase_order, item.item_code) for raw_material in transferred_raw_materials + non_stock_items: - rm_item_key = (raw_material.rm_item_code, item.purchase_order) + rm_item_key = (raw_material.rm_item_code, item.item_code, item.purchase_order) raw_material_data = backflushed_raw_materials_map.get(rm_item_key, {}) consumed_qty = raw_material_data.get('qty', 0) @@ -910,7 +910,7 @@ def get_backflushed_subcontracted_raw_materials(purchase_orders): purchase_receipt_supplied_items = get_supplied_items(args[1], args[2], references) for data in purchase_receipt_supplied_items: - pr_key = (data.rm_item_code, args[0]) + pr_key = (data.rm_item_code, data.main_item_code, args[0]) if pr_key not in backflushed_raw_materials_map: backflushed_raw_materials_map.setdefault(pr_key, frappe._dict({ "qty": 0.0, @@ -936,7 +936,7 @@ def get_backflushed_subcontracted_raw_materials(purchase_orders): def get_supplied_items(item_code, purchase_receipt, references): return frappe.get_all("Purchase Receipt Item Supplied", - fields=["rm_item_code", "consumed_qty", "serial_no", "batch_no"], + fields=["rm_item_code", "main_item_code", "consumed_qty", "serial_no", "batch_no"], filters={"main_item_code": item_code, "parent": purchase_receipt, "reference_name": ("in", references)}) def get_asset_item_details(asset_items): diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 4583c5174ef..768526705c9 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -615,6 +615,15 @@ class StockEntry(StockController): if not row.subcontracted_item: frappe.throw(_("Row {0}: Subcontracted Item is mandatory for the raw material {1}") .format(row.idx, frappe.bold(row.item_code))) + elif not row.po_detail: + filters = { + "parent": self.purchase_order, "docstatus": 1, + "rm_item_code": row.item_code, "main_item_code": row.subcontracted_item + } + + po_detail = frappe.db.get_value("Purchase Order Item Supplied", filters, "name") + if po_detail: + row.db_set("po_detail", po_detail) def validate_bom(self): for d in self.get('items'): From 32442008dcdf0028584ff8bd9501650eff9189d1 Mon Sep 17 00:00:00 2001 From: Saqib Date: Fri, 30 Oct 2020 15:30:18 +0530 Subject: [PATCH 4/5] fix: asset finance book posting date fix (#23778) --- .../assets/doctype/asset_finance_book/asset_finance_book.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json index 79fcb957d4d..d422876047e 100644 --- a/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json +++ b/erpnext/assets/doctype/asset_finance_book/asset_finance_book.json @@ -55,6 +55,7 @@ "fieldtype": "Date", "in_list_view": 1, "label": "Depreciation Posting Date", + "mandatory_depends_on": "eval:parent.doctype == 'Asset'", "reqd": 1 }, { @@ -86,7 +87,7 @@ "index_web_pages_for_search": 1, "istable": 1, "links": [], - "modified": "2020-09-16 12:11:30.631788", + "modified": "2020-10-30 15:22:29.119868", "modified_by": "Administrator", "module": "Assets", "name": "Asset Finance Book", From e1781dc0bb0afab5a2d96712e421aae15e8cbd3f Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 30 Oct 2020 15:34:04 +0530 Subject: [PATCH 5/5] fix: patch to update reason for leaving in employee --- erpnext/patches.txt | 1 + .../update_reason_for_resignation_in_employee.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 erpnext/patches/v13_0/update_reason_for_resignation_in_employee.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8b34eaa0a87..5ef53715fbb 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -732,3 +732,4 @@ erpnext.patches.v13_0.set_youtube_video_id erpnext.patches.v13_0.print_uom_after_quantity_patch erpnext.patches.v13_0.set_payment_channel_in_payment_gateway_account erpnext.patches.v13_0.create_healthcare_custom_fields_in_stock_entry_detail +erpnext.patches.v13_0.update_reason_for_resignation_in_employee diff --git a/erpnext/patches/v13_0/update_reason_for_resignation_in_employee.py b/erpnext/patches/v13_0/update_reason_for_resignation_in_employee.py new file mode 100644 index 00000000000..792118fbee2 --- /dev/null +++ b/erpnext/patches/v13_0/update_reason_for_resignation_in_employee.py @@ -0,0 +1,15 @@ +# Copyright (c) 2020, Frappe Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc("hr", "doctype", "employee") + + if frappe.db.has_column("Employee", "reason_for_resignation"): + frappe.db.sql(""" UPDATE `tabEmployee` + SET reason_for_leaving = reason_for_resignation + WHERE status = 'Left' and reason_for_leaving is null and reason_for_resignation is not null + """) +