From 176b63b3540b714a5bcc349998a4abe7db663861 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 14 Jul 2016 17:43:48 +0530 Subject: [PATCH] [fix] remove first row on mapping, fixes #5707 --- .../purchase_invoice/purchase_invoice.js | 4 +- .../doctype/sales_invoice/sales_invoice.js | 4 +- .../bank_clearance_summary.py | 34 +++++------ .../doctype/purchase_order/purchase_order.js | 6 +- .../request_for_quotation.js | 2 +- .../supplier_quotation/supplier_quotation.js | 2 +- .../crm/doctype/opportunity/opportunity.js | 2 +- erpnext/hr/doctype/appraisal/appraisal.js | 2 +- .../maintenance_schedule.js | 2 +- .../maintenance_visit/maintenance_visit.js | 6 +- .../v7_0/make_is_group_fieldtype_as_check.py | 4 +- erpnext/public/js/utils.js | 59 +++++++++++++++++++ .../installation_note/installation_note.js | 2 +- .../selling/doctype/quotation/quotation.js | 2 +- .../doctype/sales_order/sales_order.js | 2 +- .../doctype/delivery_note/delivery_note.js | 2 +- .../material_request/material_request.js | 2 +- .../purchase_receipt/purchase_receipt.js | 2 +- 18 files changed, 99 insertions(+), 40 deletions(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js index 444c3b51e6..c655626b86 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js @@ -47,7 +47,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ if(doc.docstatus===0) { cur_frm.add_custom_button(__('Purchase Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_invoice", source_doctype: "Purchase Order", get_query_filters: { @@ -61,7 +61,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({ }, __("Get items from")); cur_frm.add_custom_button(__('Purchase Receipt'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.purchase_receipt.purchase_receipt.make_purchase_invoice", source_doctype: "Purchase Receipt", get_query_filters: { diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js index 1d48df0211..64379a16e9 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.js +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.js @@ -101,7 +101,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte sales_order_btn: function() { this.$sales_order_btn = cur_frm.add_custom_button(__('Sales Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice", source_doctype: "Sales Order", get_query_filters: { @@ -118,7 +118,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte delivery_note_btn: function() { this.$delivery_note_btn = cur_frm.add_custom_button(__('Delivery Note'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice", source_doctype: "Delivery Note", get_query: function() { diff --git a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py index 07ab969b84..d9bac3cb5b 100644 --- a/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py +++ b/erpnext/accounts/report/bank_clearance_summary/bank_clearance_summary.py @@ -8,43 +8,43 @@ from frappe.utils import nowdate, getdate def execute(filters=None): if not filters: filters = {} - + columns = get_columns() data = get_entries(filters) - + return columns, data - + def get_columns(): return [ - _("Payment Document") + ":Link/DocType:130", - _("Payment Entry") + ":Dynamic Link/"+_("Payment Document")+":110", - _("Posting Date") + ":Date:100", + _("Payment Document") + ":Link/DocType:130", + _("Payment Entry") + ":Dynamic Link/"+_("Payment Document")+":110", + _("Posting Date") + ":Date:100", _("Cheque/Reference No") + "::120", - _("Clearance Date") + ":Date:100", - _("Against Account") + ":Link/Account:170", + _("Clearance Date") + ":Date:100", + _("Against Account") + ":Link/Account:170", _("Amount") + ":Currency:120" ] def get_conditions(filters): conditions = "" - + if filters.get("from_date"): conditions += " and posting_date>=%(from_date)s" if filters.get("to_date"): conditions += " and posting_date<=%(to_date)s" - + return conditions - + def get_entries(filters): conditions = get_conditions(filters) - journal_entries = frappe.db.sql("""select "Journal Entry", jv.name, jv.posting_date, + journal_entries = frappe.db.sql("""select "Journal Entry", jv.name, jv.posting_date, jv.cheque_no, jv.clearance_date, jvd.against_account, (jvd.debit - jvd.credit) - from `tabJournal Entry Account` jvd, `tabJournal Entry` jv + from `tabJournal Entry Account` jvd, `tabJournal Entry` jv where jvd.parent = jv.name and jv.docstatus=1 and jvd.account = %(account)s {0} order by posting_date DESC, jv.name DESC""".format(conditions), filters, as_list=1) - - payment_entries = frappe.db.sql("""select "Payment Entry", name, posting_date, + + payment_entries = frappe.db.sql("""select "Payment Entry", name, posting_date, reference_no, clearance_date, party, if(paid_from=%(account)s, paid_amount, received_amount) from `tabPayment Entry` where docstatus=1 and (paid_from = %(account)s or paid_to = %(account)s) {0} - order by posting_date DESC, name DESC""".format(conditions), filters, as_list=1, debug=1) - + order by posting_date DESC, name DESC""".format(conditions), filters, as_list=1) + return sorted(journal_entries + payment_entries, key=lambda k: k[2] or getdate(nowdate())) \ No newline at end of file diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 9624967a2b..15356fd471 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -87,7 +87,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( }, get_items_from_open_material_requests: function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order_based_on_supplier", source_name: this.frm.doc.supplier, get_query_filters: { @@ -150,7 +150,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( add_from_mappers: function() { cur_frm.add_custom_button(__('Material Request'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.material_request.material_request.make_purchase_order", source_doctype: "Material Request", get_query_filters: { @@ -165,7 +165,7 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend( cur_frm.add_custom_button(__('Supplier Quotation'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.buying.doctype.supplier_quotation.supplier_quotation.make_purchase_order", source_doctype: "Supplier Quotation", get_query_filters: { diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js index 9a81467552..ce1c088263 100644 --- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js +++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js @@ -135,7 +135,7 @@ erpnext.buying.RequestforQuotationController = erpnext.buying.BuyingController.e if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Material Request'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.material_request.material_request.make_request_for_quotation", source_doctype: "Material Request", get_query_filters: { diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js index b3030f7745..1859cf5005 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js @@ -15,7 +15,7 @@ erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.ext else if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Material Request'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.material_request.material_request.make_supplier_quotation", source_doctype: "Material Request", get_query_filters: { diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index 9144692b88..21a7429be2 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -128,7 +128,7 @@ cur_frm.cscript.item_code = function(doc, cdt, cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) { cur_frm.toggle_display("contact_info", doc.customer || doc.lead); - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.crm.doctype.lead.lead.make_opportunity", source_name: cur_frm.doc.lead, frm: cur_frm diff --git a/erpnext/hr/doctype/appraisal/appraisal.js b/erpnext/hr/doctype/appraisal/appraisal.js index 4cfcd7eb68..728e5c2f2c 100644 --- a/erpnext/hr/doctype/appraisal/appraisal.js +++ b/erpnext/hr/doctype/appraisal/appraisal.js @@ -24,7 +24,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){ } cur_frm.cscript.kra_template = function(doc, dt, dn) { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.hr.doctype.appraisal.appraisal.fetch_appraisal_template", source_name: cur_frm.doc.kra_template, frm: cur_frm diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js index cf0ee510b3..bcf1ae6932 100644 --- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js +++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js @@ -20,7 +20,7 @@ erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({ if (this.frm.doc.docstatus === 0) { this.frm.add_custom_button(__('Sales Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule", source_doctype: "Sales Order", get_query_filters: { diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js index 561588651d..38c20dadd4 100644 --- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js +++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js @@ -19,7 +19,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({ if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Maintenance Schedule'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.maintenance.doctype.maintenance_schedule.maintenance_schedule.make_maintenance_visit", source_doctype: "Maintenance Schedule", get_query_filters: { @@ -31,7 +31,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({ }, __("Get items from")); cur_frm.add_custom_button(__('Warranty Claim'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.support.doctype.warranty_claim.warranty_claim.make_maintenance_visit", source_doctype: "Warranty Claim", get_query_filters: { @@ -43,7 +43,7 @@ erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({ }, __("Get items from")); cur_frm.add_custom_button(__('Sales Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit", source_doctype: "Sales Order", get_query_filters: { diff --git a/erpnext/patches/v7_0/make_is_group_fieldtype_as_check.py b/erpnext/patches/v7_0/make_is_group_fieldtype_as_check.py index eab4401cc8..aef0306b56 100644 --- a/erpnext/patches/v7_0/make_is_group_fieldtype_as_check.py +++ b/erpnext/patches/v7_0/make_is_group_fieldtype_as_check.py @@ -8,6 +8,6 @@ def execute(): #In MySQL, you can't modify the same table which you use in the SELECT part. frappe.db.sql(""" update `tab{doctype}` set is_group = 1 - where name in (select parent_{field} from (select distinct parent_{field} from `tab{doctype}` + where name in (select parent_{field} from (select distinct parent_{field} from `tab{doctype}` where parent_{field} != '') as dummy_table) - """.format(doctype=doctype, field=doctype.strip().lower().replace(' ','_')), debug=1) + """.format(doctype=doctype, field=doctype.strip().lower().replace(' ','_'))) diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index ea28fd5fa8..d3472279fb 100644 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -120,6 +120,65 @@ $.extend(erpnext.utils, { } }); +erpnext.utils.map_current_doc = function(opts) { + if(opts.get_query_filters) { + opts.get_query = function() { + return {filters: opts.get_query_filters}; + } + } + var _map = function() { + // remove first item row if empty + if($.isArray(cur_frm.doc.items)) { + if(!cur_frm.doc.items[0].item_code) { + cur_frm.doc.items = cur_frm.doc.items.splice(1); + } + } + + return frappe.call({ + // Sometimes we hit the limit for URL length of a GET request + // as we send the full target_doc. Hence this is a POST request. + type: "POST", + method: opts.method, + args: { + "source_name": opts.source_name, + "target_doc": cur_frm.doc + }, + callback: function(r) { + if(!r.exc) { + var doc = frappe.model.sync(r.message); + cur_frm.refresh(); + } + } + }); + } + if(opts.source_doctype) { + var d = new frappe.ui.Dialog({ + title: __("Get From ") + __(opts.source_doctype), + fields: [ + { + fieldtype: "Link", + label: __(opts.source_doctype), + fieldname: opts.source_doctype, + options: opts.source_doctype, + get_query: opts.get_query, + reqd:1 + }, + ] + }); + d.set_primary_action(__('Get Items'), function() { + var values = d.get_values(); + if(!values) + return; + opts.source_name = values[opts.source_doctype]; + d.hide(); + _map(); + }) + d.show(); + } else if(opts.source_name) { + _map(); + } +} + // add description on posting time $(document).on('app_ready', function() { if(!frappe.datetime.is_timezone_same()) { diff --git a/erpnext/selling/doctype/installation_note/installation_note.js b/erpnext/selling/doctype/installation_note/installation_note.js index 09deea2e2d..5b99691112 100644 --- a/erpnext/selling/doctype/installation_note/installation_note.js +++ b/erpnext/selling/doctype/installation_note/installation_note.js @@ -49,7 +49,7 @@ erpnext.selling.InstallationNote = frappe.ui.form.Controller.extend({ if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('From Delivery Note'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.stock.doctype.delivery_note.delivery_note.make_installation_note", source_doctype: "Delivery Note", get_query_filters: { diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js index f61f0e9849..d111c14734 100644 --- a/erpnext/selling/doctype/quotation/quotation.js +++ b/erpnext/selling/doctype/quotation/quotation.js @@ -29,7 +29,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({ if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Opportunity'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation", source_doctype: "Opportunity", get_query_filters: { diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js index d8ed59189f..f1eeccc750 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.js +++ b/erpnext/selling/doctype/sales_order/sales_order.js @@ -97,7 +97,7 @@ erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend( if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Quotation'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.quotation.quotation.make_sales_order", source_doctype: "Quotation", get_query_filters: { diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js index ab8297c3e3..65658d6421 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.js +++ b/erpnext/stock/doctype/delivery_note/delivery_note.js @@ -37,7 +37,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend( if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Sales Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note", source_doctype: "Sales Order", get_query_filters: { diff --git a/erpnext/stock/doctype/material_request/material_request.js b/erpnext/stock/doctype/material_request/material_request.js index 0a07582105..bbd312d72a 100644 --- a/erpnext/stock/doctype/material_request/material_request.js +++ b/erpnext/stock/doctype/material_request/material_request.js @@ -87,7 +87,7 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(__('Sales Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request", source_doctype: "Sales Order", get_query_filters: { diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js index f622b63568..792f269bcf 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js @@ -52,7 +52,7 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend if(this.frm.doc.docstatus==0) { cur_frm.add_custom_button(__('Purchase Order'), function() { - frappe.model.map_current_doc({ + erpnext.utils.map_current_doc({ method: "erpnext.buying.doctype.purchase_order.purchase_order.make_purchase_receipt", source_doctype: "Purchase Order", get_query_filters: {