Ejemplo n.º 1
0
    def test_merging_with_validate_selling_price(self):
        from erpbee.accounts.doctype.pos_closing_entry.test_pos_closing_entry import init_user_and_profile
        from erpbee.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import merge_pos_invoices

        if not frappe.db.get_single_value("Selling Settings",
                                          "validate_selling_price"):
            frappe.db.set_value("Selling Settings", "Selling Settings",
                                "validate_selling_price", 1)

        make_purchase_receipt(item_code="_Test Item",
                              warehouse="_Test Warehouse - _TC",
                              qty=1,
                              rate=300)
        frappe.db.sql("delete from `tabPOS Invoice`")
        test_user, pos_profile = init_user_and_profile()
        pos_inv = create_pos_invoice(rate=300, do_not_submit=1)
        pos_inv.append('payments', {
            'mode_of_payment': 'Cash',
            'account': 'Cash - _TC',
            'amount': 300
        })
        pos_inv.append(
            'taxes', {
                "charge_type": "On Net Total",
                "account_head": "_Test Account Service Tax - _TC",
                "cost_center": "_Test Cost Center - _TC",
                "description": "Service Tax",
                "rate": 14,
                'included_in_print_rate': 1
            })
        self.assertRaises(frappe.ValidationError, pos_inv.submit)

        pos_inv2 = create_pos_invoice(rate=400, do_not_submit=1)
        pos_inv2.append('payments', {
            'mode_of_payment': 'Cash',
            'account': 'Cash - _TC',
            'amount': 400
        })
        pos_inv2.append(
            'taxes', {
                "charge_type": "On Net Total",
                "account_head": "_Test Account Service Tax - _TC",
                "cost_center": "_Test Cost Center - _TC",
                "description": "Service Tax",
                "rate": 14,
                'included_in_print_rate': 1
            })
        pos_inv2.submit()

        merge_pos_invoices()

        pos_inv2.load_from_db()
        rounded_total = frappe.db.get_value("Sales Invoice",
                                            pos_inv2.consolidated_invoice,
                                            "rounded_total")
        self.assertEqual(rounded_total, 400)
        frappe.set_user("Administrator")
        frappe.db.set_value("Selling Settings", "Selling Settings",
                            "validate_selling_price", 0)
Ejemplo n.º 2
0
    def test_sub_contracted_item_costing(self):
        from erpbee.manufacturing.doctype.production_plan.test_production_plan import make_bom

        company = "_Test Company"
        rm_item_code = "_Test Item for Reposting"
        subcontracted_item = "_Test Subcontracted Item for Reposting"

        frappe.db.set_value("Buying Settings", None,
                            "backflush_raw_materials_of_subcontract_based_on",
                            "BOM")
        make_bom(item=subcontracted_item,
                 raw_materials=[rm_item_code],
                 currency="INR")

        # Purchase raw materials on supplier warehouse: Qty = 50, Rate = 100
        pr = make_purchase_receipt(company=company,
                                   posting_date='2020-04-10',
                                   warehouse="Stores - _TC",
                                   item_code=rm_item_code,
                                   qty=10,
                                   rate=100)

        # Purchase Receipt for subcontracted item
        pr1 = make_purchase_receipt(company=company,
                                    posting_date='2020-04-20',
                                    warehouse="Finished Goods - _TC",
                                    supplier_warehouse="Stores - _TC",
                                    item_code=subcontracted_item,
                                    qty=10,
                                    rate=20,
                                    is_subcontracted="Yes")

        self.assertEqual(pr1.items[0].valuation_rate, 120)

        # Update raw material's valuation via LCV, Additional cost = 50
        lcv = create_landed_cost_voucher("Purchase Receipt", pr.name,
                                         pr.company)

        pr1.reload()
        self.assertEqual(pr1.items[0].valuation_rate, 125)

        # check outgoing_rate for DN after reposting
        incoming_rate = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Purchase Receipt",
                "voucher_no": pr1.name,
                "item_code": subcontracted_item
            }, "incoming_rate")
        self.assertEqual(incoming_rate, 125)

        # cleanup data
        pr1.cancel()
        lcv.cancel()
        pr.cancel()
