[fix] [patch]

This commit is contained in:
Rushabh Mehta 2016-05-24 16:10:21 +05:30
parent c96c4d6424
commit 1885645d6d
2 changed files with 45 additions and 37 deletions

View File

@ -10,6 +10,7 @@ from frappe.model.naming import make_autoname
from frappe.model.document import Document
class BudgetError(frappe.ValidationError): pass
class DuplicateBudgetError(frappe.ValidationError): pass
class Budget(Document):
def autoname(self):
@ -25,7 +26,7 @@ class Budget(Document):
"name": ["!=", self.name], "docstatus": ["!=", 2]})
if existing_budget:
frappe.throw(_("Another Budget record {0} already exists against {1} for fiscal year {2}")
.format(existing_budget, self.cost_center, self.fiscal_year))
.format(existing_budget, self.cost_center, self.fiscal_year), DuplicateBudgetError)
def validate_accounts(self):
account_list = []

View File

@ -1,5 +1,7 @@
import frappe
from erpnext.accounts.doctype.budget.budget import DuplicateBudgetError
def execute():
frappe.reload_doc("accounts", "doctype", "budget")
frappe.reload_doc("accounts", "doctype", "budget_account")
@ -29,7 +31,9 @@ def execute():
budget.fiscal_year = d.fiscal_year
budget.monthly_distribution = d.distribution_id
budget.company = d.company
if actions[d.company]["yearly_bgt_flag"]:
budget.action_if_annual_budget_exceeded = actions[d.company]["yearly_bgt_flag"]
if actions[d.company]["monthly_bgt_flag"]:
budget.action_if_accumulated_monthly_budget_exceeded = actions[d.company]["monthly_bgt_flag"]
else:
budget = frappe.get_doc("Budget", budget)
@ -39,8 +43,11 @@ def execute():
"budget_amount": d.budget_allocated
})
try:
budget.insert()
budget_records.append(budget)
except DuplicateBudgetError:
pass
for budget in budget_records:
budget.submit()