diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index 2bd5cc55773..fe3bb8cd4cc 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -6,7 +6,6 @@ import frappe from frappe import _, scrub from erpnext.stock.utils import get_incoming_rate from erpnext.controllers.queries import get_match_cond -from erpnext.stock.stock_ledger import get_valuation_rate from frappe.utils import flt @@ -248,6 +247,7 @@ class GrossProfitGenerator(object): return 0.0 def get_average_buying_rate(self, row, item_code): + args = row if not item_code in self.average_buying_rate: if item_code in self.non_stock_items: self.average_buying_rate[item_code] = flt(frappe.db.sql(""" @@ -255,14 +255,14 @@ class GrossProfitGenerator(object): from `tabPurchase Invoice Item` where item_code = %s and docstatus=1""", item_code)[0][0]) else: - row.voucher_type = row.parenttype - row.voucher_no = row.parent - average_buying_rate = get_incoming_rate(row) - if not average_buying_rate: - average_buying_rate = get_valuation_rate(item_code, row.warehouse, - row.parenttype, row.parent, allow_zero_rate=row.allow_zero_valuation, - currency=self.filters.currency, company=self.filters.company) + args.update({ + 'voucher_type': row.parenttype, + 'voucher_no': row.parent, + 'allow_zero_valuation': True, + 'company': self.filters.company + }) + average_buying_rate = get_incoming_rate(args) self.average_buying_rate[item_code] = flt(average_buying_rate) return self.average_buying_rate[item_code] @@ -311,8 +311,7 @@ class GrossProfitGenerator(object): `tabSales Invoice Item`.brand, `tabSales Invoice Item`.dn_detail, `tabSales Invoice Item`.delivery_note, `tabSales Invoice Item`.stock_qty as qty, `tabSales Invoice Item`.base_net_rate, `tabSales Invoice Item`.base_net_amount, - `tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return, - `tabSales Invoice Item`.allow_zero_valuation_rate as "allow_zero_valuation" + `tabSales Invoice Item`.name as "item_row", `tabSales Invoice`.is_return {sales_person_cols} from `tabSales Invoice` inner join `tabSales Invoice Item` diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index ae71f355b60..9b2fcb7088f 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -144,10 +144,9 @@ def get_incoming_rate(args): if not in_rate: voucher_no = args.get('voucher_no') or args.get('name') - in_rate = get_valuation_rate(args.get('item_code'), args.get('warehouse'), args.get('voucher_type'), voucher_no, args.get('allow_zero_valuation'), - currency=erpnext.get_company_currency(args.get('company'))) + currency=erpnext.get_company_currency(args.get('company')), company=args.get('company')) return in_rate