Ejemplo n.º 3
0
    def test_pick_list_for_batched_and_serialised_item(self):
        # check if oldest batch no and serial nos are picked
        item = frappe.db.exists("Item",
                                {'item_name': 'Batched and Serialised Item'})
        if not item:
            item = create_item("Batched and Serialised Item")
            item.has_batch_no = 1
            item.create_new_batch = 1
            item.has_serial_no = 1
            item.batch_number_series = "B-BATCH-.##"
            item.serial_no_series = "S-.####"
            item.save()
        else:
            item = frappe.get_doc("Item",
                                  {'item_name': 'Batched and Serialised Item'})

        pr1 = make_purchase_receipt(item_code="Batched and Serialised Item",
                                    qty=2,
                                    rate=100.0)

        pr1.load_from_db()
        oldest_batch_no = pr1.items[0].batch_no
        oldest_serial_nos = pr1.items[0].serial_no

        pr2 = make_purchase_receipt(item_code="Batched and Serialised Item",
                                    qty=2,
                                    rate=100.0)

        pick_list = frappe.get_doc({
            'doctype':
            'Pick List',
            'company':
            '_Test Company',
            'purpose':
            'Material Transfer',
            'locations': [{
                'item_code': 'Batched and Serialised Item',
                'qty': 2,
                'stock_qty': 2,
                'conversion_factor': 1,
            }]
        })
        pick_list.set_item_locations()

        self.assertEqual(pick_list.locations[0].batch_no, oldest_batch_no)
        self.assertEqual(pick_list.locations[0].serial_no, oldest_serial_nos)

        pr1.cancel()
        pr2.cancel()
Ejemplo n.º 4
0
	def test_last_movement_cancellation(self):
		pr = make_purchase_receipt(item_code="Macbook Pro",
			qty=1, rate=100000.0, location="Test Location")
		
		asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
		asset = frappe.get_doc('Asset', asset_name)
		asset.calculate_depreciation = 1
		asset.available_for_use_date = '2020-06-06'
		asset.purchase_date = '2020-06-06'
		asset.append("finance_books", {
			"expected_value_after_useful_life": 10000,
			"next_depreciation_date": "2020-12-31",
			"depreciation_method": "Straight Line",
			"total_number_of_depreciations": 3,
			"frequency_of_depreciation": 10
		})
		if asset.docstatus == 0:
			asset.submit()
		
		if not frappe.db.exists("Location", "Test Location 2"):
			frappe.get_doc({
				'doctype': 'Location',
				'location_name': 'Test Location 2'
			}).insert()
		
		movement = frappe.get_doc({'doctype': 'Asset Movement', 'reference_name': pr.name })
		self.assertRaises(frappe.ValidationError, movement.cancel)

		movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company, 
			assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
			reference_doctype = 'Purchase Receipt', reference_name = pr.name)
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")

		movement1.cancel()
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
Ejemplo n.º 5
0
	def test_create_asset_maintenance(self):
		pr = make_purchase_receipt(item_code="Photocopier",
			qty=1, rate=100000.0, location="Test Location")

		asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
		asset_doc = frappe.get_doc('Asset', asset_name)
		month_end_date = get_last_day(nowdate())

		purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)

		asset_doc.available_for_use_date = purchase_date
		asset_doc.purchase_date = purchase_date

		asset_doc.calculate_depreciation = 1
		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.save()

		if not frappe.db.exists("Asset Maintenance", "Photocopier"):
			asset_maintenance =	frappe.get_doc({
					"doctype": "Asset Maintenance",
					"asset_name": "Photocopier",
					"maintenance_team": "Team Awesome",
					"company": "_Test Company",
					"asset_maintenance_tasks": get_maintenance_tasks()
				}).insert()

			next_due_date = calculate_next_due_date(nowdate(), "Monthly")
			self.assertEqual(asset_maintenance.asset_maintenance_tasks[0].next_due_date, next_due_date)
Ejemplo n.º 6
0
    def test_asset_expected_value_after_useful_life(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2020-06-06'
        asset.purchase_date = '2020-06-06'
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10
            })
        asset.insert()
        accumulated_depreciation_after_full_schedule = \
         max([d.accumulated_depreciation_amount for d in asset.get("schedules")])

        asset_value_after_full_schedule = (
            flt(asset.gross_purchase_amount) -
            flt(accumulated_depreciation_after_full_schedule))

        self.assertTrue(asset.finance_books[0].expected_value_after_useful_life
                        >= asset_value_after_full_schedule)
