Skip to content

Commit

Permalink
perf: extract loop invariant db calls
Browse files Browse the repository at this point in the history
  • Loading branch information
ankush committed Sep 20, 2021
1 parent 4f7af79 commit 648b2d7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions erpnext/controllers/accounts_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,6 +980,9 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
item_allowance = {}
global_qty_allowance, global_amount_allowance = None, None

role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')
user_roles = frappe.get_roles()

for item in self.get("items"):
if item.get(item_ref_dn):
ref_amt = flt(frappe.db.get_value(ref_dt + " Item",
Expand Down Expand Up @@ -1009,9 +1012,7 @@ def validate_multiple_billing(self, ref_dt, item_ref_dn, based_on, parentfield):
total_billed_amt = abs(total_billed_amt)
max_allowed_amt = abs(max_allowed_amt)

role_allowed_to_over_bill = frappe.db.get_single_value('Accounts Settings', 'role_allowed_to_over_bill')

if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in frappe.get_roles():
if total_billed_amt - max_allowed_amt > 0.01 and role_allowed_to_over_bill not in user_roles:
if self.doctype != "Purchase Invoice":
self.throw_overbill_exception(item, max_allowed_amt)
elif not cint(frappe.db.get_single_value("Buying Settings", "bill_for_rejected_quantity_in_purchase_invoice")):
Expand Down

0 comments on commit 648b2d7

Please sign in to comment.