[cleanup] link methods made common

This commit is contained in:
Rushabh Mehta 2016-07-04 11:38:37 +05:30
parent 5f5f0bec2c
commit b33df4afe8
8 changed files with 44 additions and 106 deletions

View File

@ -8,7 +8,7 @@ from frappe import msgprint, _
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, get_timeline_data
from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
from erpnext.accounts.party_status import get_party_status
class Supplier(TransactionBase):
@ -18,7 +18,6 @@ class Supplier(TransactionBase):
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')
@ -84,14 +83,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_data(name):
'''load dashboard related data'''
frappe.has_permission(doc=frappe.get_doc('Supplier', name), throw=True)
from frappe.desk.notifications import get_open_count
return {
'count': get_open_count('Supplier', name),
'timeline_data': get_timeline_data('Supplier', name),
}

View File

@ -18,9 +18,6 @@ class EmployeeUserDisabledError(frappe.ValidationError):
class Employee(Document):
def onload(self):
self.set_onload('links', self.meta.get_links_setup())
def autoname(self):
naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by")
if not naming_method:
@ -157,22 +154,7 @@ class Employee(Document):
def on_trash(self):
delete_events(self.doctype, self.name)
def get_timeline_data(self):
'''returns timeline data based on attendance'''
return
@frappe.whitelist()
def get_dashboard_data(name):
'''load dashboard related data'''
frappe.has_permission(doc=frappe.get_doc('Employee', name), throw=True)
from frappe.desk.notifications import get_open_count
return {
'count': get_open_count('Employee', name),
'timeline_data': get_timeline_data(name),
}
def get_timeline_data(name):
def get_timeline_data(doctype, name):
'''Return timeline for attendance'''
return dict(frappe.db.sql('''select unix_timestamp(att_date), count(*)
from `tabAttendance` where employee=%s

View File

@ -18,7 +18,6 @@ class Project(Document):
if not self.get('__unsaved') and not self.get("tasks"):
self.load_tasks()
self.set_onload('links', self.meta.get_links_setup())
self.set_onload('activity_summary', frappe.db.sql('''select activity_type, sum(hours) as total_hours
from `tabTime Sheet Detail` where project=%s group by activity_type order by total_hours desc''', self.name, as_dict=True))
@ -152,19 +151,7 @@ class Project(Document):
frappe.sendmail(user.user, subject=_("Project Collaboration Invitation"), content=content.format(*messages))
user.welcome_email_sent=1
@frappe.whitelist()
def get_dashboard_data(name):
'''load dashboard related data'''
frappe.has_permission(doc=frappe.get_doc('Project', name), throw=True)
from frappe.desk.notifications import get_open_count
return {
'count': get_open_count('Project', name),
'timeline_data': get_timeline_data(name)
}
def get_timeline_data(name):
def get_timeline_data(doctype, name):
'''Return timeline for attendance'''
return dict(frappe.db.sql('''select unix_timestamp(from_time), count(*)
from `tabTime Sheet Detail` where project=%s

View File

@ -10,7 +10,7 @@ from frappe.utils import flt, cint, cstr
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, get_timeline_data
from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
from erpnext.accounts.party_status import get_party_status
class Customer(TransactionBase):
@ -20,7 +20,6 @@ class Customer(TransactionBase):
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')
@ -129,17 +128,6 @@ class Customer(TransactionBase):
.format(set_field=set_field), ({"newdn": newdn}))
@frappe.whitelist()
def get_dashboard_data(name):
'''load dashboard related data'''
frappe.has_permission(doc=frappe.get_doc('Customer', name), throw=True)
from frappe.desk.notifications import get_open_count
return {
'count': get_open_count('Customer', name),
'timeline_data': get_timeline_data('Customer', name),
}
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

@ -28,7 +28,6 @@ class Item(WebsiteGenerator):
def onload(self):
super(Item, self).onload()
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":
@ -632,19 +631,7 @@ class Item(WebsiteGenerator):
frappe.throw(_("Item variant {0} exists with same attributes")
.format(variant), ItemVariantExistsError)
@frappe.whitelist()
def get_dashboard_data(name):
'''load dashboard related data'''
frappe.has_permission(doc=frappe.get_doc('Item', name), throw=True)
from frappe.desk.notifications import get_open_count
return {
'count': get_open_count('Item', name),
'timeline_data': get_timeline_data(name),
}
def get_timeline_data(name):
def get_timeline_data(doctype, name):
'''returns timeline data based on stock ledger entry'''
return dict(frappe.db.sql('''select unix_timestamp(posting_date), count(*)
from `tabStock Ledger Entry` where item_code=%s

View File

@ -43,6 +43,8 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
var me = this;
this._super();
this.frm.dashboard.reset();
if(doc.docstatus==0) {
cur_frm.add_custom_button(__("Get Items from BOM"),
cur_frm.cscript.get_items_from_bom, "icon-sitemap", "btn-default");
@ -50,6 +52,8 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
if(doc.docstatus == 1 && doc.status != 'Stopped') {
this.frm.dashboard.show_dashboard();
if(flt(doc.per_ordered, 2) < 100) {
// make
if(doc.material_request_type === "Material Transfer" && doc.status === "Submitted")
@ -76,19 +80,6 @@ erpnext.buying.MaterialRequestController = erpnext.buying.BuyingController.exten
cur_frm.add_custom_button(__("Production Order"),
this.raise_production_orders, __("Make"));
// show
if(doc.material_request_type === "Purchase" && doc.docstatus==1) {
me.frm.add_custom_button(__("Request for Quotation"),
function() { frappe.set_route('List', 'Request for Quotation',
{'material_request': doc.name})}, __("Show"));
me.frm.add_custom_button(__("Supplier Quotation"),
function() { frappe.set_route('List', 'Supplier Quotation',
{'material_request': doc.name})}, __("Show"));
}
cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
// stop

View File

@ -0,0 +1,15 @@
from frappe import _
links = {
'fieldname': 'material_request',
'non_standard_fieldnames': {
'Supplier Quotation': 'prevdoc_detail_docname',
'Purchase Order': 'prevdoc_detail_docname',
},
'transactions': [
{
'label': _('Documents'),
'items': ['Request for Quotation', 'Supplier Quotation', 'Purchase Order']
},
]
}