Ejemplo n.º 7
0
    def test_gl_entries_with_perpetual_inventory_against_pr(self):

        pr = make_purchase_receipt(
            company="_Test Company with perpetual inventory",
            supplier_warehouse="Work In Progress - TCP1",
            warehouse="Stores - TCP1",
            cost_center="Main - TCP1",
            get_taxes_and_charges=True,
        )

        pi = make_purchase_invoice(
            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",
            get_taxes_and_charges=True,
            qty=10,
            do_not_save="True")

        for d in pi.items:
            d.purchase_receipt = pr.name

        pi.insert()
        pi.submit()
        pi.load_from_db()

        self.assertTrue(pi.status, "Unpaid")
        self.check_gle_for_pi(pi.name)
Ejemplo n.º 8
0
    def test_depreciation_entry_cancellation(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2020-06-06'
        asset.purchase_date = '2020-06-06'
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": "2020-12-31"
            })
        asset.insert()
        asset.submit()
        post_depreciation_entries(date="2021-01-01")

        asset.load_from_db()

        # cancel depreciation entry
        depr_entry = asset.get("schedules")[0].journal_entry
        self.assertTrue(depr_entry)
        frappe.get_doc("Journal Entry", depr_entry).cancel()

        asset.load_from_db()
        depr_entry = asset.get("schedules")[0].journal_entry
        self.assertFalse(depr_entry)
Ejemplo n.º 9
0
    def test_schedule_for_straight_line_method(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2030-01-01'
        asset.purchase_date = '2030-01-01'

        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 12,
                "depreciation_start_date": "2030-12-31"
            })
        asset.save()

        self.assertEqual(asset.status, "Draft")
        expected_schedules = [["2030-12-31", 30000.00, 30000.00],
                              ["2031-12-31", 30000.00, 60000.00],
                              ["2032-12-31", 30000.00, 90000.00]]

        schedules = [[
            cstr(d.schedule_date), d.depreciation_amount,
            d.accumulated_depreciation_amount
        ] for d in asset.get("schedules")]

        self.assertEqual(schedules, expected_schedules)
