Merge pull request #14070 from rohitwaghchaure/budget_validation_project_condition

Added project condition in budget validation
This commit is contained in:
rohitwaghchaure 2018-05-16 12:19:31 +05:30 committed by GitHub
commit b13a4480db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 7 deletions

View File

@ -181,28 +181,41 @@ def get_amount(args, budget):
amount = 0
if args.get('doctype') == 'Material Request' and budget.for_material_request:
amount = (get_requested_amount(args.item_code)
+ get_ordered_amount(args.item_code) + get_actual_expense(args))
amount = (get_requested_amount(args)
+ get_ordered_amount(args) + get_actual_expense(args))
elif args.get('doctype') == 'Purchase Order' and budget.for_purchase_order:
amount = get_ordered_amount(args.item_code) + get_actual_expense(args)
amount = get_ordered_amount(args) + get_actual_expense(args)
return amount
def get_requested_amount(item_code):
def get_requested_amount(args):
item_code = args.get('item_code')
condition = get_project_condiion(args)
data = frappe.db.sql(""" select ifnull((sum(stock_qty - ordered_qty) * rate), 0) as amount
from `tabMaterial Request Item` where item_code = %s and docstatus = 1
and stock_qty > ordered_qty """, item_code, as_list=1)
and stock_qty > ordered_qty and {0}""".format(condition), item_code, as_list=1)
return data[0][0] if data else 0
def get_ordered_amount(item_code):
def get_ordered_amount(args):
item_code = args.get('item_code')
condition = get_project_condiion(args)
data = frappe.db.sql(""" select ifnull(sum(amount - billed_amt), 0) as amount
from `tabPurchase Order Item` where item_code = %s and docstatus = 1
and amount > billed_amt""", item_code, as_list=1)
and amount > billed_amt and {0}""".format(condition), item_code, as_list=1)
return data[0][0] if data else 0
def get_project_condiion(args):
condition = "1=1"
if args.get('project'):
condition = "project = '%s'" %(args.get('project'))
return condition
def get_actual_expense(args):
condition1 = " and gle.posting_date <= %(month_end_date)s" \
if args.get("month_end_date") else ""

View File

@ -473,6 +473,7 @@ class BuyingController(StockController):
'item_code': data.item_code,
'item_group': data.item_group,
'posting_date': data.schedule_date,
'project': data.project,
'doctype': self.doctype
}, self.company)