From a648f46d4e67e04cb8396441889ff0b3641ba79f Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 30 Jul 2013 14:42:15 +0530 Subject: [PATCH] [fix] [minor] show stock ledger, general ledger, fixes post changes in script manager trigger [issue] webnotes/wnframework#228 --- .../journal_voucher/journal_voucher.js | 29 +++---- .../doctype/sales_invoice/sales_invoice.js | 8 +- hr/doctype/expense_claim/expense_claim.js | 12 +-- public/js/complete_setup.js | 2 +- public/js/controllers/stock_controller.js | 28 ++++--- public/js/transaction.js | 3 +- selling/doctype/opportunity/opportunity.js | 10 +-- selling/doctype/quotation/quotation.js | 2 +- setup/page/setup/setup.js | 78 +++++++++---------- stock/doctype/delivery_note/delivery_note.js | 2 + .../purchase_receipt/purchase_receipt.js | 7 ++ stock/doctype/stock_entry/stock_entry.js | 13 ++-- .../stock_reconciliation.js | 1 + .../doctype/customer_issue/customer_issue.js | 6 +- .../maintenance_visit/maintenance_visit.js | 6 +- website/templates/js/product_page.js | 2 +- 16 files changed, 106 insertions(+), 103 deletions(-) diff --git a/accounts/doctype/journal_voucher/journal_voucher.js b/accounts/doctype/journal_voucher/journal_voucher.js index a7f5b164c9..867ebbb459 100644 --- a/accounts/doctype/journal_voucher/journal_voucher.js +++ b/accounts/doctype/journal_voucher/journal_voucher.js @@ -18,10 +18,20 @@ wn.provide("erpnext.accounts"); erpnext.accounts.JournalVoucher = wn.ui.form.Controller.extend({ onload: function() { - this.load_defaults(this.frm.doc); + this.load_defaults(); this.setup_queries(); }, + load_defaults: function() { + if(this.frm.doc.__islocal && this.frm.doc.company) { + wn.model.set_default_values(this.frm.doc); + $.each(wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name, {parentfield: "entries"}), + function(i, jvd) { wn.model.set_default_values(jvd); }); + + this.frm.doc.posting_date = get_today(); + } + }, + setup_queries: function() { var me = this; @@ -82,23 +92,6 @@ cur_frm.cscript.refresh = function(doc) { } } -cur_frm.cscript.load_defaults = function(doc) { - if(!cur_frm.doc.__islocal || !cur_frm.doc.company) { return; } - - doc = locals[doc.doctype][doc.name]; - var fields_to_refresh = wn.model.set_default_values(doc); - if(fields_to_refresh) { refresh_many(fields_to_refresh); } - - fields_to_refresh = null; - var children = getchildren('Journal Voucher Detail', doc.name, 'entries'); - if(!children) { return; } - for(var i=0; i. wn.provide("erpnext"); +wn.require("app/js/controllers/stock_controller.js"); -erpnext.TransactionController = wn.ui.form.Controller.extend({ +erpnext.TransactionController = erpnext.stock.StockController.extend({ onload: function() { if(this.frm.doc.__islocal) { var me = this, diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index 81bc23cdbb..fb5bae5f61 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -86,15 +86,15 @@ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({ customer: function() { var me = this; if(this.frm.doc.customer) { - return this.frm.call({ - doc: this.frm.doc, - method: "set_customer_defaults", - }); - // TODO shift this to depends_on unhide_field(['customer_address', 'contact_person', 'customer_name', 'address_display', 'contact_display', 'contact_mobile', 'contact_email', 'territory', 'customer_group']); + + return this.frm.call({ + doc: this.frm.doc, + method: "set_customer_defaults", + }); } }, diff --git a/selling/doctype/quotation/quotation.js b/selling/doctype/quotation/quotation.js index 93af7cdea4..08ec6ab0ae 100644 --- a/selling/doctype/quotation/quotation.js +++ b/selling/doctype/quotation/quotation.js @@ -114,6 +114,7 @@ cur_frm.fields_dict.lead.get_query = function(doc,cdt,cdn) { cur_frm.cscript.lead = function(doc, cdt, cdn) { if(doc.lead) { + unhide_field('territory'); return cur_frm.call({ doc: cur_frm.doc, method: "set_lead_defaults", @@ -123,7 +124,6 @@ cur_frm.cscript.lead = function(doc, cdt, cdn) { } } }); - unhide_field('territory'); } } diff --git a/setup/page/setup/setup.js b/setup/page/setup/setup.js index ab640cf767..40b67d86cb 100644 --- a/setup/page/setup/setup.js +++ b/setup/page/setup/setup.js @@ -21,36 +21,7 @@ wn.pages.Setup.make = function(wrapper) { completed = 0; body.html('
\ -
') - - return wn.call({ - method: "setup.page.setup.setup.get", - callback: function(r) { - if(r.message) { - body.empty(); - if(wn.boot.expires_on) { - $(body).prepend("
Account expires on " - + wn.datetime.global_date_format(wn.boot.expires_on) + "
"); - } - - $completed = $('

