Example #1
0
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',
			do_not_save=1,
		)

	pi.eligibility_for_itc = "All Other ITC"

	pi.append("taxes", {
			"charge_type": "On Net Total",
			"account_head": "IGST - _GST",
			"cost_center": "Main - _GST",
			"description": "IGST @ 18.0",
			"rate": 18
		})

	pi.submit()

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

	pi1.submit()
Example #2
0
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()

    pi2 = make_purchase_invoice(company="_Test Company GST",
                                customer='_Test Registered Supplier',
                                currency='INR',
                                item='Milk',
                                warehouse='Finished Goods - _GST',
                                expense_account='Cost of Goods Sold - _GST',
                                cost_center='Main - _GST',
                                rate=250,
                                qty=1,
                                do_not_save=1)
    pi2.submit()
Example #3
0
    def test_payment_terms_are_fetched_when_creating_purchase_invoice(self):
        from erpnext.accounts.doctype.payment_entry.test_payment_entry import (
            create_payment_terms_template, )
        from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
        from erpnext.selling.doctype.sales_order.test_sales_order import (
            automatically_fetch_payment_terms,
            compare_payment_schedules,
        )

        automatically_fetch_payment_terms()

        po = create_purchase_order(qty=10, rate=100, do_not_save=1)
        create_payment_terms_template()
        po.payment_terms_template = "Test Receivable Template"
        po.submit()

        pi = make_purchase_invoice(qty=10, rate=100, do_not_save=1)
        pi.items[0].purchase_order = po.name
        pi.items[0].po_detail = po.items[0].name
        pi.insert()

        # self.assertEqual(po.payment_terms_template, pi.payment_terms_template)
        compare_payment_schedules(self, po, pi)

        automatically_fetch_payment_terms(enable=0)
Example #4
0
    def test_item_type_field_change(self):
        """Check if critical fields like `is_stock_item`, `has_batch_no` are not changed if transactions exist."""
        from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
        from erpnext.stock.doctype.delivery_note.test_delivery_note import create_delivery_note
        from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_purchase_receipt
        from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry

        transaction_creators = [
            lambda i: make_purchase_receipt(item_code=i),
            lambda i: make_purchase_invoice(item_code=i, update_stock=1),
            lambda i: make_stock_entry(
                item_code=i, qty=1, target="_Test Warehouse - _TC"),
            lambda i: create_delivery_note(item_code=i),
        ]

        properties = {
            "has_batch_no": 0,
            "allow_negative_stock": 1,
            "valuation_rate": 10
        }
        for transaction_creator in transaction_creators:
            item = make_item(properties=properties)
            transaction = transaction_creator(item.name)
            item.has_batch_no = 1
            self.assertRaises(frappe.ValidationError, item.save)

            transaction.cancel()
            # should be allowed now
            item.reload()
            item.has_batch_no = 1
            item.save()
Example #5
0
def create_purchase_invoices():
    pi = make_purchase_invoice(
        company="_Test Company SA VAT",
        supplier="_Test SA Supplier",
        supplier_warehouse="Finished Goods - _TCSV",
        warehouse="Finished Goods - _TCSV",
        currency="ZAR",
        cost_center="Main - _TCSV",
        expense_account="Cost of Goods Sold - _TCSV",
        item="_Test SA VAT Item",
        qty=1,
        rate=100,
        uom="Nos",
        do_not_save=1,
    )
    pi.append(
        "taxes",
        {
            "charge_type": "On Net Total",
            "account_head": "VAT - 15% - _TCSV",
            "cost_center": "Main - _TCSV",
            "description": "VAT 15% @ 15.0",
            "rate": 15.0,
        },
    )

    pi.submit()
Example #6
0
    def test_payment_entry_against_purchase_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(
            self):
        accounts_settings = frappe.get_doc('Accounts Settings',
                                           'Accounts Settings')
        accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
        accounts_settings.save()
        pi = make_purchase_invoice(credit_to="Creditors - _TC")

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

        pe.reference_no = "112222-2"
        pe.reference_date = nowdate()
        pe.paid_from = "_Test Bank - _TC"
        pe.paid_amount = pi.grand_total
        pe.insert()
        pe.submit()

        gl_entries = frappe.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(gle.cost_center, None)
Example #7
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 test_landed_cost_voucher_against_purchase_invoice(self):
        set_perpetual_inventory(1)

        pi = make_purchase_invoice(update_stock=1,
                                   posting_date=frappe.utils.nowdate(),
                                   posting_time=frappe.utils.nowtime())

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

        submit_landed_cost_voucher("Purchase Invoice", pi.name)

        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": "_Test Warehouse - _TC"
            },
            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 - _TC": [0.0, 250.0],
            "Expenses Included In Valuation - _TC": [0.0, 50.0]
        }

        for gle in gl_entries:
            self.assertEqual(expected_values[gle.account][0], gle.debit)
            self.assertEqual(expected_values[gle.account][1], gle.credit)

        set_perpetual_inventory(0)
