mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-30 02:14:48 +00:00
refactor: cleaner initialization
This commit is contained in:
@@ -14,23 +14,25 @@ class BudgetExceededError(frappe.ValidationError):
|
|||||||
|
|
||||||
|
|
||||||
class BudgetValidation:
|
class BudgetValidation:
|
||||||
def __init__(self, doc: object):
|
def __init__(self, doc: object | None = None, gl_map: list | None = None):
|
||||||
self.doc = doc
|
if doc:
|
||||||
self.company = doc.get("company")
|
self.document_type = doc.get("doctype")
|
||||||
self.doc_date = (
|
self.doc = doc
|
||||||
doc.get("transaction_date")
|
self.company = doc.get("company")
|
||||||
if doc.get("doctype") in ["Purchase Order", "Material Request"]
|
self.doc_date = doc.get("transaction_date")
|
||||||
else doc.get("posting_date")
|
elif gl_map:
|
||||||
)
|
# When GL Map is passed, there is a possibility of multiple fiscal year.
|
||||||
|
# TODO: need to handle it
|
||||||
|
self.document_type = "GL Map"
|
||||||
|
self.gl_map = gl_map
|
||||||
|
self.company = gl_map[0].company
|
||||||
|
self.doc_date = gl_map[0].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]
|
||||||
self.fy_start_date = fy[1]
|
self.fy_start_date = fy[1]
|
||||||
self.fy_end_date = fy[2]
|
self.fy_end_date = fy[2]
|
||||||
self.get_dimensions()
|
self.get_dimensions()
|
||||||
# TODO: handle GL map
|
|
||||||
|
|
||||||
# When GL Map is passed, there is a possibility of multiple fiscal year.
|
|
||||||
# TODO: need to handle it
|
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
self.build_validation_map()
|
self.build_validation_map()
|
||||||
@@ -77,7 +79,6 @@ class BudgetValidation:
|
|||||||
key structure - (dimension_type, dimension, GL account)
|
key structure - (dimension_type, dimension, GL account)
|
||||||
"""
|
"""
|
||||||
_budgets = self.get_budget_records()
|
_budgets = self.get_budget_records()
|
||||||
_keys = []
|
|
||||||
self.budget_map = OrderedDict()
|
self.budget_map = OrderedDict()
|
||||||
for _bud in _budgets:
|
for _bud in _budgets:
|
||||||
budget_against = frappe.scrub(_bud.budget_against)
|
budget_against = frappe.scrub(_bud.budget_against)
|
||||||
@@ -92,7 +93,6 @@ class BudgetValidation:
|
|||||||
key structure - (dimension_type, dimension, GL account)
|
key structure - (dimension_type, dimension, GL account)
|
||||||
"""
|
"""
|
||||||
self.doc_or_item_map = OrderedDict()
|
self.doc_or_item_map = OrderedDict()
|
||||||
_key = []
|
|
||||||
for itm in self.doc.items:
|
for itm in self.doc.items:
|
||||||
for dim in self.dimensions:
|
for dim in self.dimensions:
|
||||||
if itm.get(dim.get("fieldname")):
|
if itm.get(dim.get("fieldname")):
|
||||||
|
|||||||
@@ -777,7 +777,7 @@ class BuyingController(SubcontractingController):
|
|||||||
def validate_budget(self):
|
def validate_budget(self):
|
||||||
from erpnext.controllers.budget_controller import BudgetValidation
|
from erpnext.controllers.budget_controller import BudgetValidation
|
||||||
|
|
||||||
val = BudgetValidation(self)
|
val = BudgetValidation(doc=self)
|
||||||
val.validate()
|
val.validate()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user