Ejemplo n.º 1
0
    def test_merging_with_validate_selling_price(self):
        from erpnext.accounts.doctype.pos_closing_entry.test_pos_closing_entry import (
            init_user_and_profile, )
        from erpnext.accounts.doctype.pos_invoice_merge_log.pos_invoice_merge_log import (
            consolidate_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)

        item = "Test Selling Price Validation"
        make_item(item, {"is_stock_item": 1})
        make_purchase_receipt(item_code=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(item=item, 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(item=item, 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()

        consolidate_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)
Ejemplo n.º 2
0
    def test_sub_contracted_item_costing(self):
        from erpnext.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_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.º 4
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.º 5
0
	def test_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-06-06'
		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", 4000.0, 4000.0],
			["2031-12-31", 2000.0, 6000.0],
			["2032-12-31", 1000.0, 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.º 6
0
	def test_schedule_for_prorated_straight_line_method(self):
		set_prorated_depreciation_schedule()
		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.is_existing_asset = 0
		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.save()

		expected_schedules = [
			["2020-12-31", 28000.0, 28000.0],
			["2021-12-31", 30000.0, 58000.0],
			["2022-12-31", 30000.0, 88000.0],
			["2023-01-30", 2000.0, 90000.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)

		remove_prorated_depreciation_schedule()
Ejemplo n.º 7
0
	def test_putaway_rules_with_reoccurring_item(self):
		"""Test rules on same item entered multiple times with different rate."""
		rule_1 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_1, capacity=200,
			uom="Kg")
		# total capacity is 200 Kg

		pr = make_purchase_receipt(item_code="_Rice", qty=100, apply_putaway_rule=1,
			do_not_submit=1)
		pr.append("items", {
			"item_code": "_Rice",
			"warehouse": "_Test Warehouse - _TC",
			"qty": 200,
			"uom": "Kg",
			"stock_uom": "Kg",
			"stock_qty": 200,
			"received_qty": 200,
			"rate": 100,
			"conversion_factor": 1.0,
		}) # same item entered again in PR but with different rate
		pr.save()
		self.assertEqual(len(pr.items), 2)
		self.assertEqual(pr.items[0].qty, 100)
		self.assertEqual(pr.items[0].warehouse, self.warehouse_1)
		self.assertEqual(pr.items[0].putaway_rule, rule_1.name)
		# same rule applied to second item row
		# with previous assignment considered
		self.assertEqual(pr.items[1].qty, 100) # 100 unassigned in second row from 200
		self.assertEqual(pr.items[1].warehouse, self.warehouse_1)
		self.assertEqual(pr.items[1].putaway_rule, rule_1.name)

		pr.delete()
		rule_1.delete()
Ejemplo n.º 8
0
	def test_putaway_rules_multi_uom_whole_uom(self):
		"""Test if whole UOMs are handled."""
		item = frappe.get_doc("Item", "_Rice")
		if not frappe.db.get_value("UOM Conversion Detail", {"parent": "_Rice", "uom": "Bag"}):
			item.append("uoms", {
				"uom": "Bag",
				"conversion_factor": 1000
			})
			item.save()

		frappe.db.set_value("UOM", "Bag", "must_be_whole_number", 1)

		# Putaway Rule in different UOM
		rule_1 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_1, capacity=1,
			uom="Bag")
		self.assertEqual(rule_1.stock_capacity, 1000)
		# Putaway Rule in Stock UOM
		rule_2 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_2, capacity=500)
		self.assertEqual(rule_2.stock_capacity, 500)
		# total capacity is 1500 Kg

		pr = make_purchase_receipt(item_code="_Rice", qty=2, uom="Bag", stock_uom="Kg",
			conversion_factor=1000, apply_putaway_rule=1, do_not_submit=1)
		self.assertEqual(len(pr.items), 1)
		self.assertEqual(pr.items[0].qty, 1)
		self.assertEqual(pr.items[0].warehouse, self.warehouse_1)
		# leftover space was for 500 kg (0.5 Bag)
		# Since Bag is a whole UOM, 1(out of 2) Bag will be unassigned

		pr.delete()
		rule_1.delete()
		rule_2.delete()
Ejemplo n.º 9
0
	def test_putaway_rules_multi_uom(self):
		"""Test rules applied on uom other than stock uom."""
		item = frappe.get_doc("Item", "_Rice")
		if not frappe.db.get_value("UOM Conversion Detail", {"parent": "_Rice", "uom": "Bag"}):
			item.append("uoms", {
				"uom": "Bag",
				"conversion_factor": 1000
			})
			item.save()

		rule_1 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_1, capacity=3,
			uom="Bag")
		self.assertEqual(rule_1.stock_capacity, 3000)
		rule_2 = create_putaway_rule(item_code="_Rice", warehouse=self.warehouse_2, capacity=4,
			uom="Bag")
		self.assertEqual(rule_2.stock_capacity, 4000)

		# populate 'Rack 1' with 1 Bag, making the free space 2 Bags
		stock_receipt = make_stock_entry(item_code="_Rice", target=self.warehouse_1, qty=1000, basic_rate=50)

		pr = make_purchase_receipt(item_code="_Rice", qty=6, uom="Bag", stock_uom="Kg",
			conversion_factor=1000, apply_putaway_rule=1, do_not_submit=1)
		self.assertEqual(len(pr.items), 2)
		self.assertEqual(pr.items[0].qty, 4)
		self.assertEqual(pr.items[0].warehouse, self.warehouse_2)
		self.assertEqual(pr.items[1].qty, 2)
		self.assertEqual(pr.items[1].warehouse, self.warehouse_1)

		stock_receipt.cancel()
		pr.delete()
		rule_1.delete()
		rule_2.delete()
