From 104294134828fade8fce96ea27b620e020218a78 Mon Sep 17 00:00:00 2001 From: mbauskar Date: Thu, 8 Jun 2017 18:45:50 +0530 Subject: [PATCH 1/3] [hotfix] fixes for mysql Lock wait timeout exceeded --- erpnext/stock/doctype/bin/bin.json | 38 ++++++++++++++++++++++++++---- erpnext/stock/doctype/bin/bin.py | 8 ++++++- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/erpnext/stock/doctype/bin/bin.json b/erpnext/stock/doctype/bin/bin.json index 0481cfc0020..e33e54db9c7 100644 --- a/erpnext/stock/doctype/bin/bin.json +++ b/erpnext/stock/doctype/bin/bin.json @@ -1,5 +1,6 @@ { "allow_copy": 0, + "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, "autoname": "BIN/.#######", @@ -12,6 +13,7 @@ "engine": "InnoDB", "fields": [ { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -22,6 +24,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 1, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 1, "label": "Warehouse", @@ -42,6 +45,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -52,6 +56,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 1, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 1, "label": "Item Code", @@ -72,6 +77,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -83,6 +89,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Reserved Quantity", @@ -102,6 +109,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -113,6 +121,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 1, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Actual Quantity", @@ -132,6 +141,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -143,6 +153,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 0, "label": "Ordered Quantity", @@ -162,6 +173,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -173,6 +185,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Requested Quantity", @@ -192,6 +205,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -202,6 +216,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Planned Qty", @@ -221,6 +236,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -231,6 +247,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Projected Qty", @@ -250,6 +267,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -260,6 +278,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Reserved Qty for Production", @@ -278,6 +297,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -288,6 +308,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Moving Average Rate", @@ -307,6 +328,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -317,6 +339,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 1, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "UOM", @@ -337,6 +360,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -347,6 +371,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "FCFS Rate", @@ -366,6 +391,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -376,6 +402,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Valuation Rate", @@ -395,6 +422,7 @@ "unique": 0 }, { + "allow_bulk_edit": 0, "allow_on_submit": 0, "bold": 0, "collapsible": 0, @@ -405,6 +433,7 @@ "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, + "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, "label": "Stock Value", @@ -424,17 +453,17 @@ "unique": 0 } ], + "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 1, "idx": 1, "image_view": 0, "in_create": 1, - "in_dialog": 0, "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2016-12-15 14:51:43.312590", + "modified": "2017-06-08 18:42:44.714839", "modified_by": "Administrator", "module": "Stock", "name": "Bin", @@ -450,7 +479,6 @@ "export": 0, "if_owner": 0, "import": 0, - "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, @@ -471,7 +499,6 @@ "export": 0, "if_owner": 0, "import": 0, - "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, @@ -492,7 +519,6 @@ "export": 0, "if_owner": 0, "import": 0, - "is_custom": 0, "permlevel": 0, "print": 1, "read": 1, @@ -508,6 +534,8 @@ "read_only": 0, "read_only_onload": 0, "search_fields": "item_code,warehouse", + "show_name_in_global_search": 0, "sort_order": "ASC", + "track_changes": 0, "track_seen": 0 } \ No newline at end of file diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index ece82208123..6e693307dd8 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -31,6 +31,7 @@ class Bin(Document): is_group_warehouse(self.warehouse) def update_stock(self, args, allow_negative_stock=False, via_landed_cost_voucher=False): + '''Called from erpnext.stock.utils.update_bin''' self.update_qty(args) if args.get("actual_qty") or args.get("voucher_type") == "Stock Reconciliation": @@ -71,8 +72,10 @@ class Bin(Document): self.reserved_qty = flt(self.reserved_qty) + flt(args.get("reserved_qty")) self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty")) self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty")) + + self.set_projected_qty() - self.save() + self.db_save() def set_projected_qty(self): self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty) @@ -111,3 +114,6 @@ def update_item_projected_qty(item_code): frappe.db.sql('''update tabItem set total_projected_qty = ifnull((select sum(projected_qty) from tabBin where item_code=%s), 0) where name=%s''', (item_code, item_code)) + +def on_doctype_update(): + frappe.db.add_index("Bin", ["item_code", "warehouse"]) From f819c93329d68f6fa087bf29703fdb5ad9bcb64c Mon Sep 17 00:00:00 2001 From: mbauskar Date: Thu, 8 Jun 2017 23:39:58 +0530 Subject: [PATCH 2/3] [minor] replaced db_save by db_update and added patch to remove the indexes on tabBin --- erpnext/patches.txt | 1 + erpnext/patches/v8_0/delete_bin_indexes.py | 16 ++++++++++++++++ erpnext/stock/doctype/bin/bin.json | 6 +++--- erpnext/stock/doctype/bin/bin.py | 5 ++--- 4 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v8_0/delete_bin_indexes.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 7dc7e3cbc61..e52ce5eb031 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -399,3 +399,4 @@ erpnext.patches.v8_0.make_payments_table_blank_for_non_pos_invoice erpnext.patches.v8_0.delete_schools_depricated_doctypes erpnext.patches.v8_0.update_customer_pos_id erpnext.patches.v8_0.rename_items_in_status_field_of_material_request +erpnext.patches.v8_0.delete_bin_indexes diff --git a/erpnext/patches/v8_0/delete_bin_indexes.py b/erpnext/patches/v8_0/delete_bin_indexes.py new file mode 100644 index 00000000000..12cacdb9528 --- /dev/null +++ b/erpnext/patches/v8_0/delete_bin_indexes.py @@ -0,0 +1,16 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt +# -*- coding: utf-8 -*- + +from __future__ import unicode_literals +import frappe + +def execute(): + # delete bin indexes + unwanted_indexes = ["item_code", "warehouse"] + + for k in unwanted_indexes: + try: + frappe.db.sql("drop index {0} on `tabBin`".format(k)) + except: + pass \ No newline at end of file diff --git a/erpnext/stock/doctype/bin/bin.json b/erpnext/stock/doctype/bin/bin.json index e33e54db9c7..1f6e9e1785c 100644 --- a/erpnext/stock/doctype/bin/bin.json +++ b/erpnext/stock/doctype/bin/bin.json @@ -40,7 +40,7 @@ "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, - "search_index": 1, + "search_index": 0, "set_only_once": 0, "unique": 0 }, @@ -72,7 +72,7 @@ "remember_last_selected_value": 0, "report_hide": 0, "reqd": 0, - "search_index": 1, + "search_index": 0, "set_only_once": 0, "unique": 0 }, @@ -463,7 +463,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2017-06-08 18:42:44.714839", + "modified": "2017-06-13 13:06:32.601505", "modified_by": "Administrator", "module": "Stock", "name": "Bin", diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 6e693307dd8..33b97c93f10 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -72,10 +72,9 @@ class Bin(Document): self.reserved_qty = flt(self.reserved_qty) + flt(args.get("reserved_qty")) self.indented_qty = flt(self.indented_qty) + flt(args.get("indented_qty")) self.planned_qty = flt(self.planned_qty) + flt(args.get("planned_qty")) - - self.set_projected_qty() - self.db_save() + self.set_projected_qty() + self.db_update() def set_projected_qty(self): self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty) From 6f71648719ca7d1f01cff0d938898b5623e96633 Mon Sep 17 00:00:00 2001 From: mbauskar Date: Tue, 13 Jun 2017 14:36:30 +0530 Subject: [PATCH 3/3] [minor] removed the else condition in update_qty --- erpnext/stock/doctype/bin/bin.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 33b97c93f10..75510decd3c 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -56,15 +56,6 @@ class Bin(Document): if args.get("voucher_type")=="Stock Reconciliation": if args.get('is_cancelled') == 'No': self.actual_qty = args.get("qty_after_transaction") - else: - qty_after_transaction = frappe.db.get_value("""select qty_after_transaction - from `tabStock Ledger Entry` - where item_code=%s and warehouse=%s - and not (voucher_type='Stock Reconciliation' and voucher_no=%s) - order by posting_date desc limit 1""", - (self.item_code, self.warehouse, args.get('voucher_no'))) - - self.actual_qty = flt(qty_after_transaction[0][0]) if qty_after_transaction else 0.0 else: self.actual_qty = flt(self.actual_qty) + flt(args.get("actual_qty"))