From fab080c875f7542fb4f989a77a8bbbb2e791db8b Mon Sep 17 00:00:00 2001 From: marination Date: Thu, 7 Jan 2021 15:25:39 +0530 Subject: [PATCH 01/13] fix: Company Wise Valuation Rate for RM in BOM --- erpnext/manufacturing/doctype/bom/bom.js | 17 ++++++++----- erpnext/manufacturing/doctype/bom/bom.py | 24 +++++++++++++++---- .../doctype/work_order/work_order.py | 1 + 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 1c4b7a1e1c..15affd84e1 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -411,7 +411,7 @@ cur_frm.cscript.hour_rate = function(doc) { cur_frm.cscript.time_in_mins = cur_frm.cscript.hour_rate; -cur_frm.cscript.bom_no = function(doc, cdt, cdn) { +cur_frm.cscript.bom_no = function(doc, cdt, cdn) { get_bom_material_detail(doc, cdt, cdn, false); }; @@ -419,17 +419,22 @@ cur_frm.cscript.is_default = function(doc) { if (doc.is_default) cur_frm.set_value("is_active", 1); }; -var get_bom_material_detail= function(doc, cdt, cdn, scrap_items) { +var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) { + if (!doc.company) { + frappe.throw({message: __("Please select a Company first."), title: __("Mandatory")}); + } + var d = locals[cdt][cdn]; if (d.item_code) { return frappe.call({ doc: doc, method: "get_bom_material_detail", args: { - 'item_code': d.item_code, - 'bom_no': d.bom_no != null ? d.bom_no: '', + "company": doc.company, + "item_code": d.item_code, + "bom_no": d.bom_no != null ? d.bom_no: '', "scrap_items": scrap_items, - 'qty': d.qty, + "qty": d.qty, "stock_qty": d.stock_qty, "include_item_in_manufacturing": d.include_item_in_manufacturing, "uom": d.uom, @@ -468,7 +473,7 @@ cur_frm.cscript.rate = function(doc, cdt, cdn) { } if (d.bom_no) { - frappe.msgprint(__("You can not change rate if BOM mentioned agianst any item")); + frappe.msgprint(__("You cannot change the rate if BOM is mentioned against any Item.")); get_bom_material_detail(doc, cdt, cdn, scrap_items); } else { erpnext.bom.calculate_rm_cost(doc); diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 6363242b0a..03beedb663 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -65,6 +65,10 @@ class BOM(WebsiteGenerator): def validate(self): self.route = frappe.scrub(self.name).replace('_', '-') + + if not self.company: + frappe.throw(_("Please select a Company first."), title=_("Mandatory")) + self.clear_operations() self.validate_main_item() self.validate_currency() @@ -125,6 +129,7 @@ class BOM(WebsiteGenerator): self.validate_bom_currecny(item) ret = self.get_bom_material_detail({ + "company": self.company, "item_code": item.item_code, "item_name": item.item_name, "bom_no": item.bom_no, @@ -213,6 +218,7 @@ class BOM(WebsiteGenerator): for d in self.get("items"): rate = self.get_rm_rate({ + "company": self.company, "item_code": d.item_code, "bom_no": d.bom_no, "qty": d.qty, @@ -611,10 +617,20 @@ def get_valuation_rate(args): """ Get weighted average of valuation rate from all warehouses """ total_qty, total_value, valuation_rate = 0.0, 0.0, 0.0 - for d in frappe.db.sql("""select actual_qty, stock_value from `tabBin` - where item_code=%s""", args['item_code'], as_dict=1): - total_qty += flt(d.actual_qty) - total_value += flt(d.stock_value) + item_bins = frappe.db.sql(""" + select + bin.actual_qty, bin.stock_value + from + `tabBin` bin, `tabWarehouse` warehouse + where + bin.item_code=%(item)s + and bin.warehouse = warehouse.name + and warehouse.company=%(company)s""", + {"item": args['item_code'], "company": args['company']}, as_dict=1) + + for d in item_bins: + total_qty += flt(d.actual_qty) + total_value += flt(d.stock_value) if total_qty: valuation_rate = total_value / total_qty diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index cc93bf9fd6..8e7fac8ce8 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -725,6 +725,7 @@ def add_variant_item(variant_items, wo_doc, bom_no, table_name="items"): args.update(item_data) args["rate"] = get_bom_item_rate({ + "company": wo_doc.company, "item_code": args.get("item_code"), "qty": args.get("required_qty"), "uom": args.get("stock_uom"), From 3777c6aa381f35af5359039db211875c784dab50 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Fri, 8 Jan 2021 12:36:51 +0530 Subject: [PATCH 02/13] fix: payment entry multi-currency issue --- .../accounts/doctype/payment_entry/payment_entry.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index e117471738..9bdd26b805 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -401,6 +401,8 @@ frappe.ui.form.on('Payment Entry', { set_account_currency_and_balance: function(frm, account, currency_field, balance_field, callback_function) { + + var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency; if (frm.doc.posting_date && account) { frappe.call({ method: "erpnext.accounts.doctype.payment_entry.payment_entry.get_account_details", @@ -427,6 +429,14 @@ frappe.ui.form.on('Payment Entry', { if(!frm.doc.paid_amount && frm.doc.received_amount) frm.events.received_amount(frm); + + if (frm.doc.paid_from_account_currency == frm.doc.paid_to_account_currency + && frm.doc.paid_amount != frm.doc.received_amount) { + if (company_currency != frm.doc.paid_from_account_currency && + frm.doc.payment_type == "Pay") { + frm.doc.paid_amount = frm.doc.received_amount; + } + } } }, () => { From 7646d7b741ecd24ea42909cc7e0c2e128a69d393 Mon Sep 17 00:00:00 2001 From: marination Date: Mon, 11 Jan 2021 10:27:05 +0530 Subject: [PATCH 03/13] fix: Batch/Serial Selector for Batched Item --- erpnext/stock/doctype/stock_entry/stock_entry.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js index 98116ec183..f75e8b727d 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.js +++ b/erpnext/stock/doctype/stock_entry/stock_entry.js @@ -524,7 +524,7 @@ frappe.ui.form.on('Stock Entry', { }) ); } - + for (let i in frm.doc.items) { let item = frm.doc.items[i]; @@ -675,7 +675,13 @@ frappe.ui.form.on('Stock Entry Detail', { }); refresh_field("items"); - if (!d.serial_no) { + let no_batch_serial_number_value = !d.serial_no; + if (d.has_batch_no && !d.has_serial_no) { + // check only batch_no for batched item + no_batch_serial_number_value = !d.batch_no; + } + + if (no_batch_serial_number_value) { erpnext.stock.select_batch_and_serial_no(frm, d); } } From 8aeadc743eaa717bec021eb206182f7b6fc2a361 Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 13 Jan 2021 12:56:04 +0530 Subject: [PATCH 04/13] fix: assessment plan error handling for course field (#23961) * fix: assessment plan error handling for course field * fix: message rectification * fix(travis): clean-up tests * fix: travis * fix: tests Co-authored-by: pateljannat Co-authored-by: Rucha Mahabal --- .../program_enrollment/program_enrollment.py | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/erpnext/education/doctype/program_enrollment/program_enrollment.py b/erpnext/education/doctype/program_enrollment/program_enrollment.py index 6fbcd8aa97..886a7d85d8 100644 --- a/erpnext/education/doctype/program_enrollment/program_enrollment.py +++ b/erpnext/education/doctype/program_enrollment/program_enrollment.py @@ -124,21 +124,24 @@ class ProgramEnrollment(Document): @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def get_program_courses(doctype, txt, searchfield, start, page_len, filters): - if filters.get('program'): - return frappe.db.sql("""select course, course_name from `tabProgram Course` - where parent = %(program)s and course like %(txt)s {match_cond} - order by - if(locate(%(_txt)s, course), locate(%(_txt)s, course), 99999), - idx desc, - `tabProgram Course`.course asc - limit {start}, {page_len}""".format( - match_cond=get_match_cond(doctype), - start=start, - page_len=page_len), { - "txt": "%{0}%".format(txt), - "_txt": txt.replace('%', ''), - "program": filters['program'] - }) + if not filters.get('program'): + frappe.msgprint(_("Please select a Program first.")) + return [] + + return frappe.db.sql("""select course, course_name from `tabProgram Course` + where parent = %(program)s and course like %(txt)s {match_cond} + order by + if(locate(%(_txt)s, course), locate(%(_txt)s, course), 99999), + idx desc, + `tabProgram Course`.course asc + limit {start}, {page_len}""".format( + match_cond=get_match_cond(doctype), + start=start, + page_len=page_len), { + "txt": "%{0}%".format(txt), + "_txt": txt.replace('%', ''), + "program": filters['program'] + }) @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs From 1e396dcb2a58fa904f718c6223ad8ee6278a7dc8 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Wed, 13 Jan 2021 14:01:57 +0530 Subject: [PATCH 05/13] fix: validated GST state --- erpnext/regional/india/utils.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index f256a66266..0d8263835d 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -48,6 +48,9 @@ def validate_gstin_for_india(doc, method): validate_gstin_check_digit(doc.gstin) set_gst_state_and_state_number(doc) + if not doc.gst_state: + frappe.throw(_("Please Enter GST state")) + if doc.gst_state_number != doc.gstin[:2]: frappe.throw(_("Invalid GSTIN! First 2 digits of GSTIN should match with State number {0}.") .format(doc.gst_state_number)) From ef5f0c0461953315905d965aeb48ffb82979f0ae Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 13 Jan 2021 19:59:16 +0530 Subject: [PATCH 06/13] feat: Issue Summary Script Report (#23603) * feat: Issue Summary Report * feat: Add Issue Metrics to Issue Summary Report * fix: code clean-up * feat: Added Report Summary * feat: Add SLA status fields * fix: add report link to desk page * fix: sider issues Co-authored-by: Marica Co-authored-by: Nabin Hait --- .../support/desk_page/support/support.json | 4 +- .../support/report/issue_summary/__init__.py | 0 .../report/issue_summary/issue_summary.js | 73 ++++ .../report/issue_summary/issue_summary.json | 26 ++ .../report/issue_summary/issue_summary.py | 353 ++++++++++++++++++ 5 files changed, 454 insertions(+), 2 deletions(-) create mode 100644 erpnext/support/report/issue_summary/__init__.py create mode 100644 erpnext/support/report/issue_summary/issue_summary.js create mode 100644 erpnext/support/report/issue_summary/issue_summary.json create mode 100644 erpnext/support/report/issue_summary/issue_summary.py diff --git a/erpnext/support/desk_page/support/support.json b/erpnext/support/desk_page/support/support.json index 28410f3a71..18cf87ab0b 100644 --- a/erpnext/support/desk_page/support/support.json +++ b/erpnext/support/desk_page/support/support.json @@ -28,7 +28,7 @@ { "hidden": 0, "label": "Reports", - "links": "[\n {\n \"dependencies\": [\n \"Issue\"\n ],\n \"doctype\": \"Issue\",\n \"is_query_report\": true,\n \"label\": \"First Response Time for Issues\",\n \"name\": \"First Response Time for Issues\",\n \"type\": \"report\"\n }\n]" + "links": "[\n {\n \"dependencies\": [\n \"Issue\"\n ],\n \"doctype\": \"Issue\",\n \"is_query_report\": true,\n \"label\": \"First Response Time for Issues\",\n \"name\": \"First Response Time for Issues\",\n \"type\": \"report\"\n },\n {\n \"dependencies\": [\n \"Issue\"\n ],\n \"doctype\": \"Issue\",\n \"is_query_report\": true,\n \"label\": \"Issue Summary\",\n \"name\": \"Issue Summary\",\n \"type\": \"report\"\n }\n]" } ], "category": "Modules", @@ -43,7 +43,7 @@ "idx": 0, "is_standard": 1, "label": "Support", - "modified": "2020-08-11 15:49:34.307341", + "modified": "2020-10-12 18:40:22.252915", "modified_by": "Administrator", "module": "Support", "name": "Support", diff --git a/erpnext/support/report/issue_summary/__init__.py b/erpnext/support/report/issue_summary/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/erpnext/support/report/issue_summary/issue_summary.js b/erpnext/support/report/issue_summary/issue_summary.js new file mode 100644 index 0000000000..684482ac8d --- /dev/null +++ b/erpnext/support/report/issue_summary/issue_summary.js @@ -0,0 +1,73 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["Issue Summary"] = { + "filters": [ + { + fieldname: "company", + label: __("Company"), + fieldtype: "Link", + options: "Company", + default: frappe.defaults.get_user_default("Company"), + reqd: 1 + }, + { + fieldname: "based_on", + label: __("Based On"), + fieldtype: "Select", + options: ["Customer", "Issue Type", "Issue Priority", "Assigned To"], + default: "Customer", + reqd: 1 + }, + { + fieldname: "from_date", + label: __("From Date"), + fieldtype: "Date", + default: frappe.defaults.get_global_default("year_start_date"), + reqd: 1 + }, + { + fieldname:"to_date", + label: __("To Date"), + fieldtype: "Date", + default: frappe.defaults.get_global_default("year_end_date"), + reqd: 1 + }, + { + fieldname: "status", + label: __("Status"), + fieldtype: "Select", + options:[ + {label: __('Open'), value: 'Open'}, + {label: __('Replied'), value: 'Replied'}, + {label: __('Resolved'), value: 'Resolved'}, + {label: __('Closed'), value: 'Closed'} + ] + }, + { + fieldname: "priority", + label: __("Issue Priority"), + fieldtype: "Link", + options: "Issue Priority" + }, + { + fieldname: "customer", + label: __("Customer"), + fieldtype: "Link", + options: "Customer" + }, + { + fieldname: "project", + label: __("Project"), + fieldtype: "Link", + options: "Project" + }, + { + fieldname: "assigned_to", + label: __("Assigned To"), + fieldtype: "Link", + options: "User" + } + ] +}; \ No newline at end of file diff --git a/erpnext/support/report/issue_summary/issue_summary.json b/erpnext/support/report/issue_summary/issue_summary.json new file mode 100644 index 0000000000..b8a580ccef --- /dev/null +++ b/erpnext/support/report/issue_summary/issue_summary.json @@ -0,0 +1,26 @@ +{ + "add_total_row": 0, + "columns": [], + "creation": "2020-10-12 01:01:55.181777", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "filters": [], + "idx": 0, + "is_standard": "Yes", + "modified": "2020-10-12 14:54:55.655920", + "modified_by": "Administrator", + "module": "Support", + "name": "Issue Summary", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Issue", + "report_name": "Issue Summary", + "report_type": "Script Report", + "roles": [ + { + "role": "Support Team" + } + ] +} \ No newline at end of file diff --git a/erpnext/support/report/issue_summary/issue_summary.py b/erpnext/support/report/issue_summary/issue_summary.py new file mode 100644 index 0000000000..3d735314f4 --- /dev/null +++ b/erpnext/support/report/issue_summary/issue_summary.py @@ -0,0 +1,353 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +import json +from six import iteritems +from frappe import _, scrub +from frappe.utils import flt + +def execute(filters=None): + return IssueSummary(filters).run() + +class IssueSummary(object): + def __init__(self, filters=None): + self.filters = frappe._dict(filters or {}) + + def run(self): + self.get_columns() + self.get_data() + self.get_chart_data() + self.get_report_summary() + + return self.columns, self.data, None, self.chart, self.report_summary + + def get_columns(self): + self.columns = [] + + if self.filters.based_on == 'Customer': + self.columns.append({ + 'label': _('Customer'), + 'options': 'Customer', + 'fieldname': 'customer', + 'fieldtype': 'Link', + 'width': 200 + }) + + elif self.filters.based_on == 'Assigned To': + self.columns.append({ + 'label': _('User'), + 'fieldname': 'user', + 'fieldtype': 'Link', + 'options': 'User', + 'width': 200 + }) + + elif self.filters.based_on == 'Issue Type': + self.columns.append({ + 'label': _('Issue Type'), + 'fieldname': 'issue_type', + 'fieldtype': 'Link', + 'options': 'Issue Type', + 'width': 200 + }) + + elif self.filters.based_on == 'Issue Priority': + self.columns.append({ + 'label': _('Issue Priority'), + 'fieldname': 'priority', + 'fieldtype': 'Link', + 'options': 'Issue Priority', + 'width': 200 + }) + + self.statuses = ['Open', 'Replied', 'Resolved', 'Closed'] + for status in self.statuses: + self.columns.append({ + 'label': _(status), + 'fieldname': scrub(status), + 'fieldtype': 'Int', + 'width': 80 + }) + + self.columns.append({ + 'label': _('Total Issues'), + 'fieldname': 'total_issues', + 'fieldtype': 'Int', + 'width': 100 + }) + + self.sla_status_map = { + 'SLA Failed': 'failed', + 'SLA Fulfilled': 'fulfilled', + 'SLA Ongoing': 'ongoing' + } + + for label, fieldname in self.sla_status_map.items(): + self.columns.append({ + 'label': _(label), + 'fieldname': fieldname, + 'fieldtype': 'Int', + 'width': 100 + }) + + self.metrics = ['Avg First Response Time', 'Avg Response Time', 'Avg Hold Time', + 'Avg Resolution Time', 'Avg User Resolution Time'] + + for metric in self.metrics: + self.columns.append({ + 'label': _(metric), + 'fieldname': scrub(metric), + 'fieldtype': 'Duration', + 'width': 170 + }) + + def get_data(self): + self.get_issues() + self.get_rows() + + def get_issues(self): + filters = self.get_common_filters() + self.field_map = { + 'Customer': 'customer', + 'Issue Type': 'issue_type', + 'Issue Priority': 'priority', + 'Assigned To': '_assign' + } + + self.entries = frappe.db.get_all('Issue', + fields=[self.field_map.get(self.filters.based_on), 'name', 'opening_date', 'status', 'avg_response_time', + 'first_response_time', 'total_hold_time', 'user_resolution_time', 'resolution_time', 'agreement_status'], + filters=filters + ) + + def get_common_filters(self): + filters = {} + filters['opening_date'] = ('between', [self.filters.from_date, self.filters.to_date]) + + if self.filters.get('assigned_to'): + filters['_assign'] = ('like', '%' + self.filters.get('assigned_to') + '%') + + for entry in ['company', 'status', 'priority', 'customer', 'project']: + if self.filters.get(entry): + filters[entry] = self.filters.get(entry) + + return filters + + def get_rows(self): + self.data = [] + self.get_summary_data() + + for entity, data in iteritems(self.issue_summary_data): + if self.filters.based_on == 'Customer': + row = {'customer': entity} + elif self.filters.based_on == 'Assigned To': + row = {'user': entity} + elif self.filters.based_on == 'Issue Type': + row = {'issue_type': entity} + elif self.filters.based_on == 'Issue Priority': + row = {'priority': entity} + + for status in self.statuses: + count = flt(data.get(status, 0.0)) + row[scrub(status)] = count + + row['total_issues'] = data.get('total_issues', 0.0) + + for sla_status in self.sla_status_map.values(): + value = flt(data.get(sla_status), 0.0) + row[sla_status] = value + + for metric in self.metrics: + value = flt(data.get(scrub(metric)), 0.0) + row[scrub(metric)] = value + + self.data.append(row) + + def get_summary_data(self): + self.issue_summary_data = frappe._dict() + + for d in self.entries: + status = d.status + agreement_status = scrub(d.agreement_status) + + if self.filters.based_on == 'Assigned To': + if d._assign: + for entry in json.loads(d._assign): + self.issue_summary_data.setdefault(entry, frappe._dict()).setdefault(status, 0.0) + self.issue_summary_data.setdefault(entry, frappe._dict()).setdefault(agreement_status, 0.0) + self.issue_summary_data.setdefault(entry, frappe._dict()).setdefault('total_issues', 0.0) + self.issue_summary_data[entry][status] += 1 + self.issue_summary_data[entry][agreement_status] += 1 + self.issue_summary_data[entry]['total_issues'] += 1 + + else: + field = self.field_map.get(self.filters.based_on) + value = d.get(field) + if not value: + value = _('Not Specified') + + self.issue_summary_data.setdefault(value, frappe._dict()).setdefault(status, 0.0) + self.issue_summary_data.setdefault(value, frappe._dict()).setdefault(agreement_status, 0.0) + self.issue_summary_data.setdefault(value, frappe._dict()).setdefault('total_issues', 0.0) + self.issue_summary_data[value][status] += 1 + self.issue_summary_data[value][agreement_status] += 1 + self.issue_summary_data[value]['total_issues'] += 1 + + self.get_metrics_data() + + def get_metrics_data(self): + issues = [] + + metrics_list = ['avg_response_time', 'avg_first_response_time', 'avg_hold_time', + 'avg_resolution_time', 'avg_user_resolution_time'] + + for entry in self.entries: + issues.append(entry.name) + + field = self.field_map.get(self.filters.based_on) + + if issues: + if self.filters.based_on == 'Assigned To': + assignment_map = frappe._dict() + for d in self.entries: + if d._assign: + for entry in json.loads(d._assign): + for metric in metrics_list: + self.issue_summary_data.setdefault(entry, frappe._dict()).setdefault(metric, 0.0) + + self.issue_summary_data[entry]['avg_response_time'] += d.get('avg_response_time') or 0.0 + self.issue_summary_data[entry]['avg_first_response_time'] += d.get('first_response_time') or 0.0 + self.issue_summary_data[entry]['avg_hold_time'] += d.get('total_hold_time') or 0.0 + self.issue_summary_data[entry]['avg_resolution_time'] += d.get('resolution_time') or 0.0 + self.issue_summary_data[entry]['avg_user_resolution_time'] += d.get('user_resolution_time') or 0.0 + + if not assignment_map.get(entry): + assignment_map[entry] = 0 + assignment_map[entry] += 1 + + for entry in assignment_map: + for metric in metrics_list: + self.issue_summary_data[entry][metric] /= flt(assignment_map.get(entry)) + + else: + data = frappe.db.sql(""" + SELECT + {0}, AVG(first_response_time) as avg_frt, + AVG(avg_response_time) as avg_resp_time, + AVG(total_hold_time) as avg_hold_time, + AVG(resolution_time) as avg_resolution_time, + AVG(user_resolution_time) as avg_user_resolution_time + FROM `tabIssue` + WHERE + name IN %(issues)s + GROUP BY {0} + """.format(field), {'issues': issues}, as_dict=1) + + for entry in data: + value = entry.get(field) + if not value: + value = _('Not Specified') + + for metric in metrics_list: + self.issue_summary_data.setdefault(value, frappe._dict()).setdefault(metric, 0.0) + + self.issue_summary_data[value]['avg_response_time'] = entry.get('avg_resp_time') or 0.0 + self.issue_summary_data[value]['avg_first_response_time'] = entry.get('avg_frt') or 0.0 + self.issue_summary_data[value]['avg_hold_time'] = entry.get('avg_hold_time') or 0.0 + self.issue_summary_data[value]['avg_resolution_time'] = entry.get('avg_resolution_time') or 0.0 + self.issue_summary_data[value]['avg_user_resolution_time'] = entry.get('avg_user_resolution_time') or 0.0 + + def get_chart_data(self): + if not self.data: + return None + + labels = [] + open_issues = [] + replied_issues = [] + resolved_issues = [] + closed_issues = [] + + entity = self.filters.based_on + entity_field = self.field_map.get(entity) + if entity == 'Assigned To': + entity_field = 'user' + + for entry in self.data: + labels.append(entry.get(entity_field)) + open_issues.append(entry.get('open')) + replied_issues.append(entry.get('replied')) + resolved_issues.append(entry.get('resolved')) + closed_issues.append(entry.get('closed')) + + self.chart = { + 'data': { + 'labels': labels[:30], + 'datasets': [ + { + 'name': 'Open', + 'values': open_issues[:30] + }, + { + 'name': 'Replied', + 'values': replied_issues[:30] + }, + { + 'name': 'Resolved', + 'values': resolved_issues[:30] + }, + { + 'name': 'Closed', + 'values': closed_issues[:30] + } + ] + }, + 'type': 'bar', + 'barOptions': { + 'stacked': True + } + } + + def get_report_summary(self): + if not self.data: + return None + + open_issues = 0 + replied = 0 + resolved = 0 + closed = 0 + + for entry in self.data: + open_issues += entry.get('open') + replied += entry.get('replied') + resolved += entry.get('resolved') + closed += entry.get('closed') + + self.report_summary = [ + { + 'value': open_issues, + 'indicator': 'Red', + 'label': _('Open'), + 'datatype': 'Int', + }, + { + 'value': replied, + 'indicator': 'Grey', + 'label': _('Replied'), + 'datatype': 'Int', + }, + { + 'value': resolved, + 'indicator': 'Green', + 'label': _('Resolved'), + 'datatype': 'Int', + }, + { + 'value': closed, + 'indicator': 'Green', + 'label': _('Closed'), + 'datatype': 'Int', + } + ] + From 511434190dca98a987b47ba4278d72da793baa3b Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Wed, 13 Jan 2021 20:59:43 +0530 Subject: [PATCH 07/13] fix(work order): Actual start and end dates update (#24360) Currently, even when the Work Order (without Operations) is completed and Stock Entries are there, the Actual Start Date and Actual End Date is not updated. For some reason need to db_set, then it updates the Actual Start Date and Actual End Date --- erpnext/manufacturing/doctype/work_order/work_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/doctype/work_order/work_order.py b/erpnext/manufacturing/doctype/work_order/work_order.py index 8e7fac8ce8..ca530bbadd 100644 --- a/erpnext/manufacturing/doctype/work_order/work_order.py +++ b/erpnext/manufacturing/doctype/work_order/work_order.py @@ -456,10 +456,10 @@ class WorkOrder(Document): if data and len(data): dates = [d.posting_datetime for d in data] - self.actual_start_date = min(dates) + self.db_set('actual_start_date', min(dates)) if self.status == "Completed": - self.actual_end_date = max(dates) + self.db_set('actual_end_date', max(dates)) self.set_lead_time() From 53cb9f9f47fba12046db8a694f169577a34a74d4 Mon Sep 17 00:00:00 2001 From: Saqib Date: Wed, 13 Jan 2021 21:00:44 +0530 Subject: [PATCH 08/13] fix(e-invoicing): ux issues (#24358) * fix: overseas invoice rounding adjustment * fix: overseas shipping address * fix: qrcode for document name having forward slash * feat: sandbox mode toggle * fix: cannot delete sales invoice if linked to e invoice req log --- .../e_invoice_request_log.json | 7 +++--- .../e_invoice_settings.json | 9 ++++++- erpnext/regional/india/e_invoice/utils.py | 25 ++++++++++++------- 3 files changed, 27 insertions(+), 14 deletions(-) diff --git a/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json index 5c1c79dc04..3034370fea 100644 --- a/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json +++ b/erpnext/regional/doctype/e_invoice_request_log/e_invoice_request_log.json @@ -24,9 +24,8 @@ }, { "fieldname": "reference_invoice", - "fieldtype": "Link", - "label": "Reference Invoice", - "options": "Sales Invoice" + "fieldtype": "Data", + "label": "Reference Invoice" }, { "fieldname": "headers", @@ -64,7 +63,7 @@ ], "index_web_pages_for_search": 1, "links": [], - "modified": "2020-12-24 21:09:38.882866", + "modified": "2021-01-13 12:06:57.253111", "modified_by": "Administrator", "module": "Regional", "name": "E Invoice Request Log", diff --git a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json index 4dcb22a54c..db8bda75bf 100644 --- a/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json +++ b/erpnext/regional/doctype/e_invoice_settings/e_invoice_settings.json @@ -7,6 +7,7 @@ "field_order": [ "enable", "section_break_2", + "sandbox_mode", "credentials", "auth_token", "token_expiry" @@ -41,12 +42,18 @@ "label": "Credentials", "mandatory_depends_on": "enable", "options": "E Invoice User" + }, + { + "default": "0", + "fieldname": "sandbox_mode", + "fieldtype": "Check", + "label": "Sandbox Mode" } ], "index_web_pages_for_search": 1, "issingle": 1, "links": [], - "modified": "2020-12-22 15:34:57.280044", + "modified": "2021-01-13 12:04:49.449199", "modified_by": "Administrator", "module": "Regional", "name": "E Invoice Settings", diff --git a/erpnext/regional/india/e_invoice/utils.py b/erpnext/regional/india/e_invoice/utils.py index abe15043af..d0cac90e4d 100644 --- a/erpnext/regional/india/e_invoice/utils.py +++ b/erpnext/regional/india/e_invoice/utils.py @@ -218,8 +218,8 @@ def update_item_taxes(invoice, item): def get_invoice_value_details(invoice): invoice_value_details = frappe._dict(dict()) invoice_value_details.base_total = abs(invoice.base_total) - invoice_value_details.invoice_discount_amt = invoice.discount_amount - invoice_value_details.round_off = invoice.rounding_adjustment + invoice_value_details.invoice_discount_amt = invoice.base_discount_amount + invoice_value_details.round_off = invoice.base_rounding_adjustment invoice_value_details.base_grand_total = abs(invoice.base_rounded_total) or abs(invoice.base_grand_total) invoice_value_details.grand_total = abs(invoice.rounded_total) or abs(invoice.grand_total) @@ -322,7 +322,10 @@ def make_einvoice(invoice): shipping_details = payment_details = prev_doc_details = eway_bill_details = frappe._dict({}) if invoice.shipping_address_name and invoice.customer_address != invoice.shipping_address_name: - shipping_details = get_party_details(invoice.shipping_address_name) + if invoice.gst_category == 'Overseas': + shipping_details = get_overseas_address_details(invoice.shipping_address_name) + else: + shipping_details = get_party_details(invoice.shipping_address_name) if invoice.is_pos and invoice.base_paid_amount: payment_details = get_payment_details(invoice) @@ -414,15 +417,19 @@ class RequestFailed(Exception): pass class GSPConnector(): def __init__(self, doctype=None, docname=None): self.e_invoice_settings = frappe.get_cached_doc('E Invoice Settings') + sandbox_mode = self.e_invoice_settings.sandbox_mode + self.invoice = frappe.get_cached_doc(doctype, docname) if doctype and docname else None self.credentials = self.get_credentials() - self.base_url = 'https://gsp.adaequare.com' - self.authenticate_url = self.base_url + '/gsp/authenticate?grant_type=token' - self.gstin_details_url = self.base_url + '/enriched/ei/api/master/gstin' - self.generate_irn_url = self.base_url + '/enriched/ei/api/invoice' - self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn' + # authenticate url is same for sandbox & live + self.authenticate_url = 'https://gsp.adaequare.com/gsp/authenticate?grant_type=token' + self.base_url = 'https://gsp.adaequare.com' if not sandbox_mode else 'https://gsp.adaequare.com/test' + self.cancel_irn_url = self.base_url + '/enriched/ei/api/invoice/cancel' + self.irn_details_url = self.base_url + '/enriched/ei/api/invoice/irn' + self.generate_irn_url = self.base_url + '/enriched/ei/api/invoice' + self.gstin_details_url = self.base_url + '/enriched/ei/api/master/gstin' self.cancel_ewaybill_url = self.base_url + '/enriched/ei/api/ewayapi' self.generate_ewaybill_url = self.base_url + '/enriched/ei/api/ewaybill' @@ -758,7 +765,7 @@ class GSPConnector(): _file = frappe.new_doc('File') _file.update({ - 'file_name': f'QRCode_{docname}.png', + 'file_name': 'QRCode_{}.png'.format(docname.replace('/', '-')), 'attached_to_doctype': doctype, 'attached_to_name': docname, 'content': 'qrcode', From 00ccec7314283617ea7c89da6600531e6e206bac Mon Sep 17 00:00:00 2001 From: Jannat Patel <31363128+pateljannat@users.noreply.github.com> Date: Wed, 13 Jan 2021 21:02:15 +0530 Subject: [PATCH 09/13] fix: subscription prepaid date validation (#24356) --- erpnext/accounts/doctype/subscription/subscription.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/subscription/subscription.py b/erpnext/accounts/doctype/subscription/subscription.py index 552a5d476b..e023b47cac 100644 --- a/erpnext/accounts/doctype/subscription/subscription.py +++ b/erpnext/accounts/doctype/subscription/subscription.py @@ -446,7 +446,7 @@ class Subscription(Document): if not self.generate_invoice_at_period_start: return False - if self.is_new_subscription(): + if self.is_new_subscription() and getdate() >= getdate(self.current_invoice_start): return True # Check invoice dates and make sure it doesn't have outstanding invoices From 0b04e23f6d5e962c2736a308e0c4053426266bfb Mon Sep 17 00:00:00 2001 From: Anuja Pawar <60467153+Anuja-pawar@users.noreply.github.com> Date: Wed, 13 Jan 2021 21:04:03 +0530 Subject: [PATCH 10/13] fix: BOM Stock Report UoM correction (#24339) --- .../report/bom_stock_report/bom_stock_report.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py index 75ebcbc971..1c6758e6f3 100644 --- a/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py +++ b/erpnext/manufacturing/report/bom_stock_report/bom_stock_report.py @@ -20,6 +20,7 @@ def get_columns(): _("Item") + ":Link/Item:150", _("Description") + "::300", _("BOM Qty") + ":Float:160", + _("BOM UoM") + "::160", _("Required Qty") + ":Float:120", _("In Stock Qty") + ":Float:120", _("Enough Parts to Build") + ":Float:200", @@ -32,7 +33,7 @@ def get_bom_stock(filters): bom = filters.get("bom") table = "`tabBOM Item`" - qty_field = "qty" + qty_field = "stock_qty" qty_to_produce = filters.get("qty_to_produce", 1) if int(qty_to_produce) <= 0: @@ -40,7 +41,6 @@ def get_bom_stock(filters): if filters.get("show_exploded_view"): table = "`tabBOM Explosion Item`" - qty_field = "stock_qty" if filters.get("warehouse"): warehouse_details = frappe.db.get_value("Warehouse", filters.get("warehouse"), ["lft", "rgt"], as_dict=1) @@ -59,6 +59,7 @@ def get_bom_stock(filters): bom_item.item_code, bom_item.description , bom_item.{qty_field}, + bom_item.stock_uom, bom_item.{qty_field} * {qty_to_produce} / bom.quantity, sum(ledger.actual_qty) as actual_qty, sum(FLOOR(ledger.actual_qty / (bom_item.{qty_field} * {qty_to_produce} / bom.quantity))) From 33fac19bcef75d224728b9e2338c2952187883c1 Mon Sep 17 00:00:00 2001 From: Afshan <33727827+AfshanKhan@users.noreply.github.com> Date: Wed, 13 Jan 2021 21:06:04 +0530 Subject: [PATCH 11/13] fix: calculation of remaining_sub_periods if relieving date before month start date (#24319) --- erpnext/payroll/doctype/payroll_period/payroll_period.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/payroll/doctype/payroll_period/payroll_period.py b/erpnext/payroll/doctype/payroll_period/payroll_period.py index d7893d0657..46f6cd842c 100644 --- a/erpnext/payroll/doctype/payroll_period/payroll_period.py +++ b/erpnext/payroll/doctype/payroll_period/payroll_period.py @@ -5,7 +5,7 @@ from __future__ import unicode_literals import frappe from frappe import _ -from frappe.utils import date_diff, getdate, formatdate, cint, month_diff, flt +from frappe.utils import date_diff, getdate, formatdate, cint, month_diff, flt, add_months from frappe.model.document import Document from erpnext.hr.utils import get_holidays_for_employee @@ -88,6 +88,8 @@ def get_period_factor(employee, start_date, end_date, payroll_frequency, payroll period_start = joining_date if relieving_date and getdate(relieving_date) < getdate(period_end): period_end = relieving_date + if month_diff(period_end, start_date) > 1: + start_date = add_months(start_date, - (month_diff(period_end, start_date)+1)) total_sub_periods, remaining_sub_periods = 0.0, 0.0 From 4a649a4fce762ad3c1c0a046da545b287f44e53a Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Wed, 13 Jan 2021 21:10:49 +0530 Subject: [PATCH 12/13] fix: removing payment_field from loan repayment closuer (#24291) --- .../loan_repayment_and_closure/loan_repayment_and_closure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.py b/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.py index b63cc8ed5a..c6f6b990cc 100644 --- a/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.py +++ b/erpnext/loan_management/report/loan_repayment_and_closure/loan_repayment_and_closure.py @@ -103,7 +103,7 @@ def get_data(filters): loan_repayments = frappe.get_all("Loan Repayment", filters = query_filters, - fields=["posting_date", "applicant", "name", "against_loan", "payment_type", "payable_amount", + fields=["posting_date", "applicant", "name", "against_loan", "payable_amount", "pending_principal_amount", "interest_payable", "penalty_amount", "amount_paid"] ) From e62ce4b1729d64ae30081fdc096bb4da11febd50 Mon Sep 17 00:00:00 2001 From: Anuja Pawar <60467153+Anuja-pawar@users.noreply.github.com> Date: Wed, 13 Jan 2021 21:13:12 +0530 Subject: [PATCH 13/13] fix: Add button PO, PI, SI, DN and, Quotation Dashboard (#24187) --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js | 2 +- erpnext/accounts/doctype/sales_invoice/sales_invoice.js | 2 +- erpnext/buying/doctype/purchase_order/purchase_order.js | 4 ++-- erpnext/selling/doctype/quotation/quotation.js | 2 +- erpnext/stock/doctype/delivery_note/delivery_note.js | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 7830cfd370..3863768a8b 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -498,7 +498,7 @@ cur_frm.cscript.select_print_heading = function(doc,cdt,cdn){ frappe.ui.form.on("Purchase Invoice", { setup: function(frm) { frm.custom_make_buttons = { - 'Purchase Invoice': 'Debit Note', + 'Purchase Invoice': 'Return / Debit Note', 'Payment Entry': 'Payment' } diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 5efc32e11d..89b716c180 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -592,7 +592,7 @@ frappe.ui.form.on('Sales Invoice', { frm.custom_make_buttons = { 'Delivery Note': 'Delivery', - 'Sales Invoice': 'Sales Return', + 'Sales Invoice': 'Return / Credit Note', 'Payment Request': 'Payment Request', 'Payment Entry': 'Payment' }, diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 47483c9d1c..38532d18f3 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -58,8 +58,8 @@ frappe.ui.form.on("Purchase Order Item", { erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({ setup: function() { this.frm.custom_make_buttons = { - 'Purchase Receipt': 'Receipt', - 'Purchase Invoice': 'Invoice', + 'Purchase Receipt': 'Purchase Receipt', + 'Purchase Invoice': 'Purchase Invoice', 'Stock Entry': 'Material to Supplier', 'Payment Entry': 'Payment', } diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index 661e107e1e..5a0d9c9065 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -7,7 +7,7 @@ frappe.ui.form.on('Quotation', { setup: function(frm) { frm.custom_make_buttons = { - 'Sales Order': 'Make Sales Order' + 'Sales Order': 'Sales Order' }, frm.set_query("quotation_to", function() { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index 5f2658c102..cb1e31b15b 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -13,7 +13,7 @@ frappe.ui.form.on("Delivery Note", { frm.custom_make_buttons = { 'Packing Slip': 'Packing Slip', 'Installation Note': 'Installation Note', - 'Sales Invoice': 'Invoice', + 'Sales Invoice': 'Sales Invoice', 'Stock Entry': 'Return', 'Shipment': 'Shipment' },