2019-04-19 11:52:54 +00:00
|
|
|
# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
|
|
|
|
# For license information, please see license.txt
|
|
|
|
|
|
|
|
from __future__ import unicode_literals
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-04-19 11:52:54 +00:00
|
|
|
import unittest
|
2019-04-26 10:32:25 +00:00
|
|
|
from datetime import datetime
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-04-26 10:32:25 +00:00
|
|
|
import frappe
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-04-28 11:41:02 +00:00
|
|
|
from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt
|
2019-04-21 18:14:21 +00:00
|
|
|
from erpnext.buying.report.procurement_tracker.procurement_tracker import execute
|
2019-04-19 11:52:54 +00:00
|
|
|
from erpnext.stock.doctype.material_request.material_request import make_purchase_order
|
2019-04-28 11:41:02 +00:00
|
|
|
from erpnext.stock.doctype.material_request.test_material_request import make_material_request
|
|
|
|
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
|
2019-04-19 11:52:54 +00:00
|
|
|
|
2021-09-02 11:14:59 +00:00
|
|
|
|
2019-04-19 11:52:54 +00:00
|
|
|
class TestProcurementTracker(unittest.TestCase):
|
|
|
|
def test_result_for_procurement_tracker(self):
|
2019-04-28 11:41:02 +00:00
|
|
|
filters = {
|
|
|
|
'company': '_Test Procurement Company',
|
2020-05-30 04:38:32 +00:00
|
|
|
'cost_center': 'Main - _TPC'
|
2019-04-28 11:41:02 +00:00
|
|
|
}
|
|
|
|
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",
|
2019-07-25 19:39:01 +00:00
|
|
|
country="Pakistan"
|
2019-04-28 11:41:02 +00:00
|
|
|
)).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")
|
2019-04-19 11:52:54 +00:00
|
|
|
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"
|
2019-04-19 11:52:54 +00:00
|
|
|
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())
|
2019-04-19 11:52:54 +00:00
|
|
|
|
2020-05-30 04:38:32 +00:00
|
|
|
po.load_from_db()
|
|
|
|
|
2019-04-19 11:52:54 +00:00
|
|
|
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,
|
2019-04-28 11:41:02 +00:00
|
|
|
"requesting_site": "_Test Procurement Warehouse - _TPC",
|
2019-04-19 11:52:54 +00:00
|
|
|
"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,
|
2019-04-19 11:52:54 +00:00
|
|
|
"unit_of_measurement": "_Test UOM",
|
2019-04-26 10:32:25 +00:00
|
|
|
"status": "To Bill",
|
|
|
|
"purchase_order_date": date_obj,
|
2019-04-19 11:52:54 +00:00
|
|
|
"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
|
2019-04-19 11:52:54 +00:00
|
|
|
}
|
2020-05-30 04:38:32 +00:00
|
|
|
|
2019-04-28 11:41:02 +00:00
|
|
|
return expected_data
|