Ejemplo n.º 10
0
	def test_purchase_receipt_return(self):
		actual_qty_0 = get_qty_after_transaction()

		# submit purchase receipt
		pr = make_purchase_receipt(item_code="_Test Item", warehouse="_Test Warehouse - _TC", qty=5)

		actual_qty_1 = get_qty_after_transaction()

		self.assertEquals(actual_qty_0 + 5, actual_qty_1)

		pi_doc = make_purchase_invoice(pr.name)

		pi = frappe.get_doc(pi_doc)
		pi.posting_date = pr.posting_date
		pi.credit_to = "_Test Payable - _TC"
		for d in pi.get("items"):
			d.expense_account = "_Test Account Cost for Goods Sold - _TC"
			d.cost_center = "_Test Cost Center - _TC"

		for d in pi.get("taxes"):
			d.cost_center = "_Test Cost Center - _TC"

		pi.insert()
		pi.submit()

		# submit purchase return
		se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
			qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)

		actual_qty_2 = get_qty_after_transaction()

		self.assertEquals(actual_qty_1 - 5, actual_qty_2)

		return se, pr.name
Ejemplo n.º 11
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.º 12
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()
    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.º 14
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.º 15
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.º 16
0
    def test_get_voucher_wise_gl_entry(self):

        pr = make_purchase_receipt(
            item_code="_Test Item",
            posting_date="2021-02-01",
            rate=100,
            qty=1,
            warehouse="Stores - TCP1",
            company="_Test Company with perpetual inventory",
        )

        future_vouchers = get_future_stock_vouchers("2021-01-01",
                                                    "00:00:00",
                                                    for_items=["_Test Item"])

        voucher_type_and_no = ("Purchase Receipt", pr.name)
        self.assertTrue(
            voucher_type_and_no in future_vouchers,
            msg="get_future_stock_vouchers not returning correct value",
        )

        posting_date = "2021-01-01"
        gl_entries = get_voucherwise_gl_entries(future_vouchers, posting_date)
        self.assertTrue(
            voucher_type_and_no in gl_entries,
            msg="get_voucherwise_gl_entries not returning expected GLes",
        )
