[enhancement] links menu in customer, supplier, item

This commit is contained in:
Rushabh Mehta 2016-04-12 19:16:33 +05:30
parent 5d0e8dee11
commit 8bbca6fa2e
12 changed files with 87 additions and 117 deletions

View File

@ -5,7 +5,6 @@ from __future__ import unicode_literals
import frappe
from frappe import _
from frappe.utils import evaluate_filters
from frappe.desk.notifications import get_filters_for
@ -77,26 +76,3 @@ def update_status(doc):
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);
},
refresh: function(frm) {
erpnext.party.setup_dashboard(frm);
frm.dashboard.show_documents();
if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);

View File

@ -9,7 +9,7 @@ from frappe.model.naming import make_autoname
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_transaction_count, get_party_status, status_depends_on
from erpnext.accounts.party_status import get_party_status
class Supplier(TransactionBase):
def get_feed(self):
@ -18,7 +18,7 @@ class Supplier(TransactionBase):
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "supplier")
self.set_onload('transactions', status_depends_on[self.doctype])
self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
supp_master_name = frappe.defaults.get_global_default('supp_master_name')
@ -84,30 +84,3 @@ class Supplier(TransactionBase):
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):
# doc = frappe.get_doc('Supplier', supplier)
# if not doc.has_permission('read'):
# frappe.msgprint(_("Not permitted"), raise_exception=True)
#
# out = {}
# out['transaction_count'] = get_transaction_count(doc)
#
# 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

View File

@ -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']
}
]
}

View File

@ -2,7 +2,7 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.utils");
frappe.provide('erpnext.party');
erpnext.utils.get_party_details = function(frm, method, args, callback) {
if(!method) {
method = "erpnext.accounts.party.get_party_details";
@ -139,31 +139,4 @@ 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

@ -6,7 +6,7 @@ frappe.ui.form.on("Customer", {
frappe.setup_language_field(frm);
},
refresh: function(frm) {
erpnext.party.setup_dashboard(frm);
frm.dashboard.show_documents();
if(frappe.defaults.get_default("cust_master_name")!="Naming Series") {
frm.toggle_display("naming_series", false);

View File

@ -11,7 +11,7 @@ from frappe.desk.reportview import build_match_conditions
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_transaction_count, get_party_status, status_depends_on
from erpnext.accounts.party_status import get_party_status
class Customer(TransactionBase):
def get_feed(self):
@ -20,7 +20,7 @@ class Customer(TransactionBase):
def onload(self):
"""Load address and contacts in `__onload`"""
load_address_and_contact(self, "customer")
self.set_onload('transactions', status_depends_on[self.doctype])
self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
cust_master_name = frappe.defaults.get_global_default('cust_master_name')
@ -128,33 +128,6 @@ class Customer(TransactionBase):
{set_field} where customer=%(newdn)s"""\
.format(set_field=set_field), ({"newdn": newdn}))
# @frappe.whitelist()
# def get_dashboard_info(customer):
# doc = frappe.get_doc('Customer', customer)
# if not doc.has_permission('read'):
# frappe.msgprint(_("Not permitted"), raise_exception=True)
#
#
# out = {}
# out['transaction_count'] = get_transaction_count(doc)
#
# 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"]

View File

@ -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']
}
]
}

View File

@ -16,6 +16,7 @@ frappe.ui.form.on("Item", {
},
refresh: function(frm) {
if(frm.doc.is_stock_item) {
frm.add_custom_button(__("Balance"), function() {
frappe.route_options = {
@ -73,6 +74,8 @@ frappe.ui.form.on("Item", {
}
erpnext.item.toggle_attributes(frm);
frm.dashboard.show_documents();
},
validate: function(frm){

View File

@ -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

View File

@ -27,7 +27,8 @@ class Item(WebsiteGenerator):
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 @@ class Item(WebsiteGenerator):
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)
@ -568,7 +569,7 @@ class Item(WebsiteGenerator):
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"))

View File

@ -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']
}
]
}