Ejemplo n.º 10
0
	def test_landed_cost_voucher(self):
		frappe.db.set_value("Buying Settings", None, "allow_multiple_items", 1)

		pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
			warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
			get_multiple_items = True, get_taxes_and_charges = True)

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

		create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company)

		pr_lc_value = frappe.db.get_value("Purchase Receipt Item", {"parent": pr.name}, "landed_cost_voucher_amount")
		self.assertEqual(pr_lc_value, 25.0)

		last_sle_after_landed_cost = frappe.db.get_value("Stock Ledger Entry", {
				"voucher_type": pr.doctype,
				"voucher_no": pr.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, 25.0)

		gl_entries = get_gl_entries("Purchase Receipt", pr.name)

		self.assertTrue(gl_entries)

		stock_in_hand_account = get_inventory_account(pr.company, pr.get("items")[0].warehouse)
		fixed_asset_account = get_inventory_account(pr.company, pr.get("items")[1].warehouse)

		if stock_in_hand_account == fixed_asset_account:
			expected_values = {
				stock_in_hand_account: [800.0, 0.0],
				"Stock Received But Not Billed - TCP1": [0.0, 500.0],
				"Expenses Included In Valuation - TCP1": [0.0, 50.0],
				"_Test Account Customs Duty - TCP1": [0.0, 150],
				"_Test Account Shipping Charges - TCP1": [0.0, 100.00]
			}
		else:
			expected_values = {
				stock_in_hand_account: [400.0, 0.0],
				fixed_asset_account: [400.0, 0.0],
				"Stock Received But Not Billed - TCP1": [0.0, 500.0],
				"Expenses Included In Valuation - TCP1": [0.0, 300.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)
Ejemplo n.º 11
0
    def test_expense_head(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=2,
                                   rate=200000.0,
                                   location="Test Location")

        doc = make_invoice(pr.name)

        self.assertEquals('Asset Received But Not Billed - _TC',
                          doc.items[0].expense_account)
Ejemplo n.º 12
0
    def test_purchase_asset(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1

        month_end_date = get_last_day(nowdate())
        purchase_date = nowdate() if nowdate() != month_end_date else add_days(
            nowdate(), -15)

        asset.available_for_use_date = purchase_date
        asset.purchase_date = purchase_date
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": month_end_date
            })
        asset.submit()

        pi = make_invoice(pr.name)
        pi.supplier = "_Test Supplier"
        pi.insert()
        pi.submit()
        asset.load_from_db()
        self.assertEqual(asset.supplier, "_Test Supplier")
        self.assertEqual(asset.purchase_date, getdate(purchase_date))
        # Asset won't have reference to PI when purchased through PR
        self.assertEqual(asset.purchase_receipt, pr.name)

        expected_gle = (("Asset Received But Not Billed - _TC", 100000.0, 0.0),
                        ("Creditors - _TC", 0.0, 100000.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)

        pi.cancel()
        asset.cancel()
        asset.load_from_db()
        pr.load_from_db()
        pr.cancel()
        self.assertEqual(asset.docstatus, 2)
Ejemplo n.º 13
0
    def test_inter_company_transfer(self):
        se = make_serialized_item(target_warehouse="_Test Warehouse - _TC")
        serial_nos = get_serial_nos(se.get("items")[0].serial_no)

        create_delivery_note(item_code="_Test Serialized Item With Series",
                             qty=1,
                             serial_no=serial_nos[0])

        wh = create_warehouse("_Test Warehouse", company="_Test Company 1")
        make_purchase_receipt(item_code="_Test Serialized Item With Series",
                              qty=1,
                              serial_no=serial_nos[0],
                              company="_Test Company 1",
                              warehouse=wh)

        serial_no = frappe.db.get_value("Serial No",
                                        serial_nos[0],
                                        ["warehouse", "company"],
                                        as_dict=1)

        self.assertEqual(serial_no.warehouse, wh)
        self.assertEqual(serial_no.company, "_Test Company 1")
Ejemplo n.º 14
0
    def test_asset_sale(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2020-06-06'
        asset.purchase_date = '2020-06-06'
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": "2020-12-31"
            })
        asset.insert()
        asset.submit()
        post_depreciation_entries(date="2021-01-01")

        si = make_sales_invoice(asset=asset.name,
                                item_code="Macbook Pro",
                                company="_Test Company")
        si.customer = "_Test Customer"
        si.due_date = nowdate()
        si.get("items")[0].rate = 25000
        si.insert()
        si.submit()

        self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"),
                         "Sold")

        expected_gle = (("_Test Accumulated Depreciations - _TC", 20392.16,
                         0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0),
                        ("_Test Gain/Loss on Asset Disposal - _TC", 54607.84,
                         0.0), ("Debtors - _TC", 25000.0, 0.0))

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

        self.assertEqual(gle, expected_gle)

        si.cancel()
        self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"),
                         "Partially Depreciated")
Ejemplo n.º 15
0
    def test_purchase_return_valuation_reposting(self):
        pr = make_purchase_receipt(company="_Test Company",
                                   posting_date='2020-04-10',
                                   warehouse="Stores - _TC",
                                   item_code="_Test Item for Reposting",
                                   qty=5,
                                   rate=100)

        return_pr = make_purchase_receipt(company="_Test Company",
                                          posting_date='2020-04-15',
                                          warehouse="Stores - _TC",
                                          item_code="_Test Item for Reposting",
                                          is_return=1,
                                          return_against=pr.name,
                                          qty=-2)

        # check sle
        outgoing_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Purchase Receipt",
                "voucher_no": return_pr.name
            }, ["outgoing_rate", "stock_value_difference"])

        self.assertEqual(outgoing_rate, 100)
        self.assertEqual(stock_value_difference, -200)

        create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company)

        outgoing_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Purchase Receipt",
                "voucher_no": return_pr.name
            }, ["outgoing_rate", "stock_value_difference"])

        self.assertEqual(outgoing_rate, 110)
        self.assertEqual(stock_value_difference, -220)
