mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-03 04:09:11 +00:00
[minor] [fix] test cases fix for perpetual accounting
This commit is contained in:
@@ -329,15 +329,31 @@ class DocType(SellingController):
|
||||
get_obj('Sales Common').check_credit(self, total)
|
||||
|
||||
def make_gl_entries(self):
|
||||
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
|
||||
if not cint(webnotes.defaults.get_global_default("perpetual_accounting")):
|
||||
return
|
||||
|
||||
gl_entries = []
|
||||
gl_entries = []
|
||||
warehouse_item_map = {}
|
||||
for item in self.doclist.get({"parentfield": "delivery_note_details"}):
|
||||
self.check_expense_account(item)
|
||||
if item.buying_amount:
|
||||
warehouse_item_map.setdefault(item.warehouse, [])
|
||||
if item.item_code not in warehouse_item_map[item.warehouse]:
|
||||
warehouse_item_map[item.warehouse].append(item.item_code)
|
||||
|
||||
|
||||
|
||||
|
||||
if [item.item_code, item.warehouse] not in item_warehouse:
|
||||
item_warehouse.append([item.item_code, item.warehouse])
|
||||
|
||||
for
|
||||
|
||||
|
||||
|
||||
for wh, cc_dict in expense_account_map.items:
|
||||
for cost_center, warehouse_list in cc_dict.items():
|
||||
gl_entries += self.get_gl_entries_for_stock(item.expense_account,
|
||||
-1*item.buying_amount, cost_center=item.cost_center)
|
||||
cost_center=item.cost_center, warehouse_list=warehouse_list)
|
||||
|
||||
if gl_entries:
|
||||
from accounts.general_ledger import make_gl_entries
|
||||
|
||||
@@ -205,14 +205,17 @@ class DocType(BuyingController):
|
||||
if pr_qty:
|
||||
sl_entries.append(self.get_sl_entries(d, {
|
||||
"actual_qty": flt(pr_qty),
|
||||
"serial_no": cstr(d.serial_no).strip()
|
||||
"serial_no": cstr(d.serial_no).strip(),
|
||||
"incoming_rate": d.valuation_rate
|
||||
|
||||
}))
|
||||
|
||||
if flt(d.rejected_qty) > 0:
|
||||
sl_entries.append(self.get_sl_entries(d, {
|
||||
"warehouse": self.doc.rejected_warehouse,
|
||||
"actual_qty": flt(d.rejected_qty) * flt(d.conversion_factor),
|
||||
"serial_no": cstr(d.rejected_serial_no).strip()
|
||||
"serial_no": cstr(d.rejected_serial_no).strip(),
|
||||
"incoming_rate": d.valuation_rate
|
||||
}))
|
||||
|
||||
self.bk_flush_supp_wh(sl_entries)
|
||||
@@ -312,16 +315,17 @@ class DocType(BuyingController):
|
||||
return get_obj('Purchase Common').get_rate(arg,self)
|
||||
|
||||
def make_gl_entries(self):
|
||||
if not cint(webnotes.defaults.get_global_default("auto_inventory_accounting")):
|
||||
if not cint(webnotes.defaults.get_global_default("perpetual_accounting")):
|
||||
return
|
||||
|
||||
from accounts.general_ledger import make_gl_entries
|
||||
|
||||
against_stock_account = self.get_company_default("stock_received_but_not_billed")
|
||||
total_valuation_amount = self.get_total_valuation_amount()
|
||||
gl_entries = self.get_gl_entries_for_stock(against_stock_account, total_valuation_amount)
|
||||
warehouse_list = [d.warehouse for d in
|
||||
self.doclist.get({"parentfield": "purchase_receipt_details"})]
|
||||
|
||||
gl_entries = self.get_gl_entries_for_stock(against_stock_account, warehouse_list=warehouse_list)
|
||||
|
||||
if gl_entries:
|
||||
from accounts.general_ledger import make_gl_entries
|
||||
make_gl_entries(gl_entries, cancel=(self.doc.docstatus == 2))
|
||||
|
||||
def get_total_valuation_amount(self):
|
||||
|
||||
@@ -23,6 +23,8 @@ from webnotes.utils import cint
|
||||
|
||||
class TestPurchaseReceipt(unittest.TestCase):
|
||||
def test_make_purchase_invoice(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
self._clear_stock_account_balance()
|
||||
from stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
|
||||
|
||||
pr = webnotes.bean(copy=test_records[0]).insert()
|
||||
@@ -42,8 +44,9 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
self.assertRaises(webnotes.ValidationError, webnotes.bean(pi).submit)
|
||||
|
||||
def test_purchase_receipt_no_gl_entry(self):
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
self._clear_stock_account_balance()
|
||||
pr = webnotes.bean(copy=test_records[0])
|
||||
pr.run_method("calculate_taxes_and_totals")
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
@@ -54,11 +57,12 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
self.assertTrue(not gl_entries)
|
||||
|
||||
def test_purchase_receipt_gl_entry(self):
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
self.assertEqual(cint(webnotes.defaults.get_global_default("auto_inventory_accounting")), 1)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
self.assertEqual(cint(webnotes.defaults.get_global_default("perpetual_accounting")), 1)
|
||||
|
||||
self._clear_stock_account_balance()
|
||||
|
||||
pr = webnotes.bean(copy=test_records[0])
|
||||
pr.run_method("calculate_taxes_and_totals")
|
||||
pr.insert()
|
||||
pr.submit()
|
||||
|
||||
@@ -67,20 +71,28 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
order by account desc""", pr.doc.name, as_dict=1)
|
||||
self.assertTrue(gl_entries)
|
||||
|
||||
stock_in_hand_account = webnotes.conn.get_value("Company", pr.doc.company,
|
||||
"stock_in_hand_account")
|
||||
stock_in_hand_account = webnotes.conn.get_value("Warehouse", pr.doclist[1].warehouse,
|
||||
"account")
|
||||
|
||||
expected_values = [
|
||||
[stock_in_hand_account, 750.0, 0.0],
|
||||
["Stock Received But Not Billed - _TC", 0.0, 750.0]
|
||||
]
|
||||
fixed_asset_account = webnotes.conn.get_value("Warehouse", pr.doclist[2].warehouse,
|
||||
"account")
|
||||
|
||||
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)
|
||||
expected_values = {
|
||||
stock_in_hand_account: [375.0, 0.0],
|
||||
fixed_asset_account: [375.0, 0.0],
|
||||
"Stock Received But Not Billed - _TC": [0.0, 750.0]
|
||||
}
|
||||
|
||||
for gle in gl_entries:
|
||||
self.assertEquals(expected_values[gle.account][0], gle.debit)
|
||||
self.assertEquals(expected_values[gle.account][1], gle.credit)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
def _clear_stock_account_balance(self):
|
||||
webnotes.conn.sql("delete from `tabStock Ledger Entry`")
|
||||
webnotes.conn.sql("""delete from `tabBin`""")
|
||||
webnotes.conn.sql("""delete from `tabGL Entry`""")
|
||||
|
||||
def test_subcontracting(self):
|
||||
pr = webnotes.bean(copy=test_records[1])
|
||||
@@ -115,8 +127,8 @@ test_records = [
|
||||
"item_code": "_Test Item",
|
||||
"item_name": "_Test Item",
|
||||
"parentfield": "purchase_receipt_details",
|
||||
"received_qty": 10.0,
|
||||
"qty": 10.0,
|
||||
"received_qty": 5.0,
|
||||
"qty": 5.0,
|
||||
"rejected_qty": 0.0,
|
||||
"import_rate": 50.0,
|
||||
"amount": 500.0,
|
||||
@@ -124,6 +136,22 @@ test_records = [
|
||||
"stock_uom": "Nos",
|
||||
"uom": "_Test UOM",
|
||||
},
|
||||
{
|
||||
"conversion_factor": 1.0,
|
||||
"description": "_Test Item",
|
||||
"doctype": "Purchase Receipt Item",
|
||||
"item_code": "_Test Item",
|
||||
"item_name": "_Test Item",
|
||||
"parentfield": "purchase_receipt_details",
|
||||
"received_qty": 5.0,
|
||||
"qty": 5.0,
|
||||
"rejected_qty": 0.0,
|
||||
"import_rate": 50.0,
|
||||
"amount": 500.0,
|
||||
"warehouse": "_Test Warehouse 1 - _TC",
|
||||
"stock_uom": "Nos",
|
||||
"uom": "_Test UOM",
|
||||
},
|
||||
{
|
||||
"account_head": "_Test Account Shipping Charges - _TC",
|
||||
"add_deduct_tax": "Add",
|
||||
|
||||
@@ -6,7 +6,7 @@ import webnotes, unittest
|
||||
|
||||
class TestSerialNo(unittest.TestCase):
|
||||
def test_aii_gl_entries_for_serial_no_in_store(self):
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
|
||||
sr = webnotes.bean(copy=test_records[0])
|
||||
sr.doc.serial_no = "_Test Serial No 1"
|
||||
@@ -64,11 +64,11 @@ class TestSerialNo(unittest.TestCase):
|
||||
|
||||
self.assertEquals(gl_count[0][0], 4)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
|
||||
def test_aii_gl_entries_for_serial_no_delivered(self):
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 1)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 1)
|
||||
|
||||
sr = webnotes.bean(copy=test_records[0])
|
||||
sr.doc.serial_no = "_Test Serial No 2"
|
||||
@@ -80,7 +80,7 @@ class TestSerialNo(unittest.TestCase):
|
||||
order by account desc""", sr.doc.name, as_dict=1)
|
||||
self.assertFalse(gl_entries)
|
||||
|
||||
webnotes.defaults.set_global_default("auto_inventory_accounting", 0)
|
||||
webnotes.defaults.set_global_default("perpetual_accounting", 0)
|
||||
|
||||
test_dependencies = ["Item"]
|
||||
test_records = [
|
||||
|
||||
@@ -2,16 +2,19 @@ test_records = [
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse",
|
||||
"company": "_Test Company"
|
||||
"company": "_Test Company",
|
||||
"account": "_Test Account Stock In Hand - _TC"
|
||||
}],
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse 1",
|
||||
"company": "_Test Company"
|
||||
"company": "_Test Company",
|
||||
"account": "_Test Account Fixed Assets - _TC"
|
||||
}],
|
||||
[{
|
||||
"doctype": "Warehouse",
|
||||
"warehouse_name": "_Test Warehouse 2",
|
||||
"company": "_Test Company 1"
|
||||
"company": "_Test Company 1",
|
||||
"account": "_Test Account Stock In Hand - _TC"
|
||||
}]
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user