Setup Completed

\ -
') - .appendTo(body); - - $.each(r.message, function(i, item) { - render_item(item) - }); - - var completed_percent = cint(flt(completed) / total * 100) + "%"; - $completed - .find(".progress-bar") - .css({"width": completed_percent}); - $(body) - .find(".completed-percent") - .html("(" + completed_percent + ")"); - } - } - }); +
'); var render_item = function(item, dependency) { if(item.type==="Section") { @@ -68,12 +39,12 @@ wn.pages.Setup.make = function(wrapper) { .appendTo(body); $('
').appendTo(row); - + if(item.type==="Link") { var col = $('').appendTo(row); - + } else { var col = $(repl('
\ %(count)s\ @@ -102,12 +73,12 @@ wn.pages.Setup.make = function(wrapper) { col.addClass("col-offset-1"); else $('
').appendTo(row); - + if(item.doctype) { var badge = col.find(".badge, .data-link") .attr("data-doctype", item.doctype) .css({"cursor": "pointer"}) - + if(item.single) { badge.click(function() { wn.set_route("Form", $(this).attr("data-doctype")) @@ -118,10 +89,10 @@ wn.pages.Setup.make = function(wrapper) { }) } } - + // tree $links = $('
').appendTo(row); - + if(item.tree) { $(' Browse\ | \ @@ -134,7 +105,7 @@ wn.pages.Setup.make = function(wrapper) { mylink.click(function() { wn.set_route(item.tree, item.doctype); }) - + } else if(item.single) { $(' Edit') .appendTo($links) @@ -183,7 +154,7 @@ wn.pages.Setup.make = function(wrapper) { wn.route_options = {doctype:$(this).attr("data-doctype")} wn.set_route("data-import-tool"); }) - + if(item.links) { $.each(item.links, function(i, link) { var newlinks = $(' | \ @@ -192,11 +163,40 @@ wn.pages.Setup.make = function(wrapper) { .appendTo($links) }) } - + if(item.dependencies) { $.each(item.dependencies, function(i, d) { render_item(d, true); }) } } + + return wn.call({ + method: "setup.page.setup.setup.get", + callback: function(r) { + if(r.message) { + body.empty(); + if(wn.boot.expires_on) { + $(body).prepend("
Account expires on " + + wn.datetime.global_date_format(wn.boot.expires_on) + "
"); + } + + $completed = $('

Setup Completed

\ +
') + .appendTo(body); + + $.each(r.message, function(i, item) { + render_item(item) + }); + + var completed_percent = cint(flt(completed) / total * 100) + "%"; + $completed + .find(".progress-bar") + .css({"width": completed_percent}); + $(body) + .find(".completed-percent") + .html("(" + completed_percent + ")"); + } + } + }); } \ No newline at end of file diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index 88a9840694..c5ae4315eb 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -36,6 +36,8 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend( if (doc.docstatus==1) { cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); + this.show_stock_ledger(); + this.show_general_ledger(); } if(doc.docstatus==0 && !doc.__islocal) { diff --git a/stock/doctype/purchase_receipt/purchase_receipt.js b/stock/doctype/purchase_receipt/purchase_receipt.js index a134da14d3..8705143cf2 100644 --- a/stock/doctype/purchase_receipt/purchase_receipt.js +++ b/stock/doctype/purchase_receipt/purchase_receipt.js @@ -33,6 +33,9 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend this.make_purchase_invoice); } cur_frm.add_custom_button('Send SMS', cur_frm.cscript['Send SMS']); + + this.show_stock_ledger(); + this.show_general_ledger(); } cur_frm.add_custom_button(wn._('From Purchase Order'), @@ -68,6 +71,10 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend var item = wn.model.get_doc(cdt, cdn); wn.model.round_floats_in(item, ["qty", "received_qty"]); + if(!(item.received_qty || item.rejected_qty) && item.qty) { + item.received_qty = item.qty; + } + if(item.qty > item.received_qty) { msgprint(wn._("Error") + ": " + wn._(wn.meta.get_label(item.doctype, "qty", item.name)) + " > " + wn._(wn.meta.get_label(item.doctype, "received_qty", item.name))); diff --git a/stock/doctype/stock_entry/stock_entry.js b/stock/doctype/stock_entry/stock_entry.js index 9e8c9a62af..4ade2ff4d4 100644 --- a/stock/doctype/stock_entry/stock_entry.js +++ b/stock/doctype/stock_entry/stock_entry.js @@ -25,8 +25,8 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ set_default_account: function() { var me = this; - if (sys_defaults.auto_inventory_accounting && !this.frm.doc.expense_adjustment_account) { - if (this.frm.doc.purpose == "Sales Return") + if (cint(wn.defaults.get_default("auto_inventory_accounting")) && !this.frm.doc.expense_adjustment_account) { + if (this.frm.doc.purpose == "Sales Return") account_for = "stock_in_hand_account"; else if (this.frm.doc.purpose == "Purchase Return") account_for = "stock_received_but_not_billed"; @@ -78,7 +78,7 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ } }; - if (sys_defaults.auto_inventory_accounting) { + if(cint(wn.defaults.get_default("auto_inventory_accounting"))) { this.frm.add_fetch("company", "stock_adjustment_account", "expense_adjustment_account"); this.frm.fields_dict["expense_adjustment_account"].get_query = function() { @@ -105,11 +105,8 @@ erpnext.stock.StockEntry = erpnext.stock.StockController.extend({ erpnext.hide_naming_series(); this.toggle_related_fields(this.frm.doc); this.toggle_enable_bom(); - if (this.frm.doc.docstatus==1) { - this.show_stock_ledger(); - if(wn.boot.auto_inventory_accounting) - this.show_general_ledger(); - } + this.show_stock_ledger(); + this.show_general_ledger(); if(this.frm.doc.docstatus === 1 && wn.boot.profile.can_create.indexOf("Journal Voucher")!==-1) { diff --git a/stock/doctype/stock_reconciliation/stock_reconciliation.js b/stock/doctype/stock_reconciliation/stock_reconciliation.js index 501b5afb25..2db8cba6b2 100644 --- a/stock/doctype/stock_reconciliation/stock_reconciliation.js +++ b/stock/doctype/stock_reconciliation/stock_reconciliation.js @@ -68,6 +68,7 @@ erpnext.stock.StockReconciliation = erpnext.stock.StockController.extend({ } else if(this.frm.doc.docstatus == 1) { this.frm.set_intro("Cancelling this Stock Reconciliation will nullify its effect."); this.show_stock_ledger(); + this.show_general_ledger(); } else { this.frm.set_intro(""); } diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 4f45220660..9535fbadfc 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -26,13 +26,13 @@ erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({ customer: function() { var me = this; if(this.frm.doc.customer) { + // TODO shift this to depends_on + unhide_field(['customer_address', 'contact_person']); + return this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", }); - - // TODO shift this to depends_on - unhide_field(['customer_address', 'contact_person']); } }, diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js index f4e4a35542..4257afaf0f 100644 --- a/support/doctype/maintenance_visit/maintenance_visit.js +++ b/support/doctype/maintenance_visit/maintenance_visit.js @@ -62,13 +62,13 @@ erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({ customer: function() { var me = this; if(this.frm.doc.customer) { + // TODO shift this to depends_on + cur_frm.cscript.hide_contact_info(); + return this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", }); - - // TODO shift this to depends_on - cur_frm.cscript.hide_contact_info(); } }, }); diff --git a/website/templates/js/product_page.js b/website/templates/js/product_page.js index 97d8f3d622..adfeb5e4ad 100644 --- a/website/templates/js/product_page.js +++ b/website/templates/js/product_page.js @@ -18,7 +18,7 @@ $(document).ready(function() { var item_code = $('[itemscope] [itemprop="name"]').text().trim(); var qty = 0; - return wn.call({ + wn.call({ type: "POST", method: "website.helpers.product.get_product_info", args: {