Ejemplo n.º 17
0
    def test_schedule_for_double_declining_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 = '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": "Double Declining Balance",
                "total_number_of_depreciations": 3,
                "frequency_of_depreciation": 10,
                "depreciation_start_date": "2020-06-06"
            })
        asset.insert()
        self.assertEqual(asset.status, "Draft")
        asset.save()

        expected_schedules = [["2020-06-06", 66666.67, 66666.67],
                              ["2021-04-06", 22222.22, 88888.89],
                              ["2022-02-06", 1111.11, 90000.0]]

        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.º 18
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.º 19
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.º 20
0
    def test_putaway_rules_with_same_priority(self):
        """Test if rule with more free space is applied,
		among two rules with same priority and capacity."""
        rule_1 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_1,
                                     capacity=500,
                                     uom="Kg")
        rule_2 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_2,
                                     capacity=500,
                                     uom="Kg")

        # out of 500 kg capacity, occupy 100 kg in warehouse_1
        stock_receipt = make_stock_entry(item_code="_Rice",
                                         target=self.warehouse_1,
                                         qty=100,
                                         basic_rate=50)

        pr = make_purchase_receipt(item_code="_Rice",
                                   qty=700,
                                   apply_putaway_rule=1,
                                   do_not_submit=1)
        self.assertEqual(len(pr.items), 2)
        self.assertEqual(pr.items[0].qty, 500)
        # warehouse_2 has 500 kg free space, it is given priority
        self.assertEqual(pr.items[0].warehouse, self.warehouse_2)
        self.assertEqual(pr.items[1].qty, 200)
        # warehouse_1 has 400 kg free space, it is given less priority
        self.assertEqual(pr.items[1].warehouse, self.warehouse_1)

        stock_receipt.cancel()
        pr.delete()
        rule_1.delete()
        rule_2.delete()
Ejemplo n.º 21
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 = '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,
			"depreciation_start_date": "2020-06-06"
		})
		asset.save()
		self.assertEqual(asset.status, "Draft")
		expected_schedules = [
			["2020-06-06", 147.54, 147.54],
			["2021-04-06", 44852.46, 45000.0],
			["2022-02-06", 45000.0, 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.º 22
0
    def _test_purchase_return_return_against_purchase_order(self):

        actual_qty_0 = get_qty_after_transaction()

        from erpnext.buying.doctype.purchase_order.test_purchase_order import (
            test_records as purchase_order_test_records,
        )

        from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt, make_purchase_invoice

        # submit purchase receipt
        po = frappe.copy_doc(purchase_order_test_records[0])
        po.transaction_date = nowdate()
        po.is_subcontracted = None
        po.get("items")[0].item_code = "_Test Item"
        po.get("items")[0].rate = 50
        po.insert()
        po.submit()

        pr_doc = make_purchase_receipt(po.name)

        pr = frappe.get_doc(pr_doc)
        pr.posting_date = po.transaction_date
        pr.insert()
        pr.submit()

        actual_qty_1 = get_qty_after_transaction()

        self.assertEquals(actual_qty_0 + 10, actual_qty_1)

        pi_doc = make_purchase_invoice(po.name)

        pi = frappe.get_doc(pi_doc)
        pi.posting_date = pr.posting_date
        pi.credit_to = "_Test Payable - _TC"
        for d in pi.get("items"):
            d.expense_account = "_Test Account Cost for Goods Sold - _TC"
            d.cost_center = "_Test Cost Center - _TC"
        for d in pi.get("taxes"):
            d.cost_center = "_Test Cost Center - _TC"

        pi.run_method("calculate_taxes_and_totals")
        pi.bill_no = "NA"
        pi.insert()
        pi.submit()

        # submit purchase return
        se = make_stock_entry(
            item_code="_Test Item",
            source="_Test Warehouse - _TC",
            qty=5,
            purpose="Purchase Return",
            purchase_receipt_no=pr.name,
        )

        actual_qty_2 = get_qty_after_transaction()

        self.assertEquals(actual_qty_1 - 5, actual_qty_2)

        return se, pr.name
Ejemplo n.º 23
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.º 24
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.º 25
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(flt(lcv.items[0].applicable_charges, 2), 41.07)
        self.assertEqual(flt(lcv.items[2].applicable_charges, 2), 41.08)
Ejemplo n.º 26
0
    def test_putaway_rules_with_insufficient_capacity(self):
        """Test if qty exceeding capacity, is handled."""
        rule_1 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_1,
                                     capacity=100,
                                     uom="Kg")
        rule_2 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_2,
                                     capacity=200,
                                     uom="Kg")

        pr = make_purchase_receipt(item_code="_Rice",
                                   qty=350,
                                   apply_putaway_rule=1,
                                   do_not_submit=1)
        self.assertEqual(len(pr.items), 2)
        self.assertEqual(pr.items[0].qty, 200)
        self.assertEqual(pr.items[0].warehouse, self.warehouse_2)
        self.assertEqual(pr.items[1].qty, 100)
        self.assertEqual(pr.items[1].warehouse, self.warehouse_1)
        # total 300 assigned, 50 unassigned

        pr.delete()
        rule_1.delete()
        rule_2.delete()
