Beispiel #1
0
    def test_payment_against_purchase_invoice_to_check_status(self):
        pi = make_purchase_invoice(supplier="_Test Supplier USD",
                                   debit_to="_Test Payable USD - _TC",
                                   currency="USD",
                                   conversion_rate=50)

        pe = get_payment_entry("Purchase Invoice",
                               pi.name,
                               bank_account="_Test Bank USD - _TC")
        pe.reference_no = "1"
        pe.reference_date = "2016-01-01"
        pe.source_exchange_rate = 50
        pe.insert()
        pe.submit()

        outstanding_amount, status = frappe.db.get_value(
            "Purchase Invoice", pi.name, ["outstanding_amount", "status"])
        self.assertEqual(flt(outstanding_amount), 0)
        self.assertEqual(status, 'Paid')

        pe.cancel()

        outstanding_amount, status = frappe.db.get_value(
            "Purchase Invoice", pi.name, ["outstanding_amount", "status"])
        self.assertEqual(flt(outstanding_amount), 250)
        self.assertEqual(status, 'Unpaid')
def create_purchase_invoices():

    pi = make_purchase_invoice(
        company="_Test Company GST",
        supplier='_Test Registered Supplier',
        currency='INR',
        warehouse='Finished Goods - _GST',
        cost_center='Main - _GST',
        expense_account='Cost of Goods Sold - _GST',
        do_not_save=1,
    )

    pi.eligibility_for_itc = "All Other ITC"

    pi.append(
        "taxes", {
            "charge_type": "On Net Total",
            "account_head": "CGST - _GST",
            "cost_center": "Main - _GST",
            "description": "CGST @ 9.0",
            "rate": 9
        })

    pi.append(
        "taxes", {
            "charge_type": "On Net Total",
            "account_head": "SGST - _GST",
            "cost_center": "Main - _GST",
            "description": "SGST @ 9.0",
            "rate": 9
        })

    pi.submit()

    pi1 = make_purchase_invoice(company="_Test Company GST",
                                supplier='_Test Registered Supplier',
                                currency='INR',
                                warehouse='Finished Goods - _GST',
                                cost_center='Main - _GST',
                                expense_account='Cost of Goods Sold - _GST',
                                item="Milk",
                                do_not_save=1)

    pi1.shipping_address = "_Test Supplier GST-1-Billing"
    pi1.save()

    pi1.submit()
	def test_landed_cost_voucher_against_purchase_invoice(self):

		pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
			posting_time=frappe.utils.nowtime(), cash_bank_account="Cash - TCP1",
			company="_Test Company with perpetual inventory", supplier_warehouse="Work In Progress - TCP1",
			warehouse= "Stores - TCP1", cost_center = "Main - TCP1",
			expense_account ="_Test Account Cost for Goods Sold - TCP1")

		last_sle = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		create_landed_cost_voucher("Purchase Invoice", pi.name, pi.company)

		pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name},
			"landed_cost_voucher_amount")

		self.assertEqual(pi_lc_value, 50.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pi.doctype,
				"voucher_no": pi.name,
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1"
			},
			fieldname=["qty_after_transaction", "stock_value"], as_dict=1)

		self.assertEqual(last_sle.qty_after_transaction, last_sle_after_landed_cost.qty_after_transaction)

		self.assertEqual(last_sle_after_landed_cost.stock_value - last_sle.stock_value, 50.0)

		gl_entries = get_gl_entries("Purchase Invoice", pi.name)

		self.assertTrue(gl_entries)
		stock_in_hand_account = get_inventory_account(pi.company, pi.get("items")[0].warehouse)

		expected_values = {
			stock_in_hand_account: [300.0, 0.0],
			"Creditors - TCP1": [0.0, 250.0],
			"Expenses Included In Valuation - TCP1": [0.0, 50.0]
		}

		for gle in gl_entries:
			if not gle.get('is_cancelled'):
				self.assertEqual(expected_values[gle.account][0], gle.debit)
				self.assertEqual(expected_values[gle.account][1], gle.credit)
Beispiel #4
0
	def test_payment_order_creation_against_payment_entry(self):
		purchase_invoice = make_purchase_invoice()
		payment_entry = get_payment_entry("Purchase Invoice", purchase_invoice.name, bank_account="_Test Bank - _TC")
		payment_entry.reference_no = "_Test_Payment_Order"
		payment_entry.reference_date = getdate()
		payment_entry.party_bank_account = "Checking Account - Citi Bank"
		payment_entry.insert()
		payment_entry.submit()

		doc = create_payment_order_against_payment_entry(payment_entry, "Payment Entry")
		reference_doc = doc.get("references")[0]
		self.assertEquals(reference_doc.reference_name, payment_entry.name)
		self.assertEquals(reference_doc.reference_doctype, "Payment Entry")
		self.assertEquals(reference_doc.supplier, "_Test Supplier")
		self.assertEquals(reference_doc.amount, 250)
