From ed376cacc80921505d6d7615c0b96c89569a5ed2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 3 May 2018 16:24:52 +0530 Subject: [PATCH] Set Qty in transactions based on serial no via Stock Settings (#13897) --- erpnext/patches.txt | 3 +- ...n_transactions_based_on_serial_no_input.py | 12 +++++++ erpnext/public/js/controllers/transaction.js | 2 +- .../setup_wizard/operations/defaults_setup.py | 1 + erpnext/stock/doctype/serial_no/serial_no.py | 2 +- .../stock_settings/stock_settings.json | 33 ++++++++++++++++++- .../doctype/stock_settings/stock_settings.py | 5 +-- 7 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 3e035b1de1..fa25b806b5 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -499,4 +499,5 @@ erpnext.patches.v10_0.update_hub_connector_domain erpnext.patches.v10_0.set_student_party_type erpnext.patches.v10_0.update_project_in_sle erpnext.patches.v10_0.fix_reserved_qty_for_sub_contract -erpnext.patches.v10_0.taxes_issue_with_pos \ No newline at end of file +erpnext.patches.v10_0.taxes_issue_with_pos +erpnext.patches.v10_0.set_qty_in_transactions_based_on_serial_no_input \ No newline at end of file diff --git a/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py b/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py new file mode 100644 index 0000000000..5dbcb1d38f --- /dev/null +++ b/erpnext/patches/v10_0/set_qty_in_transactions_based_on_serial_no_input.py @@ -0,0 +1,12 @@ +# Copyright (c) 2017, Frappe and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + frappe.reload_doc("stock", "doctype", "stock_settings") + + ss = frappe.get_doc("Stock Settings") + ss.set_qty_in_transactions_based_on_serial_no_input = 1 + ss.save() \ No newline at end of file diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 9ed20c9bfa..4ab413b321 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -401,7 +401,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ item.serial_no = valid_serial_nos.join('\n'); refresh_field("serial_no", item.name, item.parentfield); - if(!doc.is_return) { + if(!doc.is_return && cint(user_defaults.set_qty_in_transactions_based_on_serial_no_input)) { frappe.model.set_value(item.doctype, item.name, "qty", valid_serial_nos.length / item.conversion_factor); frappe.model.set_value(item.doctype, item.name, "stock_qty", valid_serial_nos.length); diff --git a/erpnext/setup/setup_wizard/operations/defaults_setup.py b/erpnext/setup/setup_wizard/operations/defaults_setup.py index b54d94e9ff..7aba807cf0 100644 --- a/erpnext/setup/setup_wizard/operations/defaults_setup.py +++ b/erpnext/setup/setup_wizard/operations/defaults_setup.py @@ -37,6 +37,7 @@ def set_default_settings(args): stock_settings.auto_indent = 1 stock_settings.auto_insert_price_list_rate_if_missing = 1 stock_settings.automatically_set_serial_nos_based_on_fifo = 1 + stock_settings.set_qty_in_transactions_based_on_serial_no_input = 1 stock_settings.save() selling_settings = frappe.get_doc("Selling Settings") diff --git a/erpnext/stock/doctype/serial_no/serial_no.py b/erpnext/stock/doctype/serial_no/serial_no.py index 233a45c64e..a8cab80cbe 100644 --- a/erpnext/stock/doctype/serial_no/serial_no.py +++ b/erpnext/stock/doctype/serial_no/serial_no.py @@ -198,7 +198,7 @@ def validate_serial_no(sle, item_det): frappe.throw(_("Serial No {0} quantity {1} cannot be a fraction").format(sle.item_code, sle.actual_qty)) if len(serial_nos) and len(serial_nos) != abs(cint(sle.actual_qty)): - frappe.throw(_("{0} Serial Numbers required for Item {1}. You have provided {2}.").format(sle.actual_qty, sle.item_code, len(serial_nos)), + frappe.throw(_("{0} Serial Numbers required for Item {1}. You have provided {2}.").format(abs(sle.actual_qty), sle.item_code, len(serial_nos)), SerialNoQtyError) if len(serial_nos) != len(set(serial_nos)): diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.json b/erpnext/stock/doctype/stock_settings/stock_settings.json index 761f807a2d..11fc17413a 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.json +++ b/erpnext/stock/doctype/stock_settings/stock_settings.json @@ -463,6 +463,37 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_bulk_edit": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "1", + "fieldname": "set_qty_in_transactions_based_on_serial_no_input", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Set Qty in Transactions based on Serial No Input", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "unique": 0 + }, { "allow_bulk_edit": 0, "allow_on_submit": 0, @@ -679,7 +710,7 @@ "issingle": 1, "istable": 0, "max_attachments": 0, - "modified": "2017-11-17 01:35:49.562613", + "modified": "2018-05-03 12:37:12.905394", "modified_by": "Administrator", "module": "Stock", "name": "Stock Settings", diff --git a/erpnext/stock/doctype/stock_settings/stock_settings.py b/erpnext/stock/doctype/stock_settings/stock_settings.py index 89ece33b08..da7c2be49b 100644 --- a/erpnext/stock/doctype/stock_settings/stock_settings.py +++ b/erpnext/stock/doctype/stock_settings/stock_settings.py @@ -11,8 +11,9 @@ from frappe.utils.html_utils import clean_html class StockSettings(Document): def validate(self): - for key in ["item_naming_by", "item_group", "stock_uom", "allow_negative_stock", "default_warehouse"]: - frappe.db.set_default(key, self.get(key, "")) + for key in ["item_naming_by", "item_group", "stock_uom", + "allow_negative_stock", "default_warehouse", "set_qty_in_transactions_based_on_serial_no_input"]: + frappe.db.set_default(key, self.get(key, "")) from erpnext.setup.doctype.naming_series.naming_series import set_by_naming_series set_by_naming_series("Item", "item_code",