Ejemplo n.º 16
0
	def test_movement(self):
		pr = make_purchase_receipt(item_code="Macbook Pro",
			qty=1, rate=100000.0, location="Test Location")

		asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
		asset = frappe.get_doc('Asset', asset_name)
		asset.calculate_depreciation = 1
		asset.available_for_use_date = '2020-06-06'
		asset.purchase_date = '2020-06-06'
		asset.append("finance_books", {
			"expected_value_after_useful_life": 10000,
			"next_depreciation_date": "2020-12-31",
			"depreciation_method": "Straight Line",
			"total_number_of_depreciations": 3,
			"frequency_of_depreciation": 10
		})

		if asset.docstatus == 0:
			asset.submit()

		# check asset movement is created
		if not frappe.db.exists("Location", "Test Location 2"):
			frappe.get_doc({
				'doctype': 'Location',
				'location_name': 'Test Location 2'
			}).insert()

		movement1 = create_asset_movement(purpose = 'Transfer', company = asset.company, 
			assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'target_location': 'Test Location 2'}],
			reference_doctype = 'Purchase Receipt', reference_name = pr.name)
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")

		movement2 = create_asset_movement(purpose = 'Transfer', company = asset.company, 
			assets = [{ 'asset': asset.name , 'source_location': 'Test Location 2', 'target_location': 'Test Location'}],
			reference_doctype = 'Purchase Receipt', reference_name = pr.name)
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")

		movement1.cancel()
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")

		employee = make_employee("*****@*****.**", company="_Test Company")
		movement3 = create_asset_movement(purpose = 'Issue', company = asset.company, 
			assets = [{ 'asset': asset.name , 'source_location': 'Test Location', 'to_employee': employee}],
			reference_doctype = 'Purchase Receipt', reference_name = pr.name)
		
		# after issuing asset should belong to an employee not at a location
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), None)
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "custodian"), employee)
Ejemplo n.º 17
0
    def test_scrap_asset(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2020-01-01'
        asset.purchase_date = '2020-01-01'
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 10,
                "frequency_of_depreciation": 1
            })
        asset.insert()
        asset.submit()

        post_depreciation_entries(date=add_months('2020-01-01', 4))

        scrap_asset(asset.name)

        asset.load_from_db()
        self.assertEqual(asset.status, "Scrapped")
        self.assertTrue(asset.journal_entry_for_scrap)

        expected_gle = (("_Test Accumulated Depreciations - _TC", 36000.0,
                         0.0), ("_Test Fixed Asset - _TC", 0.0, 100000.0),
                        ("_Test Gain/Loss on Asset Disposal - _TC", 64000.0,
                         0.0))

        gle = frappe.db.sql(
            """select account, debit, credit from `tabGL Entry`
			where voucher_type='Journal Entry' and voucher_no = %s
			order by account""", asset.journal_entry_for_scrap)
        self.assertEqual(gle, expected_gle)

        restore_asset(asset.name)

        asset.load_from_db()
        self.assertFalse(asset.journal_entry_for_scrap)
        self.assertEqual(asset.status, "Partially Depreciated")
Ejemplo n.º 18
0
	def test_landed_cost_voucher_for_odd_numbers (self):

		pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", do_not_save=True)
		pr.items[0].cost_center = "Main - TCP1"
		for x in range(2):
			pr.append("items", {
				"item_code": "_Test Item",
				"warehouse": "Stores - TCP1",
				"cost_center": "Main - TCP1",
				"qty": 5,
				"rate": 50
			})
		pr.submit()

		lcv = create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company, 123.22)

		self.assertEqual(lcv.items[0].applicable_charges, 41.07)
		self.assertEqual(lcv.items[2].applicable_charges, 41.08)
Ejemplo n.º 19
0
    def test_depreciation(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=100000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.purchase_date = '2020-01-30'
        asset.available_for_use_date = "2020-01-30"
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 10000,
                "depreciation_method": "Straight Line",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": "2020-12-31"
            })
        asset.insert()
        asset.submit()
        asset.load_from_db()
        self.assertEqual(asset.status, "Submitted")

        frappe.db.set_value("Company", "_Test Company",
                            "series_for_depreciation_entry", "DEPR-")
        post_depreciation_entries(date="2021-01-01")
        asset.load_from_db()

        # check depreciation entry series
        self.assertEqual(asset.get("schedules")[0].journal_entry[:4], "DEPR")

        expected_gle = (("_Test Accumulated Depreciations - _TC", 0.0,
                         30000.0), ("_Test Depreciations - _TC", 30000.0, 0.0))

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

        self.assertEqual(gle, expected_gle)
        self.assertEqual(asset.get("value_after_depreciation"), 0)
