From e98b326ba30a8b2b245f741ceca71a7bba19f231 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 12 Jun 2014 12:24:11 +0530 Subject: [PATCH 1/5] Stock Entry: Always set valuation rate automatically if source warehouse provided or sales return. Fixes #932 --- erpnext/stock/doctype/stock_entry/stock_entry.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index ac81f88e88..da176b0976 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -205,8 +205,10 @@ class StockEntry(StockController): # get incoming rate if not d.bom_no: - if not flt(d.incoming_rate): - d.incoming_rate = self.get_incoming_rate(args) + if not flt(d.incoming_rate) or d.s_warehouse or self.purpose == "Sales Return": + incoming_rate = self.get_incoming_rate(args) + if incoming_rate: + d.incoming_rate = incoming_rate d.amount = flt(d.transfer_qty) * flt(d.incoming_rate) raw_material_cost += flt(d.amount) From 2128c98c353285f9d76c2d276af018397a06d41f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 12 Jun 2014 12:42:22 +0530 Subject: [PATCH 2/5] available qty validation. Fixes #1045 --- erpnext/stock/doctype/stock_entry/stock_entry.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index da176b0976..bbe461e79a 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -202,6 +202,10 @@ class StockEntry(StockController): }) # get actual stock at source warehouse d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 + if d.s_warehouse and d.actual_qty <= d.transfer_qty: + frappe.throw(_("""Row {0}: Qty not avalable in warehouse {1} on {2} {3}. + Available Qty: {4}, Transfer Qty: {5}""").format(d.idx, d.s_warehouse, + self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty)) # get incoming rate if not d.bom_no: From 46dc3b1442d0ab8debb42d385acf343b3d979d04 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 12 Jun 2014 12:48:28 +0530 Subject: [PATCH 3/5] validations added in stock entry --- erpnext/stock/doctype/stock_entry/stock_entry.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index bbe461e79a..2037117e05 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -70,6 +70,9 @@ class StockEntry(StockController): def set_transfer_qty(self): for item in self.get("mtn_details"): + if not flt(item.qty): + frappe.throw(_("Row {0}: Qty is mandatory").format(item.idx)) + item.transfer_qty = flt(item.qty * item.conversion_factor, self.precision("transfer_qty", item)) def validate_item(self): @@ -191,6 +194,9 @@ class StockEntry(StockController): raw_material_cost = 0.0 + if not self.posting_date or not self.posting_time: + frappe.throw(_("Posting date and posting time is mandatory")) + for d in self.get('mtn_details'): args = frappe._dict({ "item_code": d.item_code, @@ -200,6 +206,7 @@ class StockEntry(StockController): "qty": d.s_warehouse and -1*d.transfer_qty or d.transfer_qty, "serial_no": d.serial_no }) + # get actual stock at source warehouse d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 if d.s_warehouse and d.actual_qty <= d.transfer_qty: From e7f2d3179d42d121c612e083911ecb423a0b6de8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 12 Jun 2014 14:58:09 +0530 Subject: [PATCH 4/5] update other_charges in custom print formats --- erpnext/patches.txt | 1 + ...other_charges_in_custom_purchase_print_formats.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 erpnext/patches/v4_0/update_other_charges_in_custom_purchase_print_formats.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 8755837b70..02c651f9ed 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -58,3 +58,4 @@ execute:frappe.reset_perms("Stock Ledger Entry") #2014-06-09 erpnext.patches.v4_0.create_custom_fields_for_india_specific_fields erpnext.patches.v4_0.save_default_letterhead erpnext.patches.v4_0.update_custom_print_formats_for_renamed_fields +erpnext.patches.v4_0.update_other_charges_in_custom_purchase_print_formats diff --git a/erpnext/patches/v4_0/update_other_charges_in_custom_purchase_print_formats.py b/erpnext/patches/v4_0/update_other_charges_in_custom_purchase_print_formats.py new file mode 100644 index 0000000000..c0f9ee008f --- /dev/null +++ b/erpnext/patches/v4_0/update_other_charges_in_custom_purchase_print_formats.py @@ -0,0 +1,12 @@ +# 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 +import re + +def execute(): + for name, html in frappe.db.sql("""select name, html from `tabPrint Format` + where standard = 'No' and html like '%%purchase\\_tax\\_details%%'"""): + html = re.sub(r"\bpurchase_tax_details\b", "other_charges", html) + frappe.db.set_value("Print Format", name, "html", html) From f2202fc01419f826d056a62e23879514b4a7d0e8 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 12 Jun 2014 15:20:47 +0530 Subject: [PATCH 5/5] minor fix --- erpnext/stock/doctype/stock_entry/stock_entry.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 2037117e05..d8164f7e21 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -197,6 +197,8 @@ class StockEntry(StockController): if not self.posting_date or not self.posting_time: frappe.throw(_("Posting date and posting time is mandatory")) + allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock") + for d in self.get('mtn_details'): args = frappe._dict({ "item_code": d.item_code, @@ -209,7 +211,8 @@ class StockEntry(StockController): # get actual stock at source warehouse d.actual_qty = get_previous_sle(args).get("qty_after_transaction") or 0 - if d.s_warehouse and d.actual_qty <= d.transfer_qty: + + if d.s_warehouse and not allow_negative_stock and d.actual_qty <= d.transfer_qty: frappe.throw(_("""Row {0}: Qty not avalable in warehouse {1} on {2} {3}. Available Qty: {4}, Transfer Qty: {5}""").format(d.idx, d.s_warehouse, self.posting_date, self.posting_time, d.actual_qty, d.transfer_qty))