def run_purchase(current_date): # make material requests for purchase items that have negative projected qtys if can_make("Material Request"): report = "Items To Be Requested" for row in query_report.run( report)["result"][:how_many("Material Request")]: mr = webnotes.new_bean("Material Request") mr.doc.material_request_type = "Purchase" mr.doc.transaction_date = current_date mr.doc.fiscal_year = current_date.year mr.doclist.append({ "doctype": "Material Request Item", "parentfield": "indent_details", "schedule_date": webnotes.utils.add_days(current_date, 7), "item_code": row[0], "qty": -row[-1] }) mr.insert() mr.submit() # make supplier quotations if can_make("Supplier Quotation"): from stock.doctype.material_request.material_request import make_supplier_quotation report = "Material Requests for which Supplier Quotations are not created" for row in query_report.run( report)["result"][:how_many("Supplier Quotation")]: if row[0] != "Total": sq = webnotes.bean(make_supplier_quotation(row[0])) sq.doc.transaction_date = current_date sq.doc.fiscal_year = current_date.year sq.insert() sq.submit() webnotes.conn.commit() # make purchase orders if can_make("Purchase Order"): from stock.doctype.material_request.material_request import make_purchase_order report = "Requested Items To Be Ordered" for row in query_report.run( report)["result"][:how_many("Purchase Order")]: if row[0] != "Total": po = webnotes.bean(make_purchase_order(row[0])) po.doc.transaction_date = current_date po.doc.fiscal_year = current_date.year po.insert() po.submit() webnotes.conn.commit()
def test_make_purchase_order(self): from stock.doctype.material_request.material_request import make_purchase_order mr = webnotes.bean(copy=test_records[0]).insert() self.assertRaises(webnotes.ValidationError, make_purchase_order, mr.doc.name) mr = webnotes.bean("Material Request", mr.doc.name) mr.submit() po = make_purchase_order(mr.doc.name) self.assertEquals(po[0]["doctype"], "Purchase Order") self.assertEquals(len(po), len(mr.doclist))
def test_make_purchase_order(self): from stock.doctype.material_request.material_request import make_purchase_order mr = webnotes.bean(copy=test_records[0]).insert() self.assertRaises(webnotes.ValidationError, make_purchase_order, mr.doc.name) mr = webnotes.bean("Material Request", mr.doc.name) mr.submit() po = make_purchase_order(mr.doc.name) self.assertEquals(po[0]["doctype"], "Purchase Order") self.assertEquals(len(po), len(mr.doclist))
def test_completed_qty_for_purchase(self): webnotes.conn.sql("""delete from `tabBin`""") # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.insert() mr.submit() # check if per complete is None self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}]) self._test_requested_qty(54.0, 3.0) # map a purchase order from stock.doctype.material_request.material_request import make_purchase_order po_doclist = make_purchase_order(mr.doc.name) po_doclist[0].supplier = "_Test Supplier" po_doclist[0].transaction_date = "2013-07-07" po_doclist[1].qty = 27.0 po_doclist[2].qty = 1.5 po_doclist[1].schedule_date = "2013-07-09" po_doclist[2].schedule_date = "2013-07-09" # check for stopped status of Material Request po = webnotes.bean(copy=po_doclist) po.insert() mr.obj.update_status('Stopped') self.assertRaises(webnotes.ValidationError, po.submit) self.assertRaises(webnotes.ValidationError, po.cancel) mr.obj.update_status('Submitted') po = webnotes.bean(copy=po_doclist) po.insert() po.submit() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": 50}, {"ordered_qty": 27.0}, {"ordered_qty": 1.5}]) self._test_requested_qty(27.0, 1.5) po.cancel() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}]) self._test_requested_qty(54.0, 3.0)
def test_completed_qty_for_purchase(self): webnotes.conn.sql("""delete from `tabBin`""") # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.insert() mr.submit() # check if per complete is None self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}]) self._test_requested_qty(54.0, 3.0) # map a purchase order from stock.doctype.material_request.material_request import make_purchase_order po_doclist = make_purchase_order(mr.doc.name) po_doclist[0].supplier = "_Test Supplier" po_doclist[1].qty = 27.0 po_doclist[2].qty = 1.5 po_doclist[1].schedule_date = "2013-07-09" po_doclist[2].schedule_date = "2013-07-09" # check for stopped status of Material Request po = webnotes.bean(copy=po_doclist) po.insert() mr.obj.update_status('Stopped') self.assertRaises(webnotes.ValidationError, po.submit) self.assertRaises(webnotes.ValidationError, po.cancel) mr.obj.update_status('Submitted') po = webnotes.bean(copy=po_doclist) po.insert() po.submit() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": 50}, {"ordered_qty": 27.0}, {"ordered_qty": 1.5}]) self._test_requested_qty(27.0, 1.5) po.cancel() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": None}, {"ordered_qty": None}, {"ordered_qty": None}]) self._test_requested_qty(54.0, 3.0)
def run_purchase(current_date): # make material requests for purchase items that have negative projected qtys if can_make("Material Request"): report = "Items To Be Requested" for row in query_report.run(report)["result"][:how_many("Material Request")]: mr = webnotes.new_bean("Material Request") mr.doc.material_request_type = "Purchase" mr.doc.transaction_date = current_date mr.doc.fiscal_year = "2013" mr.doclist.append({ "doctype": "Material Request Item", "parentfield": "indent_details", "schedule_date": webnotes.utils.add_days(current_date, 7), "item_code": row[0], "qty": -row[-1] }) mr.insert() mr.submit() # make supplier quotations if can_make("Supplier Quotation"): from stock.doctype.material_request.material_request import make_supplier_quotation report = "Material Requests for which Supplier Quotations are not created" for row in query_report.run(report)["result"][:how_many("Supplier Quotation")]: if row[0] != "Total": sq = webnotes.bean(make_supplier_quotation(row[0])) sq.doc.transaction_date = current_date sq.doc.fiscal_year = "2013" sq.insert() sq.submit() webnotes.conn.commit() # make purchase orders if can_make("Purchase Order"): from stock.doctype.material_request.material_request import make_purchase_order report = "Requested Items To Be Ordered" for row in query_report.run(report)["result"][:how_many("Purchase Order")]: if row[0] != "Total": po = webnotes.bean(make_purchase_order(row[0])) po.doc.transaction_date = current_date po.doc.fiscal_year = "2013" po.insert() po.submit() webnotes.conn.commit()