Ejemplo n.º 20
0
	def test_landed_cost_voucher_for_serialized_item(self):
		frappe.db.sql("delete from `tabSerial No` where name in ('SN001', 'SN002', 'SN003', 'SN004', 'SN005')")
		pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
		supplier_warehouse = "Work in Progress - TCP1", get_multiple_items = True,
		get_taxes_and_charges = True, do_not_submit = True)

		pr.items[0].item_code = "_Test Serialized Item"
		pr.items[0].serial_no = "SN001\nSN002\nSN003\nSN004\nSN005"
		pr.submit()

		serial_no_rate = frappe.db.get_value("Serial No", "SN001", "purchase_rate")

		create_landed_cost_voucher("Purchase Receipt", pr.name, pr.company)

		serial_no = frappe.db.get_value("Serial No", "SN001",
			["warehouse", "purchase_rate"], as_dict=1)

		self.assertEqual(serial_no.purchase_rate - serial_no_rate, 5.0)
		self.assertEqual(serial_no.warehouse, "Stores - TCP1")
Ejemplo n.º 21
0
	def test_multiple_landed_cost_voucher_against_pr(self):
		pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1",
			supplier_warehouse = "Stores - TCP1", do_not_save=True)

		pr.append("items", {
			"item_code": "_Test Item",
			"warehouse": "Stores - TCP1",
			"cost_center": "Main - TCP1",
			"qty": 5,
			"rate": 100
		})

		pr.submit()

		lcv1 = make_landed_cost_voucher(company = pr.company, receipt_document_type = 'Purchase Receipt',
			receipt_document=pr.name, charges=100, do_not_save=True)

		lcv1.insert()
		lcv1.set('items', [
			lcv1.get('items')[0]
		])
		distribute_landed_cost_on_items(lcv1)

		lcv1.submit()

		lcv2 = make_landed_cost_voucher(company = pr.company, receipt_document_type = 'Purchase Receipt',
			receipt_document=pr.name, charges=100, do_not_save=True)

		lcv2.insert()
		lcv2.set('items', [
			lcv2.get('items')[1]
		])
		distribute_landed_cost_on_items(lcv2)

		lcv2.submit()

		pr.load_from_db()

		self.assertEqual(pr.items[0].landed_cost_voucher_amount, 100)
		self.assertEqual(pr.items[1].landed_cost_voucher_amount, 100)
Ejemplo n.º 22
0
	def test_asset_depreciation_value_adjustment(self):
		pr = make_purchase_receipt(item_code="Macbook Pro",
			qty=1, rate=100000.0, location="Test Location")

		asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
		asset_doc = frappe.get_doc('Asset', asset_name)
		asset_doc.calculate_depreciation = 1

		month_end_date = get_last_day(nowdate())
		purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)

		asset_doc.available_for_use_date = purchase_date
		asset_doc.purchase_date = purchase_date
		asset_doc.calculate_depreciation = 1
		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()

		current_value = get_current_asset_value(asset_doc.name)
		adj_doc = make_asset_value_adjustment(asset = asset_doc.name,
			current_asset_value = current_value, new_asset_value = 50000.0)
		adj_doc.submit()

		expected_gle = (
			("_Test Accumulated Depreciations - _TC", 0.0, 50000.0),
			("_Test Depreciations - _TC", 50000.0, 0.0)
		)

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

		self.assertEqual(gle, expected_gle)
Ejemplo n.º 23
0
    def test_pro_rata_depreciation_entry_for_wdv(self):
        pr = make_purchase_receipt(item_code="Macbook Pro",
                                   qty=1,
                                   rate=8000.0,
                                   location="Test Location")

        asset_name = frappe.db.get_value("Asset",
                                         {"purchase_receipt": pr.name}, 'name')
        asset = frappe.get_doc('Asset', asset_name)
        asset.calculate_depreciation = 1
        asset.available_for_use_date = '2030-06-06'
        asset.purchase_date = '2030-01-01'
        asset.append(
            "finance_books", {
                "expected_value_after_useful_life": 1000,
                "depreciation_method": "Written Down Value",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 12,
                "depreciation_start_date": "2030-12-31"
            })
        asset.save(ignore_permissions=True)

        self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0)

        expected_schedules = [
            ["2030-12-31", 2279.45, 2279.45],
            ["2031-12-31", 2860.28, 5139.73],
            ["2032-12-31", 1430.14, 6569.87],
            ["2033-06-06", 430.13, 7000.0],
        ]

        schedules = [[
            cstr(d.schedule_date),
            flt(d.depreciation_amount, 2),
            flt(d.accumulated_depreciation_amount, 2)
        ] for d in asset.get("schedules")]

        self.assertEqual(schedules, expected_schedules)
