[fix] warehouse test cases

This commit is contained in:
Rushabh Mehta 2017-01-16 17:23:20 +05:30
parent 6695830f3f
commit ffd80a6061

View File

@ -3,7 +3,7 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cint, flt, cstr, now
from frappe.utils import cint, flt, cstr
from frappe import msgprint, _
import frappe.defaults
from erpnext.accounts.utils import get_fiscal_year
@ -14,7 +14,7 @@ class StockController(AccountsController):
def validate(self):
super(StockController, self).validate()
self.validate_inspection()
def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
if self.docstatus == 2:
delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
@ -43,16 +43,16 @@ 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:
for sle in sle_list:
if warehouse_account.get(sle.warehouse):
# from warehouse account
self.check_expense_account(item_row)
if not sle.stock_value_difference:
self.validate_negative_stock(sle)
@ -80,16 +80,16 @@ class StockController(AccountsController):
for wh in warehouse_with_no_account:
if frappe.db.get_value("Warehouse", wh, "company"):
frappe.throw(_("Warehouse {0} is not linked to any account, please create/link the corresponding (Asset) account for the warehouse.").format(wh))
msgprint(_("No accounting entries for the following warehouses") + ": \n" +
"\n".join(warehouse_with_no_account))
return process_gl_map(gl_list)
def validate_negative_stock(self, sle):
if sle.qty_after_transaction < 0 and sle.actual_qty < 0:
frappe.throw(_("For the Item {0}, valuation rate not found for warehouse {1}. To be able to do accounting entries (for booking expenses), we need valuation rate for item {2}. Please create an incoming stock transaction, on or before {3} {4}, and then try submiting {5}")
.format(sle.item_code, sle.warehouse,
.format(sle.item_code, sle.warehouse,
sle.item_code, sle.posting_date, sle.posting_time, self.name))
def get_voucher_details(self, default_expense_account, default_cost_center, sle_map):
@ -248,7 +248,7 @@ class StockController(AccountsController):
incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
return incoming_rate
def validate_warehouse(self):
from erpnext.stock.utils import validate_warehouse_company
@ -257,7 +257,7 @@ class StockController(AccountsController):
for w in warehouses:
validate_warehouse_company(w, self.company)
def update_billing_percentage(self, update_modified=True):
self._update_percent_field({
"target_dt": self.doctype + " Item",
@ -271,21 +271,21 @@ class StockController(AccountsController):
def validate_inspection(self):
'''Checks if quality inspection is set for Items that require inspection.
On submit, throw an exception'''
inspection_required_fieldname = None
if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
inspection_required_fieldname = "inspection_required_before_purchase"
elif self.doctype in ["Delivery Note", "Sales Invoice"]:
inspection_required_fieldname = "inspection_required_before_delivery"
if not inspection_required_fieldname or \
(self.doctype in ["Sales Invoice", "Purchase Invoice"] and not self.update_stock):
return
for d in self.get('items'):
if (frappe.db.get_value("Item", d.item_code, inspection_required_fieldname)
if (frappe.db.get_value("Item", d.item_code, inspection_required_fieldname)
and not d.quality_inspection):
frappe.msgprint(_("Quality Inspection required for Item {0}").format(d.item_code))
if self.docstatus==1:
raise frappe.ValidationError
@ -301,7 +301,7 @@ def update_gl_entries_after(posting_date, posting_time, for_warehouses=None, for
future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items)
gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date)
for voucher_type, voucher_no in future_stock_vouchers:
existing_gle = gle.get((voucher_type, voucher_no), [])
voucher_obj = frappe.get_doc(voucher_type, voucher_no)
@ -364,14 +364,19 @@ def get_voucherwise_gl_entries(future_stock_vouchers, posting_date):
return gl_entries
def get_warehouse_account():
if not frappe.flags.warehouse_account_map:
if not frappe.flags.warehouse_account_map or frappe.flags.in_test:
warehouse_account = frappe._dict()
for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount
where account_type = 'Stock' and (warehouse is not null and warehouse != ''
and is_group != 1) and is_group=0 """, as_dict=1):
warehouse_account.setdefault(d.warehouse, d)
for d in frappe.db.sql("""select
warehouse, name, account_currency
from
tabAccount
where
account_type = 'Stock'
and (warehouse is not null and warehouse != '')
and is_group=0 """, as_dict=1):
warehouse_account.setdefault(d.warehouse, d)
frappe.flags.warehouse_account_map = warehouse_account
return frappe.flags.warehouse_account_map