mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
refactor: budget controller
This commit is contained in:
@@ -409,6 +409,10 @@ def validate_budget_records(args, budget_records, expense_amount):
|
|||||||
args["for_material_request"] = budget.for_material_request
|
args["for_material_request"] = budget.for_material_request
|
||||||
args["for_purchase_order"] = budget.for_purchase_order
|
args["for_purchase_order"] = budget.for_purchase_order
|
||||||
args["from_fiscal_year"], args["to_fiscal_year"] = budget.from_fiscal_year, budget.to_fiscal_year
|
args["from_fiscal_year"], args["to_fiscal_year"] = budget.from_fiscal_year, budget.to_fiscal_year
|
||||||
|
args["budget_start_date"], args["budget_end_date"] = (
|
||||||
|
budget.budget_start_date,
|
||||||
|
budget.budget_end_date,
|
||||||
|
)
|
||||||
|
|
||||||
if yearly_action in ("Stop", "Warn"):
|
if yearly_action in ("Stop", "Warn"):
|
||||||
compare_expense_with_budget(
|
compare_expense_with_budget(
|
||||||
|
|||||||
@@ -162,16 +162,19 @@ class BudgetValidation:
|
|||||||
|
|
||||||
def get_budget_records(self) -> list:
|
def get_budget_records(self) -> list:
|
||||||
bud = qb.DocType("Budget")
|
bud = qb.DocType("Budget")
|
||||||
bud_acc = qb.DocType("Budget Account")
|
|
||||||
query = (
|
query = (
|
||||||
qb.from_(bud)
|
qb.from_(bud)
|
||||||
.inner_join(bud_acc)
|
|
||||||
.on(bud.name == bud_acc.parent)
|
|
||||||
.select(
|
.select(
|
||||||
bud.name,
|
bud.name,
|
||||||
bud.budget_against,
|
bud.budget_against,
|
||||||
bud.company,
|
bud.company,
|
||||||
bud.monthly_distribution,
|
bud.account,
|
||||||
|
bud.budget_amount,
|
||||||
|
bud.from_fiscal_year,
|
||||||
|
bud.to_fiscal_year,
|
||||||
|
bud.budget_start_date,
|
||||||
|
bud.budget_end_date,
|
||||||
bud.applicable_on_material_request,
|
bud.applicable_on_material_request,
|
||||||
bud.action_if_annual_budget_exceeded_on_mr,
|
bud.action_if_annual_budget_exceeded_on_mr,
|
||||||
bud.action_if_accumulated_monthly_budget_exceeded_on_mr,
|
bud.action_if_accumulated_monthly_budget_exceeded_on_mr,
|
||||||
@@ -184,13 +187,15 @@ class BudgetValidation:
|
|||||||
bud.applicable_on_cumulative_expense,
|
bud.applicable_on_cumulative_expense,
|
||||||
bud.action_if_annual_exceeded_on_cumulative_expense,
|
bud.action_if_annual_exceeded_on_cumulative_expense,
|
||||||
bud.action_if_accumulated_monthly_exceeded_on_cumulative_expense,
|
bud.action_if_accumulated_monthly_exceeded_on_cumulative_expense,
|
||||||
bud_acc.account,
|
|
||||||
bud_acc.budget_amount,
|
|
||||||
)
|
)
|
||||||
.where(bud.docstatus.eq(1) & bud.fiscal_year.eq(self.fiscal_year) & bud.company.eq(self.company))
|
.where(
|
||||||
|
(bud.docstatus == 1)
|
||||||
|
& (bud.company == self.company)
|
||||||
|
& (bud.budget_start_date <= self.doc_date)
|
||||||
|
& (bud.budget_end_date >= self.doc_date)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# add dimension fields
|
|
||||||
for x in self.dimensions:
|
for x in self.dimensions:
|
||||||
query = query.select(bud[x.get("fieldname")])
|
query = query.select(bud[x.get("fieldname")])
|
||||||
|
|
||||||
@@ -312,8 +317,8 @@ class BudgetValidation:
|
|||||||
frappe.bold(key[2]),
|
frappe.bold(key[2]),
|
||||||
frappe.bold(frappe.unscrub(key[0])),
|
frappe.bold(frappe.unscrub(key[0])),
|
||||||
frappe.bold(key[1]),
|
frappe.bold(key[1]),
|
||||||
frappe.bold(fmt_money(annual_diff, currency=currency)),
|
|
||||||
frappe.bold(fmt_money(budget_amt, currency=currency)),
|
frappe.bold(fmt_money(budget_amt, currency=currency)),
|
||||||
|
frappe.bold(fmt_money(annual_diff, currency=currency)),
|
||||||
)
|
)
|
||||||
self.execute_action(config.action_for_annual, _msg)
|
self.execute_action(config.action_for_annual, _msg)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user