brotherton-erpnext/erpnext/buying/report/procurement_tracker/test_procurement_tracker.py

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

76 lines
2.5 KiB
Python
Raw Normal View History

# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import unittest
2019-04-26 10:32:25 +00:00
from datetime import datetime
2019-04-26 10:32:25 +00:00
import frappe
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
from erpnext.buying.report.procurement_tracker.procurement_tracker import execute
from erpnext.stock.doctype.material_request.material_request import make_purchase_order
from erpnext.stock.doctype.material_request.test_material_request import make_material_request
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
class TestProcurementTracker(unittest.TestCase):
def test_result_for_procurement_tracker(self):
filters = {
'company': '_Test Procurement Company',
2020-05-30 04:38:32 +00:00
'cost_center': 'Main - _TPC'
}
expected_data = self.generate_expected_data()
report = execute(filters)
length = len(report[1])
self.assertEqual(expected_data, report[1][length-1])
def generate_expected_data(self):
if not frappe.db.exists("Company", "_Test Procurement Company"):
frappe.get_doc(dict(
doctype="Company",
company_name="_Test Procurement Company",
abbr="_TPC",
default_currency="INR",
country="Pakistan"
)).insert()
warehouse = create_warehouse("_Test Procurement Warehouse", company="_Test Procurement Company")
2020-05-30 04:38:32 +00:00
mr = make_material_request(company="_Test Procurement Company", warehouse=warehouse, cost_center="Main - _TPC")
po = make_purchase_order(mr.name)
2019-04-25 20:01:05 +00:00
po.supplier = "_Test Supplier"
2020-05-29 19:21:19 +00:00
po.get("items")[0].cost_center = "Main - _TPC"
po.submit()
2019-04-25 20:01:05 +00:00
pr = make_purchase_receipt(po.name)
2020-05-29 19:21:19 +00:00
pr.get("items")[0].cost_center = "Main - _TPC"
2019-04-25 20:01:05 +00:00
pr.submit()
2019-04-26 10:32:25 +00:00
frappe.db.commit()
date_obj = datetime.date(datetime.now())
2020-05-30 04:38:32 +00:00
po.load_from_db()
expected_data = {
2019-04-26 10:32:25 +00:00
"material_request_date": date_obj,
2020-05-30 04:38:32 +00:00
"cost_center": "Main - _TPC",
2019-04-26 10:32:25 +00:00
"project": None,
"requesting_site": "_Test Procurement Warehouse - _TPC",
"requestor": "Administrator",
"material_request_no": mr.name,
2020-06-12 09:59:40 +00:00
"item_code": '_Test Item',
2019-04-26 10:32:25 +00:00
"quantity": 10.0,
"unit_of_measurement": "_Test UOM",
2019-04-26 10:32:25 +00:00
"status": "To Bill",
"purchase_order_date": date_obj,
"purchase_order": po.name,
2019-04-25 20:01:05 +00:00
"supplier": "_Test Supplier",
"estimated_cost": 0.0,
2020-06-12 09:59:40 +00:00
"actual_cost": 0.0,
2020-05-30 04:38:32 +00:00
"purchase_order_amt": po.net_total,
"purchase_order_amt_in_company_currency": po.base_net_total,
2019-04-26 10:32:25 +00:00
"expected_delivery_date": date_obj,
"actual_delivery_date": date_obj
}
2020-05-30 04:38:32 +00:00
return expected_data