Merge pull request #1654 from nabinhait/v4-hotfix

fixes and patches
This commit is contained in:
Pratik Vyas 2014-05-15 18:11:39 +05:30
commit 740dd447b4
4 changed files with 77 additions and 37 deletions

View File

@ -3,38 +3,43 @@
from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.widgets.reportview import execute as runreport
def execute(filters=None):
if not filters: filters = {}
employee_filters = filters.get("company") and \
[["Employee", "company", "=", filters.get("company")]] or None
employees = runreport(doctype="Employee", fields=["name", "employee_name", "department"],
filters=employee_filters)
if not employees:
frappe.throw(_("No employee found!"))
leave_types = frappe.db.sql_list("select name from `tabLeave Type`")
if filters.get("fiscal_year"):
fiscal_years = [filters["fiscal_year"]]
else:
fiscal_years = frappe.db.sql_list("select name from `tabFiscal Year` order by name desc")
allocations = frappe.db.sql("""select employee, fiscal_year, leave_type, total_leaves_allocated
from `tabLeave Allocation`
where docstatus=1 and employee in (%s)""" %
from `tabLeave Allocation`
where docstatus=1 and employee in (%s)""" %
','.join(['%s']*len(employees)), employees, as_dict=True)
applications = frappe.db.sql("""select employee, fiscal_year, leave_type,
applications = frappe.db.sql("""select employee, fiscal_year, leave_type,
SUM(total_leave_days) as leaves
from `tabLeave Application`
from `tabLeave Application`
where status="Approved" and docstatus = 1 and employee in (%s)
group by employee, fiscal_year, leave_type""" %
group by employee, fiscal_year, leave_type""" %
','.join(['%s']*len(employees)), employees, as_dict=True)
columns = [
"Fiscal Year", "Employee:Link/Employee:150", "Employee Name::200", "Department::150"
]
for leave_type in leave_types:
columns.append(leave_type + " Allocated:Float")
columns.append(leave_type + " Taken:Float")
@ -42,13 +47,13 @@ def execute(filters=None):
data = {}
for d in allocations:
data.setdefault((d.fiscal_year, d.employee,
data.setdefault((d.fiscal_year, d.employee,
d.leave_type), frappe._dict()).allocation = d.total_leaves_allocated
for d in applications:
data.setdefault((d.fiscal_year, d.employee,
data.setdefault((d.fiscal_year, d.employee,
d.leave_type), frappe._dict()).leaves = d.leaves
result = []
for fiscal_year in fiscal_years:
for employee in employees:
@ -60,4 +65,4 @@ def execute(filters=None):
row.append(tmp.leaves or 0)
row.append((tmp.allocation or 0) - (tmp.leaves or 0))
return columns, result
return columns, result

View File

@ -4,6 +4,7 @@ erpnext.patches.v4_0.validate_v3_patch
erpnext.patches.v4_0.update_user_properties
erpnext.patches.v4_0.move_warehouse_user_to_restrictions
erpnext.patches.v4_0.new_permissions
erpnext.patches.v4_0.global_defaults_to_system_settings
erpnext.patches.v4_0.update_incharge_name_to_sales_person_in_maintenance_schedule
execute:frappe.reload_doc('accounts', 'doctype', 'sales_invoice') # 2014-01-29
execute:frappe.reload_doc('selling', 'doctype', 'sales_order') # 2014-01-29
@ -42,3 +43,4 @@ execute:frappe.delete_doc_if_exists("DocType", "Warehouse User")
execute:frappe.db.sql("delete from `tabWebsite Item Group` where ifnull(item_group, '')=''")
execute:frappe.delete_doc("Print Format", "SalesInvoice")
execute:import frappe.defaults;frappe.defaults.clear_default("price_list_currency")

View File

@ -0,0 +1,33 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt
from __future__ import unicode_literals
import frappe
from collections import Counter
from frappe.core.doctype.user.user import STANDARD_USERS
def execute():
system_settings = frappe.get_doc("System Settings")
# set values from global_defauls
global_defauls = frappe.db.get_value("Global Defaults", None,
["time_zone", "date_format", "number_format", "float_precision", "session_expiry"])
if global_defauls:
for key, val in global_defauls.items():
if not system_settings.get(key):
system_settings[key] = val
# language
if not system_settings.get("language"):
# find most common language
lang = frappe.db.sql_list("""select language from `tabUser`
where ifnull(language, '')!='' and language not like "Loading%%" and name not in ({standard_users})""".format(
standard_users=", ".join(["%s"]*len(STANDARD_USERS))), tuple(STANDARD_USERS))
lang = Counter(lang).most_common(1)
lang = (len(lang) > 0) and lang[0][0] or "english"
system_settings.language = lang
system_settings.save()

View File

@ -8,32 +8,32 @@ def execute(filters=None):
columns = get_columns()
sl_entries = get_stock_ledger_entries(filters)
item_details = get_item_details(filters)
data = []
for sle in sl_entries:
item_detail = item_details[sle.item_code]
voucher_link_icon = """<a href="%s"><i class="icon icon-share"
voucher_link_icon = """<a href="%s"><i class="icon icon-share"
style="cursor: pointer;"></i></a>""" \
% ("/".join(["#Form", sle.voucher_type, sle.voucher_no]),)
data.append([sle.date, sle.item_code, item_detail.item_name, item_detail.item_group,
item_detail.brand, item_detail.description, sle.warehouse, item_detail.stock_uom,
sle.actual_qty, sle.qty_after_transaction, sle.stock_value, sle.voucher_type,
sle.voucher_no, voucher_link_icon, sle.batch_no, sle.serial_no, sle.company])
data.append([sle.date, sle.item_code, item_detail.item_name, item_detail.item_group,
item_detail.brand, item_detail.description, sle.warehouse, item_detail.stock_uom,
sle.actual_qty, sle.qty_after_transaction, sle.valuation_rate, sle.stock_value,
sle.voucher_type, sle.voucher_no, voucher_link_icon, sle.batch_no, sle.serial_no, sle.company])
return columns, data
def get_columns():
return ["Date:Datetime:95", "Item:Link/Item:100", "Item Name::100",
return ["Date:Datetime:95", "Item:Link/Item:130", "Item Name::100",
"Item Group:Link/Item Group:100", "Brand:Link/Brand:100",
"Description::200", "Warehouse:Link/Warehouse:100",
"Stock UOM:Link/UOM:100", "Qty:Float:50", "Balance Qty:Float:80",
"Balance Value:Currency:100", "Voucher Type::100", "Voucher #::100", "Link::30",
"Stock UOM:Link/UOM:100", "Qty:Float:50", "Balance Qty:Float:100", "Valuation Rate:Currency:110",
"Balance Value:Currency:110", "Voucher Type::110", "Voucher #::100", "Link::30",
"Batch:Link/Batch:100", "Serial #:Link/Serial No:100", "Company:Link/Company:100"]
def get_stock_ledger_entries(filters):
return frappe.db.sql("""select concat_ws(" ", posting_date, posting_time) as date,
item_code, warehouse, actual_qty, qty_after_transaction,
item_code, warehouse, actual_qty, qty_after_transaction, valuation_rate,
stock_value, voucher_type, voucher_no, batch_no, serial_no, company
from `tabStock Ledger Entry`
where company = %(company)s and
@ -44,31 +44,31 @@ def get_stock_ledger_entries(filters):
def get_item_details(filters):
item_details = {}
for item in frappe.db.sql("""select name, item_name, description, item_group,
for item in frappe.db.sql("""select name, item_name, description, item_group,
brand, stock_uom from `tabItem` {item_conditions}"""\
.format(item_conditions=get_item_conditions(filters)), filters, as_dict=1):
item_details.setdefault(item.name, item)
return item_details
def get_item_conditions(filters):
conditions = []
if filters.get("item_code"):
conditions.append("name=%(item_code)s")
if filters.get("brand"):
conditions.append("brand=%(brand)s")
return "where {}".format(" and ".join(conditions)) if conditions else ""
def get_sle_conditions(filters):
conditions = []
item_conditions=get_item_conditions(filters)
if item_conditions:
conditions.append("""item_code in (select name from tabItem
conditions.append("""item_code in (select name from tabItem
{item_conditions})""".format(item_conditions=item_conditions))
if filters.get("warehouse"):
conditions.append("warehouse=%(warehouse)s")
if filters.get("voucher_no"):
conditions.append("voucher_no=%(voucher_no)s")
return "and {}".format(" and ".join(conditions)) if conditions else ""
return "and {}".format(" and ".join(conditions)) if conditions else ""