Esempio n. 1
0
    def test_cwip_accounting(self):
        from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
            make_purchase_invoice as make_purchase_invoice_from_pr)

        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=5000,
                                   do_not_submit=True,
                                   location="Test Location")

        pr.set('taxes', [{
            'category': 'Total',
            'add_deduct_tax': 'Add',
            'charge_type': 'On Net Total',
            'account_head': '_Test Account Service Tax - _TC',
            'description': '_Test Account Service Tax',
            'cost_center': 'Main - _TC',
            'rate': 5.0
        }, {
            'category': 'Valuation and Total',
            'add_deduct_tax': 'Add',
            'charge_type': 'On Net Total',
            'account_head': '_Test Account Shipping Charges - _TC',
            'description': '_Test Account Shipping Charges',
            'cost_center': 'Main - _TC',
            'rate': 5.0
        }])

        pr.submit()

        expected_gle = (("Asset Received But Not Billed - _TC", 0.0, 5250.0),
                        ("CWIP Account - _TC", 5250.0, 0.0))

        gle = frappe.db.sql(
            """select account, debit, credit from `tabGL Entry`
			where voucher_type='Purchase Receipt' and voucher_no = %s
			order by account""", pr.name)

        self.assertEqual(gle, expected_gle)

        pi = make_purchase_invoice_from_pr(pr.name)
        pi.submit()

        expected_gle = (
            ("_Test Account Service Tax - _TC", 250.0, 0.0),
            ("_Test Account Shipping Charges - _TC", 250.0, 0.0),
            ("Asset Received But Not Billed - _TC", 5250.0, 0.0),
            ("Creditors - _TC", 0.0, 5500.0),
            ("Expenses Included In Asset Valuation - _TC", 0.0, 250.0),
        )

        gle = frappe.db.sql(
            """select account, debit, credit from `tabGL Entry`
			where voucher_type='Purchase Invoice' and voucher_no = %s
			order by account""", pi.name)

        self.assertEqual(gle, expected_gle)

        asset = frappe.db.get_value('Asset', {
            'purchase_receipt': pr.name,
            'docstatus': 0
        }, 'name')

        asset_doc = frappe.get_doc('Asset', asset)

        month_end_date = get_last_day(nowdate())
        asset_doc.available_for_use_date = nowdate(
        ) if nowdate() != month_end_date else add_days(nowdate(), -15)
        self.assertEqual(asset_doc.gross_purchase_amount, 5250.0)

        asset_doc.append(
            "finance_books", {
                "expected_value_after_useful_life": 200,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": month_end_date
            })
        asset_doc.submit()

        expected_gle = (("_Test Fixed Asset - _TC", 5250.0, 0.0),
                        ("CWIP Account - _TC", 0.0, 5250.0))

        gle = frappe.db.sql(
            """select account, debit, credit from `tabGL Entry`
			where voucher_type='Asset' and voucher_no = %s
			order by account""", asset_doc.name)

        self.assertEqual(gle, expected_gle)
Esempio n. 2
0
	def test_cwip_accounting(self):
		from erpnext.stock.doctype.purchase_receipt.purchase_receipt import (
			make_purchase_invoice as make_purchase_invoice_from_pr)

		pr = make_purchase_receipt(item_code="Macbook Pro",
			qty=1, rate=5000, do_not_submit=True, location="Test Location")

		pr.set('taxes', [{
			'category': 'Total',
			'add_deduct_tax': 'Add',
			'charge_type': 'On Net Total',
			'account_head': '_Test Account Service Tax - _TC',
			'description': '_Test Account Service Tax',
			'cost_center': 'Main - _TC',
			'rate': 5.0
		}, {
			'category': 'Valuation and Total',
			'add_deduct_tax': 'Add',
			'charge_type': 'On Net Total',
			'account_head': '_Test Account Shipping Charges - _TC',
			'description': '_Test Account Shipping Charges',
			'cost_center': 'Main - _TC',
			'rate': 5.0
		}])

		pr.submit()

		expected_gle = (
			("Asset Received But Not Billed - _TC", 0.0, 5250.0),
			("CWIP Account - _TC", 5250.0, 0.0)
		)

		gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
			where voucher_type='Purchase Receipt' and voucher_no = %s
			order by account""", pr.name)

		self.assertEqual(gle, expected_gle)

		pi = make_purchase_invoice_from_pr(pr.name)
		pi.submit()

		expected_gle = (
			("_Test Account Service Tax - _TC", 250.0, 0.0),
			("_Test Account Shipping Charges - _TC", 250.0, 0.0),
			("Asset Received But Not Billed - _TC", 5250.0, 0.0),
			("Creditors - _TC", 0.0, 5500.0),
			("Expenses Included In Asset Valuation - _TC", 0.0, 250.0),
		)

		gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
			where voucher_type='Purchase Invoice' and voucher_no = %s
			order by account""", pi.name)

		self.assertEqual(gle, expected_gle)

		asset = frappe.db.get_value('Asset',
			{'purchase_receipt': pr.name, 'docstatus': 0}, 'name')

		asset_doc = frappe.get_doc('Asset', asset)

		month_end_date = get_last_day(nowdate())
		asset_doc.available_for_use_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)
		self.assertEqual(asset_doc.gross_purchase_amount, 5250.0)

		asset_doc.append("finance_books", {
			"expected_value_after_useful_life": 200,
			"depreciation_method": "Straight Line",
			"total_number_of_depreciations": 3,
			"frequency_of_depreciation": 10,
			"depreciation_start_date": month_end_date
		})
		asset_doc.submit()

		expected_gle = (
			("_Test Fixed Asset - _TC", 5250.0, 0.0),
			("CWIP Account - _TC", 0.0, 5250.0)
		)

		gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry`
			where voucher_type='Asset' and voucher_no = %s
			order by account""", asset_doc.name)

		self.assertEqual(gle, expected_gle)