Skip to content

Commit

Permalink
fix: incorrect Difference Amount (#42008)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Jun 24, 2024
1 parent 379a290 commit 7d91c6c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
17 changes: 12 additions & 5 deletions erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,9 @@ def _changed(item):
fields=["total_qty as qty", "avg_rate as rate"],
)[0]

bundle_data.qty = abs(bundle_data.qty)
self.calculate_difference_amount(item, bundle_data)

return True

inventory_dimensions_dict = {}
Expand Down Expand Up @@ -464,11 +466,16 @@ def _changed(item):
frappe.msgprint(_("Removed items with no change in quantity or value."))

def calculate_difference_amount(self, item, item_dict):
self.difference_amount += flt(item.qty, item.precision("qty")) * flt(
item.valuation_rate or item_dict.get("rate"), item.precision("valuation_rate")
) - flt(item_dict.get("qty"), item.precision("qty")) * flt(
item_dict.get("rate"), item.precision("valuation_rate")
)
qty_precision = item.precision("qty")
val_precision = item.precision("valuation_rate")

new_qty = flt(item.qty, qty_precision)
new_valuation_rate = flt(item.valuation_rate or item_dict.get("rate"), val_precision)

current_qty = flt(item_dict.get("qty"), qty_precision)
current_valuation_rate = flt(item_dict.get("rate"), val_precision)

self.difference_amount += (new_qty * new_valuation_rate) - (current_qty * current_valuation_rate)

def validate_data(self):
def _get_msg(row_num, msg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,7 @@ def test_not_reconcile_all_batch(self):
)

sr.reload()
self.assertEqual(sr.difference_amount, 98900.0)

self.assertTrue(sr.items[0].current_valuation_rate)
current_sabb = sr.items[0].current_serial_and_batch_bundle
Expand Down

0 comments on commit 7d91c6c

Please sign in to comment.