Ejemplo n.º 27
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.º 28
0
    def test_putaway_rules_priority(self):
        """Test if rule is applied by priority, irrespective of free space."""
        rule_1 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_1,
                                     capacity=200,
                                     uom="Kg")
        rule_2 = create_putaway_rule(item_code="_Rice",
                                     warehouse=self.warehouse_2,
                                     capacity=300,
                                     uom="Kg",
                                     priority=2)

        pr = make_purchase_receipt(item_code="_Rice",
                                   qty=300,
                                   apply_putaway_rule=1,
                                   do_not_submit=1)
        self.assertEqual(len(pr.items), 2)
        self.assertEqual(pr.items[0].qty, 200)
        self.assertEqual(pr.items[0].warehouse, self.warehouse_1)
        self.assertEqual(pr.items[1].qty, 100)
        self.assertEqual(pr.items[1].warehouse, self.warehouse_2)

        self.assertUnchangedItemsOnResave(pr)

        pr.delete()
        rule_1.delete()
        rule_2.delete()
Ejemplo n.º 29
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)

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

        serial_no = frappe.get_doc("Serial No", serial_nos[0])

        # check Serial No details after delivery
        self.assertEqual(serial_no.status, "Delivered")
        self.assertEqual(serial_no.warehouse, None)
        self.assertEqual(serial_no.company, "_Test Company")
        self.assertEqual(serial_no.delivery_document_type, "Delivery Note")
        self.assertEqual(serial_no.delivery_document_no, dn.name)

        wh = create_warehouse("_Test Warehouse", company="_Test Company 1")
        pr = 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.reload()

        # check Serial No details after purchase in second company
        self.assertEqual(serial_no.status, "Active")
        self.assertEqual(serial_no.warehouse, wh)
        self.assertEqual(serial_no.company, "_Test Company 1")
        self.assertEqual(serial_no.purchase_document_type, "Purchase Receipt")
        self.assertEqual(serial_no.purchase_document_no, pr.name)
Ejemplo n.º 30
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.º 31
0
	def test_purchase_receipt_return(self):
		actual_qty_0 = get_qty_after_transaction()

		# submit purchase receipt
		pr = make_purchase_receipt(item_code="_Test Item", warehouse="_Test Warehouse - _TC", qty=5)

		actual_qty_1 = get_qty_after_transaction()

		self.assertEquals(actual_qty_0 + 5, actual_qty_1)

		pi_doc = make_purchase_invoice(pr.name)

		pi = frappe.get_doc(pi_doc)
		pi.posting_date = pr.posting_date
		pi.credit_to = "_Test Payable - _TC"
		for d in pi.get("items"):
			d.expense_account = "_Test Account Cost for Goods Sold - _TC"
			d.cost_center = "_Test Cost Center - _TC"

		for d in pi.get("taxes"):
			d.cost_center = "_Test Cost Center - _TC"

		pi.insert()
		pi.submit()

		# submit purchase return
		se = make_stock_entry(item_code="_Test Item", source="_Test Warehouse - _TC",
			qty=5, purpose="Purchase Return", purchase_receipt_no=pr.name)

		actual_qty_2 = get_qty_after_transaction()

		self.assertEquals(actual_qty_1 - 5, actual_qty_2)

		return se, pr.name
