Skip to content

Commit

Permalink
test: increase assertions to cover all cases
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Apr 12, 2022
1 parent 2a0f105 commit 3fe9b13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion erpnext/stock/report/stock_balance/stock_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ def get_items(filters: StockBalanceFilter):
if brand := filters.get("brand"):
item_filters["brand"] = brand

return frappe.get_all("Item", filters=item_filters, pluck="name", order_by=None, debug=1)
return frappe.get_all("Item", filters=item_filters, pluck="name", order_by=None)


def get_item_details(items, sle, filters: StockBalanceFilter):
Expand Down
10 changes: 7 additions & 3 deletions erpnext/stock/report/stock_balance/test_stock_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ def assertInvariants(self, rows):
# value invariant
self.assertAlmostEqual(row.bal_val, row.opening_val + row.in_val - row.out_val, msg)

# valuation rate
self.assertAlmostEqual(row.val_rate, row.bal_val / row.bal_qty, 3, msg)

# check against SLE
last_sle = item_wh_stock[(row.item_code, row.warehouse)]
self.assertAlmostEqual(row.bal_qty, last_sle.qty_after_transaction, 3)
self.assertAlmostEqual(row.bal_val, last_sle.stock_value, 3)

# valuation rate
if not row.bal_qty:
continue
self.assertAlmostEqual(row.val_rate, row.bal_val / row.bal_qty, 3, msg)

# ----------- tests

def test_basic_stock_balance(self):
Expand Down Expand Up @@ -133,6 +135,7 @@ def test_uom_converted_info(self):

rows = stock_balance(self.filters.update({"include_uom": "Box"}))
self.assertEqual(rows[0].bal_qty_alt, 1)
self.assertInvariants(rows)

def test_item_group(self):
self.filters.pop("item_code", None)
Expand Down Expand Up @@ -167,3 +170,4 @@ def test_show_item_attr(self):
self.filters.update({"show_variant_attributes": 1, "item_code": variant.name})
)
self.assertPartialDictEq(attributes, rows[0])
self.assertInvariants(rows)

0 comments on commit 3fe9b13

Please sign in to comment.