[minor] [enhance] fixes #6222

This commit is contained in:
Rushabh Mehta 2016-09-19 15:27:09 +05:30
parent e35dbca01b
commit bd15e31ea1
3 changed files with 66 additions and 77 deletions

View File

@ -2,6 +2,19 @@
// License: GNU General Public License v3. See license.txt
frappe.ui.form.on("Supplier", {
setup: function(frm) {
frm.set_query('default_price_list', { 'buying': 1});
frm.set_query('account', 'accounts', function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
return {
filters: {
'account_type': 'Payable',
'company': d.company,
"is_group": 0
}
}
});
},
refresh: function(frm) {
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);
@ -16,23 +29,14 @@ frappe.ui.form.on("Supplier", {
else {
unhide_field(['address_html','contact_html']);
erpnext.utils.render_address_and_contact(frm);
frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.set_route('query-report', 'General Ledger',
{party_type:'Supplier', party:frm.doc.name});
});
frm.add_custom_button(__('Accounts Payable'), function() {
frappe.set_route('query-report', 'Accounts Payable', {supplier:frm.doc.name});
});
}
},
});
cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) {
return{
filters:{'buying': 1}
}
}
cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
return {
filters: {
'account_type': 'Payable',
'company': d.company,
"is_group": 0
}
}
}

View File

@ -2,6 +2,29 @@
// License: GNU General Public License v3. See license.txt
frappe.ui.form.on("Customer", {
setup: function(frm) {
frm.add_fetch('lead_name', 'company_name', 'customer_name');
frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
frm.set_query('customer_group', {'is_group': 0});
frm.set_query('default_price_list', { 'selling': 1});
frm.set_query('account', 'accounts', function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
var filters = {
'account_type': 'Receivable',
'company': d.company,
"is_group": 0
};
if(doc.party_account_currency) {
$.extend(filters, {"account_currency": doc.party_account_currency});
}
return {
filters: filters
}
});
},
refresh: function(frm) {
if(frappe.defaults.get_default("cust_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);
@ -13,6 +36,14 @@ frappe.ui.form.on("Customer", {
if(!frm.doc.__islocal) {
erpnext.utils.render_address_and_contact(frm);
frm.add_custom_button(__('Accounting Ledger'), function() {
frappe.set_route('query-report', 'General Ledger',
{party_type:'Customer', party:frm.doc.name});
});
frm.add_custom_button(__('Accounts Receivable'), function() {
frappe.set_route('query-report', 'Accounts Receivable', {customer:frm.doc.name});
});
} else {
erpnext.utils.clear_address_and_contact(frm);
}
@ -23,55 +54,5 @@ frappe.ui.form.on("Customer", {
},
validate: function(frm) {
if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name);
}
},
});
cur_frm.cscript.onload = function(doc, dt, dn) {
cur_frm.cscript.load_defaults(doc, dt, dn);
}
cur_frm.cscript.load_defaults = function(doc, dt, dn) {
doc = locals[doc.doctype][doc.name];
if(!(doc.__islocal && doc.lead_name)) { return; }
var fields_to_refresh = frappe.model.set_default_values(doc);
if(fields_to_refresh) { refresh_many(fields_to_refresh); }
}
cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
cur_frm.fields_dict['customer_group'].get_query = function(doc, dt, dn) {
return{
filters:{'is_group': 0}
}
}
cur_frm.fields_dict.lead_name.get_query = function(doc, cdt, cdn) {
return{
query: "erpnext.controllers.queries.lead_query"
}
}
cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) {
return{
filters:{'selling': 1}
}
}
cur_frm.fields_dict['accounts'].grid.get_field('account').get_query = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
var filters = {
'account_type': 'Receivable',
'company': d.company,
"is_group": 0
};
if(doc.party_account_currency) {
$.extend(filters, {"account_currency": doc.party_account_currency});
}
return {
filters: filters
}
}

View File

@ -46,9 +46,22 @@ class Customer(TransactionBase):
def validate(self):
self.flags.is_new_doc = self.is_new()
self.flags.old_lead = self.lead_name
validate_party_accounts(self)
self.status = get_party_status(self)
def on_update(self):
self.validate_name_with_customer_group()
if self.flags.old_lead != self.lead_name:
self.update_lead_status()
self.update_address()
self.update_contact()
if self.flags.is_new_doc:
self.create_lead_address_contact()
def update_lead_status(self):
'''If Customer created from Lead, update lead status to "Converted"
update Customer link in Quotation, Opportunity'''
@ -88,15 +101,6 @@ class Customer(TransactionBase):
if not frappe.db.exists("Contact", c.name):
c.insert()
def on_update(self):
self.validate_name_with_customer_group()
self.update_address()
self.update_contact()
if self.flags.is_new_doc:
self.create_lead_address_contact()
def validate_name_with_customer_group(self):
if frappe.db.exists("Customer Group", self.name):
frappe.throw(_("A Customer Group exists with same name please change the Customer name or rename the Customer Group"), frappe.NameError)