Ejemplo n.º 32
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.º 33
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.º 34
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,
                "depreciation_start_date": "2020-06-06"
            })
        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.º 35
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,
        )

        self.assertTrue(
            cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)

        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.º 36
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.º 37
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.º 38
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_purchase_invoice(asset.name, asset.item_code,
                                   asset.gross_purchase_amount, asset.company,
                                   asset.purchase_date)
        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))
        self.assertEqual(asset.purchase_invoice, pi.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.load_from_db()
        self.assertEqual(asset.supplier, None)
        self.assertEqual(asset.purchase_invoice, None)

        self.assertFalse(
            frappe.db.get_value("GL Entry", {
                "voucher_type": "Purchase Invoice",
                "voucher_no": pi.name
            }))
Ejemplo n.º 39
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_purchase_invoice(asset.name, asset.item_code, asset.gross_purchase_amount,
			asset.company, asset.purchase_date)
		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))
		self.assertEqual(asset.purchase_invoice, pi.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.load_from_db()
		self.assertEqual(asset.supplier, None)
		self.assertEqual(asset.purchase_invoice, None)

		self.assertFalse(frappe.db.get_value("GL Entry",
			{"voucher_type": "Purchase Invoice", "voucher_no": pi.name}))
Ejemplo n.º 40
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", 100000.0, 0.0),
			("_Test Fixed Asset - _TC", 0.0, 100000.0),
			("_Test Gain/Loss on Asset Disposal - _TC", 0, 25000.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()
		frappe.delete_doc("Sales Invoice", si.name)

		self.assertEqual(frappe.db.get_value("Asset", asset.name, "status"), "Partially Depreciated")
Ejemplo n.º 41
0
	def test_movement_for_serialized_asset(self):
		asset_item = "Test Serialized Asset Item"
		pr = make_purchase_receipt(item_code=asset_item, rate = 1000, qty=3, location = "Mumbai")
		asset_name = frappe.db.get_value('Asset', {'purchase_receipt': pr.name}, 'name')

		asset = frappe.get_doc('Asset', asset_name)
		month_end_date = get_last_day(nowdate())
		asset.available_for_use_date = nowdate() if nowdate() != month_end_date else add_days(nowdate(), -15)

		asset.calculate_depreciation = 1
		asset.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.submit()
		serial_nos = frappe.db.get_value('Asset Movement', {'reference_name': pr.name}, 'serial_no')

		mov1 = create_asset_movement(asset=asset_name, purpose = 'Transfer',
			company=asset.company, source_location = "Mumbai", target_location="Pune", serial_no=serial_nos)
		self.assertEqual(mov1.target_location, "Pune")

		serial_no = frappe.db.get_value('Serial No', {'asset': asset_name}, 'name')

		employee = make_employee("*****@*****.**")
		create_asset_movement(asset=asset_name, purpose = 'Transfer',
			company=asset.company, serial_no=serial_no, to_employee=employee)

		self.assertEqual(frappe.db.get_value('Serial No', serial_no, 'employee'), employee)

		create_asset_movement(asset=asset_name, purpose = 'Transfer', company=asset.company,
			serial_no=serial_no, from_employee=employee, to_employee="_T-Employee-00001")

		self.assertEqual(frappe.db.get_value('Serial No', serial_no, 'location'), "Pune")

		mov4 = create_asset_movement(asset=asset_name, purpose = 'Transfer',
			company=asset.company, source_location = "Pune", target_location="Nagpur", serial_no=serial_nos)
		self.assertEqual(mov4.target_location, "Nagpur")
		self.assertEqual(frappe.db.get_value('Serial No', serial_no, 'location'), "Nagpur")
		self.assertEqual(frappe.db.get_value('Serial No', serial_no, 'employee'), "_T-Employee-00001")
Ejemplo n.º 42
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-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-06-06"
		})
		asset.insert()
		asset.submit()
		post_depreciation_entries(date="2021-01-01")

		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", 100000.0, 0.0),
			("_Test Fixed Asset - _TC", 0.0, 100000.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")
	def test_landed_cost_voucher_for_odd_numbers (self):
		set_perpetual_inventory(1)

		pr = make_purchase_receipt(do_not_save=True)
		pr.items[0].cost_center = "_Test Company - _TC"
		for x in range(2):
			pr.append("items", {
				"item_code": "_Test Item",
				"warehouse": "_Test Warehouse - _TC",
				"cost_center": "_Test Company - _TC",
				"qty": 5,
				"rate": 50
			})
		pr.submit()

		lcv = submit_landed_cost_voucher("Purchase Receipt", pr.name, 123.22)
		
		self.assertEquals(lcv.items[0].applicable_charges, 41.07)
		self.assertEquals(lcv.items[2].applicable_charges, 41.08)		
		
		set_perpetual_inventory(0)
Ejemplo n.º 44
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,
			"depreciation_start_date": "2020-06-06"
		})

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

		movement1 = create_asset_movement(asset= asset.name, purpose = 'Transfer',
			company=asset.company, source_location="Test Location", target_location="Test Location 2")
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location 2")

		movement2 = create_asset_movement(asset= asset.name, purpose = 'Transfer',
			company=asset.company, source_location = "Test Location 2", target_location="Test Location")
		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")

		movement2.cancel()
		self.assertEqual(frappe.db.get_value("Asset", asset.name, "location"), "Test Location")
Ejemplo n.º 45
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, 32129.24),
			("_Test Depreciations - _TC", 32129.24, 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)
	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.º 47
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,
			"depreciation_start_date": "2020-06-06"
		})
		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)
	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.º 49
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)