Allow to make budget for the same cost center with different account (#15149)
This commit is contained in:
parent
0631aed3d9
commit
6fb2117767
@ -27,12 +27,20 @@ class Budget(Document):
|
|||||||
def validate_duplicate(self):
|
def validate_duplicate(self):
|
||||||
budget_against_field = frappe.scrub(self.budget_against)
|
budget_against_field = frappe.scrub(self.budget_against)
|
||||||
budget_against = self.get(budget_against_field)
|
budget_against = self.get(budget_against_field)
|
||||||
existing_budget = frappe.db.get_value("Budget", {budget_against_field: budget_against,
|
|
||||||
"fiscal_year": self.fiscal_year, "company": self.company,
|
accounts = [d.account for d in self.accounts] or []
|
||||||
"name": ["!=", self.name], "docstatus": ["!=", 2]})
|
existing_budget = frappe.db.sql("""
|
||||||
if existing_budget:
|
select
|
||||||
frappe.throw(_("Another Budget record '{0}' already exists against {1} '{2}' for fiscal year {3}")
|
b.name, ba.account from `tabBudget` b, `tabBudget Account` ba
|
||||||
.format(existing_budget, self.budget_against, budget_against, self.fiscal_year), DuplicateBudgetError)
|
where
|
||||||
|
ba.parent = b.name and b.company = %s and %s=%s and
|
||||||
|
b.fiscal_year=%s and b.name != %sand ba.account in (%s) """
|
||||||
|
% ('%s', budget_against_field, '%s', '%s', '%s', ','.join(['%s'] * len(accounts))),
|
||||||
|
(self.company, budget_against, self.fiscal_year, self.name) + tuple(accounts), as_dict=1)
|
||||||
|
|
||||||
|
for d in existing_budget:
|
||||||
|
frappe.throw(_("Another Budget record '{0}' already exists against {1} '{2}' and account '{3}' for fiscal year {4}")
|
||||||
|
.format(d.name, self.budget_against, budget_against, d.account, self.fiscal_year), DuplicateBudgetError)
|
||||||
|
|
||||||
def validate_accounts(self):
|
def validate_accounts(self):
|
||||||
account_list = []
|
account_list = []
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user