From dc981dc546a798bdd9306d70e3c33dbf115d4607 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Mon, 3 Apr 2017 14:17:08 +0530 Subject: [PATCH] [fix] Auto serial no fecthed on the invoice even if stock update is disabled issue --- erpnext/controllers/accounts_controller.py | 8 +++++--- erpnext/patches.txt | 3 ++- ...ll_to_serial_nos_for_disabled_sales_invoices.py | 14 ++++++++++++++ erpnext/public/js/controllers/transaction.js | 10 +++++++--- erpnext/stock/get_item_details.py | 13 ++++++++++++- 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 erpnext/patches/v8_0/set_null_to_serial_nos_for_disabled_sales_invoices.py diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index 910c19c9ca..ecbf59da1b 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -192,11 +192,13 @@ class AccountsController(TransactionBase): if (item.get(fieldname) is None or fieldname in force_item_fields): item.set(fieldname, value) - elif fieldname == "cost_center" and not item.get("cost_center"): + elif fieldname in ['cost_center', 'conversion_factor'] and not item.get(fieldname): item.set(fieldname, value) - elif fieldname == "conversion_factor" and not item.get("conversion_factor"): - item.set(fieldname, value) + elif fieldname == "serial_no": + stock_qty = item.get("stock_qty") * -1 if item.get("stock_qty") < 0 else item.get("stock_qty") + if stock_qty != len(item.get('serial_no').split('\n')): + item.set(fieldname, value) if ret.get("pricing_rule"): # if user changed the discount percentage then set user's discount percentage ? diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 9c2b1c49ad..522c4fca9c 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -385,4 +385,5 @@ erpnext.patches.v8_0.addresses_linked_to_lead execute:frappe.delete_doc('DocType', 'Purchase Common') erpnext.patches.v8_0.update_stock_qty_value_in_purchase_invoice erpnext.patches.v8_0.update_supplier_address_in_stock_entry -erpnext.patches.v8_0.rename_is_sample_item_to_allow_zero_valuation_rate \ No newline at end of file +erpnext.patches.v8_0.rename_is_sample_item_to_allow_zero_valuation_rate +erpnext.patches.v8_0.set_null_to_serial_nos_for_disabled_sales_invoices \ No newline at end of file diff --git a/erpnext/patches/v8_0/set_null_to_serial_nos_for_disabled_sales_invoices.py b/erpnext/patches/v8_0/set_null_to_serial_nos_for_disabled_sales_invoices.py new file mode 100644 index 0000000000..197d6ded61 --- /dev/null +++ b/erpnext/patches/v8_0/set_null_to_serial_nos_for_disabled_sales_invoices.py @@ -0,0 +1,14 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe +from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty + +def execute(): + frappe.db.sql(""" + update + `tabSales Invoice Item` + set serial_no = NULL + where + parent in (select name from `tabSales Invoice` where update_stock = 0 and docstatus = 1)""") \ No newline at end of file diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 7e0dccc6a1..a583f7d05b 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -260,6 +260,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ customer: me.frm.doc.customer, supplier: me.frm.doc.supplier, currency: me.frm.doc.currency, + update_stock: in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0, conversion_rate: me.frm.doc.conversion_rate, price_list: me.frm.doc.selling_price_list || me.frm.doc.buying_price_list, @@ -275,7 +276,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ name: me.frm.doc.name, project: item.project || me.frm.doc.project, qty: item.qty, - stock_qty: item.stock_qty + stock_qty: item.stock_qty, + conversion_factor: item.conversion_factor } }, @@ -762,7 +764,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ "ignore_pricing_rule": me.frm.doc.ignore_pricing_rule, "doctype": me.frm.doc.doctype, "name": me.frm.doc.name, - "is_return": cint(me.frm.doc.is_return) + "is_return": cint(me.frm.doc.is_return), + "update_stock": in_list(['Sales Invoice', 'Purchase Invoice'], me.frm.doc.doctype) ? cint(me.frm.doc.update_stock) : 0, }; }, @@ -781,7 +784,8 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ "parent": d.parent, "pricing_rule": d.pricing_rule, "warehouse": d.warehouse, - "serial_no": d.serial_no + "serial_no": d.serial_no, + "conversion_factor": d.conversion_factor }); // if doctype is Quotation Item / Sales Order Iten then add Margin Type and rate in item_list diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index 3ada10ba6b..c2e77df3fe 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -161,7 +161,7 @@ def get_basic_details(args, item): "min_order_qty": flt(item.min_order_qty) if args.doctype == "Material Request" else "", "conversion_factor": 1.0, "qty": args.qty or 1.0, - "stock_qty": 1.0, + "stock_qty": args.qty or 1.0, "price_list_rate": 0.0, "base_price_list_rate": 0.0, "rate": 0.0, @@ -172,10 +172,18 @@ def get_basic_details(args, item): "net_amount": 0.0, "discount_percentage": 0.0, "supplier": item.default_supplier, + "update_stock": args.get("update_stock") if args.get('doctype') in ['Sales Invoice', 'Purchase Invoice'] else 0, "delivered_by_supplier": item.delivered_by_supplier if args.get("doctype") in ["Sales Order", "Sales Invoice"] else 0, "is_fixed_asset": item.is_fixed_asset }) + # calculate conversion factor + conversion_factor = args.get("conversion_factor") or get_conversion_factor(item.item_code, args.uom).get("conversion_factor") or 1.0 + out.update({ + "conversion_factor": conversion_factor, + "stock_qty": out.qty * conversion_factor + }) + # if default specified in item is for another company, fetch from company for d in [["Account", "income_account", "default_income_account"], ["Account", "expense_account", "default_expense_account"], @@ -532,6 +540,9 @@ def get_serial_no(args): args = json.loads(args) args = frappe._dict(args) + if args.get('doctype') == 'Sales Invoice' and not args.get('update_stock'): + return "" + if args.get('warehouse') and args.get('stock_qty') and args.get('item_code'): if frappe.get_value('Item', {'item_code': args.item_code}, "has_serial_no") == 1: