From 60403b2d8f72e39e8d720b0ab07a412b6ba4ffa4 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 25 Jul 2013 18:53:22 +0530 Subject: [PATCH 1/4] [fix] [minor] [grid] set_colum_disp should force refresh the whole grid --- accounts/doctype/sales_invoice/sales_invoice.js | 7 ++++--- buying/doctype/purchase_common/purchase_common.js | 8 ++++---- public/js/feature_setup.js | 3 +-- stock/doctype/delivery_note/delivery_note.js | 3 +-- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index 773956a67a..e4de474470 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -176,13 +176,14 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { if(cint(doc.is_pos) == 1) { hide_field(par_flds); unhide_field('payments_section'); - for(f in item_flds_normal) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal[f], false); + cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal, false); } else { hide_field('payments_section'); unhide_field(par_flds); - for(f in item_flds_normal) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal[f], true); + cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_normal, true); } - for(f in item_flds_pos) cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos[f], (cint(doc.update_stock)==1?true:false)); + + cur_frm.fields_dict['entries'].grid.set_column_disp(item_flds_pos, (cint(doc.update_stock)==1?true:false)); // India related fields var cp = wn.control_panel; diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 04263c3a5e..494a9dcb2c 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -485,12 +485,12 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ // toggle columns var item_grid = this.frm.fields_dict[this.fname].grid; - var show = this.frm.doc.currency != company_currency; - $.each(["purchase_rate", "purchase_ref_rate", "amount", "rate"], function(i, fname) { - if(wn.meta.get_docfield(item_grid.doctype, fname)) - item_grid.set_column_disp(fname, show); + var fieldnames = $.map(["purchase_rate", "purchase_ref_rate", "amount", "rate"], function(fname) { + return wn.meta.get_docfield(item_grid.doctype, fname, me.frm.docname) ? fname : null; }); + item_grid.set_column_disp(fieldnames, this.frm.doc.currency != company_currency); + // set labels var $wrapper = $(this.frm.wrapper); $.each(field_label_map, function(fname, label) { diff --git a/public/js/feature_setup.js b/public/js/feature_setup.js index abd3370d87..add4bfda9a 100644 --- a/public/js/feature_setup.js +++ b/public/js/feature_setup.js @@ -209,8 +209,7 @@ $(document).bind('form_refresh', function() { if(fort=='fields') { hide_field(pscript.feature_dict[sys_feat][cur_frm.doc.doctype][fort]); } else if(cur_frm.fields_dict[fort]) { - for(grid_field in pscript.feature_dict[sys_feat][cur_frm.doc.doctype][fort]) - cur_frm.fields_dict[fort].grid.set_column_disp(pscript.feature_dict[sys_feat][cur_frm.doc.doctype][fort][grid_field], false); + cur_frm.fields_dict[fort].grid.set_column_disp(pscript.feature_dict[sys_feat][cur_frm.doc.doctype][fort], false); } else { msgprint('Grid "'+fort+'" does not exists'); } diff --git a/stock/doctype/delivery_note/delivery_note.js b/stock/doctype/delivery_note/delivery_note.js index e93e6d3a78..a006766179 100644 --- a/stock/doctype/delivery_note/delivery_note.js +++ b/stock/doctype/delivery_note/delivery_note.js @@ -46,8 +46,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend( // unhide expense_account and cost_center is auto_inventory_accounting enabled var aii_enabled = cint(sys_defaults.auto_inventory_accounting) - cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("expense_account", aii_enabled); - cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp("cost_center", aii_enabled); + cur_frm.fields_dict[cur_frm.cscript.fname].grid.set_column_disp(["expense_account", "cost_center"], aii_enabled); if (this.frm.doc.docstatus===0) { cur_frm.add_custom_button(wn._('From Sales Order'), From 52b049145bb5dce6cef0b178f91a839dfab2c166 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 25 Jul 2013 19:13:45 +0530 Subject: [PATCH 2/4] [fix] [minor] call refresh_fields after cur_frm.call when doc is passed --- accounts/doctype/sales_invoice/sales_invoice.js | 5 ++++- buying/doctype/purchase_common/purchase_common.js | 1 - selling/doctype/installation_note/installation_note.js | 6 ------ selling/doctype/opportunity/opportunity.js | 4 ---- selling/doctype/sales_common/sales_common.js | 1 - support/doctype/customer_issue/customer_issue.js | 3 --- .../doctype/maintenance_schedule/maintenance_schedule.js | 3 --- support/doctype/maintenance_visit/maintenance_visit.js | 3 --- support/doctype/support_ticket/support_ticket.js | 3 --- 9 files changed, 4 insertions(+), 25 deletions(-) diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index b61cbb0b4a..aa21d5dd7e 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -120,6 +120,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte } // TODO toggle display of fields + cur_frm.cscript.hide_fields(this.frm.doc); }, debit_to: function() { @@ -162,7 +163,7 @@ $.extend(cur_frm.cscript, new erpnext.accounts.SalesInvoiceController({frm: cur_ // Hide Fields // ------------ -cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { +cur_frm.cscript.hide_fields = function(doc) { par_flds = ['project_name', 'due_date', 'is_opening', 'conversion_rate', 'source', 'total_advance', 'gross_profit', 'gross_profit_percent', 'get_advances_received', @@ -189,6 +190,8 @@ cur_frm.cscript.hide_fields = function(doc, cdt, cdn) { var cp = wn.control_panel; if (cp.country == 'India') unhide_field(['c_form_applicable', 'c_form_no']); else hide_field(['c_form_applicable', 'c_form_no']); + + cur_frm.refresh_fields(); } diff --git a/buying/doctype/purchase_common/purchase_common.js b/buying/doctype/purchase_common/purchase_common.js index 494a9dcb2c..148ba1c920 100644 --- a/buying/doctype/purchase_common/purchase_common.js +++ b/buying/doctype/purchase_common/purchase_common.js @@ -90,7 +90,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ freeze: true, callback: function(r) { if(!r.exc) { - me.frm.refresh_fields(); if(me.frm.doc.price_list_name !== price_list_name) me.price_list_name(); } } diff --git a/selling/doctype/installation_note/installation_note.js b/selling/doctype/installation_note/installation_note.js index dce0a31252..5ad698a0ca 100644 --- a/selling/doctype/installation_note/installation_note.js +++ b/selling/doctype/installation_note/installation_note.js @@ -81,9 +81,6 @@ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); // TODO shift this to depends_on @@ -105,9 +102,6 @@ erpnext.selling.InstallationNote = wn.ui.form.Controller.extend({ }, method: "get_customer_address", freeze: true, - callback: function(r) { - me.frm.refresh_fields(); - } }); } }, diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index 7c647c3f76..0ac22a116d 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -89,9 +89,6 @@ erpnext.selling.Opportunity = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); // TODO shift this to depends_on @@ -208,7 +205,6 @@ cur_frm.cscript['Declare Opportunity Lost'] = function(){ return; } dialog.hide(); - cur_frm.refresh(); }, btn: this }) diff --git a/selling/doctype/sales_common/sales_common.js b/selling/doctype/sales_common/sales_common.js index 9a13c4f98c..246d4a1ad3 100644 --- a/selling/doctype/sales_common/sales_common.js +++ b/selling/doctype/sales_common/sales_common.js @@ -142,7 +142,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ freeze: true, callback: function(r) { if(!r.exc) { - me.frm.refresh_fields(); (me.frm.doc.price_list_name !== price_list_name) ? me.price_list_name() : me.price_list_currency(); diff --git a/support/doctype/customer_issue/customer_issue.js b/support/doctype/customer_issue/customer_issue.js index 96662b95c7..3620c7e10a 100644 --- a/support/doctype/customer_issue/customer_issue.js +++ b/support/doctype/customer_issue/customer_issue.js @@ -29,9 +29,6 @@ erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); // TODO shift this to depends_on diff --git a/support/doctype/maintenance_schedule/maintenance_schedule.js b/support/doctype/maintenance_schedule/maintenance_schedule.js index d84726986a..f8652d7e16 100644 --- a/support/doctype/maintenance_schedule/maintenance_schedule.js +++ b/support/doctype/maintenance_schedule/maintenance_schedule.js @@ -47,9 +47,6 @@ erpnext.support.MaintenanceSchedule = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); } }, diff --git a/support/doctype/maintenance_visit/maintenance_visit.js b/support/doctype/maintenance_visit/maintenance_visit.js index f3faf3f292..9f5fc5d915 100644 --- a/support/doctype/maintenance_visit/maintenance_visit.js +++ b/support/doctype/maintenance_visit/maintenance_visit.js @@ -65,9 +65,6 @@ erpnext.support.MaintenanceVisit = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); // TODO shift this to depends_on diff --git a/support/doctype/support_ticket/support_ticket.js b/support/doctype/support_ticket/support_ticket.js index bd7e6ccf1f..d8cc798c95 100644 --- a/support/doctype/support_ticket/support_ticket.js +++ b/support/doctype/support_ticket/support_ticket.js @@ -26,9 +26,6 @@ erpnext.support.CustomerIssue = wn.ui.form.Controller.extend({ this.frm.call({ doc: this.frm.doc, method: "set_customer_defaults", - callback: function(r) { - if(!r.exc) me.frm.refresh_fields(); - } }); } } From 23de6df72efe90dc58e087f907aaf85ea1135a5a Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 25 Jul 2013 19:30:13 +0530 Subject: [PATCH 3/4] [fix] [minor] replace single quote in territory name while creating territories in setup control --- setup/doctype/setup_control/setup_control.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup/doctype/setup_control/setup_control.py b/setup/doctype/setup_control/setup_control.py index b029da3e2b..5a1840436e 100644 --- a/setup/doctype/setup_control/setup_control.py +++ b/setup/doctype/setup_control/setup_control.py @@ -256,7 +256,7 @@ def create_territories(): if name and not webnotes.conn.exists("Territory", name): webnotes.bean({ "doctype": "Territory", - "territory_name": name, + "territory_name": name.replace("'", ""), "parent_territory": root_territory, "is_group": "No" }).insert() From 3986badd06ab17060c5849d7d23914caec1eda11 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 26 Jul 2013 11:01:17 +0530 Subject: [PATCH 4/4] [feature] If customer/supplier account freezed do not allow to make any transaction --- controllers/accounts_controller.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/controllers/accounts_controller.py b/controllers/accounts_controller.py index abefb9bc3d..27bb2a5155 100644 --- a/controllers/accounts_controller.py +++ b/controllers/accounts_controller.py @@ -34,6 +34,8 @@ class AccountsController(TransactionBase): self.validate_value("grand_total", ">=", 0) self.set_total_in_words() + self.validate_for_freezed_account() + def set_missing_values(self, for_validate=False): for fieldname in ["posting_date", "transaction_date"]: if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): @@ -52,6 +54,18 @@ class AccountsController(TransactionBase): if date_field and self.doc.fields[date_field]: validate_fiscal_year(self.doc.fields[date_field], self.doc.fiscal_year, label=self.meta.get_label(date_field)) + + def validate_for_freezed_account(self): + for fld in ["customer", "supplier"]: + if self.meta.get_field(fld): + accounts = webnotes.conn.get_values("Account", {"master_type": fld.upper(), + "master_name": self.doc.fields[fld], "company": self.doc.company}, + "freeze_account", as_dict=1) + + if accounts: + if not filter(lambda x: cstr(x.freeze_account) in ["", "No"], accounts): + msgprint(_("Account for this ") + fld + _(" has been freezed. ") + + self.doc.doctype + _(" can not be made."), raise_exception=1) def set_price_list_currency(self, buying_or_selling): # TODO - change this, since price list now has only one currency allowed