chore: Tests

- Added test for mapping secnd return doc
- Added test for billing % of partially returned doc
- Handled PR with 0 billing amount
This commit is contained in:
marination 2020-11-03 12:01:56 +05:30
parent 3991b84b2b
commit f21e3fbf04
3 changed files with 68 additions and 6 deletions

View File

@ -255,6 +255,32 @@ class TestDeliveryNote(unittest.TestCase):
self.assertEqual(dn.items[0].returned_qty, 2) self.assertEqual(dn.items[0].returned_qty, 2)
self.assertEqual(dn.per_returned, 40) self.assertEqual(dn.per_returned, 40)
from erpnext.controllers.sales_and_purchase_return import make_return_doc
return_dn_2 = make_return_doc("Delivery Note", dn.name)
# Check if unreturned amount is mapped in 2nd return
self.assertEqual(return_dn_2.items[0].qty, -3)
si = make_sales_invoice(dn.name)
si.submit()
self.assertEqual(si.items[0].qty, 3)
dn.load_from_db()
# DN should be completed on billing all unreturned amount
self.assertEqual(dn.items[0].billed_amt, 1500)
self.assertEqual(dn.per_billed, 100)
self.assertEqual(dn.status, 'Completed')
si.load_from_db()
si.cancel()
dn.load_from_db()
self.assertEqual(dn.per_billed, 0)
dn1.cancel()
dn.cancel()
def test_sales_return_for_non_bundled_items_full(self): def test_sales_return_for_non_bundled_items_full(self):
from erpnext.stock.doctype.item.test_item import make_item from erpnext.stock.doctype.item.test_item import make_item

View File

@ -513,7 +513,7 @@ def update_billed_amount_based_on_po(po_detail, update_modified=True):
where po_detail=%s and (pr_detail is null or pr_detail = '') and docstatus=1""", po_detail) where po_detail=%s and (pr_detail is null or pr_detail = '') and docstatus=1""", po_detail)
billed_against_po = billed_against_po and billed_against_po[0][0] or 0 billed_against_po = billed_against_po and billed_against_po[0][0] or 0
# Get all Delivery Note Item rows against the Sales Order Item row # Get all Purchase Receipt Item rows against the Purchase Order Item row
pr_details = frappe.db.sql("""select pr_item.name, pr_item.amount, pr_item.parent pr_details = frappe.db.sql("""select pr_item.name, pr_item.amount, pr_item.parent
from `tabPurchase Receipt Item` pr_item, `tabPurchase Receipt` pr from `tabPurchase Receipt Item` pr_item, `tabPurchase Receipt` pr
where pr.name=pr_item.parent and pr_item.purchase_order_item=%s where pr.name=pr_item.parent and pr_item.purchase_order_item=%s
@ -544,6 +544,9 @@ def update_billed_amount_based_on_po(po_detail, update_modified=True):
return updated_pr return updated_pr
def update_billing_percentage(pr_doc, update_modified=True): def update_billing_percentage(pr_doc, update_modified=True):
# Reload as billed amount was set in db directly
pr_doc.load_from_db()
# Update Billing % based on pending accepted qty # Update Billing % based on pending accepted qty
total_amount, total_billed_amount = 0, 0 total_amount, total_billed_amount = 0, 0
for item in pr_doc.items: for item in pr_doc.items:
@ -567,7 +570,7 @@ def update_billing_percentage(pr_doc, update_modified=True):
total_amount += total_billable_amount total_amount += total_billable_amount
total_billed_amount += flt(item.billed_amt) total_billed_amount += flt(item.billed_amt)
percent_billed = round(100 * (total_billed_amount / total_amount), 6) percent_billed = round(100 * (total_billed_amount / (total_amount or 1)), 6)
pr_doc.db_set("per_billed", percent_billed) pr_doc.db_set("per_billed", percent_billed)
pr_doc.load_from_db() pr_doc.load_from_db()

View File

@ -100,7 +100,10 @@ class TestPurchaseReceipt(unittest.TestCase):
self.assertFalse(frappe.db.get_all('Serial No', {'batch_no': batch_no})) self.assertFalse(frappe.db.get_all('Serial No', {'batch_no': batch_no}))
def test_purchase_receipt_gl_entry(self): def test_purchase_receipt_gl_entry(self):
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", get_multiple_items = True, get_taxes_and_charges = True) pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
get_multiple_items = True, get_taxes_and_charges = True)
self.assertEqual(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1) self.assertEqual(cint(erpnext.is_perpetual_inventory_enabled(pr.company)), 1)
gl_entries = get_gl_entries("Purchase Receipt", pr.name) gl_entries = get_gl_entries("Purchase Receipt", pr.name)
@ -245,10 +248,12 @@ class TestPurchaseReceipt(unittest.TestCase):
pr.get("items")[0].rejected_warehouse) pr.get("items")[0].rejected_warehouse)
def test_purchase_return_partial(self): def test_purchase_return_partial(self):
pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1",
return_pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1", is_return=1, return_against=pr.name, qty=-2, do_not_submit=1) is_return=1, return_against=pr.name, qty=-2, do_not_submit=1)
return_pr.items[0].purchase_receipt_item = pr.items[0].name return_pr.items[0].purchase_receipt_item = pr.items[0].name
return_pr.submit() return_pr.submit()
@ -283,6 +288,33 @@ class TestPurchaseReceipt(unittest.TestCase):
self.assertEqual(pr.items[0].returned_qty, 2) self.assertEqual(pr.items[0].returned_qty, 2)
self.assertEqual(pr.per_returned, 40) self.assertEqual(pr.per_returned, 40)
from erpnext.controllers.sales_and_purchase_return import make_return_doc
return_pr_2 = make_return_doc("Purchase Receipt", pr.name)
# Check if unreturned amount is mapped in 2nd return
self.assertEqual(return_pr_2.items[0].qty, -3)
# Make PI against unreturned amount
pi = make_purchase_invoice(pr.name)
pi.submit()
self.assertEqual(pi.items[0].qty, 3)
pr.load_from_db()
# PR should be completed on billing all unreturned amount
self.assertEqual(pr.items[0].billed_amt, 150)
self.assertEqual(pr.per_billed, 100)
self.assertEqual(pr.status, 'Completed')
pi.load_from_db()
pi.cancel()
pr.load_from_db()
self.assertEqual(pr.per_billed, 0)
return_pr.cancel()
pr.cancel()
def test_purchase_return_full(self): def test_purchase_return_full(self):
pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1") pr = make_purchase_receipt(company="_Test Company with perpetual inventory", warehouse = "Stores - TCP1", supplier_warehouse = "Work in Progress - TCP1")
@ -406,6 +438,7 @@ class TestPurchaseReceipt(unittest.TestCase):
self.assertEqual(pr1.per_billed, 100) self.assertEqual(pr1.per_billed, 100)
self.assertEqual(pr1.status, "Completed") self.assertEqual(pr1.status, "Completed")
pr2.load_from_db()
self.assertEqual(pr2.get("items")[0].billed_amt, 2000) self.assertEqual(pr2.get("items")[0].billed_amt, 2000)
self.assertEqual(pr2.per_billed, 80) self.assertEqual(pr2.per_billed, 80)
self.assertEqual(pr2.status, "To Bill") self.assertEqual(pr2.status, "To Bill")