mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 07:32:50 +00:00
refactor: handle budget for material request
This commit is contained in:
@@ -18,7 +18,9 @@ class BudgetValidation:
|
|||||||
self.doc = doc
|
self.doc = doc
|
||||||
self.company = doc.get("company")
|
self.company = doc.get("company")
|
||||||
self.doc_date = (
|
self.doc_date = (
|
||||||
doc.get("transaction_date") if doc.get("doctype") == "Purchase Order" else doc.get("posting_date")
|
doc.get("transaction_date")
|
||||||
|
if doc.get("doctype") in ["Purchase Order", "Material Request"]
|
||||||
|
else doc.get("posting_date")
|
||||||
)
|
)
|
||||||
fy = get_fiscal_year(self.doc_date)
|
fy = get_fiscal_year(self.doc_date)
|
||||||
self.fiscal_year = fy[0]
|
self.fiscal_year = fy[0]
|
||||||
@@ -167,7 +169,6 @@ class BudgetValidation:
|
|||||||
conditions.append(mr.material_request_type.eq("Purchase"))
|
conditions.append(mr.material_request_type.eq("Purchase"))
|
||||||
conditions.append(mr.status.ne("Stopped"))
|
conditions.append(mr.status.ne("Stopped"))
|
||||||
conditions.append(mr.transaction_date[self.fy_start_date : self.fy_end_date])
|
conditions.append(mr.transaction_date[self.fy_start_date : self.fy_end_date])
|
||||||
conditions.append(mri.amount.gt(mri.billed_amt))
|
|
||||||
conditions.append(mri.expense_account.isin(exp_accounts))
|
conditions.append(mri.expense_account.isin(exp_accounts))
|
||||||
conditions.append(mri.item_code.isin(items))
|
conditions.append(mri.item_code.isin(items))
|
||||||
|
|
||||||
@@ -200,6 +201,20 @@ class BudgetValidation:
|
|||||||
)
|
)
|
||||||
frappe.throw(_msg, BudgetExceededError, title=_("Budget Exceeded"))
|
frappe.throw(_msg, BudgetExceededError, title=_("Budget Exceeded"))
|
||||||
|
|
||||||
|
if budget.applicable_on_material_request and v_map.get("requested_amount") > v_map.get(
|
||||||
|
"budget_amount"
|
||||||
|
):
|
||||||
|
# TODO: handle monthly accumulation
|
||||||
|
# action_if_accumulated_monthly_budget_exceeded_on_po,
|
||||||
|
if budget.action_if_annual_budget_exceeded_on_po == "Warn":
|
||||||
|
msg.append("some warning message")
|
||||||
|
|
||||||
|
if budget.action_if_annual_budget_exceeded_on_po == "Stop":
|
||||||
|
_msg = _(
|
||||||
|
"Expenses have gone above budget: {}".format(get_link_to_form("Budget", budget.name))
|
||||||
|
)
|
||||||
|
frappe.throw(_msg, BudgetExceededError, title=_("Budget Exceeded"))
|
||||||
|
|
||||||
def validate_for_overbooking(self):
|
def validate_for_overbooking(self):
|
||||||
# TODO: Need to fetch historical amount and add them to the current document; GL effect is pending
|
# TODO: Need to fetch historical amount and add them to the current document; GL effect is pending
|
||||||
# TODO: handle applicable checkboxes
|
# TODO: handle applicable checkboxes
|
||||||
|
|||||||
Reference in New Issue
Block a user