Skip to content

Commit

Permalink
fix: Overallocation of 'qty' from Cr Notes to Parent Invoice
Browse files Browse the repository at this point in the history
Cr Notes 'qty' are overallocated to parent invoice, when there are
mulitple instances of same item in Invoice.
  • Loading branch information
ruthra-kumar committed Mar 20, 2023
1 parent baa789b commit 848e56b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion erpnext/accounts/report/gross_profit/gross_profit.py
Expand Up @@ -501,7 +501,14 @@ def get_average_rate_based_on_group_by(self):
):
returned_item_rows = self.returned_invoices[row.parent][row.item_code]
for returned_item_row in returned_item_rows:
row.qty += flt(returned_item_row.qty)
# returned_items 'qty' should be stateful
if returned_item_row.qty != 0:
if row.qty >= abs(returned_item_row.qty):
row.qty += returned_item_row.qty
returned_item_row.qty = 0
else:
row.qty = 0
returned_item_row.qty += row.qty
row.base_amount += flt(returned_item_row.base_amount, self.currency_precision)
row.buying_amount = flt(flt(row.qty) * flt(row.buying_rate), self.currency_precision)
if flt(row.qty) or row.base_amount:
Expand Down

0 comments on commit 848e56b

Please sign in to comment.