Beispiel #5
0
    def test_payment_entry_for_blocked_supplier_payments(self):
        supplier = frappe.get_doc('Supplier', '_Test Supplier')
        supplier.on_hold = 1
        supplier.hold_type = 'Payments'
        supplier.save()

        pi = make_purchase_invoice()

        self.assertRaises(frappe.ValidationError,
                          get_payment_entry,
                          dt='Purchase Invoice',
                          dn=pi.name,
                          bank_account="_Test Bank - _TC")

        supplier.on_hold = 0
        supplier.save()
Beispiel #6
0
    def test_payment_entry_for_blocked_supplier_payments_past_date(self):
        # this test is meant to fail only if something fails in the try block
        with self.assertRaises(Exception):
            try:
                supplier = frappe.get_doc('Supplier', '_Test Supplier')
                supplier.on_hold = 1
                supplier.hold_type = 'Payments'
                supplier.release_date = '2018-03-01'
                supplier.save()

                pi = make_purchase_invoice()

                get_payment_entry('Purchase Invoice',
                                  pi.name,
                                  bank_account="_Test Bank - _TC")

                supplier.on_hold = 0
                supplier.save()
            except:
                pass
            else:
                raise Exception
Beispiel #7
0
    def test_payment_entry_against_pi(self):
        pi = make_purchase_invoice(supplier="_Test Supplier USD",
                                   debit_to="_Test Payable USD - _TC",
                                   currency="USD",
                                   conversion_rate=50)
        pe = get_payment_entry("Purchase Invoice",
                               pi.name,
                               bank_account="_Test Bank USD - _TC")
        pe.reference_no = "1"
        pe.reference_date = "2016-01-01"
        pe.source_exchange_rate = 50
        pe.insert()
        pe.submit()

        expected_gle = dict(
            (d[0], d) for d in [["_Test Payable USD - _TC", 12500, 0, pi.name],
                                ["_Test Bank USD - _TC", 0, 12500, None]])

        self.validate_gl_entries(pe.name, expected_gle)

        outstanding_amount = flt(
            frappe.db.get_value("Sales Invoice", pi.name,
                                "outstanding_amount"))
        self.assertEqual(outstanding_amount, 0)
Beispiel #8
0
    def test_asset_cwip_toggling_cases(self):
        cwip = frappe.db.get_value("Asset Category", "Computers",
                                   "enable_cwip_accounting")
        name = frappe.db.get_value("Asset Category Account",
                                   filters={"parent": "Computers"},
                                   fieldname=["name"])
        cwip_acc = "CWIP Account - _TC"

        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", 0)
        frappe.db.set_value("Asset Category Account", name,
                            "capital_work_in_progress_account", "")
        frappe.db.get_value("Company", "_Test Company",
                            "capital_work_in_progress_account", "")

        # case 0 -- PI with cwip disable, Asset with cwip disabled, No cwip account set
        pi = make_purchase_invoice(item_code="Macbook Pro",
                                   qty=1,
                                   rate=200000.0,
                                   location="Test Location",
                                   update_stock=1)
        asset = frappe.db.get_value('Asset', {
            'purchase_invoice': pi.name,
            'docstatus': 0
        }, 'name')
        asset_doc = frappe.get_doc('Asset', asset)
        asset_doc.available_for_use_date = nowdate()
        asset_doc.calculate_depreciation = 0
        asset_doc.submit()
        gle = frappe.db.sql(
            """select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
            asset_doc.name)
        self.assertFalse(gle)

        # case 1 -- PR with cwip disabled, Asset with cwip enabled
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=200000.0,
                                   location="Test Location")
        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", 1)
        frappe.db.set_value("Asset Category Account", name,
                            "capital_work_in_progress_account", cwip_acc)
        asset = frappe.db.get_value('Asset', {
            'purchase_receipt': pr.name,
            'docstatus': 0
        }, 'name')
        asset_doc = frappe.get_doc('Asset', asset)
        asset_doc.available_for_use_date = nowdate()
        asset_doc.calculate_depreciation = 0
        asset_doc.submit()
        gle = frappe.db.sql(
            """select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
            asset_doc.name)
        self.assertFalse(gle)

        # case 2 -- PR with cwip enabled, Asset with cwip disabled
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=200000.0,
                                   location="Test Location")
        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", 0)
        asset = frappe.db.get_value('Asset', {
            'purchase_receipt': pr.name,
            'docstatus': 0
        }, 'name')
        asset_doc = frappe.get_doc('Asset', asset)
        asset_doc.available_for_use_date = nowdate()
        asset_doc.calculate_depreciation = 0
        asset_doc.submit()
        gle = frappe.db.sql(
            """select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
            asset_doc.name)
        self.assertTrue(gle)

        # case 3 -- PI with cwip disabled, Asset with cwip enabled
        pi = make_purchase_invoice(item_code="Macbook Pro",
                                   qty=1,
                                   rate=200000.0,
                                   location="Test Location",
                                   update_stock=1)
        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", 1)
        asset = frappe.db.get_value('Asset', {
            'purchase_invoice': pi.name,
            'docstatus': 0
        }, 'name')
        asset_doc = frappe.get_doc('Asset', asset)
        asset_doc.available_for_use_date = nowdate()
        asset_doc.calculate_depreciation = 0
        asset_doc.submit()
        gle = frappe.db.sql(
            """select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
            asset_doc.name)
        self.assertFalse(gle)

        # case 4 -- PI with cwip enabled, Asset with cwip disabled
        pi = make_purchase_invoice(item_code="Macbook Pro",
                                   qty=1,
                                   rate=200000.0,
                                   location="Test Location",
                                   update_stock=1)
        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", 0)
        asset = frappe.db.get_value('Asset', {
            'purchase_invoice': pi.name,
            'docstatus': 0
        }, 'name')
        asset_doc = frappe.get_doc('Asset', asset)
        asset_doc.available_for_use_date = nowdate()
        asset_doc.calculate_depreciation = 0
        asset_doc.submit()
        gle = frappe.db.sql(
            """select name from `tabGL Entry` where voucher_type='Asset' and voucher_no = %s""",
            asset_doc.name)
        self.assertTrue(gle)

        frappe.db.set_value("Asset Category", "Computers",
                            "enable_cwip_accounting", cwip)
        frappe.db.set_value("Asset Category Account", name,
                            "capital_work_in_progress_account", cwip_acc)
        frappe.db.get_value("Company", "_Test Company",
                            "capital_work_in_progress_account", cwip_acc)