Ejemplo n.º 24
0
	def test_current_asset_value(self):
		pr = make_purchase_receipt(item_code="Macbook Pro",
			qty=1, rate=100000.0, location="Test Location")

		asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
		asset_doc = frappe.get_doc('Asset', asset_name)

		month_end_date = get_last_day(nowdate())
		purchase_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)

		asset_doc.available_for_use_date = purchase_date
		asset_doc.purchase_date = purchase_date
		asset_doc.calculate_depreciation = 1
		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()

		current_value = get_current_asset_value(asset_doc.name)
		self.assertEqual(current_value, 100000.0)
Ejemplo n.º 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)
Ejemplo n.º 26
0
    def test_reposting_of_sales_return_for_packed_item(self):
        company = "_Test Company"
        packed_item_code = "_Test Item for Reposting"
        bundled_item = "_Test Bundled Item for Reposting"
        create_product_bundle_item(bundled_item, [[packed_item_code, 4]])

        # Purchase Return: Qty = 50, Rate = 100
        pr = make_purchase_receipt(company=company,
                                   posting_date='2020-04-10',
                                   warehouse="Stores - _TC",
                                   item_code=packed_item_code,
                                   qty=50,
                                   rate=100)

        #Delivery Note: Qty = 5, Rate = 150
        dn = create_delivery_note(item_code=bundled_item,
                                  qty=5,
                                  rate=150,
                                  warehouse="Stores - _TC",
                                  company=company,
                                  expense_account="Cost of Goods Sold - _TC",
                                  cost_center="Main - _TC")

        # check outgoing_rate for DN
        outgoing_rate = abs(
            frappe.db.get_value("Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn.name
            }, "stock_value_difference") / 20)

        self.assertEqual(dn.packed_items[0].incoming_rate, 100)
        self.assertEqual(outgoing_rate, 100)

        # Return Entry: Qty = -2, Rate = 150
        return_dn = create_delivery_note(
            is_return=1,
            return_against=dn.name,
            item_code=bundled_item,
            qty=-2,
            rate=150,
            company=company,
            warehouse="Stores - _TC",
            expense_account="Cost of Goods Sold - _TC",
            cost_center="Main - _TC")

        # check incoming rate for Return entry
        incoming_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": return_dn.name
            }, ["incoming_rate", "stock_value_difference"])

        self.assertEqual(return_dn.packed_items[0].incoming_rate, 100)
        self.assertEqual(incoming_rate, 100)
        self.assertEqual(stock_value_difference, 800)

        #-------------------------------

        # Landed Cost Voucher to update the rate of incoming Purchase Return: Additional cost = 50
        lcv = create_landed_cost_voucher("Purchase Receipt", pr.name,
                                         pr.company)

        # check outgoing_rate for DN after reposting
        outgoing_rate = abs(
            frappe.db.get_value("Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": dn.name
            }, "stock_value_difference") / 20)
        self.assertEqual(outgoing_rate, 101)

        dn.reload()
        self.assertEqual(dn.packed_items[0].incoming_rate, 101)

        # check incoming rate for Return entry after reposting
        incoming_rate, stock_value_difference = frappe.db.get_value(
            "Stock Ledger Entry", {
                "voucher_type": "Delivery Note",
                "voucher_no": return_dn.name
            }, ["incoming_rate", "stock_value_difference"])

        self.assertEqual(incoming_rate, 101)
        self.assertEqual(stock_value_difference, 808)

        return_dn.reload()
        self.assertEqual(return_dn.packed_items[0].incoming_rate, 101)

        # Cleanup data
        return_dn.cancel()
        dn.cancel()
        lcv.cancel()
        pr.cancel()
Ejemplo n.º 27
0
    def test_cwip_accounting(self):
        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))

        pr_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(pr_gle, expected_gle)

        pi = make_invoice(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),
        )

        pi_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(pi_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)