Example #9
0
def create_purchase_invoices():
    pi = make_purchase_invoice(
        company="_Test Company UAE VAT",
        supplier="_Test UAE Supplier",
        supplier_warehouse="_Test UAE VAT Supplier Warehouse - _TCUV",
        warehouse="_Test UAE VAT Supplier Warehouse - _TCUV",
        currency="AED",
        cost_center="Main - _TCUV",
        expense_account="Cost of Goods Sold - _TCUV",
        item="_Test UAE VAT Item",
        do_not_save=1,
        uom="Nos",
    )
    pi.append(
        "taxes",
        {
            "charge_type": "On Net Total",
            "account_head": "VAT 5% - _TCUV",
            "cost_center": "Main - _TCUV",
            "description": "VAT 5% @ 5.0",
            "rate": 5.0,
        },
    )

    pi.recoverable_standard_rated_expenses = 1

    pi.submit()
Example #10
0
def create_batch(item_code, rate, create_item_price_for_batch):
	pi = make_purchase_invoice(company="_Test Company",
		warehouse= "Stores - _TC", cost_center = "Main - _TC", update_stock=1,
		expense_account ="_Test Account Cost for Goods Sold - _TC", item_code=item_code)

	batch = frappe.db.get_value('Batch', {'item': item_code, 'reference_name': pi.name})

	if not create_item_price_for_batch:
		create_price_list_for_batch(item_code, None, rate)
	else:
		create_price_list_for_batch(item_code, batch, rate)

	return batch
Example #11
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()
Example #12
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()
	def test_landed_cost_voucher_against_purchase_invoice(self):
		set_perpetual_inventory(1)
		
		pi = make_purchase_invoice(update_stock=1, posting_date=frappe.utils.nowdate(),
			posting_time=frappe.utils.nowtime())

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

		submit_landed_cost_voucher("Purchase Invoice", pi.name)
		
		pi_lc_value = frappe.db.get_value("Purchase Invoice Item", {"parent": pi.name}, 
			"landed_cost_voucher_amount")
			
		self.assertEquals(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": "_Test Warehouse - _TC"
			},
			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 - _TC": [0.0, 250.0],
			"Expenses Included In Valuation - _TC": [0.0, 50.0]
		}

		for gle in gl_entries:
			self.assertEquals(expected_values[gle.account][0], gle.debit)
			self.assertEquals(expected_values[gle.account][1], gle.credit)

		set_perpetual_inventory(0)
Example #14
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)
	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)
Example #16
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)
Example #17
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
Example #18
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
Example #19
0
	def test_payment_entry_against_purchase_invoice_for_disable_allow_cost_center_in_entry_of_bs_account(self):
		accounts_settings = frappe.get_doc('Accounts Settings', 'Accounts Settings')
		accounts_settings.allow_cost_center_in_entry_of_bs_account = 0
		accounts_settings.save()
		pi =  make_purchase_invoice(credit_to="Creditors - _TC")

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

		pe.reference_no = "112222-2"
		pe.reference_date = nowdate()
		pe.paid_from = "_Test Bank - _TC"
		pe.paid_amount = pi.grand_total
		pe.insert()
		pe.submit()

		gl_entries = frappe.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(gle.cost_center, None)
    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)
Example #21
0
def create_asset_repair(**args):
    from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
    from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse

    args = frappe._dict(args)

    if args.asset:
        asset = args.asset
    else:
        asset = create_asset(is_existing_asset=1, submit=1)
    asset_repair = frappe.new_doc("Asset Repair")
    asset_repair.update({
        "asset": asset.name,
        "asset_name": asset.asset_name,
        "failure_date": nowdate(),
        "description": "Test Description",
        "repair_cost": 0,
        "company": asset.company
    })

    if args.stock_consumption:
        asset_repair.stock_consumption = 1
        asset_repair.warehouse = create_warehouse("Test Warehouse",
                                                  company=asset.company)
        asset_repair.append(
            "stock_items", {
                "item": args.item or args.item_code or "_Test Item",
                "valuation_rate":
                args.rate if args.get("rate") is not None else 100,
                "consumed_quantity": args.qty or 1
            })

    asset_repair.insert(ignore_if_duplicate=True)

    if args.submit:
        asset_repair.repair_status = "Completed"
        asset_repair.cost_center = "_Test Cost Center - _TC"

        if args.stock_consumption:
            stock_entry = frappe.get_doc({
                "doctype": "Stock Entry",
                "stock_entry_type": "Material Receipt",
                "company": asset.company
            })
            stock_entry.append(
                'items', {
                    "t_warehouse": asset_repair.warehouse,
                    "item_code": asset_repair.stock_items[0].item,
                    "qty": asset_repair.stock_items[0].consumed_quantity
                })
            stock_entry.submit()

        if args.capitalize_repair_cost:
            asset_repair.capitalize_repair_cost = 1
            asset_repair.repair_cost = 1000
            if asset.calculate_depreciation:
                asset_repair.increase_in_asset_life = 12
            asset_repair.purchase_invoice = make_purchase_invoice().name

        asset_repair.submit()
    return asset_repair