Beispiel #9
0
def add_payments():
	if frappe.flags.test_payments_created:
		return

	frappe.set_user("Administrator")

	try:
		frappe.get_doc({
			"doctype": "Supplier",
			"supplier_group":"All Supplier Groups",
			"supplier_type": "Company",
			"supplier_name": "Conrad Electronic"
		}).insert()

	except frappe.DuplicateEntryError:
		pass

	pi = make_purchase_invoice(supplier="Conrad Electronic", qty=1, rate=690)
	pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Conrad Oct 18"
	pe.reference_date = "2018-10-24"
	pe.insert()
	pe.submit()

	try:
		frappe.get_doc({
			"doctype": "Supplier",
			"supplier_group":"All Supplier Groups",
			"supplier_type": "Company",
			"supplier_name": "Mr G"
		}).insert()
	except frappe.DuplicateEntryError:
		pass

	pi = make_purchase_invoice(supplier="Mr G", qty=1, rate=1200)
	pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Herr G Oct 18"
	pe.reference_date = "2018-10-24"
	pe.insert()
	pe.submit()

	pi = make_purchase_invoice(supplier="Mr G", qty=1, rate=1700)
	pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Herr G Nov 18"
	pe.reference_date = "2018-11-01"
	pe.insert()
	pe.submit()

	try:
		frappe.get_doc({
			"doctype": "Supplier",
			"supplier_group":"All Supplier Groups",
			"supplier_type": "Company",
			"supplier_name": "Poore Simon's"
		}).insert()
	except frappe.DuplicateEntryError:
		pass

	try:
		frappe.get_doc({
			"doctype": "Customer",
			"customer_group":"All Customer Groups",
			"customer_type": "Company",
			"customer_name": "Poore Simon's"
		}).insert()
	except frappe.DuplicateEntryError:
		pass

	pi = make_purchase_invoice(supplier="Poore Simon's", qty=1, rate=3900)
	pe = get_payment_entry("Purchase Invoice", pi.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Poore Simon's Oct 18"
	pe.reference_date = "2018-10-28"
	pe.insert()
	pe.submit()

	si = create_sales_invoice(customer="Poore Simon's", qty=1, rate=3900)
	pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Poore Simon's Oct 18"
	pe.reference_date = "2018-10-28"
	pe.insert()
	pe.submit()

	try:
		frappe.get_doc({
			"doctype": "Customer",
			"customer_group":"All Customer Groups",
			"customer_type": "Company",
			"customer_name": "Fayva"
		}).insert()
	except frappe.DuplicateEntryError:
		pass

	si = create_sales_invoice(customer="Fayva", qty=1, rate=109080)
	pe = get_payment_entry("Sales Invoice", si.name, bank_account="_Test Bank - _TC")
	pe.reference_no = "Fayva Oct 18"
	pe.reference_date = "2018-10-29"
	pe.insert()
	pe.submit()

	mode_of_payment = frappe.get_doc({
		"doctype": "Mode of Payment",
		"name": "Cash"
	})

	if not frappe.db.get_value('Mode of Payment Account', {'company': "_Test Company", 'parent': "Cash"}):
		mode_of_payment.append("accounts", {
			"company": "_Test Company",
			"default_account": "_Test Bank - _TC"
		})
		mode_of_payment.save()

	si = create_sales_invoice(customer="Fayva", qty=1, rate=109080, do_not_submit=1)
	si.is_pos = 1
	si.append("payments", {
		"mode_of_payment": "Cash",
		"account": "_Test Bank - _TC",
		"amount": 109080
	})
	si.save()
	si.submit()

	frappe.flags.test_payments_created = True