From bc7659ab90d21510b500ba9acf854c1c1a86940e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 15 May 2014 11:36:26 +0530 Subject: [PATCH 1/4] Employee leave balance report fixes #1647 --- .../employee_leave_balance.py | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py index 8098db4c8ce..c1d8bcfba40 100644 --- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py +++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py @@ -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 \ No newline at end of file + return columns, result From b5a8cab8df98cd008647a92150fc8329efd697bc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 15 May 2014 11:50:46 +0530 Subject: [PATCH 2/4] Valuation Rate column in Stock Ledger report. Fixed #1633 --- .../stock/report/stock_ledger/stock_ledger.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/erpnext/stock/report/stock_ledger/stock_ledger.py b/erpnext/stock/report/stock_ledger/stock_ledger.py index 298e971373c..5068326af06 100644 --- a/erpnext/stock/report/stock_ledger/stock_ledger.py +++ b/erpnext/stock/report/stock_ledger/stock_ledger.py @@ -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 = """""" \ % ("/".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 "" \ No newline at end of file + + return "and {}".format(" and ".join(conditions)) if conditions else "" From d0a915c47af4d77a271e89c940e6d820a3ffaa7e Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 15 May 2014 16:42:23 +0530 Subject: [PATCH 3/4] Global Defaults to system settings. Fixes #1653 --- erpnext/patches.txt | 1 + .../v4_0/global_defaults_to_system_settings.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 erpnext/patches/v4_0/global_defaults_to_system_settings.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index dae2b4b476b..5315f79de60 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -42,3 +42,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") +erpnext.patches.v4_0.global_defaults_to_system_settings diff --git a/erpnext/patches/v4_0/global_defaults_to_system_settings.py b/erpnext/patches/v4_0/global_defaults_to_system_settings.py new file mode 100644 index 00000000000..5a3c41c82bd --- /dev/null +++ b/erpnext/patches/v4_0/global_defaults_to_system_settings.py @@ -0,0 +1,17 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# MIT License. See license.txt + +from __future__ import unicode_literals + +import frappe + +def execute(): + global_defauls = frappe.db.get_value("Global Defaults", None, + ["time_zone", "date_format", "number_format", "float_precision", "session_expiry"]) + + if global_defauls: + system_settings = frappe.get_doc("System Settings") + for key, val in global_defauls.items(): + system_settings[key] = val + system_settings.ignore_mandatory = True + system_settings.save() From 941957512620fe09026207107b12a93fbac74718 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 15 May 2014 17:17:58 +0530 Subject: [PATCH 4/4] Merged language patch with global_defaults_to_system_settings patch --- erpnext/patches.txt | 3 ++- .../global_defaults_to_system_settings.py | 24 +++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 5315f79de60..3fc2b11536a 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -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,4 +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") -erpnext.patches.v4_0.global_defaults_to_system_settings + diff --git a/erpnext/patches/v4_0/global_defaults_to_system_settings.py b/erpnext/patches/v4_0/global_defaults_to_system_settings.py index 5a3c41c82bd..ab4f24140aa 100644 --- a/erpnext/patches/v4_0/global_defaults_to_system_settings.py +++ b/erpnext/patches/v4_0/global_defaults_to_system_settings.py @@ -4,14 +4,30 @@ 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: - system_settings = frappe.get_doc("System Settings") for key, val in global_defauls.items(): - system_settings[key] = val - system_settings.ignore_mandatory = True - system_settings.save() + 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()