Example #22
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()

	company = frappe.db.get_single_value('Global Defaults', 'default_company')
	frappe.get_doc({
		"doctype": "Mode of Payment",
		"name": "Cash"
	}).append("accounts", {
		"company": company,
		"default_account": "_Test Bank - _TC"
	}).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
    def test_deferred_expense(self):
        self.clear_old_entries()

        # created deferred expense accounts, if not found
        deferred_expense_account = create_account(
            account_name="Deferred Expense",
            parent_account="Current Assets - _CD",
            company="_Test Company DR",
        )

        acc_settings = frappe.get_doc("Accounts Settings", "Accounts Settings")
        acc_settings.book_deferred_entries_based_on = "Months"
        acc_settings.save()

        supplier = create_supplier(supplier_name="_Test Furniture Supplier",
                                   supplier_group="Local",
                                   supplier_type="Company")
        supplier.save()

        item = create_item(
            "_Test Office Desk",
            is_stock_item=0,
            warehouse="All Warehouses - _CD",
            company="_Test Company DR",
        )
        item.enable_deferred_expense = 1
        item.deferred_expense_account = deferred_expense_account
        item.no_of_months_exp = 3
        item.save()

        pi = make_purchase_invoice(
            item=item.name,
            company="_Test Company DR",
            supplier="_Test Furniture Supplier",
            is_return=False,
            update_stock=False,
            posting_date=frappe.utils.datetime.date(2021, 5, 1),
            parent_cost_center="Main - _CD",
            cost_center="Main - _CD",
            do_not_save=True,
            rate=300,
            price_list_rate=300,
            warehouse="All Warehouses - _CD",
            qty=1,
        )
        pi.set_posting_time = True
        pi.items[0].enable_deferred_expense = 1
        pi.items[0].service_start_date = "2021-05-01"
        pi.items[0].service_end_date = "2021-08-01"
        pi.items[0].deferred_expense_account = deferred_expense_account
        pi.items[0].expense_account = "Office Maintenance Expenses - _CD"
        pi.save()
        pi.submit()

        pda = frappe.get_doc(
            dict(
                doctype="Process Deferred Accounting",
                posting_date=nowdate(),
                start_date="2021-05-01",
                end_date="2021-08-01",
                type="Expense",
                company="_Test Company DR",
            ))
        pda.insert()
        pda.submit()

        # execute report
        fiscal_year = frappe.get_doc(
            "Fiscal Year", frappe.defaults.get_user_default("fiscal_year"))
        self.filters = frappe._dict({
            "company":
            frappe.defaults.get_user_default("Company"),
            "filter_based_on":
            "Date Range",
            "period_start_date":
            "2021-05-01",
            "period_end_date":
            "2021-08-01",
            "from_fiscal_year":
            fiscal_year.year,
            "to_fiscal_year":
            fiscal_year.year,
            "periodicity":
            "Monthly",
            "type":
            "Expense",
            "with_upcoming_postings":
            False,
        })

        report = Deferred_Revenue_and_Expense_Report(filters=self.filters)
        report.run()
        expected = [
            {
                "key": "may_2021",
                "total": -100.0,
                "actual": -100.0
            },
            {
                "key": "jun_2021",
                "total": -100.0,
                "actual": -100.0
            },
            {
                "key": "jul_2021",
                "total": -100.0,
                "actual": -100.0
            },
            {
                "key": "aug_2021",
                "total": 0,
                "actual": 0
            },
        ]
        self.assertEqual(report.period_total, expected)
Example #24
0
def add_vouchers():
	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, is_paid=1, do_not_save =1)
	pi.cash_bank_account = "_Test Bank - _TC"
	pi.insert()
	pi.submit()
	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.paid_amount = 690
	pe.received_amount = 690
	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
Example #25
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)