mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-25 07:54:46 +00:00
[fix] [minor] Repost future gl entries and testcases
This commit is contained in:
@@ -123,7 +123,6 @@ class DocType(SellingController):
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
def validate_proj_cust(self):
|
||||
"""check for does customer belong to same project as entered.."""
|
||||
if self.doc.project_name and self.doc.customer:
|
||||
|
||||
@@ -7,13 +7,13 @@ import unittest
|
||||
import webnotes
|
||||
import webnotes.defaults
|
||||
from webnotes.utils import cint
|
||||
from accounts.utils import get_stock_and_account_difference
|
||||
from stock.doctype.purchase_receipt.test_purchase_receipt import get_gl_entries, test_records as pr_test_records
|
||||
|
||||
class TestDeliveryNote(unittest.TestCase):
|
||||
def _insert_purchase_receipt(self):
|
||||
from stock.doctype.purchase_receipt.test_purchase_receipt import test_records as pr_test_records
|
||||
def _insert_purchase_receipt(self, item_code=None):
|
||||
pr = webnotes.bean(copy=pr_test_records[0])
|
||||
pr.run_method("calculate_taxes_and_totals")
|
||||
if item_code:
|
||||
pr.doclist[1].item_code = item_code
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
@@ -61,13 +61,14 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
from `tabGL Entry` where voucher_type='Delivery Note' and voucher_no=%s
|
||||
order by account desc""", dn.doc.name, as_dict=1)
|
||||
|
||||
self.assertTrue(not gl_entries)
|
||||
self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name))
|
||||
|
||||
def test_delivery_note_gl_entry(self):
|
||||
self.clear_stock_account_balance()
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
self.assertEqual(cint(webnotes.defaults.get_global_default("perpetual_accounting")), 1)
|
||||
webnotes.conn.set_value("Item", "_Test Item", "valuation_method", "FIFO")
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
|
||||
@@ -84,25 +85,78 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
dn.insert()
|
||||
dn.submit()
|
||||
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Delivery Note' and voucher_no=%s
|
||||
order by account asc""", dn.doc.name, as_dict=1)
|
||||
gl_entries = get_gl_entries("Delivery Note", dn.doc.name)
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
expected_values = sorted([
|
||||
[stock_in_hand_account, 0.0, 375.0],
|
||||
["Cost of Goods Sold - _TC", 375.0, 0.0]
|
||||
])
|
||||
expected_values = {
|
||||
stock_in_hand_account: [0.0, 375.0],
|
||||
"Cost of Goods Sold - _TC": [375.0, 0.0]
|
||||
}
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEquals(expected_values[i][0], gle.account)
|
||||
self.assertEquals(expected_values[i][1], gle.debit)
|
||||
self.assertEquals(expected_values[i][2], gle.credit)
|
||||
|
||||
self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account))
|
||||
|
||||
# check stock in hand balance
|
||||
bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date)
|
||||
self.assertEquals(bal, prev_bal - 375.0)
|
||||
self.assertFalse(get_stock_and_account_difference([dn.doclist[1].warehouse]))
|
||||
|
||||
# back dated purchase receipt
|
||||
pr = webnotes.bean(copy=pr_test_records[0])
|
||||
pr.doc.posting_date = "2013-01-01"
|
||||
pr.doclist[1].import_rate = 100
|
||||
pr.doclist[1].amount = 100
|
||||
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
gl_entries = get_gl_entries("Delivery Note", dn.doc.name)
|
||||
self.assertTrue(gl_entries)
|
||||
expected_values = {
|
||||
stock_in_hand_account: [0.0, 666.65],
|
||||
"Cost of Goods Sold - _TC": [666.65, 0.0]
|
||||
}
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account))
|
||||
|
||||
dn.cancel()
|
||||
self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name))
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
def test_delivery_note_gl_entry_packing_item(self):
|
||||
self.clear_stock_account_balance()
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
|
||||
self._insert_purchase_receipt()
|
||||
self._insert_purchase_receipt("_Test Item Home Desktop 100")
|
||||
|
||||
dn = webnotes.bean(copy=test_records[0])
|
||||
dn.doclist[1].item_code = "_Test Sales BOM Item"
|
||||
dn.doclist[1].qty = 1
|
||||
|
||||
stock_in_hand_account = webnotes.conn.get_value("Warehouse", dn.doclist[1].warehouse,
|
||||
"account")
|
||||
|
||||
from accounts.utils import get_balance_on
|
||||
prev_bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date)
|
||||
|
||||
dn.insert()
|
||||
dn.submit()
|
||||
|
||||
gl_entries = get_gl_entries("Delivery Note", dn.doc.name)
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
expected_values = {
|
||||
stock_in_hand_account: [0.0, 525],
|
||||
"Cost of Goods Sold - _TC": [525.0, 0.0]
|
||||
}
|
||||
for i, gle in enumerate(gl_entries):
|
||||
self.assertEquals([gle.debit, gle.credit], expected_values.get(gle.account))
|
||||
|
||||
# check stock in hand balance
|
||||
bal = get_balance_on(stock_in_hand_account, dn.doc.posting_date)
|
||||
self.assertEquals(bal, prev_bal - 525.0)
|
||||
|
||||
dn.cancel()
|
||||
self.assertFalse(get_gl_entries("Delivery Note", dn.doc.name))
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
@@ -163,6 +217,8 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.conn.sql("delete from `tabGL Entry`")
|
||||
|
||||
test_dependencies = ["Sales BOM"]
|
||||
|
||||
test_records = [
|
||||
[
|
||||
{
|
||||
@@ -196,8 +252,10 @@ test_records = [
|
||||
"export_rate": 100.0,
|
||||
"amount": 500.0,
|
||||
"warehouse": "_Test Warehouse - _TC",
|
||||
"stock_uom": "_Test UOM"
|
||||
"stock_uom": "_Test UOM",
|
||||
"expense_account": "Cost of Goods Sold - _TC",
|
||||
"cost_center": "Main - _TC"
|
||||
}
|
||||
]
|
||||
|
||||
]
|
||||
]
|
||||
|
||||
@@ -302,11 +302,8 @@ class DocType(BuyingController):
|
||||
|
||||
def get_gl_entries_for_stock(self):
|
||||
against_stock_account = self.get_company_default("stock_received_but_not_billed")
|
||||
item_acc_map = {}
|
||||
for item in self.doclist.get({"parentfield": "purchase_receipt_details"}):
|
||||
item_acc_map.setdefault(item.name, [against_stock_account, None])
|
||||
|
||||
gl_entries = super(DocType, self).get_gl_entries_for_stock(item_acc_map)
|
||||
|
||||
gl_entries = super(DocType, self).get_gl_entries_for_stock(against_stock_account, None)
|
||||
return gl_entries
|
||||
|
||||
|
||||
|
||||
@@ -50,11 +50,7 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
"warehouse": "_Test Warehouse - _TC"}, "stock_value")
|
||||
self.assertEqual(bin_stock_value, 375)
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s
|
||||
order by account desc""", pr.doc.name, as_dict=1)
|
||||
|
||||
self.assertTrue(not gl_entries)
|
||||
self.assertFalse(get_gl_entries("Purchase Receipt", pr.doc.name))
|
||||
|
||||
def test_purchase_receipt_gl_entry(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
@@ -66,14 +62,12 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
gl_entries = webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type='Purchase Receipt' and voucher_no=%s
|
||||
order by account desc""", pr.doc.name, as_dict=1)
|
||||
gl_entries = get_gl_entries("Purchase Receipt", pr.doc.name)
|
||||
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
stock_in_hand_account = webnotes.conn.get_value("Warehouse", pr.doclist[1].warehouse,
|
||||
"account")
|
||||
|
||||
"account")
|
||||
fixed_asset_account = webnotes.conn.get_value("Warehouse", pr.doclist[2].warehouse,
|
||||
"account")
|
||||
|
||||
@@ -87,9 +81,9 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
self.assertEquals(expected_values[gle.account][0], gle.debit)
|
||||
self.assertEquals(expected_values[gle.account][1], gle.credit)
|
||||
|
||||
self.assertFalse(get_stock_and_account_difference([pr.doclist[1].warehouse,
|
||||
pr.doclist[2].warehouse]))
|
||||
|
||||
pr.cancel()
|
||||
self.assertFalse(get_gl_entries("Purchase Receipt", pr.doc.name))
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
def _clear_stock_account_balance(self):
|
||||
@@ -126,6 +120,11 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
|
||||
self.assertEqual(webnotes.conn.get_value("Serial No", pr.doclist[1].serial_no,
|
||||
"status"), "Not Available")
|
||||
|
||||
def get_gl_entries(voucher_type, voucher_no):
|
||||
return webnotes.conn.sql("""select account, debit, credit
|
||||
from `tabGL Entry` where voucher_type=%s and voucher_no=%s
|
||||
order by account desc""", (voucher_type, voucher_no), as_dict=1)
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -320,7 +320,7 @@ class DocType(StockController):
|
||||
sl_entries.append(self.get_sl_entries(d, {
|
||||
"warehouse": cstr(d.s_warehouse),
|
||||
"actual_qty": -flt(d.transfer_qty),
|
||||
"incoming_rate": flt(d.incoming_rate)
|
||||
"incoming_rate": 0
|
||||
}))
|
||||
|
||||
if cstr(d.t_warehouse):
|
||||
|
||||
@@ -298,8 +298,8 @@ class DocType(StockController):
|
||||
if not self.doc.cost_center:
|
||||
msgprint(_("Please enter Cost Center"), raise_exception=1)
|
||||
|
||||
super(DocType, self).get_gl_entries_for_stock(expense_account=self.doc.expense_account,
|
||||
cost_center=self.doc.cost_center)
|
||||
return super(DocType, self).get_gl_entries_for_stock(self.doc.expense_account,
|
||||
self.doc.cost_center)
|
||||
|
||||
|
||||
def validate_expense_account(self):
|
||||
|
||||
@@ -12,7 +12,7 @@ from accounts.utils import get_fiscal_year, get_stock_and_account_difference, ge
|
||||
|
||||
|
||||
class TestStockReconciliation(unittest.TestCase):
|
||||
def atest_reco_for_fifo(self):
|
||||
def test_reco_for_fifo(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
# [[qty, valuation_rate, posting_date,
|
||||
# posting_time, expected_stock_value, bin_qty, bin_valuation]]
|
||||
@@ -90,7 +90,6 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
self.assertEqual(res and flt(res[0][0], 4) or 0, d[4])
|
||||
|
||||
# bin qty and stock value
|
||||
print "bin"
|
||||
bin = webnotes.conn.sql("""select actual_qty, stock_value from `tabBin`
|
||||
where item_code = '_Test Item' and warehouse = '_Test Warehouse - _TC'""")
|
||||
|
||||
@@ -103,7 +102,7 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
stock_reco.doc.name)
|
||||
self.assertFalse(gl_entries)
|
||||
|
||||
def atest_reco_fifo_gl_entries(self):
|
||||
def test_reco_fifo_gl_entries(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
|
||||
# [[qty, valuation_rate, posting_date, posting_time, stock_in_hand_debit]]
|
||||
@@ -120,23 +119,23 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
[50, 1000, "2013-01-01", "12:00"],
|
||||
[5, 1000, "2013-01-01", "12:00"],
|
||||
[1, 1000, "2012-12-01", "00:00"],
|
||||
|
||||
]
|
||||
|
||||
for d in input_data:
|
||||
# print d[0], d[1], d[2], d[3]
|
||||
self.cleanup_data()
|
||||
self.insert_existing_sle("FIFO")
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
|
||||
stock_reco = self.submit_stock_reconciliation(d[0], d[1], d[2], d[3])
|
||||
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Warehouse - _TC"]))
|
||||
# cancel
|
||||
stock_reco.cancel()
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Warehouse - _TC"]))
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
def atest_reco_moving_average_gl_entries(self):
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
|
||||
|
||||
stock_reco.cancel()
|
||||
self.assertFalse(get_stock_and_account_difference(["_Test Account Stock In Hand - _TC"]))
|
||||
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
def test_reco_moving_average_gl_entries(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
|
||||
# [[qty, valuation_rate, posting_date,
|
||||
@@ -259,6 +258,7 @@ class TestStockReconciliation(unittest.TestCase):
|
||||
pr3.insert()
|
||||
pr3.submit()
|
||||
|
||||
|
||||
pr4 = webnotes.bean(copy=stock_entry)
|
||||
pr4.doc.posting_date = "2013-01-05"
|
||||
pr4.doc.fiscal_year = "_Test Fiscal Year 2013"
|
||||
|
||||
Reference in New Issue
Block a user