From 38d0ed9f3a8a3a0ab343983b044ce8ec37d084b2 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 14 Oct 2014 16:07:56 +0530 Subject: [PATCH] Negative stock allowed for perpetual inventory. Blocked in specific case --- .../accounts/doctype/accounts_settings/accounts_settings.py | 3 --- erpnext/controllers/buying_controller.py | 3 +++ erpnext/controllers/stock_controller.py | 5 ++++- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py index 7280322a68..f0890dd439 100644 --- a/erpnext/accounts/doctype/accounts_settings/accounts_settings.py +++ b/erpnext/accounts/doctype/accounts_settings/accounts_settings.py @@ -14,9 +14,6 @@ class AccountsSettings(Document): frappe.db.set_default("auto_accounting_for_stock", self.auto_accounting_for_stock) if cint(self.auto_accounting_for_stock): - if cint(frappe.db.get_value("Stock Settings", None, "allow_negative_stock")): - frappe.throw(_("Negative stock is not allowed in case of Perpetual Inventory, please disable it from Stock Settings")) - # set default perpetual account in company for company in frappe.db.sql("select name from tabCompany"): frappe.get_doc("Company", company[0]).save() diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 66d5792e2d..cf57658342 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -277,6 +277,9 @@ class BuyingController(StockController): "qty": -1 * required_qty, "serial_no": rm.serial_no }) + if not item_rate: + from erpnext.controllers.stock_controller import get_valuation_rate + item_rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse) rm.rate = item_rate or bom_item.rate else: rm.rate = bom_item.rate diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index ad553d8c83..a72a3d09fb 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -30,7 +30,7 @@ class StockController(AccountsController): def get_gl_entries(self, warehouse_account=None, default_expense_account=None, default_cost_center=None, allow_negative_stock=False): - block_negative_stock(allow_negative_stock) + # block_negative_stock(allow_negative_stock) if not warehouse_account: warehouse_account = get_warehouse_account() @@ -319,4 +319,7 @@ def get_valuation_rate(item_code, warehouse): if not valuation_rate: valuation_rate = frappe.db.get_value("Item Price", {"item_code": item_code, "buying": 1}, "price_list_rate") + if not valuation_rate: + frappe.throw(_("Purchase rate for item: {0} not found, which is required to book accounting entry. Please mention item price against a buying price list.").format(item_code)) + return valuation_rate diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index fc35222bb0..ed4257fd9b 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -287,7 +287,7 @@ class PurchaseReceipt(BuyingController): from erpnext.accounts.general_ledger import process_gl_map from erpnext.controllers.stock_controller import block_negative_stock - block_negative_stock(allow_negative_stock) + # block_negative_stock(allow_negative_stock) stock_rbnb = self.get_company_default("stock_received_but_not_billed") expenses_included_in_valuation = self.get_company_default("expenses_included_in_valuation")