[fix] dashboard for customer, supplier

This commit is contained in:
Rushabh Mehta 2016-04-11 17:34:25 +05:30
parent 126ef64203
commit 5d0e8dee11
12 changed files with 213 additions and 218 deletions

View File

@ -5,12 +5,14 @@ from __future__ import unicode_literals
import frappe import frappe
from frappe import _
from frappe.utils import evaluate_filters from frappe.utils import evaluate_filters
from erpnext.startup.notifications import get_notification_config from frappe.desk.notifications import get_filters_for
# NOTE: if you change this also update triggers in erpnext/hooks.py
status_depends_on = { status_depends_on = {
'Customer': ('Opportunity', 'Quotation', 'Sales Order', 'Sales Invoice', 'Project', 'Issue'), 'Customer': ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'Project', 'Issue'),
'Supplier': ('Supplier Quotation', 'Purchase Order', 'Purchase Invoice') 'Supplier': ('Supplier Quotation', 'Purchase Order', 'Purchase Receipt', 'Purchase Invoice')
} }
default_status = { default_status = {
@ -35,11 +37,11 @@ def notify_status(doc, method):
return return
party = frappe.get_doc(party_type, name) party = frappe.get_doc(party_type, name)
config = get_notification_config().get('for_doctype').get(doc.doctype) filters = get_filters_for(doc.doctype)
status = None status = None
if config: if filters:
if evaluate_filters(doc, config): if evaluate_filters(doc, filters):
# filters match, passed document is open # filters match, passed document is open
status = 'Open' status = 'Open'
@ -56,21 +58,45 @@ def notify_status(doc, method):
party.status = status party.status = status
update_status(party, ) update_status(party, )
def update_status(doc): def get_party_status(doc):
'''Set status as open if there is any open notification''' '''return party status based on open documents'''
config = get_notification_config() status = default_status[doc.doctype]
original_status = doc.status
doc.status = default_status[doc.doctype]
for doctype in status_depends_on[doc.doctype]: for doctype in status_depends_on[doc.doctype]:
filters = config.get('for_doctype', {}).get(doctype) or {} filters = get_filters_for(doctype)
filters[doc.doctype.lower()] = doc.name filters[doc.doctype.lower()] = doc.name
if filters: if filters:
open_count = frappe.get_all(doctype, fields='count(*) as count', filters=filters) open_count = frappe.get_all(doctype, fields='name', filters=filters, limit_page_length=1)
if open_count[0].count > 0: if len(open_count) > 0:
doc.status = 'Open' status = 'Open'
break break
if doc.status != original_status: return status
doc.db_set('status', doc.status)
def update_status(doc):
'''Set status as open if there is any open notification'''
status = get_party_status(doc)
if doc.status != status:
doc.db_set('status', status)
def get_transaction_count(doc):
'''Return list of open documents given party doc'''
out = []
for doctype in status_depends_on[doc.doctype]:
filters = get_filters_for(doctype)
filters[doc.doctype.lower()] = doc.name
if filters:
open_count = frappe.get_all(doctype, fields='count(*) as count', filters=filters)[0].count
out.append({'name': doctype, 'count': open_count})
return out
@frappe.whitelist()
def get_transaction_info(party_type, party_name):
doc = frappe.get_doc(party_type, party_name)
if not doc.has_permission('read'):
frappe.msgprint(_("Not permitted"), raise_exception=True)
out = {}
out['transaction_count'] = get_transaction_count(doc)
return out

View File

@ -6,7 +6,7 @@ frappe.ui.form.on("Supplier", {
frappe.setup_language_field(frm); frappe.setup_language_field(frm);
}, },
refresh: function(frm) { refresh: function(frm) {
frm.cscript.make_dashboard(frm.doc); erpnext.party.setup_dashboard(frm);
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") { if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false); frm.toggle_display("naming_series", false);
@ -26,55 +26,23 @@ frappe.ui.form.on("Supplier", {
frm.events.add_custom_buttons(frm); frm.events.add_custom_buttons(frm);
}, },
add_custom_buttons: function(frm) { add_custom_buttons: function(frm) {
["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"].forEach(function(doctype, i) { // ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"].forEach(function(doctype, i) {
if(frappe.model.can_read(doctype)) { // if(frappe.model.can_read(doctype)) {
frm.add_custom_button(__(doctype), function() { // frm.add_custom_button(__(doctype), function() {
frappe.route_options = {"supplier": frm.doc.name}; // frappe.route_options = {"supplier": frm.doc.name};
frappe.set_route("List", doctype); // frappe.set_route("List", doctype);
}, __("View")); // }, __("View"));
} // }
if(frappe.model.can_create(doctype)) { // if(frappe.model.can_create(doctype)) {
frm.add_custom_button(__(doctype), function() { // frm.add_custom_button(__(doctype), function() {
frappe.route_options = {"supplier": frm.doc.name}; // frappe.route_options = {"supplier": frm.doc.name};
new_doc(doctype); // new_doc(doctype);
}, __("Make")); // }, __("Make"));
} // }
}); // });
}, },
}); });
cur_frm.cscript.make_dashboard = function(doc) {
cur_frm.dashboard.reset();
if(doc.__islocal)
return;
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
cur_frm.dashboard.set_headline('<span class="text-muted">' + __('Loading') + '</span>')
cur_frm.dashboard.add_doctype_badge("Supplier Quotation", "supplier");
cur_frm.dashboard.add_doctype_badge("Purchase Order", "supplier");
cur_frm.dashboard.add_doctype_badge("Purchase Receipt", "supplier");
cur_frm.dashboard.add_doctype_badge("Purchase Invoice", "supplier");
return frappe.call({
type: "GET",
method: "erpnext.buying.doctype.supplier.supplier.get_dashboard_info",
args: {
supplier: cur_frm.doc.name
},
callback: function(r) {
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
cur_frm.dashboard.set_headline(
__("Total billing this year") + ": <b>"
+ format_currency(r.message.billing_this_year, cur_frm.doc.party_account_currency)
+ '</b> / <span class="text-muted">' + __("Total Unpaid") + ": <b>"
+ format_currency(r.message.total_unpaid, cur_frm.doc.party_account_currency)
+ '</b></span>');
}
cur_frm.dashboard.set_badge_count(r.message);
}
})
}
cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) { cur_frm.fields_dict['default_price_list'].get_query = function(doc, cdt, cdn) {
return{ return{
filters:{'buying': 1} filters:{'buying': 1}

View File

@ -13,7 +13,7 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"fieldname": "basic_info", "fieldname": "basic_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -21,7 +21,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "", "label": "Name and Type",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"oldfieldtype": "Section Break", "oldfieldtype": "Section Break",
@ -191,6 +191,32 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "language",
"fieldtype": "Select",
"hidden": 0,
"ignore_user_permissions": 0,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Print Language",
"length": 0,
"no_copy": 0,
"options": "Loading...",
"permlevel": 0,
"precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 1, "bold": 1,
@ -220,7 +246,7 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"fieldname": "section_break_7", "fieldname": "section_break_7",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -228,6 +254,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Currency and Price List",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"permlevel": 0, "permlevel": 0,
@ -266,31 +293,6 @@
"set_only_once": 0, "set_only_once": 0,
"unique": 0 "unique": 0
}, },
{
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
"fieldname": "default_price_list",
"fieldtype": "Link",
"hidden": 0,
"ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
"label": "Price List",
"length": 0,
"no_copy": 0,
"options": "Price List",
"permlevel": 0,
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
"report_hide": 0,
"reqd": 0,
"search_index": 0,
"set_only_once": 0,
"unique": 0
},
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
@ -319,19 +321,18 @@
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 0,
"fieldname": "language", "fieldname": "default_price_list",
"fieldtype": "Select", "fieldtype": "Link",
"hidden": 0, "hidden": 0,
"ignore_user_permissions": 0, "ignore_user_permissions": 1,
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "Print Language", "label": "Price List",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"options": "Loading...", "options": "Price List",
"permlevel": 0, "permlevel": 0,
"precision": "",
"print_hide": 0, "print_hide": 0,
"print_hide_if_no_value": 0, "print_hide_if_no_value": 0,
"read_only": 0, "read_only": 0,
@ -420,7 +421,7 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts", "fieldname": "address_contacts",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -684,7 +685,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-04-08 07:43:07.541419", "modified": "2016-04-11 08:01:21.188319",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Buying", "module": "Buying",
"name": "Supplier", "name": "Supplier",

View File

@ -9,6 +9,7 @@ from frappe.model.naming import make_autoname
from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.utilities.address_and_contact import load_address_and_contact
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
from erpnext.accounts.party import validate_party_accounts from erpnext.accounts.party import validate_party_accounts
from erpnext.accounts.party_status import get_transaction_count, get_party_status, status_depends_on
class Supplier(TransactionBase): class Supplier(TransactionBase):
def get_feed(self): def get_feed(self):
@ -17,6 +18,7 @@ class Supplier(TransactionBase):
def onload(self): def onload(self):
"""Load address and contacts in `__onload`""" """Load address and contacts in `__onload`"""
load_address_and_contact(self, "supplier") load_address_and_contact(self, "supplier")
self.set_onload('transactions', status_depends_on[self.doctype])
def autoname(self): def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name') supp_master_name = frappe.defaults.get_global_default('supp_master_name')
@ -47,6 +49,7 @@ class Supplier(TransactionBase):
msgprint(_("Series is mandatory"), raise_exception=1) msgprint(_("Series is mandatory"), raise_exception=1)
validate_party_accounts(self) validate_party_accounts(self)
self.status = get_party_status(self)
def get_contacts(self,nm): def get_contacts(self,nm):
if nm: if nm:
@ -82,30 +85,29 @@ class Supplier(TransactionBase):
{set_field} where supplier=%(newdn)s"""\ {set_field} where supplier=%(newdn)s"""\
.format(set_field=set_field), ({"newdn": newdn})) .format(set_field=set_field), ({"newdn": newdn}))
@frappe.whitelist() # @frappe.whitelist()
def get_dashboard_info(supplier): # def get_dashboard_info(supplier):
if not frappe.has_permission("Supplier", "read", supplier): # doc = frappe.get_doc('Supplier', supplier)
frappe.throw(_("No permission")) # if not doc.has_permission('read'):
# frappe.msgprint(_("Not permitted"), raise_exception=True)
out = {} #
for doctype in ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]: # out = {}
out[doctype] = frappe.db.get_value(doctype, # out['transaction_count'] = get_transaction_count(doc)
{"supplier": supplier, "docstatus": ["!=", 2] }, "count(*)") #
# billing_this_year = frappe.db.sql("""
billing_this_year = frappe.db.sql(""" # select sum(credit_in_account_currency) - sum(debit_in_account_currency)
select sum(credit_in_account_currency) - sum(debit_in_account_currency) # from `tabGL Entry`
from `tabGL Entry` # where voucher_type='Purchase Invoice' and party_type = 'Supplier'
where voucher_type='Purchase Invoice' and party_type = 'Supplier' # and party=%s and fiscal_year = %s""",
and party=%s and fiscal_year = %s""", # (supplier, frappe.db.get_default("fiscal_year")))
(supplier, frappe.db.get_default("fiscal_year"))) #
# total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
total_unpaid = frappe.db.sql("""select sum(outstanding_amount) # from `tabPurchase Invoice`
from `tabPurchase Invoice` # where supplier=%s and docstatus = 1""", supplier)
where supplier=%s and docstatus = 1""", supplier) #
#
# out["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
out["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0 # out["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
out["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0 # out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany")
out["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany") #
# return out
return out

View File

@ -135,8 +135,9 @@ doc_events = {
}, },
# bubble transaction notification on master # bubble transaction notification on master
('Opportunity', 'Quotation', 'Sales Order', 'Sales Invoice', 'Supplier Quotation', ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice',
'Purchase Order', 'Purchase Invoice', 'Project', 'Issue'): { 'Supplier Quotation', 'Purchase Order', 'Purchase Receipt',
'Purchase Invoice', 'Project', 'Issue'): {
'on_change': 'erpnext.accounts.party_status.notify_status' 'on_change': 'erpnext.accounts.party_status.notify_status'
} }
} }

View File

@ -44,7 +44,7 @@
padding: 50% 0; padding: 50% 0;
text-align: center; text-align: center;
line-height: 0; line-height: 0;
color: #fff; color: #d1d8dd;
font-size: 30px; font-size: 30px;
background-size: cover; background-size: cover;
border: 1px solid transparent; border: 1px solid transparent;

View File

@ -2,6 +2,7 @@
// License: GNU General Public License v3. See license.txt // License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.utils"); frappe.provide("erpnext.utils");
frappe.provide('erpnext.party');
erpnext.utils.get_party_details = function(frm, method, args, callback) { erpnext.utils.get_party_details = function(frm, method, args, callback) {
if(!method) { if(!method) {
method = "erpnext.accounts.party.get_party_details"; method = "erpnext.accounts.party.get_party_details";
@ -69,7 +70,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field,
if(r.message) { if(r.message) {
frm.set_value(display_field, r.message) frm.set_value(display_field, r.message)
} }
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) { if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) {
if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier", if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier",
frm.doc.customer || frm.doc.supplier, address_field)) return; frm.doc.customer || frm.doc.supplier, address_field)) return;
@ -99,7 +100,7 @@ erpnext.utils.get_address_display = function(frm, address_field, display_field,
} else { } else {
frm.set_value(display_field, null); frm.set_value(display_field, null);
} }
} }
erpnext.utils.get_contact_details = function(frm) { erpnext.utils.get_contact_details = function(frm) {
@ -139,3 +140,30 @@ erpnext.utils.get_shipping_address = function(frm){
} }
}); });
} }
erpnext.party.setup_dashboard = function(frm) {
frm.dashboard.reset(frm.doc);
if(frm.doc.__islocal)
return;
$.each(frm.doc.__onload.transactions, function(i, doctype) {
frm.dashboard.add_doctype_badge(doctype, frm.doc.doctype.toLowerCase());
})
return frappe.call({
type: "GET",
method: "erpnext.accounts.party_status.get_transaction_info",
args: {
party_type: frm.doc.doctype,
party_name: frm.doc.name
},
callback: function(r) {
$.each(r.message.transaction_count, function(i, d) {
if(d.count) {
frm.dashboard.set_badge_count(d.name, d.count)
}
})
}
});
}

View File

@ -1,3 +1,5 @@
@import "../../../../frappe/frappe/public/less/variables.less";
.erpnext-footer { .erpnext-footer {
margin: 11px auto; margin: 11px auto;
text-align: center; text-align: center;
@ -54,7 +56,7 @@
padding: 50% 0; padding: 50% 0;
text-align: center; text-align: center;
line-height: 0; line-height: 0;
color: #fff; color: @text-extra-muted;
font-size: 30px; font-size: 30px;
background-size: cover; background-size: cover;
border: 1px solid transparent; border: 1px solid transparent;

View File

@ -6,7 +6,7 @@ frappe.ui.form.on("Customer", {
frappe.setup_language_field(frm); frappe.setup_language_field(frm);
}, },
refresh: function(frm) { refresh: function(frm) {
frm.cscript.setup_dashboard(frm.doc); erpnext.party.setup_dashboard(frm);
if(frappe.defaults.get_default("cust_master_name")!="Naming Series") { if(frappe.defaults.get_default("cust_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false); frm.toggle_display("naming_series", false);
@ -29,20 +29,20 @@ frappe.ui.form.on("Customer", {
frm.events.add_custom_buttons(frm); frm.events.add_custom_buttons(frm);
}, },
add_custom_buttons: function(frm) { add_custom_buttons: function(frm) {
["Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].forEach(function(doctype, i) { // ["Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].forEach(function(doctype, i) {
if(frappe.model.can_read(doctype)) { // if(frappe.model.can_read(doctype)) {
frm.add_custom_button(__(doctype), function() { // frm.add_custom_button(__(doctype), function() {
frappe.route_options = {"customer": frm.doc.name}; // frappe.route_options = {"customer": frm.doc.name};
frappe.set_route("List", doctype); // frappe.set_route("List", doctype);
}, __("View")); // }, __("View"));
} // }
if(frappe.model.can_create(doctype)) { // if(frappe.model.can_create(doctype)) {
frm.add_custom_button(__(doctype), function() { // frm.add_custom_button(__(doctype), function() {
frappe.route_options = {"customer": frm.doc.name}; // frappe.route_options = {"customer": frm.doc.name};
new_doc(doctype); // new_doc(doctype);
}, __("Make")); // }, __("Make"));
} // }
}); // });
}, },
validate: function(frm) { validate: function(frm) {
if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name); if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name);
@ -64,40 +64,6 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn) {
cur_frm.add_fetch('lead_name', 'company_name', 'customer_name'); cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate'); cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
cur_frm.cscript.setup_dashboard = function(doc) {
cur_frm.dashboard.reset(doc);
if(doc.__islocal)
return;
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager"))
cur_frm.dashboard.set_headline('<span class="text-muted">'+ __('Loading...')+ '</span>')
cur_frm.dashboard.add_doctype_badge("Opportunity", "customer");
cur_frm.dashboard.add_doctype_badge("Quotation", "customer");
cur_frm.dashboard.add_doctype_badge("Sales Order", "customer");
cur_frm.dashboard.add_doctype_badge("Delivery Note", "customer");
cur_frm.dashboard.add_doctype_badge("Sales Invoice", "customer");
cur_frm.dashboard.add_doctype_badge("Project", "customer");
return frappe.call({
type: "GET",
method: "erpnext.selling.doctype.customer.customer.get_dashboard_info",
args: {
customer: cur_frm.doc.name
},
callback: function(r) {
if (in_list(user_roles, "Accounts User") || in_list(user_roles, "Accounts Manager")) {
cur_frm.dashboard.set_headline(
__("Total billing this year") + ": <b>"
+ format_currency(r.message.billing_this_year, cur_frm.doc.party_account_currency)
+ '</b> / <span class="text-muted">' + __("Unpaid") + ": <b>"
+ format_currency(r.message.total_unpaid, cur_frm.doc.party_account_currency)
+ '</b></span>');
}
cur_frm.dashboard.set_badge_count(r.message);
}
});
}
cur_frm.fields_dict['customer_group'].get_query = function(doc, dt, dn) { cur_frm.fields_dict['customer_group'].get_query = function(doc, dt, dn) {
return{ return{
filters:{'is_group': 'No'} filters:{'is_group': 'No'}

View File

@ -13,7 +13,7 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"fieldname": "basic_info", "fieldname": "basic_info",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"hidden": 0, "hidden": 0,
@ -21,7 +21,7 @@
"ignore_xss_filter": 0, "ignore_xss_filter": 0,
"in_filter": 0, "in_filter": 0,
"in_list_view": 0, "in_list_view": 0,
"label": "", "label": "Name and Type",
"length": 0, "length": 0,
"no_copy": 0, "no_copy": 0,
"oldfieldtype": "Section Break", "oldfieldtype": "Section Break",
@ -452,7 +452,7 @@
{ {
"allow_on_submit": 0, "allow_on_submit": 0,
"bold": 0, "bold": 0,
"collapsible": 0, "collapsible": 1,
"depends_on": "eval:!doc.__islocal", "depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts", "fieldname": "address_contacts",
"fieldtype": "Section Break", "fieldtype": "Section Break",
@ -954,7 +954,7 @@
"issingle": 0, "issingle": 0,
"istable": 0, "istable": 0,
"max_attachments": 0, "max_attachments": 0,
"modified": "2016-04-08 07:43:01.381976", "modified": "2016-04-11 08:00:08.829976",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Selling", "module": "Selling",
"name": "Customer", "name": "Customer",

View File

@ -11,6 +11,7 @@ from frappe.desk.reportview import build_match_conditions
from erpnext.utilities.transaction_base import TransactionBase from erpnext.utilities.transaction_base import TransactionBase
from erpnext.utilities.address_and_contact import load_address_and_contact from erpnext.utilities.address_and_contact import load_address_and_contact
from erpnext.accounts.party import validate_party_accounts from erpnext.accounts.party import validate_party_accounts
from erpnext.accounts.party_status import get_transaction_count, get_party_status, status_depends_on
class Customer(TransactionBase): class Customer(TransactionBase):
def get_feed(self): def get_feed(self):
@ -19,6 +20,7 @@ class Customer(TransactionBase):
def onload(self): def onload(self):
"""Load address and contacts in `__onload`""" """Load address and contacts in `__onload`"""
load_address_and_contact(self, "customer") load_address_and_contact(self, "customer")
self.set_onload('transactions', status_depends_on[self.doctype])
def autoname(self): def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name') cust_master_name = frappe.defaults.get_global_default('cust_master_name')
@ -42,6 +44,7 @@ class Customer(TransactionBase):
def validate(self): def validate(self):
self.flags.is_new_doc = self.is_new() self.flags.is_new_doc = self.is_new()
validate_party_accounts(self) validate_party_accounts(self)
self.status = get_party_status(self)
def update_lead_status(self): def update_lead_status(self):
if self.lead_name: if self.lead_name:
@ -125,32 +128,31 @@ class Customer(TransactionBase):
{set_field} where customer=%(newdn)s"""\ {set_field} where customer=%(newdn)s"""\
.format(set_field=set_field), ({"newdn": newdn})) .format(set_field=set_field), ({"newdn": newdn}))
@frappe.whitelist() # @frappe.whitelist()
def get_dashboard_info(customer): # def get_dashboard_info(customer):
if not frappe.has_permission("Customer", "read", customer): # doc = frappe.get_doc('Customer', customer)
frappe.msgprint(_("Not permitted"), raise_exception=True) # if not doc.has_permission('read'):
# frappe.msgprint(_("Not permitted"), raise_exception=True)
out = {} #
for doctype in ["Opportunity", "Quotation", "Sales Order", "Delivery Note", #
"Sales Invoice", "Project"]: # out = {}
out[doctype] = frappe.db.get_value(doctype, # out['transaction_count'] = get_transaction_count(doc)
{"customer": customer, "docstatus": ["!=", 2] }, "count(*)") #
# billing_this_year = frappe.db.sql("""
billing_this_year = frappe.db.sql(""" # select sum(debit_in_account_currency) - sum(credit_in_account_currency)
select sum(debit_in_account_currency) - sum(credit_in_account_currency) # from `tabGL Entry`
from `tabGL Entry` # where voucher_type='Sales Invoice' and party_type = 'Customer'
where voucher_type='Sales Invoice' and party_type = 'Customer' # and party=%s and fiscal_year = %s""",
and party=%s and fiscal_year = %s""", # (customer, frappe.db.get_default("fiscal_year")))
(customer, frappe.db.get_default("fiscal_year"))) #
# total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
total_unpaid = frappe.db.sql("""select sum(outstanding_amount) # from `tabSales Invoice`
from `tabSales Invoice` # where customer=%s and docstatus = 1""", customer)
where customer=%s and docstatus = 1""", customer) #
# out["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0
out["billing_this_year"] = billing_this_year[0][0] if billing_this_year else 0 # out["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0
out["total_unpaid"] = total_unpaid[0][0] if total_unpaid else 0 #
# return out
return out
def get_customer_list(doctype, txt, searchfield, start, page_len, filters): def get_customer_list(doctype, txt, searchfield, start, page_len, filters):

View File

@ -26,7 +26,6 @@ def get_notification_config():
"Leave Application": {"status": "Open"}, "Leave Application": {"status": "Open"},
"Expense Claim": {"approval_status": "Draft"}, "Expense Claim": {"approval_status": "Draft"},
"Job Applicant": {"status": "Open"}, "Job Applicant": {"status": "Open"},
"Purchase Receipt": {"docstatus": 0},
"Delivery Note": {"docstatus": 0}, "Delivery Note": {"docstatus": 0},
"Stock Entry": {"docstatus": 0}, "Stock Entry": {"docstatus": 0},
"Material Request": { "Material Request": {
@ -34,13 +33,13 @@ def get_notification_config():
"status": ("not in", ("Stopped",)), "status": ("not in", ("Stopped",)),
"per_ordered": ("<", 100) "per_ordered": ("<", 100)
}, },
"Request for Quotation": { "Request for Quotation": { "docstatus": 0 },
"docstatus": 0 "Supplier Quotation": {"docstatus": 0},
},
"Purchase Order": { "Purchase Order": {
"status": ("not in", ("Completed", "Closed")), "status": ("not in", ("Completed", "Closed")),
"docstatus": ("<", 2) "docstatus": ("<", 2)
}, },
"Purchase Receipt": {"docstatus": 0},
"Production Order": { "status": "In Process" }, "Production Order": { "status": "In Process" },
"BOM": {"docstatus": 0}, "BOM": {"docstatus": 0},
"Timesheet": {"docstatus": 0}, "Timesheet": {"docstatus": 0},