def _test_delivery_note_return_against_sales_order(self, item_code, delivered_qty, returned_qty): self._insert_material_receipt() from selling.doctype.sales_order.test_sales_order \ import test_records as sales_order_test_records actual_qty_0 = self._get_actual_qty() so = webnotes.bean(copy=sales_order_test_records[0]) so.doclist[1].item_code = item_code so.doclist[1].qty = 5.0 so.insert() so.submit() dn_doclist = webnotes.map_doclist([ ["Sales Order", "Delivery Note"], ["Sales Order Item", "Delivery Note Item"], ["Sales Taxes and Charges", "Sales Taxes and Charges"], ["Sales Team", "Sales Team"]], so.doc.name) dn = webnotes.bean(dn_doclist) dn.doc.status = "Draft" dn.doc.posting_date = so.doc.delivery_date dn.insert() dn.submit() actual_qty_1 = self._get_actual_qty() self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1) si_doclist = webnotes.map_doclist([ ["Sales Order", "Sales Invoice"], ["Sales Order Item", "Sales Invoice Item"], ["Sales Taxes and Charges", "Sales Taxes and Charges"], ["Sales Team", "Sales Team"]], so.doc.name) si = webnotes.bean(si_doclist) si.doc.posting_date = dn.doc.posting_date si.doc.debit_to = "_Test Customer - _TC" for d in si.doclist.get({"parentfield": "entries"}): d.income_account = "Sales - _TC" d.cost_center = "_Test Cost Center - _TC" si.insert() si.submit() # insert and submit stock entry for sales return se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Sales Return" se.doc.delivery_note_no = dn.doc.name se.doc.posting_date = "2013-03-10" se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty se.insert() se.submit() actual_qty_2 = self._get_actual_qty() self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2) return se
def test_incorrect_mapping_of_stock_entry(self): # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.doc.material_request_type = "Transfer" mr.insert() mr.submit() # map a stock entry se_doclist = webnotes.map_doclist([["Material Request", "Stock Entry"], ["Material Request Item", "Stock Entry Detail"]], mr.doc.name) se_doclist[0].fields.update({ "posting_date": "2013-03-01", "posting_time": "00:00" }) se_doclist[1].fields.update({ "qty": 60.0, "transfer_qty": 60.0, "s_warehouse": "_Test Warehouse", "t_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) se_doclist[2].fields.update({ "qty": 3.0, "transfer_qty": 3.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) # check for stopped status of Material Request se = webnotes.bean(copy=se_doclist) self.assertRaises(webnotes.MappingMismatchError, se.insert)
def test_incorrect_mapping_of_stock_entry(self): # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.doc.material_request_type = "Transfer" mr.insert() mr.submit() # map a stock entry se_doclist = webnotes.map_doclist( [["Material Request", "Stock Entry"], ["Material Request Item", "Stock Entry Detail"]], mr.doc.name) se_doclist[0].fields.update({ "posting_date": "2013-03-01", "posting_time": "00:00", "fiscal_year": "_Test Fiscal Year 2013", }) se_doclist[1].fields.update({ "qty": 60.0, "transfer_qty": 60.0, "s_warehouse": "_Test Warehouse", "t_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) se_doclist[2].fields.update({ "qty": 3.0, "transfer_qty": 3.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) # check for stopped status of Material Request se = webnotes.bean(copy=se_doclist) self.assertRaises(webnotes.MappingMismatchError, se.insert)
def test_completed_qty_for_over_transfer(self): webnotes.conn.sql("""delete from `tabBin`""") webnotes.conn.sql("""delete from `tabStock Ledger Entry`""") # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.doc.material_request_type = "Transfer" 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 stock entry se_doclist = webnotes.map_doclist([["Material Request", "Stock Entry"], ["Material Request Item", "Stock Entry Detail"]], mr.doc.name) se_doclist[0].fields.update({ "posting_date": "2013-03-01", "posting_time": "00:00" }) se_doclist[1].fields.update({ "qty": 60.0, "transfer_qty": 60.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) se_doclist[2].fields.update({ "qty": 3.0, "transfer_qty": 3.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) # make available the qty in _Test Warehouse 1 before transfer self._insert_stock_entry(60.0, 3.0) # check for stopped status of Material Request se = webnotes.bean(copy=se_doclist) se.insert() mr.obj.update_status('Stopped') self.assertRaises(webnotes.ValidationError, se.submit) self.assertRaises(webnotes.ValidationError, se.cancel) mr.obj.update_status('Submitted') se = webnotes.bean(copy=se_doclist) se.insert() se.submit() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": 100}, {"ordered_qty": 60.0}, {"ordered_qty": 3.0}]) self._test_requested_qty(0.0, 0.0) # check if per complete is as expected for Stock Entry cancelled se.cancel() mr.load_from_db() self._test_expected(mr.doclist, [{"per_ordered": 0}, {"ordered_qty": 0}, {"ordered_qty": 0}]) self._test_requested_qty(54.0, 3.0)
def test_purchase_receipt_return(self): self._clear_stock() actual_qty_0 = self._get_actual_qty() from stock.doctype.purchase_receipt.test_purchase_receipt \ import test_records as purchase_receipt_test_records # submit purchase receipt pr = webnotes.bean(copy=purchase_receipt_test_records[0]) pr.insert() pr.submit() actual_qty_1 = self._get_actual_qty() self.assertEquals(actual_qty_0 + 10, actual_qty_1) pi_doclist = webnotes.map_doclist( [["Purchase Receipt", "Purchase Invoice"], ["Purchase Receipt Item", "Purchase Invoice Item"], ["Purchase Taxes and Charges", "Purchase Taxes and Charges"]], pr.doc.name) pi = webnotes.bean(pi_doclist) pi.doc.posting_date = pr.doc.posting_date pi.doc.credit_to = "_Test Supplier - _TC" for d in pi.doclist.get({"parentfield": "entries"}): d.expense_head = "_Test Account Cost for Goods Sold - _TC" d.cost_center = "_Test Cost Center - _TC" for d in pi.doclist.get({"parentfield": "purchase_tax_details"}): d.cost_center = "_Test Cost Center - _TC" pi.run_method("calculate_taxes_and_totals") pi.insert() pi.submit() # submit purchase return se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr.doc.name se.doc.posting_date = "2013-03-01" se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].s_warehouse = "_Test Warehouse" se.insert() se.submit() actual_qty_2 = self._get_actual_qty() self.assertEquals(actual_qty_1 - 5, actual_qty_2) webnotes.conn.set_default("company", self.old_default_company) return se, pr.doc.name
def test_purchase_receipt_return(self): self._clear_stock() actual_qty_0 = self._get_actual_qty() from stock.doctype.purchase_receipt.test_purchase_receipt \ import test_records as purchase_receipt_test_records # submit purchase receipt pr = webnotes.bean(copy=purchase_receipt_test_records[0]) pr.insert() pr.submit() actual_qty_1 = self._get_actual_qty() self.assertEquals(actual_qty_0 + 10, actual_qty_1) pi_doclist = webnotes.map_doclist([ ["Purchase Receipt", "Purchase Invoice"], ["Purchase Receipt Item", "Purchase Invoice Item"], ["Purchase Taxes and Charges", "Purchase Taxes and Charges"]], pr.doc.name) pi = webnotes.bean(pi_doclist) pi.doc.posting_date = pr.doc.posting_date pi.doc.credit_to = "_Test Supplier - _TC" for d in pi.doclist.get({"parentfield": "entries"}): d.expense_head = "_Test Account Cost for Goods Sold - _TC" d.cost_center = "_Test Cost Center - _TC" for d in pi.doclist.get({"parentfield": "purchase_tax_details"}): d.cost_center = "_Test Cost Center - _TC" pi.run_method("calculate_taxes_and_totals") pi.insert() pi.submit() # submit purchase return se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr.doc.name se.doc.posting_date = "2013-03-01" se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].s_warehouse = "_Test Warehouse" se.insert() se.submit() actual_qty_2 = self._get_actual_qty() self.assertEquals(actual_qty_1 - 5, actual_qty_2) webnotes.conn.set_default("company", self.old_default_company) return se, pr.doc.name
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 po_doclist = webnotes.map_doclist([["Material Request", "Purchase Order"], ["Material Request Item", "Purchase Order Item"]], mr.doc.name) po_doclist[0].fields.update({ "supplier": "_Test Supplier", "supplier_name": "_Test Supplier", "transaction_date": mr.doc.transaction_date, "fiscal_year": "_Test Fiscal Year 2013", "currency": "INR", "conversion_rate": 1.0, "grand_total_import": 0.0 }) po_doclist[1].qty = 27.0 po_doclist[2].qty = 1.5 # 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": 0}, {"ordered_qty": 0}, {"ordered_qty": 0}]) self._test_requested_qty(54.0, 3.0)
def _test_delivery_note_return(self, item_code, delivered_qty, returned_qty): self._insert_material_receipt() from stock.doctype.delivery_note.test_delivery_note \ import test_records as delivery_note_test_records actual_qty_0 = self._get_actual_qty() # make a delivery note based on this invoice dn = webnotes.bean(copy=delivery_note_test_records[0]) dn.doclist[1].item_code = item_code dn.insert() dn.submit() actual_qty_1 = self._get_actual_qty() self.assertEquals(actual_qty_0 - delivered_qty, actual_qty_1) si_doclist = webnotes.map_doclist( [["Delivery Note", "Sales Invoice"], ["Delivery Note Item", "Sales Invoice Item"], ["Sales Taxes and Charges", "Sales Taxes and Charges"], ["Sales Team", "Sales Team"]], dn.doc.name) si = webnotes.bean(si_doclist) si.doc.posting_date = dn.doc.posting_date si.doc.debit_to = "_Test Customer - _TC" for d in si.doclist.get({"parentfield": "entries"}): d.income_account = "Sales - _TC" d.cost_center = "_Test Cost Center - _TC" si.insert() si.submit() # insert and submit stock entry for sales return se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Sales Return" se.doc.delivery_note_no = dn.doc.name se.doc.posting_date = "2013-03-10" se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = returned_qty se.insert() se.submit() actual_qty_2 = self._get_actual_qty() self.assertEquals(actual_qty_1 + returned_qty, actual_qty_2) return se
def _test_purchase_return_return_against_purchase_order(self): self._clear_stock() actual_qty_0 = self._get_actual_qty() from buying.doctype.purchase_order.test_purchase_order \ import test_records as purchase_order_test_records # submit purchase receipt po = webnotes.bean(copy=purchase_order_test_records[0]) po.doc.is_subcontracted = None po.doclist[1].item_code = "_Test Item" po.doclist[1].import_rate = 50 po.insert() po.submit() pr_doclist = webnotes.map_doclist([ ["Purchase Order", "Purchase Receipt"], ["Purchase Order Item", "Purchase Receipt Item"], ["Purchase Taxes and Charges", "Purchase Taxes and Charges"]], po.doc.name) pr = webnotes.bean(pr_doclist) pr.doc.posting_date = po.doc.transaction_date pr.insert() pr.submit() actual_qty_1 = self._get_actual_qty() self.assertEquals(actual_qty_0 + 10, actual_qty_1) pi_doclist = webnotes.map_doclist([ ["Purchase Order", "Purchase Invoice"], ["Purchase Order Item", "Purchase Invoice Item"], ["Purchase Taxes and Charges", "Purchase Taxes and Charges"]], po.doc.name) pi = webnotes.bean(pi_doclist) pi.doc.posting_date = pr.doc.posting_date pi.doc.credit_to = "_Test Supplier - _TC" for d in pi.doclist.get({"parentfield": "entries"}): d.expense_head = "_Test Account Cost for Goods Sold - _TC" d.cost_center = "_Test Cost Center - _TC" for d in pi.doclist.get({"parentfield": "purchase_tax_details"}): d.cost_center = "_Test Cost Center - _TC" pi.run_method("calculate_taxes_and_totals") pi.insert() pi.submit() # submit purchase return se = webnotes.bean(copy=test_records[0]) se.doc.purpose = "Purchase Return" se.doc.purchase_receipt_no = pr.doc.name se.doc.posting_date = "2013-03-01" se.doc.fiscal_year = "_Test Fiscal Year 2013" se.doclist[1].qty = se.doclist[1].transfer_qty = 5 se.doclist[1].s_warehouse = "_Test Warehouse" se.insert() se.submit() actual_qty_2 = self._get_actual_qty() self.assertEquals(actual_qty_1 - 5, actual_qty_2) return se, pr.doc.name
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 po_doclist = webnotes.map_doclist( [["Material Request", "Purchase Order"], ["Material Request Item", "Purchase Order Item"]], mr.doc.name) po_doclist[0].fields.update({ "supplier": "_Test Supplier", "supplier_name": "_Test Supplier", "transaction_date": mr.doc.transaction_date, "fiscal_year": "_Test Fiscal Year 2013", "currency": "INR", "conversion_rate": 1.0, "grand_total_import": 0.0 }) po_doclist[1].qty = 27.0 po_doclist[2].qty = 1.5 # 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": 0 }, { "ordered_qty": 0 }, { "ordered_qty": 0 }]) self._test_requested_qty(54.0, 3.0)
def test_completed_qty_for_over_transfer(self): webnotes.conn.sql("""delete from `tabBin`""") webnotes.conn.sql("""delete from `tabStock Ledger Entry`""") # submit material request of type Purchase mr = webnotes.bean(copy=test_records[0]) mr.doc.material_request_type = "Transfer" 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 stock entry se_doclist = webnotes.map_doclist( [["Material Request", "Stock Entry"], ["Material Request Item", "Stock Entry Detail"]], mr.doc.name) se_doclist[0].fields.update({ "posting_date": "2013-03-01", "posting_time": "00:00", "fiscal_year": "_Test Fiscal Year 2013", }) se_doclist[1].fields.update({ "qty": 60.0, "transfer_qty": 60.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) se_doclist[2].fields.update({ "qty": 3.0, "transfer_qty": 3.0, "s_warehouse": "_Test Warehouse 1", "incoming_rate": 1.0 }) # make available the qty in _Test Warehouse 1 before transfer self._insert_stock_entry(60.0, 3.0) # check for stopped status of Material Request se = webnotes.bean(copy=se_doclist) se.insert() mr.obj.update_status('Stopped') self.assertRaises(webnotes.ValidationError, se.submit) self.assertRaises(webnotes.ValidationError, se.cancel) mr.obj.update_status('Submitted') se = webnotes.bean(copy=se_doclist) se.insert() se.submit() # check if per complete is as expected mr.load_from_db() self._test_expected(mr.doclist, [{ "per_ordered": 100 }, { "ordered_qty": 60.0 }, { "ordered_qty": 3.0 }]) self._test_requested_qty(0.0, 0.0) # check if per complete is as expected for Stock Entry cancelled se.cancel() mr.load_from_db() self._test_expected(mr.doclist, [{ "per_ordered": 0 }, { "ordered_qty": 0 }, { "ordered_qty": 0 }]) self._test_requested_qty(54.0, 3.0)