mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-27 00:44:45 +00:00
refactor: always query booked expenses
This commit is contained in:
@@ -76,27 +76,21 @@ class BudgetValidation:
|
|||||||
|
|
||||||
def validate_for_overbooking(self):
|
def validate_for_overbooking(self):
|
||||||
for key, v in self.to_validate.items():
|
for key, v in self.to_validate.items():
|
||||||
if self.document_type == "Purchase Order":
|
self.get_ordered_amount(key)
|
||||||
self.get_ordered_amount(key)
|
self.get_requested_amount(key)
|
||||||
|
|
||||||
if self.document_type == "Material Request":
|
# Validation happens after submit for Purchase Order and
|
||||||
self.get_requested_amount(key)
|
# Material Request and so will be included in the query
|
||||||
|
# result
|
||||||
# Amt from current Purchase Order is included in `self.ordered_amount` as doc is
|
if self.document_type in ["Purchase Order", "Material Request"]:
|
||||||
# in submitted status by the time validation happens
|
|
||||||
if self.document_type in "Purchase Order":
|
|
||||||
v["current_amount"] = 0
|
v["current_amount"] = 0
|
||||||
elif self.document_type in "Material Request":
|
|
||||||
v["current_amount"] = sum([x.amount for x in v.get("items_to_process", [])])
|
|
||||||
elif self.document_type == "GL Map":
|
elif self.document_type == "GL Map":
|
||||||
v["current_amount"] = sum([x.debit - x.credit for x in v.get("gl_to_process", [])])
|
v["current_amount"] = sum([x.debit - x.credit for x in v.get("gl_to_process", [])])
|
||||||
|
|
||||||
# If limit breached, exit early
|
# If limit breached, exit early
|
||||||
self.handle_action(v)
|
self.handle_action(v)
|
||||||
|
|
||||||
if self.document_type == "GL Map":
|
self.get_actual_expense(key)
|
||||||
self.get_actual_expense(key)
|
|
||||||
|
|
||||||
self.handle_action(v)
|
self.handle_action(v)
|
||||||
|
|
||||||
def build_budget_keys_and_map(self):
|
def build_budget_keys_and_map(self):
|
||||||
@@ -206,8 +200,9 @@ class BudgetValidation:
|
|||||||
.where(Criterion.all(conditions))
|
.where(Criterion.all(conditions))
|
||||||
.run(as_dict=True)
|
.run(as_dict=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
if ordered_amount:
|
if ordered_amount:
|
||||||
self.to_validate[key]["ordered_amount"] = ordered_amount[0].amount
|
self.to_validate[key]["ordered_amount"] = ordered_amount[0].amount or 0
|
||||||
|
|
||||||
def get_requested_amount(self, key: tuple | None = None):
|
def get_requested_amount(self, key: tuple | None = None):
|
||||||
if key:
|
if key:
|
||||||
@@ -237,8 +232,9 @@ class BudgetValidation:
|
|||||||
.where(Criterion.all(conditions))
|
.where(Criterion.all(conditions))
|
||||||
.run(as_dict=True)
|
.run(as_dict=True)
|
||||||
)
|
)
|
||||||
|
|
||||||
if requested_amount:
|
if requested_amount:
|
||||||
self.to_validate[key]["requested_amount"] = requested_amount[0].amount
|
self.to_validate[key]["requested_amount"] = requested_amount[0].amount or 0
|
||||||
|
|
||||||
def get_actual_expense(self, key: tuple | None = None):
|
def get_actual_expense(self, key: tuple | None = None):
|
||||||
if key:
|
if key:
|
||||||
@@ -363,3 +359,4 @@ class BudgetValidation:
|
|||||||
get_link_to_form("Budget", budget.name),
|
get_link_to_form("Budget", budget.name),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.stop(_msg)
|
||||||
|
|||||||
Reference in New Issue
Block a user