Fixed Stock Entry Test Cases frappe/frappe#478

This commit is contained in:
Anand Doshi 2014-04-07 18:51:58 +05:30
parent 103cc58cb6
commit 2ce39cf770
9 changed files with 573 additions and 573 deletions

View File

@ -114,7 +114,7 @@ class JournalVoucher(AccountsController):
def create_remarks(self):
r = []
if self.cheque_no :
if self.cheque_no:
if self.cheque_date:
r.append('Via Reference #%s dated %s' %
(self.cheque_no, formatdate(self.cheque_date)))

View File

@ -124,7 +124,7 @@ class PurchaseInvoice(BuyingController):
check_list = []
for d in self.get('entries'):
if d.purchase_order and not d.purchase_order in check_list and not d.purchase_receipt:
check_list.append(d.purhcase_order)
check_list.append(d.purchase_order)
stopped = frappe.db.sql("select name from `tabPurchase Order` where status = 'Stopped' and name = %s", d.purchase_order)
if stopped:
msgprint("One cannot do any transaction against 'Purchase Order' : %s, it's status is 'Stopped'" % (d.purhcase_order))

View File

@ -758,18 +758,17 @@ def make_return_jv(stock_entry):
result = make_return_jv_from_purchase_receipt(se, ref)
# create jv doc and fetch balance for each unique row item
jv_list = [{
"__islocal": 1,
"doctype": "Journal Voucher",
jv = frappe.new_doc("Journal Voucher")
jv.update({
"posting_date": se.posting_date,
"voucher_type": se.purpose == "Sales Return" and "Credit Note" or "Debit Note",
"fiscal_year": se.fiscal_year,
"company": se.company
}]
})
from erpnext.accounts.utils import get_balance_on
for r in result:
jv_list.append({
jv.append("entries", {
"__islocal": 1,
"doctype": "Journal Voucher Detail",
"parentfield": "entries",
@ -780,7 +779,7 @@ def make_return_jv(stock_entry):
if r.get("account") else 0
})
return jv_list
return jv
def make_return_jv_from_sales_invoice(se, ref):
# customer account entry
@ -804,9 +803,9 @@ def make_return_jv_from_sales_invoice(se, ref):
def get_sales_account_from_item(doc, ref_item):
account = None
if not ref_item.income_account:
if not getattr(ref_item, "income_account", None):
if ref_item.parent_item:
parent_item = doc.get({"item_code": ref_item.parent_item})[0]
parent_item = doc.get(doc.fname, {"item_code": ref_item.parent_item})[0]
account = parent_item.income_account
else:
account = ref_item.income_account
@ -818,7 +817,7 @@ def make_return_jv_from_delivery_note(se, ref):
ref.doc.name)
if not invoices_against_delivery:
sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if d.against_sales_order]
sales_orders_against_delivery = [d.against_sales_order for d in ref.doc.get_all_children() if getattr(d, "against_sales_order", None)]
if sales_orders_against_delivery:
invoices_against_delivery = get_invoice_list("Sales Invoice Item", "sales_order",
@ -877,7 +876,8 @@ def make_return_jv_from_purchase_receipt(se, ref):
if not invoice_against_receipt:
purchase_orders_against_receipt = [d.prevdoc_docname for d in
ref.get({"prevdoc_doctype": "Purchase Order"}) if d.prevdoc_docname]
ref.doc.get(ref.doc.fname, {"prevdoc_doctype": "Purchase Order"})
if getattr(d, "prevdoc_docname", None)]
if purchase_orders_against_receipt:
invoice_against_receipt = get_invoice_list("Purchase Invoice Item", "purchase_order",

View File

@ -3,6 +3,7 @@
from __future__ import unicode_literals
import frappe, unittest
import frappe.defaults
from frappe.utils import flt, getdate
from erpnext.stock.doctype.serial_no.serial_no import *
from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
@ -31,7 +32,6 @@ class TestStockEntry(unittest.TestCase):
st2.submit()
from erpnext.stock.utils import reorder_item
reorder_item()
mr_name = frappe.db.sql("""select parent from `tabMaterial Request Item`
@ -39,8 +39,6 @@ class TestStockEntry(unittest.TestCase):
self.assertTrue(mr_name)
frappe.db.set_default("company", self.old_default_company)
def test_material_receipt_gl_entry(self):
self._clear_stock_account_balance()
set_perpetual_inventory()
@ -367,14 +365,14 @@ class TestStockEntry(unittest.TestCase):
def _test_sales_return_jv(self, se):
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
jv_list = make_return_jv(se.name)
jv = make_return_jv(se.name)
self.assertEqual(len(jv_list), 3)
self.assertEqual(jv_list[0].get("voucher_type"), "Credit Note")
self.assertEqual(jv_list[0].get("posting_date"), se.posting_date)
self.assertEqual(jv_list[1].get("account"), "_Test Customer - _TC")
self.assertEqual(jv_list[2].get("account"), "Sales - _TC")
self.assertTrue(jv_list[1].get("against_invoice"))
self.assertEqual(len(jv.get("entries")), 2)
self.assertEqual(jv.get("voucher_type"), "Credit Note")
self.assertEqual(jv.get("posting_date"), se.posting_date)
self.assertEqual(jv.get("entries")[0].get("account"), "_Test Customer - _TC")
self.assertEqual(jv.get("entries")[1].get("account"), "Sales - _TC")
self.assertTrue(jv.get("entries")[0].get("against_invoice"))
def test_make_return_jv_for_sales_invoice_non_packing_item(self):
self._clear_stock_account_balance()
@ -527,14 +525,14 @@ class TestStockEntry(unittest.TestCase):
def _test_purchase_return_jv(self, se):
from erpnext.stock.doctype.stock_entry.stock_entry import make_return_jv
jv_list = make_return_jv(se.name)
jv = make_return_jv(se.name)
self.assertEqual(len(jv_list), 3)
self.assertEqual(jv_list[0].get("voucher_type"), "Debit Note")
self.assertEqual(jv_list[0].get("posting_date"), se.posting_date)
self.assertEqual(jv_list[1].get("account"), "_Test Supplier - _TC")
self.assertEqual(jv_list[2].get("account"), "_Test Account Cost for Goods Sold - _TC")
self.assertTrue(jv_list[1].get("against_voucher"))
self.assertEqual(len(jv.get("entries")), 2)
self.assertEqual(jv.get("voucher_type"), "Debit Note")
self.assertEqual(jv.get("posting_date"), se.posting_date)
self.assertEqual(jv.get("entries")[0].get("account"), "_Test Supplier - _TC")
self.assertEqual(jv.get("entries")[1].get("account"), "_Test Account Cost for Goods Sold - _TC")
self.assertTrue(jv.get("entries")[0].get("against_voucher"))
def test_make_return_jv_for_purchase_receipt(self):
self._clear_stock_account_balance()
@ -774,10 +772,9 @@ class TestStockEntry(unittest.TestCase):
# permission tests
def test_warehouse_user(self):
import frappe.defaults
set_perpetual_inventory(0)
frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", "Restriction")
frappe.defaults.add_default("Warehouse", "_Test Warehouse 1 - _TC", "test@example.com", "Restriction")
frappe.defaults.add_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", "Restriction")
frappe.get_doc("User", "test@example.com")\
.add_roles("Sales User", "Sales Manager", "Material User", "Material Manager")
@ -797,15 +794,17 @@ class TestStockEntry(unittest.TestCase):
st1.insert()
st1.submit()
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC1", "test@example.com", parenttype="Restriction")
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1", "test2@example.com", parenttype="Restriction")
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 1 - _TC",
"test@example.com", parenttype="Restriction")
frappe.defaults.clear_default("Warehouse", "_Test Warehouse 2 - _TC1",
"test2@example.com", parenttype="Restriction")
def test_freeze_stocks (self):
self._clear_stock_account_balance()
frappe.db.set_value('Stock Settings', None,'stock_auth_role', '')
# test freeze_stocks_upto
date_newer_than_test_records = add_days(getdate(test_records[0][0]['posting_date']), 5)
date_newer_than_test_records = add_days(getdate(test_records[0]['posting_date']), 5)
frappe.db.set_value("Stock Settings", None, "stock_frozen_upto", date_newer_than_test_records)
se = frappe.copy_doc(test_records[0]).insert()
self.assertRaises (StockFreezeError, se.submit)

View File

@ -169,9 +169,13 @@ def get_sle_before_datetime(args, for_update=False):
def get_sle_after_datetime(args, for_update=False):
"""get Stock Ledger Entries after a particular datetime, for reposting"""
# NOTE: using for update of
return get_stock_ledger_entries(args,
["timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s)"],
"asc", for_update=for_update)
conditions = ["timestamp(posting_date, posting_time) > timestamp(%(posting_date)s, %(posting_time)s)"]
# Excluding name: Workaround for MariaDB timestamp() floating microsecond issue
if args.get("name"):
conditions.append("name!=%(name)s")
return get_stock_ledger_entries(args, conditions, "asc", for_update=for_update)
def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, for_update=False):
"""get stock ledger entries filtered by specific posting datetime conditions"""
@ -180,7 +184,7 @@ def get_stock_ledger_entries(args, conditions=None, order="desc", limit=None, fo
if not args.get("posting_time"):
args["posting_time"] = "00:00"
return frappe.db.sql("""select * from `tabStock Ledger Entry`
return frappe.db.sql("""select *, timestamp(posting_date, posting_time) as "timestamp" from `tabStock Ledger Entry`
where item_code = %%(item_code)s
and warehouse = %%(warehouse)s
and ifnull(is_cancelled, 'No')='No'

View File

@ -189,7 +189,7 @@ def reorder_item():
and exists (select name from `tabItem`
where `tabItem`.name = `tabBin`.item_code and
is_stock_item='Yes' and (is_purchase_item='Yes' or is_sub_contracted_item='Yes') and
(ifnull(end_of_life, '')='' or end_of_life > now()))""", as_dict=True)
(ifnull(end_of_life, '')='' or end_of_life > curdate()))""", as_dict=True)
for bin in bin_list:
#check if re-order is required
item_reorder = frappe.db.get("Item Reorder",
@ -235,20 +235,18 @@ def create_material_request(material_requests):
if not items:
continue
mr = [{
"doctype": "Material Request",
mr = frappe.new_doc("Material Request")
mr.update({
"company": company,
"fiscal_year": current_fiscal_year,
"transaction_date": nowdate(),
"material_request_type": request_type
}]
})
for d in items:
item = frappe.get_doc("Item", d.item_code)
mr.append({
mr.append("indent_details", {
"doctype": "Material Request Item",
"parenttype": "Material Request",
"parentfield": "indent_details",
"item_code": d.item_code,
"schedule_date": add_days(nowdate(),cint(item.lead_time_days)),
"uom": item.stock_uom,
@ -260,10 +258,9 @@ def create_material_request(material_requests):
"brand": item.brand,
})
mr_doc = frappe.get_doc(mr)
mr_doc.insert()
mr_doc.submit()
mr_list.append(mr_doc)
mr.insert()
mr.submit()
mr_list.append(mr)
except:
if frappe.local.message_log: