From bfa7f171bddf771ece6167788d588b137215ef74 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 7 Oct 2014 12:17:31 +0530 Subject: [PATCH] Stock reconciliation sl entries --- erpnext/stock/doctype/bin/bin.py | 12 +++++++++++- .../doctype/stock_ledger_entry/stock_ledger_entry.py | 3 +++ .../stock_reconciliation/stock_reconciliation.py | 1 - erpnext/stock/report/stock_ledger/stock_ledger.py | 7 ++----- erpnext/stock/stock_ledger.py | 2 +- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py index 0244213a96..d094bc2fce 100644 --- a/erpnext/stock/doctype/bin/bin.py +++ b/erpnext/stock/doctype/bin/bin.py @@ -43,7 +43,17 @@ class Bin(Document): def update_qty(self, args): # update the stock values (for current quantities) if args.get("voucher_type")=="Stock Reconciliation": - self.actual_qty = args.get("qty_after_transaction") + 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")) diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 1bb189bd74..7fdd440f2e 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -49,6 +49,9 @@ class StockLedgerEntry(Document): if not self.get(k): frappe.throw(_("{0} is required").format(self.meta.get_label(k))) + if self.voucher_type != "Stock Reconciliation" and not self.actual_qty: + frappe.throw(_("Actual Qty is mandatory")) + def validate_item(self): item_det = frappe.db.sql("""select name, has_batch_no, docstatus, is_stock_item from tabItem where name=%s""", self.item_code, as_dict=True)[0] diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index f39829de98..2aa9ab61c6 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -172,7 +172,6 @@ class StockReconciliation(StockController): "voucher_no": self.name, "company": self.company, "stock_uom": frappe.db.get_value("Item", row.item_code, "stock_uom"), - "voucher_detail_no": row.voucher_detail_no, "fiscal_year": self.fiscal_year, "is_cancelled": "No", "qty_after_transaction": row.qty, diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 4c5458dbb2..44f32c9751 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -13,16 +13,13 @@ def execute(filters=None): data = [] for sle in sl_entries: item_detail = item_details[sle.item_code] - voucher_link_icon = """""" \ - % ("/".join(["#Form", sle.voucher_type, sle.voucher_no]),) data.append([sle.date, sle.item_code, item_detail.item_name, item_detail.item_group, item_detail.brand, item_detail.description, sle.warehouse, item_detail.stock_uom, sle.actual_qty, sle.qty_after_transaction, (sle.incoming_rate if sle.actual_qty > 0 else 0.0), sle.valuation_rate, sle.stock_value, sle.voucher_type, sle.voucher_no, - voucher_link_icon, sle.batch_no, sle.serial_no, sle.company]) + sle.batch_no, sle.serial_no, sle.company]) return columns, data @@ -31,7 +28,7 @@ def get_columns(): _("Brand") + ":Link/Brand:100", _("Description") + "::200", _("Warehouse") + ":Link/Warehouse:100", _("Stock UOM") + ":Link/UOM:100", _("Qty") + ":Float:50", _("Balance Qty") + ":Float:100", _("Incoming Rate") + ":Currency:110", _("Valuation Rate") + ":Currency:110", _("Balance Value") + ":Currency:110", - _("Voucher Type") + "::110", _("Voucher #") + "::100", _("Link") + "::30", _("Batch") + ":Link/Batch:100", + _("Voucher Type") + "::110", _("Voucher #") + ":Dynamic Link/Voucher Type:100", _("Batch") + ":Link/Batch:100", _("Serial #") + ":Link/Serial No:100", _("Company") + ":Link/Company:100"] def get_stock_ledger_entries(filters): diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 03bbf2f138..db65cd4a29 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -27,7 +27,7 @@ def make_sl_entries(sl_entries, is_amended=None): if sle.get('is_cancelled') == 'Yes': sle['actual_qty'] = -flt(sle['actual_qty']) - if sle.get("actual_qty"): + if sle.get("actual_qty") or sle.voucher_type=="Stock Reconciliation": sle_id = make_entry(sle) args = sle.copy()