def test_delivery_note_for_enable_allow_cost_center_in_entry_of_bs_account(self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") company = dataent.db.get_value('Warehouse', '_Test Warehouse - _TC', 'company') set_perpetual_inventory(1, company) set_valuation_method("_Test Item", "FIFO") make_stock_entry(target="_Test Warehouse - _TC", qty=5, basic_rate=100) stock_in_hand_account = get_inventory_account('_Test Company') dn = create_delivery_note(cost_center=cost_center) gl_entries = get_gl_entries("Delivery Note", dn.name) self.assertTrue(gl_entries) expected_values = { "Cost of Goods Sold - _TC": { "cost_center": cost_center }, stock_in_hand_account: { "cost_center": cost_center } } for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) set_perpetual_inventory(0, company) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_jv_account_and_party_balance_for_enable_allow_cost_center_in_entry_of_bs_account( self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center from epaas.accounts.utils import get_balance_on accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, cost_center=cost_center, save=False) account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center) jv.voucher_type = "Bank Entry" jv.multi_currency = 0 jv.cheque_no = "112233" jv.cheque_date = nowdate() jv.insert() jv.submit() expected_account_balance = account_balance - 100 account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=cost_center) self.assertEqual(expected_account_balance, account_balance) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_purchase_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") pi = make_purchase_invoice_against_cost_center(cost_center=cost_center, credit_to="Creditors - _TC") self.assertEqual(pi.cost_center, cost_center) expected_values = { "Creditors - _TC": { "cost_center": cost_center }, "_Test Account Cost for Goods Sold - _TC": { "cost_center": cost_center } } gl_entries = dataent.db.sql("""select account, cost_center, account_currency, debit, credit, debit_in_account_currency, credit_in_account_currency from `tabGL Entry` where voucher_type='Purchase Invoice' and voucher_no=%s order by account asc""", pi.name, as_dict=1) self.assertTrue(gl_entries) for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_jv_for_enable_allow_cost_center_in_entry_of_bs_account(self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") jv = make_journal_entry("_Test Cash - _TC", "_Test Bank - _TC", 100, cost_center=cost_center, save=False) jv.voucher_type = "Bank Entry" jv.multi_currency = 0 jv.cheque_no = "112233" jv.cheque_date = nowdate() jv.insert() jv.submit() expected_values = { "_Test Cash - _TC": { "cost_center": cost_center }, "_Test Bank - _TC": { "cost_center": cost_center } } gl_entries = dataent.db.sql( """select account, cost_center, debit, credit from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no=%s order by account asc""", jv.name, as_dict=1) self.assertTrue(gl_entries) for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_purchase_receipt_for_enable_allow_cost_center_in_entry_of_bs_account( self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") if not dataent.db.exists('Location', 'Test Location'): dataent.get_doc({ 'doctype': 'Location', 'location_name': 'Test Location' }).insert() set_perpetual_inventory(1, "_Test Company") pr = make_purchase_receipt(cost_center=cost_center) stock_in_hand_account = get_inventory_account( pr.company, pr.get("items")[0].warehouse) gl_entries = get_gl_entries("Purchase Receipt", pr.name) self.assertTrue(gl_entries) expected_values = { "Stock Received But Not Billed - _TC": { "cost_center": cost_center }, stock_in_hand_account: { "cost_center": cost_center } } for i, gle in enumerate(gl_entries): self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) set_perpetual_inventory(0, pr.company) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_payment_entry_against_purchase_invoice_for_enable_allow_cost_center_in_entry_of_bs_account(self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") pi = make_purchase_invoice_against_cost_center(cost_center=cost_center, credit_to="Creditors - _TC") pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC") self.assertEqual(pe.cost_center, pi.cost_center) pe.reference_no = "112222-1" pe.reference_date = nowdate() pe.paid_from = "_Test Bank - _TC" pe.paid_amount = pi.grand_total pe.insert() pe.submit() expected_values = { "_Test Bank - _TC": { "cost_center": cost_center }, "Creditors - _TC": { "cost_center": cost_center } } gl_entries = dataent.db.sql("""select account, cost_center, account_currency, debit, credit, debit_in_account_currency, credit_in_account_currency from `tabGL Entry` where voucher_type='Payment Entry' and voucher_no=%s order by account asc""", pe.name, as_dict=1) self.assertTrue(gl_entries) for gle in gl_entries: self.assertEqual(expected_values[gle.account]["cost_center"], gle.cost_center) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()
def test_payment_entry_account_and_party_balance_for_enable_allow_cost_center_in_entry_of_bs_account(self): from epaas.accounts.doctype.cost_center.test_cost_center import create_cost_center from epaas.accounts.utils import get_balance_on accounts_settings = dataent.get_doc('Accounts Settings', 'Accounts Settings') accounts_settings.allow_cost_center_in_entry_of_bs_account = 1 accounts_settings.save() cost_center = "_Test Cost Center for BS Account - _TC" create_cost_center(cost_center_name="_Test Cost Center for BS Account", company="_Test Company") si = create_sales_invoice_against_cost_center(cost_center=cost_center, debit_to="Debtors - _TC") account_balance = get_balance_on(account="_Test Bank - _TC", cost_center=si.cost_center) party_balance = get_balance_on(party_type="Customer", party=si.customer, cost_center=si.cost_center) party_account_balance = get_balance_on(si.debit_to, cost_center=si.cost_center) pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC") pe.reference_no = "112211-1" pe.reference_date = nowdate() pe.paid_to = "_Test Bank - _TC" pe.paid_amount = si.grand_total pe.insert() pe.submit() expected_account_balance = account_balance + si.grand_total expected_party_balance = party_balance - si.grand_total expected_party_account_balance = party_account_balance - si.grand_total account_balance = get_balance_on(account=pe.paid_to, cost_center=pe.cost_center) party_balance = get_balance_on(party_type="Customer", party=pe.party, cost_center=pe.cost_center) party_account_balance = get_balance_on(account=pe.paid_from, cost_center=pe.cost_center) self.assertEqual(pe.cost_center, si.cost_center) self.assertEqual(expected_account_balance, account_balance) self.assertEqual(expected_party_balance, party_balance) self.assertEqual(expected_party_account_balance, party_account_balance) accounts_settings.allow_cost_center_in_entry_of_bs_account = 0 accounts_settings.save()