Skip to content

Commit

Permalink
fix: wrong buying amount if delivered and billed qty varies
Browse files Browse the repository at this point in the history
(cherry picked from commit b8da0d9)
  • Loading branch information
rtdany10 authored and mergify[bot] committed Mar 21, 2024
1 parent c072cd9 commit 2b31113
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions erpnext/accounts/report/gross_profit/gross_profit.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,20 +669,20 @@ def get_buying_amount(self, row, item_code):
elif row.sales_order and row.so_detail:
incoming_amount = self.get_buying_amount_from_so_dn(row.sales_order, row.so_detail, item_code)
if incoming_amount:
return incoming_amount
return flt(row.qty) * incoming_amount
else:
return flt(row.qty) * self.get_average_buying_rate(row, item_code)

return flt(row.qty) * self.get_average_buying_rate(row, item_code)

def get_buying_amount_from_so_dn(self, sales_order, so_detail, item_code):
from frappe.query_builder.functions import Sum
from frappe.query_builder.functions import Avg

delivery_note_item = frappe.qb.DocType("Delivery Note Item")

query = (
frappe.qb.from_(delivery_note_item)
.select(Sum(delivery_note_item.incoming_rate * delivery_note_item.stock_qty))
.select(Avg(delivery_note_item.incoming_rate))
.where(delivery_note_item.docstatus == 1)
.where(delivery_note_item.item_code == item_code)
.where(delivery_note_item.against_sales_order == sales_order)
Expand Down

0 comments on commit 2b31113

Please sign in to comment.