Merge pull request #5195 from nabinhait/stock_non_stock_item_toggle
Dont allow to toggle stock and non-stock settings if any transaction exists against the item
diff --git a/erpnext/accounts/party_status.py b/erpnext/accounts/party_status.py
index 791250c..53810b7 100644
--- a/erpnext/accounts/party_status.py
+++ b/erpnext/accounts/party_status.py
@@ -6,11 +6,12 @@
import frappe
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 = {
- 'Customer': ('Opportunity', 'Quotation', 'Sales Order', 'Sales Invoice', 'Project', 'Issue'),
- 'Supplier': ('Supplier Quotation', 'Purchase Order', 'Purchase Invoice')
+ 'Customer': ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'Project', 'Issue'),
+ 'Supplier': ('Supplier Quotation', 'Purchase Order', 'Purchase Receipt', 'Purchase Invoice')
}
default_status = {
@@ -35,11 +36,11 @@
return
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
- if config:
- if evaluate_filters(doc, config):
+ if filters:
+ if evaluate_filters(doc, filters):
# filters match, passed document is open
status = 'Open'
@@ -56,21 +57,22 @@
party.status = status
update_status(party, )
-def update_status(doc):
- '''Set status as open if there is any open notification'''
- config = get_notification_config()
-
- original_status = doc.status
-
- doc.status = default_status[doc.doctype]
+def get_party_status(doc):
+ '''return party status based on open documents'''
+ status = default_status[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
if filters:
- open_count = frappe.get_all(doctype, fields='count(*) as count', filters=filters)
- if open_count[0].count > 0:
- doc.status = 'Open'
+ open_count = frappe.get_all(doctype, fields='name', filters=filters, limit_page_length=1)
+ if len(open_count) > 0:
+ status = 'Open'
break
- if doc.status != original_status:
- doc.db_set('status', doc.status)
+ return 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)
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index 95a1aff..a4896f1 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -6,7 +6,7 @@
frappe.setup_language_field(frm);
},
refresh: function(frm) {
- frm.cscript.make_dashboard(frm.doc);
+ frm.dashboard.show_documents();
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);
@@ -26,55 +26,23 @@
frm.events.add_custom_buttons(frm);
},
add_custom_buttons: function(frm) {
- ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"].forEach(function(doctype, i) {
- if(frappe.model.can_read(doctype)) {
- frm.add_custom_button(__(doctype), function() {
- frappe.route_options = {"supplier": frm.doc.name};
- frappe.set_route("List", doctype);
- }, __("View"));
- }
- if(frappe.model.can_create(doctype)) {
- frm.add_custom_button(__(doctype), function() {
- frappe.route_options = {"supplier": frm.doc.name};
- new_doc(doctype);
- }, __("Make"));
- }
- });
+ // ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"].forEach(function(doctype, i) {
+ // if(frappe.model.can_read(doctype)) {
+ // frm.add_custom_button(__(doctype), function() {
+ // frappe.route_options = {"supplier": frm.doc.name};
+ // frappe.set_route("List", doctype);
+ // }, __("View"));
+ // }
+ // if(frappe.model.can_create(doctype)) {
+ // frm.add_custom_button(__(doctype), function() {
+ // frappe.route_options = {"supplier": frm.doc.name};
+ // new_doc(doctype);
+ // }, __("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) {
return{
filters:{'buying': 1}
diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json
index bafa142..f505061 100644
--- a/erpnext/buying/doctype/supplier/supplier.json
+++ b/erpnext/buying/doctype/supplier/supplier.json
@@ -13,7 +13,7 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 0,
+ "collapsible": 1,
"fieldname": "basic_info",
"fieldtype": "Section Break",
"hidden": 0,
@@ -21,7 +21,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
- "label": "",
+ "label": "Name and Type",
"length": 0,
"no_copy": 0,
"oldfieldtype": "Section Break",
@@ -193,6 +193,32 @@
},
{
"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,
"bold": 1,
"collapsible": 0,
"default": "0",
@@ -220,7 +246,7 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 0,
+ "collapsible": 1,
"fieldname": "section_break_7",
"fieldtype": "Section Break",
"hidden": 0,
@@ -228,6 +254,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
+ "label": "Currency and Price List",
"length": 0,
"no_copy": 0,
"permlevel": 0,
@@ -270,31 +297,6 @@
"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,
- "bold": 0,
- "collapsible": 0,
"fieldname": "column_break_10",
"fieldtype": "Column Break",
"hidden": 0,
@@ -319,19 +321,18 @@
"allow_on_submit": 0,
"bold": 0,
"collapsible": 0,
- "fieldname": "language",
- "fieldtype": "Select",
+ "fieldname": "default_price_list",
+ "fieldtype": "Link",
"hidden": 0,
- "ignore_user_permissions": 0,
+ "ignore_user_permissions": 1,
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
- "label": "Print Language",
+ "label": "Price List",
"length": 0,
"no_copy": 0,
- "options": "Loading...",
+ "options": "Price List",
"permlevel": 0,
- "precision": "",
"print_hide": 0,
"print_hide_if_no_value": 0,
"read_only": 0,
@@ -420,7 +421,7 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 0,
+ "collapsible": 1,
"depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts",
"fieldtype": "Section Break",
@@ -684,7 +685,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-04-08 07:43:07.541419",
+ "modified": "2016-04-11 08:01:21.188319",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier",
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index f010626..4b384fa 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -9,6 +9,7 @@
from erpnext.utilities.address_and_contact import load_address_and_contact
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.accounts.party import validate_party_accounts
+from erpnext.accounts.party_status import get_party_status
class Supplier(TransactionBase):
def get_feed(self):
@@ -17,6 +18,7 @@
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "supplier")
+ self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
@@ -47,6 +49,7 @@
msgprint(_("Series is mandatory"), raise_exception=1)
validate_party_accounts(self)
+ self.status = get_party_status(self)
def get_contacts(self,nm):
if nm:
@@ -81,31 +84,3 @@
frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
{set_field} where supplier=%(newdn)s"""\
.format(set_field=set_field), ({"newdn": newdn}))
-
-@frappe.whitelist()
-def get_dashboard_info(supplier):
- if not frappe.has_permission("Supplier", "read", supplier):
- frappe.throw(_("No permission"))
-
- out = {}
- for doctype in ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]:
- out[doctype] = frappe.db.get_value(doctype,
- {"supplier": supplier, "docstatus": ["!=", 2] }, "count(*)")
-
- billing_this_year = frappe.db.sql("""
- select sum(credit_in_account_currency) - sum(debit_in_account_currency)
- from `tabGL Entry`
- where voucher_type='Purchase Invoice' and party_type = 'Supplier'
- and party=%s and fiscal_year = %s""",
- (supplier, frappe.db.get_default("fiscal_year")))
-
- total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
- from `tabPurchase Invoice`
- where supplier=%s and docstatus = 1""", supplier)
-
-
- 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["company_currency"] = frappe.db.sql_list("select distinct default_currency from tabCompany")
-
- return out
diff --git a/erpnext/buying/doctype/supplier/supplier_links.py b/erpnext/buying/doctype/supplier/supplier_links.py
new file mode 100644
index 0000000..8986eca
--- /dev/null
+++ b/erpnext/buying/doctype/supplier/supplier_links.py
@@ -0,0 +1,15 @@
+from frappe import _
+
+links = {
+ 'fieldname': 'supplier',
+ 'transactions': [
+ {
+ 'label': _('Procurement'),
+ 'items': ['Material Request', 'Request for Quotation', 'Supplier Quotation']
+ },
+ {
+ 'label': _('Orders'),
+ 'items': ['Purchase Order', 'Purchase Receipt', 'Purchase Invoice']
+ }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/controllers/website_list_for_contact.py b/erpnext/controllers/website_list_for_contact.py
index e411cdf..6b514b2 100644
--- a/erpnext/controllers/website_list_for_contact.py
+++ b/erpnext/controllers/website_list_for_contact.py
@@ -31,6 +31,9 @@
parties_doctype = 'Request for Quotation Supplier' if doctype == 'Request for Quotation' else doctype
# find party for this contact
customers, suppliers = get_customers_suppliers(parties_doctype, user)
+
+ if not customers and not suppliers: return []
+
key, parties = get_party_details(customers, suppliers)
if doctype == 'Request for Quotation':
@@ -93,7 +96,6 @@
return result
def get_customers_suppliers(doctype, user):
- from erpnext.shopping_cart.cart import get_customer
meta = frappe.get_meta(doctype)
contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"],
filters={"email_id": user})
@@ -101,9 +103,6 @@
customers = [c.customer for c in contacts if c.customer] if meta.get_field("customer") else None
suppliers = [c.supplier for c in contacts if c.supplier] if meta.get_field("supplier") else None
- if not customers and not suppliers:
- return [get_customer().name], None
-
return customers, suppliers
def has_website_permission(doc, ptype, user, verbose=False):
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 1a521c6..fe4d0b6 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -135,9 +135,10 @@
},
# bubble transaction notification on master
- ('Opportunity', 'Quotation', 'Sales Order', 'Sales Invoice', 'Supplier Quotation',
- 'Purchase Order', 'Purchase Invoice', 'Project', 'Issue'): {
- 'on_update': 'erpnext.accounts.party_status.notify_status'
+ ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice',
+ 'Supplier Quotation', 'Purchase Order', 'Purchase Receipt',
+ 'Purchase Invoice', 'Project', 'Issue'): {
+ 'on_change': 'erpnext.accounts.party_status.notify_status'
}
}
diff --git a/erpnext/patches/v7_0/update_party_status.py b/erpnext/patches/v7_0/update_party_status.py
index c9cab95..1307377 100644
--- a/erpnext/patches/v7_0/update_party_status.py
+++ b/erpnext/patches/v7_0/update_party_status.py
@@ -1,7 +1,9 @@
import frappe
+from erpnext.accounts.party_status import update_status
def execute():
for doctype in ('Customer', 'Supplier'):
+ frappe.reload_doctype(doctype)
for doc in frappe.get_all(doctype):
doc = frappe.get_doc(doctype, doc.name)
- doc.update_status()
\ No newline at end of file
+ update_status(doc)
\ No newline at end of file
diff --git a/erpnext/public/css/erpnext.css b/erpnext/public/css/erpnext.css
index d1d26bc..75fab56 100644
--- a/erpnext/public/css/erpnext.css
+++ b/erpnext/public/css/erpnext.css
@@ -44,7 +44,7 @@
padding: 50% 0;
text-align: center;
line-height: 0;
- color: #fff;
+ color: #d1d8dd;
font-size: 30px;
background-size: cover;
border: 1px solid transparent;
diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js
index 1896f88..5f9a276 100644
--- a/erpnext/public/js/utils/party.js
+++ b/erpnext/public/js/utils/party.js
@@ -2,6 +2,7 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.utils");
+
erpnext.utils.get_party_details = function(frm, method, args, callback) {
if(!method) {
method = "erpnext.accounts.party.get_party_details";
@@ -69,7 +70,7 @@
if(r.message) {
frm.set_value(display_field, r.message)
}
-
+
if(frappe.meta.get_docfield(frm.doc.doctype, "taxes") && !is_your_company_address) {
if(!erpnext.utils.validate_mandatory(frm, "Customer/Supplier",
frm.doc.customer || frm.doc.supplier, address_field)) return;
@@ -99,7 +100,7 @@
} else {
frm.set_value(display_field, null);
}
-
+
}
erpnext.utils.get_contact_details = function(frm) {
@@ -138,4 +139,4 @@
}
}
});
-}
+}
\ No newline at end of file
diff --git a/erpnext/public/less/erpnext.less b/erpnext/public/less/erpnext.less
index 29d1533..23ee841 100644
--- a/erpnext/public/less/erpnext.less
+++ b/erpnext/public/less/erpnext.less
@@ -1,3 +1,5 @@
+@import "../../../../frappe/frappe/public/less/variables.less";
+
.erpnext-footer {
margin: 11px auto;
text-align: center;
@@ -54,7 +56,7 @@
padding: 50% 0;
text-align: center;
line-height: 0;
- color: #fff;
+ color: @text-extra-muted;
font-size: 30px;
background-size: cover;
border: 1px solid transparent;
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index 1d4bd41..3f6ab24 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -6,7 +6,7 @@
frappe.setup_language_field(frm);
},
refresh: function(frm) {
- frm.cscript.setup_dashboard(frm.doc);
+ frm.dashboard.show_documents();
if(frappe.defaults.get_default("cust_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);
@@ -29,20 +29,20 @@
frm.events.add_custom_buttons(frm);
},
add_custom_buttons: function(frm) {
- ["Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].forEach(function(doctype, i) {
- if(frappe.model.can_read(doctype)) {
- frm.add_custom_button(__(doctype), function() {
- frappe.route_options = {"customer": frm.doc.name};
- frappe.set_route("List", doctype);
- }, __("View"));
- }
- if(frappe.model.can_create(doctype)) {
- frm.add_custom_button(__(doctype), function() {
- frappe.route_options = {"customer": frm.doc.name};
- new_doc(doctype);
- }, __("Make"));
- }
- });
+ // ["Opportunity", "Quotation", "Sales Order", "Delivery Note", "Sales Invoice"].forEach(function(doctype, i) {
+ // if(frappe.model.can_read(doctype)) {
+ // frm.add_custom_button(__(doctype), function() {
+ // frappe.route_options = {"customer": frm.doc.name};
+ // frappe.set_route("List", doctype);
+ // }, __("View"));
+ // }
+ // if(frappe.model.can_create(doctype)) {
+ // frm.add_custom_button(__(doctype), function() {
+ // frappe.route_options = {"customer": frm.doc.name};
+ // new_doc(doctype);
+ // }, __("Make"));
+ // }
+ // });
},
validate: function(frm) {
if(frm.doc.lead_name) frappe.model.clear_doc("Lead", frm.doc.lead_name);
@@ -64,40 +64,6 @@
cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
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) {
return{
filters:{'is_group': 'No'}
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index ba7aa24..ddbcf5b 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -13,7 +13,7 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 0,
+ "collapsible": 1,
"fieldname": "basic_info",
"fieldtype": "Section Break",
"hidden": 0,
@@ -21,7 +21,7 @@
"ignore_xss_filter": 0,
"in_filter": 0,
"in_list_view": 0,
- "label": "",
+ "label": "Name and Type",
"length": 0,
"no_copy": 0,
"oldfieldtype": "Section Break",
@@ -452,7 +452,7 @@
{
"allow_on_submit": 0,
"bold": 0,
- "collapsible": 0,
+ "collapsible": 1,
"depends_on": "eval:!doc.__islocal",
"fieldname": "address_contacts",
"fieldtype": "Section Break",
@@ -954,7 +954,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2016-04-08 07:43:01.381976",
+ "modified": "2016-04-11 08:00:08.829976",
"modified_by": "Administrator",
"module": "Selling",
"name": "Customer",
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 8a7da63..51aedef 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -11,6 +11,7 @@
from erpnext.utilities.transaction_base import TransactionBase
from erpnext.utilities.address_and_contact import load_address_and_contact
from erpnext.accounts.party import validate_party_accounts
+from erpnext.accounts.party_status import get_party_status
class Customer(TransactionBase):
def get_feed(self):
@@ -19,6 +20,7 @@
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "customer")
+ self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
@@ -42,6 +44,7 @@
def validate(self):
self.flags.is_new_doc = self.is_new()
validate_party_accounts(self)
+ self.status = get_party_status(self)
def update_lead_status(self):
if self.lead_name:
@@ -125,34 +128,6 @@
{set_field} where customer=%(newdn)s"""\
.format(set_field=set_field), ({"newdn": newdn}))
-@frappe.whitelist()
-def get_dashboard_info(customer):
- if not frappe.has_permission("Customer", "read", customer):
- frappe.msgprint(_("Not permitted"), raise_exception=True)
-
- out = {}
- for doctype in ["Opportunity", "Quotation", "Sales Order", "Delivery Note",
- "Sales Invoice", "Project"]:
- out[doctype] = frappe.db.get_value(doctype,
- {"customer": customer, "docstatus": ["!=", 2] }, "count(*)")
-
- billing_this_year = frappe.db.sql("""
- select sum(debit_in_account_currency) - sum(credit_in_account_currency)
- from `tabGL Entry`
- where voucher_type='Sales Invoice' and party_type = 'Customer'
- and party=%s and fiscal_year = %s""",
- (customer, frappe.db.get_default("fiscal_year")))
-
- total_unpaid = frappe.db.sql("""select sum(outstanding_amount)
- from `tabSales Invoice`
- where customer=%s and docstatus = 1""", customer)
-
- 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
-
- return out
-
-
def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
if frappe.db.get_default("cust_master_name") == "Customer Name":
fields = ["name", "customer_group", "territory"]
diff --git a/erpnext/selling/doctype/customer/customer_links.py b/erpnext/selling/doctype/customer/customer_links.py
new file mode 100644
index 0000000..9410dbe
--- /dev/null
+++ b/erpnext/selling/doctype/customer/customer_links.py
@@ -0,0 +1,19 @@
+from frappe import _
+
+links = {
+ 'fieldname': 'customer',
+ 'transactions': [
+ {
+ 'label': _('Pre Sales'),
+ 'items': ['Lead', 'Opportunity', 'Quotation']
+ },
+ {
+ 'label': _('Orders'),
+ 'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
+ },
+ {
+ 'label': _('Projects'),
+ 'items': ['Project']
+ }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index c353b8d..2c3257e 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -24,7 +24,7 @@
@frappe.whitelist()
def get_cart_quotation(doc=None):
- party = get_customer()
+ party = get_party()
if not doc:
quotation = _get_cart_quotation(party)
@@ -150,7 +150,7 @@
def _get_cart_quotation(party=None):
if not party:
- party = get_customer()
+ party = get_party()
quotation = frappe.get_all("Quotation", fields=["name"], filters=
{party.doctype.lower(): party.name, "order_type": "Shopping Cart", "docstatus": 0},
@@ -182,7 +182,7 @@
return qdoc
def update_party(fullname, company_name=None, mobile_no=None, phone=None):
- party = get_customer()
+ party = get_party()
party.customer_name = company_name or fullname
party.customer_type == "Company" if company_name else "Individual"
@@ -211,7 +211,7 @@
def apply_cart_settings(party=None, quotation=None):
if not party:
- party = get_customer()
+ party = get_party()
if not quotation:
quotation = _get_cart_quotation(party)
@@ -276,20 +276,24 @@
# # append taxes
quotation.append_taxes_from_master()
-def get_customer(user=None):
+def get_party(user=None):
if not user:
user = frappe.session.user
- customer = frappe.db.get_value("Contact", {"email_id": user}, "customer")
+ party = frappe.db.get_value("Contact", {"email_id": user}, ["customer", "supplier"], as_dict=1)
+ if party:
+ party_doctype = 'Customer' if party.customer else 'Supplier'
+ party = party.customer or party.supplier
+
cart_settings = frappe.get_doc("Shopping Cart Settings")
-
+
debtors_account = ''
-
+
if cart_settings.enable_checkout:
debtors_account = get_debtors_account(cart_settings)
-
- if customer:
- return frappe.get_doc("Customer", customer)
+
+ if party:
+ return frappe.get_doc(party_doctype, party)
else:
customer = frappe.new_doc("Customer")
@@ -300,7 +304,7 @@
"customer_group": get_shopping_cart_settings().default_customer_group,
"territory": get_root_of("Territory")
})
-
+
if debtors_account:
customer.update({
"accounts": [{
@@ -308,7 +312,7 @@
"account": debtors_account
}]
})
-
+
customer.flags.ignore_mandatory = True
customer.insert(ignore_permissions=True)
@@ -326,12 +330,12 @@
def get_debtors_account(cart_settings):
payment_gateway_account_currency = \
frappe.get_doc("Payment Gateway Account", cart_settings.payment_gateway_account).currency
-
+
account_name = _("Debtors ({0})".format(payment_gateway_account_currency))
-
+
debtors_account_name = get_account_name("Receivable", "Asset", is_group=0,\
account_currency=payment_gateway_account_currency, company=cart_settings.company)
-
+
if not debtors_account_name:
debtors_account = frappe.get_doc({
"doctype": "Account",
@@ -340,18 +344,18 @@
"is_group": 0,
"parent_account": get_account_name(root_type="Asset", is_group=1, company=cart_settings.company),
"account_name": account_name,
- "currency": payment_gateway_account_currency
+ "currency": payment_gateway_account_currency
}).insert(ignore_permissions=True)
-
+
return debtors_account.name
-
+
else:
return debtors_account_name
-
+
def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
if not party:
- return
+ party = get_party()
address_docs = frappe.db.sql("""select * from `tabAddress`
where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
@@ -371,7 +375,7 @@
if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
# creates a customer if one does not exist
- get_customer()
+ get_party()
doc.link_address()
@frappe.whitelist()
@@ -439,4 +443,4 @@
return territory
def show_terms(doc):
- return doc.tc_name
+ return doc.tc_name
diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py
index 0fe04ba..a51852a 100644
--- a/erpnext/shopping_cart/test_shopping_cart.py
+++ b/erpnext/shopping_cart/test_shopping_cart.py
@@ -4,7 +4,7 @@
from __future__ import unicode_literals
import unittest
import frappe
-from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_customer
+from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_party
class TestShoppingCart(unittest.TestCase):
"""
@@ -118,7 +118,7 @@
"doctype": "Quotation",
"quotation_to": "Customer",
"order_type": "Shopping Cart",
- "customer": get_customer(frappe.session.user).name,
+ "customer": get_party(frappe.session.user).name,
"docstatus": 0,
"contact_email": frappe.session.user,
"selling_price_list": "_Test Price List Rest of the World",
diff --git a/erpnext/startup/notifications.py b/erpnext/startup/notifications.py
index 537c10c..700ced2 100644
--- a/erpnext/startup/notifications.py
+++ b/erpnext/startup/notifications.py
@@ -26,7 +26,6 @@
"Leave Application": {"status": "Open"},
"Expense Claim": {"approval_status": "Draft"},
"Job Applicant": {"status": "Open"},
- "Purchase Receipt": {"docstatus": 0},
"Delivery Note": {"docstatus": 0},
"Stock Entry": {"docstatus": 0},
"Material Request": {
@@ -34,13 +33,13 @@
"status": ("not in", ("Stopped",)),
"per_ordered": ("<", 100)
},
- "Request for Quotation": {
- "docstatus": 0
- },
+ "Request for Quotation": { "docstatus": 0 },
+ "Supplier Quotation": {"docstatus": 0},
"Purchase Order": {
"status": ("not in", ("Completed", "Closed")),
"docstatus": ("<", 2)
},
+ "Purchase Receipt": {"docstatus": 0},
"Production Order": { "status": "In Process" },
"BOM": {"docstatus": 0},
"Timesheet": {"docstatus": 0},
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 213050c..4df7128 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -16,6 +16,7 @@
},
refresh: function(frm) {
+
if(frm.doc.is_stock_item) {
frm.add_custom_button(__("Balance"), function() {
frappe.route_options = {
@@ -73,6 +74,8 @@
}
erpnext.item.toggle_attributes(frm);
+
+ frm.dashboard.show_documents();
},
validate: function(frm){
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index fab43a9..94d2e8d 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -2298,7 +2298,7 @@
"issingle": 0,
"istable": 0,
"max_attachments": 1,
- "modified": "2016-04-04 06:45:30.554933",
+ "modified": "2016-04-11 09:15:30.911215",
"modified_by": "Administrator",
"module": "Stock",
"name": "Item",
@@ -2468,6 +2468,7 @@
"read_only": 0,
"read_only_onload": 0,
"search_fields": "item_name,description,item_group,customer_code",
+ "sort_field": "idx desc, modified desc",
"sort_order": "DESC",
"title_field": "item_name",
"track_seen": 0
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 3ae9b5a..8286b5f 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -27,7 +27,8 @@
def onload(self):
super(Item, self).onload()
- self.get("__onload").sle_exists = self.check_if_sle_exists()
+ self.set_onload('sle_exists', self.check_if_sle_exists())
+ self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
if frappe.db.get_default("item_naming_by")=="Naming Series":
@@ -84,7 +85,7 @@
if not self.get("__islocal"):
self.old_item_group = frappe.db.get_value(self.doctype, self.name, "item_group")
- self.old_website_item_groups = frappe.db.sql_list("""select item_group
+ self.old_website_item_groups = frappe.db.sql_list("""select item_group
from `tabWebsite Item Group`
where parentfield='website_item_groups' and parenttype='Item' and parent=%s""", self.name)
@@ -577,7 +578,7 @@
if variant:
frappe.throw(_("Item variant {0} exists with same attributes")
.format(variant), ItemVariantExistsError)
-
+
def validate_fixed_asset_item(self):
if self.is_fixed_asset and self.is_stock_item:
frappe.throw(_("Fixed Asset Item must be a non-stock item"))
diff --git a/erpnext/stock/doctype/item/item_links.py b/erpnext/stock/doctype/item/item_links.py
new file mode 100644
index 0000000..5f76a4c
--- /dev/null
+++ b/erpnext/stock/doctype/item/item_links.py
@@ -0,0 +1,36 @@
+from frappe import _
+
+links = {
+ 'fieldname': 'item_code',
+ 'non_standard_fieldnames': {
+ 'Production Order': 'production_item',
+ 'Product Bundle': 'new_item_code'
+ },
+ 'transactions': [
+ {
+ 'label': _('Related'),
+ 'items': ['BOM', 'Product Bundle', 'Serial No', 'Batch']
+ },
+ {
+ 'label': _('Pricing'),
+ 'items': ['Item Price', 'Pricing Rule']
+ },
+ {
+ 'label': _('Sell'),
+ 'items': ['Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice']
+ },
+ {
+ 'label': _('Buy'),
+ 'items': ['Material Request', 'Supplier Quotation', 'Request for Quotation',
+ 'Purchase Order', 'Purchase Invoice']
+ },
+ {
+ 'label': _('Move'),
+ 'items': ['Stock Entry']
+ },
+ {
+ 'label': _('Manufacture'),
+ 'items': ['Production Order']
+ }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/templates/pages/rfq.html b/erpnext/templates/pages/rfq.html
index dfbbbc9..e4dc4e6 100644
--- a/erpnext/templates/pages/rfq.html
+++ b/erpnext/templates/pages/rfq.html
@@ -64,7 +64,7 @@
<div class="row grand-total-row">
<div class="col-xs-10 text-right">{{ _("Grand Total") }}</div>
<div class="col-xs-2 text-right">
- {{doc.currency_symbol}} <span class="tax-grand-total">0.0</span>
+ {{doc.currency_symbol}} <span class="tax-grand-total">0.0</span>
</div>
</div>
{% endif %}
diff --git a/erpnext/templates/pages/rfq.py b/erpnext/templates/pages/rfq.py
index 181cf73..4c488d9 100644
--- a/erpnext/templates/pages/rfq.py
+++ b/erpnext/templates/pages/rfq.py
@@ -4,16 +4,16 @@
from __future__ import unicode_literals
import frappe
from frappe import _
-from erpnext.controllers.website_list_for_contact import get_customers_suppliers, \
- get_party_details
+from erpnext.controllers.website_list_for_contact import (get_customers_suppliers,
+ get_party_details)
def get_context(context):
context.no_cache = 1
context.doc = frappe.get_doc(frappe.form_dict.doctype, frappe.form_dict.name)
context.parents = frappe.form_dict.parents
context.doc.supplier = get_supplier()
- update_supplier_details(context)
unauthorized_user(context.doc.supplier)
+ update_supplier_details(context)
context["title"] = frappe.form_dict.name
def get_supplier():
@@ -31,13 +31,13 @@
return status
def unauthorized_user(supplier):
- status = check_supplier_has_docname_access(supplier)
+ status = check_supplier_has_docname_access(supplier) or False
if status == False:
frappe.throw(_("Not Permitted"), frappe.PermissionError)
def update_supplier_details(context):
supplier_doc = frappe.get_doc("Supplier", context.doc.supplier)
- context.doc.currency = supplier_doc.default_currency
+ context.doc.currency = supplier_doc.default_currency or frappe.db.get_value("Company", context.doc.company, "default_currency")
context.doc.currency_symbol = frappe.db.get_value("Currency", context.doc.currency, "symbol")
context.doc.number_format = frappe.db.get_value("Currency", context.doc.currency, "number_format")
- context.doc.buying_price_list = supplier_doc.default_price_list
\ No newline at end of file
+ context.doc.buying_price_list = supplier_doc.default_price_list or ''
\ No newline at end of file