# Copyright (c) 2015, SolutionERP LLC and Contributors
# License: GNU General Public License v3. See license.txt


import xhiveframework
from xhiveframework.tests.utils import XhiveframeworkTestCase


class TestPurchaseOrder(XhiveframeworkTestCase):
	def test_make_purchase_order(self):
		from xhiveerp.buying.doctype.supplier_quotation.supplier_quotation import make_purchase_order

		sq = xhiveframework.copy_doc(test_records[0]).insert()

		self.assertRaises(xhiveframework.ValidationError, make_purchase_order, sq.name)

		sq = xhiveframework.get_doc("Supplier Quotation", sq.name)
		sq.submit()
		po = make_purchase_order(sq.name)

		self.assertEqual(po.doctype, "Purchase Order")
		self.assertEqual(len(po.get("items")), len(sq.get("items")))

		po.naming_series = "_T-Purchase Order-"

		for doc in po.get("items"):
			if doc.get("item_code"):
				doc.set("schedule_date", "2013-04-12")

		po.insert()


test_records = xhiveframework.get_test_records("Supplier Quotation")
