Browse Source

fix: Rewrite tests

develop
Deepesh Garg 3 years ago
parent
commit
8985231a96
  1. 37
      erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py
  2. 30
      erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py

37
erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.py

@ -231,25 +231,25 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertEqual(expected_values[gle.account][2], gle.credit) self.assertEqual(expected_values[gle.account][2], gle.credit)
def test_purchase_invoice_with_exchange_rate_difference(self): def test_purchase_invoice_with_exchange_rate_difference(self):
pr = make_purchase_receipt(currency = "USD", conversion_rate = 70) from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice as create_purchase_invoice
pi = make_purchase_invoice(currency = "USD", conversion_rate = 80, do_not_save = "True")
pi.items[0].purchase_receipt = pr.name pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse='Stores - TCP1',
pi.items[0].pr_detail = pr.items[0].name currency = "USD", conversion_rate = 70)
pi = create_purchase_invoice(pr.name)
pi.conversion_rate = 80
pi.insert() pi.insert()
pi.submit() pi.submit()
# fetching the latest GL Entry with 'Exchange Gain/Loss - _TC' account # Get exchnage gain and loss account
gl_entries = frappe.get_all('GL Entry', filters = {'account': 'Exchange Gain/Loss - _TC'}) exchange_gain_loss_account = frappe.db.get_value('Company', pi.company, 'exchange_gain_loss_account')
voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no')
self.assertEqual(pi.name, voucher_no)
exchange_gain_loss_amount = frappe.get_value('GL Entry', gl_entries[0]['name'], 'debit') # fetching the latest GL Entry with exchange gain and loss account account
amount = frappe.db.get_value('GL Entry', {'account': exchange_gain_loss_account, 'voucher_no': pi.name}, 'debit')
discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount) discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount)
self.assertEqual(exchange_gain_loss_amount, discrepancy_caused_by_exchange_rate_diff) self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount)
def test_purchase_invoice_change_naming_series(self): def test_purchase_invoice_change_naming_series(self):
pi = frappe.copy_doc(test_records[1]) pi = frappe.copy_doc(test_records[1])
@ -1031,22 +1031,21 @@ class TestPurchaseInvoice(unittest.TestCase):
# Check GLE for Purchase Invoice # Check GLE for Purchase Invoice
# Zero net effect on final TDS Payable on invoice # Zero net effect on final TDS Payable on invoice
expected_gle = [ expected_gle = [
['_Test Account Cost for Goods Sold - _TC', 30000, 0], ['_Test Account Cost for Goods Sold - _TC', 30000],
['_Test Account Excise Duty - _TC', 0, 3000], ['_Test Account Excise Duty - _TC', -3000],
['Creditors - _TC', 0, 27000], ['Creditors - _TC', -27000],
['TDS Payable - _TC', 3000, 3000] ['TDS Payable - _TC', 0]
] ]
gl_entries = frappe.db.sql("""select account, debit, credit gl_entries = frappe.db.sql("""select account, sum(debit - credit) as amount
from `tabGL Entry` from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no=%s where voucher_type='Purchase Invoice' and voucher_no=%s
group by account
order by account asc""", (purchase_invoice.name), as_dict=1) order by account asc""", (purchase_invoice.name), as_dict=1)
print(gl_entries)
for i, gle in enumerate(gl_entries): for i, gle in enumerate(gl_entries):
self.assertEqual(expected_gle[i][0], gle.account) self.assertEqual(expected_gle[i][0], gle.account)
self.assertEqual(expected_gle[i][1], gle.debit) self.assertEqual(expected_gle[i][1], gle.amount)
self.assertEqual(expected_gle[i][2], gle.credit)
def update_tax_witholding_category(company, account, date): def update_tax_witholding_category(company, account, date):
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year

30
erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py

@ -1054,30 +1054,30 @@ class TestPurchaseReceipt(unittest.TestCase):
def test_purchase_receipt_with_exchange_rate_difference(self): def test_purchase_receipt_with_exchange_rate_difference(self):
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice as create_purchase_invoice
from erpnext.accounts.doctype.purchase_invoice.purchase_invoice import make_purchase_receipt as create_purchase_receipt
pi = create_purchase_invoice(currency = "USD", conversion_rate = 70) pi = create_purchase_invoice(company="_Test Company with perpetual inventory",
cost_center = "Main - TCP1",
create_warehouse("_Test Warehouse for Valuation", company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
properties={"account": '_Test Account Stock In Hand - TCP1'}) expense_account ="_Test Account Cost for Goods Sold - TCP1",
currency = "USD", conversion_rate = 70)
pr = make_purchase_receipt(warehouse = '_Test Warehouse for Valuation - TCP1',
company="_Test Company with perpetual inventory", currency = "USD", conversion_rate = 80,
do_not_save = "True")
pr = create_purchase_receipt(pi.name)
pr.conversion_rate = 80
pr.items[0].purchase_invoice = pi.name pr.items[0].purchase_invoice = pi.name
pr.items[0].purchase_invoice_item = pi.items[0].name pr.items[0].purchase_invoice_item = pi.items[0].name
pr.insert() pr.save()
pr.submit() pr.submit()
# fetching the latest GL Entry with 'Exchange Gain/Loss - TCP1' account # Get exchnage gain and loss account
gl_entries = frappe.get_all('GL Entry', filters = {'account': 'Exchange Gain/Loss - TCP1'}) exchange_gain_loss_account = frappe.db.get_value('Company', pr.company, 'exchange_gain_loss_account')
voucher_no = frappe.get_value('GL Entry', gl_entries[0]['name'], 'voucher_no')
self.assertEqual(pr.name, voucher_no)
exchange_gain_loss_amount = frappe.get_value('GL Entry', gl_entries[0]['name'], 'debit') # fetching the latest GL Entry with exchange gain and loss account account
amount = frappe.db.get_value('GL Entry', {'account': exchange_gain_loss_account, 'voucher_no': pr.name}, 'credit')
discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount) discrepancy_caused_by_exchange_rate_diff = abs(pi.items[0].base_net_amount - pr.items[0].base_net_amount)
self.assertEqual(exchange_gain_loss_amount, discrepancy_caused_by_exchange_rate_diff)
self.assertEqual(discrepancy_caused_by_exchange_rate_diff, amount)
def get_sl_entries(voucher_type, voucher_no): def get_sl_entries(voucher_type, voucher_no):
return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference

Loading…
Cancel
Save