From 0a6aaf42573f7968f619b89d9eb17c3cf3ff0466 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 7 Feb 2017 01:23:26 +0530 Subject: [PATCH] Get standard/historical valuation rate where missing: some minor fixes --- .../purchase_invoice_item.json | 4 ++-- .../sales_invoice_item.json | 4 ++-- erpnext/controllers/stock_controller.py | 16 +++++++------- .../delivery_note_item.json | 4 ++-- .../purchase_receipt_item.json | 4 ++-- .../stock_entry_detail.json | 4 ++-- erpnext/stock/stock_ledger.py | 22 ++++++++++++------- 7 files changed, 32 insertions(+), 26 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json index eff5df5849..a91d97409c 100755 --- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json +++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json @@ -1316,7 +1316,7 @@ "unique": 0 }, { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "columns": 0, @@ -1816,7 +1816,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-06 17:05:03.737297", + "modified": "2017-02-07 01:21:03.737800", "modified_by": "Administrator", "module": "Accounts", "name": "Purchase Invoice Item", diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index c36f001e28..bf6d9868a2 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -1382,7 +1382,7 @@ "unique": 0 }, { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "columns": 0, @@ -1910,7 +1910,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-06 17:01:16.812686", + "modified": "2017-02-07 01:21:47.142162", "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 6e3047c3e1..b08826a5c9 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -43,7 +43,7 @@ class StockController(AccountsController): gl_list = [] warehouse_with_no_account = [] - + for item_row in voucher_details: sle_list = sle_map.get(item_row.name) if sle_list: @@ -58,9 +58,10 @@ class StockController(AccountsController): # or incoming entry not found while delivering the item), # try to pick valuation rate from previous sle or Item master and update in SLE # Otherwise, throw an exception - - if not sle.stock_value_difference and sle.voucher_type != "Stock Reconciliation" \ + + if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \ and not item_row.get("is_sample_item"): + sle = self.update_stock_ledger_entries(sle) gl_list.append(self.get_gl_dict({ @@ -95,7 +96,7 @@ class StockController(AccountsController): def update_stock_ledger_entries(self, sle): sle.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, - sle.voucher_type, sle.voucher_no) + self.doctype, self.name) sle.stock_value = flt(sle.qty_after_transaction) * flt(sle.valuation_rate) sle.stock_value_difference = flt(sle.actual_qty) * flt(sle.valuation_rate) @@ -162,18 +163,17 @@ class StockController(AccountsController): stock_ledger = {} stock_ledger_entries = frappe.db.sql(""" select - name, warehouse, stock_value_difference, valuation_rate + name, warehouse, stock_value_difference, valuation_rate, voucher_detail_no, item_code, posting_date, posting_time, - actual_qty, qty_after_transaction, voucher_type, voucher_no + actual_qty, qty_after_transaction from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s """, (self.doctype, self.name), as_dict=True) - + for sle in stock_ledger_entries: stock_ledger.setdefault(sle.voucher_detail_no, []).append(sle) - return stock_ledger def make_adjustment_entry(self, expected_gle, voucher_obj): diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json index 9108edd7c0..1147d8d5e0 100644 --- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json +++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json @@ -1477,7 +1477,7 @@ "width": "120px" }, { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "columns": 0, @@ -1719,7 +1719,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-06 17:00:24.354000", + "modified": "2017-02-07 01:22:03.047137", "modified_by": "Administrator", "module": "Stock", "name": "Delivery Note Item", diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json index 43e2f3be78..590371397e 100755 --- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json +++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json @@ -1575,7 +1575,7 @@ "unique": 0 }, { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "columns": 0, @@ -1913,7 +1913,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-06 17:04:23.305884", + "modified": "2017-02-07 01:21:36.348032", "modified_by": "Administrator", "module": "Stock", "name": "Purchase Receipt Item", diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json index fadaeb09fd..34b3c85f71 100644 --- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json +++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json @@ -1004,7 +1004,7 @@ "unique": 0 }, { - "allow_on_submit": 0, + "allow_on_submit": 1, "bold": 0, "collapsible": 0, "columns": 0, @@ -1183,7 +1183,7 @@ "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2017-02-06 17:08:06.841514", + "modified": "2017-02-07 01:21:14.367586", "modified_by": "Administrator", "module": "Stock", "name": "Stock Entry Detail", diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index c387e0f05a..10722cc0d9 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -261,10 +261,7 @@ class update_entries_after(object): # Get valuation rate from previous SLE or Item master, if item is not a sample item if not self.valuation_rate and sle.voucher_detail_no: - ref_item_dt = sle.voucher_type + " Detail" if sle.voucher_type == "Stock Entry" else " Item" - - is_sample_item = frappe.db.get_value(ref_item_dt, sle.voucher_detail_no, "is_sample_item") - + is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no) if not is_sample_item: self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, sle.voucher_type, sle.voucher_no, self.allow_zero_rate) @@ -292,8 +289,13 @@ class update_entries_after(object): while qty_to_pop: if not self.stock_queue: # Get valuation rate from last sle if exists or from valuation rate field in item master - _rate = get_valuation_rate(sle.item_code, sle.warehouse, - sle.voucher_type, sle.voucher_no, self.allow_zero_rate) + is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no) + if not is_sample_item: + _rate = get_valuation_rate(sle.item_code, sle.warehouse, + sle.voucher_type, sle.voucher_no, self.allow_zero_rate) + else: + _rate = 0 + self.stock_queue.append([0, _rate]) index = None @@ -339,7 +341,11 @@ class update_entries_after(object): if not self.stock_queue: self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate]) - + + def check_if_sample_item(self, voucher_type, voucher_detail_no): + ref_item_dt = voucher_type + (" Detail" if voucher_type == "Stock Entry" else " Item") + return frappe.db.get_value(ref_item_dt, voucher_detail_no, "is_sample_item") + def get_sle_before_datetime(self): """get previous stock ledger entry before current time-bucket""" return get_stock_ledger_entries(self.args, "<", "desc", "limit 1", for_update=False) @@ -438,6 +444,6 @@ def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zer if not allow_zero_rate and not valuation_rate \ and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")): - frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries. If the item is transacting as a sample item in {1} {2}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting this entry").format(item_code, voucher_type, voucher_no)) + frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries for {1} {2}. If the item is transacting as a sample item in the {1}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting/cancelling this entry").format(item_code, voucher_type, voucher_no)) return valuation_rate