Merge pull request #1667 from nabinhait/v4-hotfix
Server side onload functionality in multiple docs && support ticket status
This commit is contained in:
commit
1a7c3897b1
@ -19,7 +19,7 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
cur_frm.toggle_enable(['account_name', 'group_or_ledger', 'company'], false);
|
||||
|
||||
if(doc.group_or_ledger=='Ledger') {
|
||||
cur_frm.toggle_display('freeze_account', doc.can_freeze_account);
|
||||
cur_frm.toggle_display('freeze_account', doc.__onload && doc.__onload.can_freeze_account);
|
||||
}
|
||||
|
||||
// read-only for root accounts
|
||||
|
@ -12,16 +12,9 @@ class Account(Document):
|
||||
|
||||
def onload(self):
|
||||
frozen_accounts_modifier = frappe.db.get_value("Accounts Settings", "Accounts Settings", "frozen_accounts_modifier")
|
||||
print frozen_accounts_modifier
|
||||
if frozen_accounts_modifier in frappe.user.get_roles():
|
||||
self.can_freeze_account = True
|
||||
self.get("__onload").can_freeze_account = True
|
||||
|
||||
def as_dict(self, no_nulls=False):
|
||||
doc = super(Account, self).as_dict(no_nulls)
|
||||
if self.get("can_freeze_account"):
|
||||
doc["can_freeze_account"] = self.can_freeze_account
|
||||
|
||||
return doc
|
||||
|
||||
def autoname(self):
|
||||
self.name = self.account_name.strip() + ' - ' + \
|
||||
|
@ -110,6 +110,12 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
entries_add: function(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
this.frm.script_manager.copy_from_first_row("entries", row, ["expense_account", "cost_center"]);
|
||||
},
|
||||
|
||||
on_submit: function() {
|
||||
$.each(this.frm.doc["entries"], function(i, row) {
|
||||
if(row.purchase_receipt) frappe.model.clear_doc("Purchase Receipt", row.purchase_receipt)
|
||||
})
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -387,6 +387,10 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
|
||||
if(cint(frappe.boot.notification_settings.sales_invoice)) {
|
||||
cur_frm.email_doc(frappe.boot.notification_settings.sales_invoice_message);
|
||||
}
|
||||
|
||||
$.each(doc["entries"], function(i, row) {
|
||||
if(row.delivery_note) frappe.model.clear_doc("Delivery Note", row.delivery_note)
|
||||
})
|
||||
}
|
||||
|
||||
cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) {
|
||||
|
@ -88,6 +88,7 @@ class StatusUpdater(Document):
|
||||
|
||||
def on_communication(self):
|
||||
self.communication_set = True
|
||||
self.get("communications").sort(key=lambda d: d.creation)
|
||||
self.set_status(update=True)
|
||||
del self.communication_set
|
||||
|
||||
|
@ -18,9 +18,10 @@ erpnext.hr.EmployeeController = frappe.ui.form.Controller.extend({
|
||||
refresh: function() {
|
||||
var me = this;
|
||||
erpnext.toggle_naming_series();
|
||||
if(!this.frm.doc.__islocal && !this.frm.doc.salary_structure_exists) {
|
||||
cur_frm.add_custom_button(__('Make Salary Structure'), function() {
|
||||
me.make_salary_structure(this); });
|
||||
if(!this.frm.doc.__islocal && this.frm.doc.__onload &&
|
||||
!this.frm.doc.__onload.salary_structure_exists) {
|
||||
cur_frm.add_custom_button(__('Make Salary Structure'), function() {
|
||||
me.make_salary_structure(this); });
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -14,17 +14,9 @@ from frappe.model.mapper import get_mapped_doc
|
||||
|
||||
class Employee(Document):
|
||||
def onload(self):
|
||||
self.salary_structure_exists = frappe.db.get_value("Salary Structure",
|
||||
self.get("__onload").salary_structure_exists = frappe.db.get_value("Salary Structure",
|
||||
{"employee": self.name, "is_active": "Yes", "docstatus": ["!=", 2]})
|
||||
|
||||
def as_dict(self, no_nulls=False):
|
||||
doc = super(Employee, self).as_dict(no_nulls)
|
||||
|
||||
if hasattr(self, "salary_structure_exists"):
|
||||
doc["salary_structure_exists"] = self.salary_structure_exists
|
||||
|
||||
return doc
|
||||
|
||||
def autoname(self):
|
||||
naming_method = frappe.db.get_value("HR Settings", None, "emp_created_by")
|
||||
if not naming_method:
|
||||
|
@ -57,6 +57,7 @@ var calculate_totals = function(doc, cdt, cdn) {
|
||||
|
||||
cur_frm.cscript.validate = function(doc, cdt, cdn) {
|
||||
calculate_totals(doc, cdt, cdn);
|
||||
if(doc.employee && doc.is_active == "Yes") frappe.model.clear_doc("Employee", doc.employee);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
|
||||
|
@ -42,6 +42,10 @@ cur_frm.cscript.refresh = function(doc, dt, dn) {
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.validate = function(doc, dt, dn) {
|
||||
if(doc.lead_name) frappe.model.clear_doc("Lead", doc.lead_name);
|
||||
}
|
||||
|
||||
cur_frm.cscript.setup_dashboard = function(doc) {
|
||||
cur_frm.dashboard.reset(doc);
|
||||
if(doc.__islocal)
|
||||
|
@ -10,7 +10,7 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
|
||||
this.frm.fields_dict.customer.get_query = function(doc, cdt, cdn) {
|
||||
return { query: "erpnext.controllers.queries.customer_query" } }
|
||||
},
|
||||
|
||||
|
||||
onload: function() {
|
||||
if(cur_frm.fields_dict.lead_owner.df.options.match(/^User/)) {
|
||||
cur_frm.fields_dict.lead_owner.get_query = function(doc, cdt, cdn) {
|
||||
@ -27,31 +27,30 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
|
||||
<span class="help">'+__('Automatically extract Leads from a mail box e.g.')+' "sales@example.com"</span></p>';
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
refresh: function() {
|
||||
var doc = this.frm.doc;
|
||||
erpnext.toggle_naming_series();
|
||||
this.frm.clear_custom_buttons();
|
||||
|
||||
this.frm.__is_customer = this.frm.__is_customer || this.frm.doc.__is_customer;
|
||||
if(!this.frm.doc.__islocal && !this.frm.doc.__is_customer) {
|
||||
if(!this.frm.doc.__islocal && this.frm.doc.__onload && !this.frm.doc.__onload.is_customer) {
|
||||
this.frm.add_custom_button(__("Create Customer"), this.create_customer);
|
||||
this.frm.add_custom_button(__("Create Opportunity"), this.create_opportunity);
|
||||
this.frm.appframe.add_button(__("Send SMS"), this.frm.cscript.send_sms, "icon-mobile-phone");
|
||||
}
|
||||
|
||||
|
||||
cur_frm.communication_view = new frappe.views.CommunicationList({
|
||||
list: frappe.get_list("Communication", {"parenttype": "Lead", "parent":this.frm.doc.name}),
|
||||
parent: this.frm.fields_dict.communication_html.wrapper,
|
||||
doc: this.frm.doc,
|
||||
recipients: this.frm.doc.email_id
|
||||
});
|
||||
|
||||
|
||||
if(!this.frm.doc.__islocal) {
|
||||
this.make_address_list();
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
make_address_list: function() {
|
||||
var me = this;
|
||||
if(!this.frm.address_list) {
|
||||
@ -73,15 +72,15 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({
|
||||
// note: render_address_row is defined in contact_control.js
|
||||
}
|
||||
this.frm.address_list.run();
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
create_customer: function() {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.selling.doctype.lead.lead.make_customer",
|
||||
frm: cur_frm
|
||||
})
|
||||
},
|
||||
|
||||
},
|
||||
|
||||
create_opportunity: function() {
|
||||
frappe.model.open_mapped_doc({
|
||||
method: "erpnext.selling.doctype.lead.lead.make_opportunity",
|
||||
|
@ -13,8 +13,7 @@ from erpnext.controllers.selling_controller import SellingController
|
||||
class Lead(SellingController):
|
||||
def onload(self):
|
||||
customer = frappe.db.get_value("Customer", {"lead_name": self.name})
|
||||
if customer:
|
||||
self.set("__is_customer", customer)
|
||||
self.get("__onload").is_customer = customer
|
||||
|
||||
def validate(self):
|
||||
self._prev = frappe._dict({
|
||||
|
@ -9,7 +9,8 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
|
||||
}
|
||||
|
||||
if(!doc.__islocal) {
|
||||
cur_frm.toggle_enable("default_currency", !cur_frm.doc.__transactions_exist);
|
||||
cur_frm.toggle_enable("default_currency", (cur_frm.doc.__onload &&
|
||||
!cur_frm.doc.__onload.transactions_exist));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,7 @@ from frappe.model.document import Document
|
||||
|
||||
class Company(Document):
|
||||
def onload(self):
|
||||
self.set("__transactions_exist", self.check_if_transactions_exist())
|
||||
self.get("__onload").transactions_exist = self.check_if_transactions_exist()
|
||||
|
||||
def check_if_transactions_exist(self):
|
||||
exists = False
|
||||
|
@ -17,7 +17,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
|
||||
refresh: function(doc, dt, dn) {
|
||||
this._super();
|
||||
|
||||
if(!doc.__billing_complete && doc.docstatus==1) {
|
||||
if(doc.__onload && !doc.__onload.billing_complete && doc.docstatus==1) {
|
||||
// show Make Invoice button only if Delivery Note is not created from Sales Invoice
|
||||
var from_sales_invoice = false;
|
||||
from_sales_invoice = cur_frm.doc.delivery_note_details.some(function(item) {
|
||||
|
@ -37,7 +37,7 @@ class DeliveryNote(SellingController):
|
||||
where docstatus=1 and delivery_note=%s""", self.name)
|
||||
if billed_qty:
|
||||
total_qty = sum((item.qty for item in self.get("delivery_note_details")))
|
||||
self.set("__billing_complete", billed_qty[0][0] == total_qty)
|
||||
self.get("__onload").billing_complete = (billed_qty[0][0] == total_qty)
|
||||
|
||||
def get_portal_page(self):
|
||||
return "shipment" if self.docstatus==1 else None
|
||||
|
@ -25,7 +25,7 @@ cur_frm.cscript.refresh = function(doc) {
|
||||
|
||||
if (!doc.__islocal && doc.is_stock_item == 'Yes') {
|
||||
cur_frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method'],
|
||||
doc.__sle_exists=="exists" ? false : true);
|
||||
(doc.__onload && doc.__onload.sle_exists=="exists") ? false : true);
|
||||
}
|
||||
|
||||
erpnext.item.toggle_reqd(cur_frm);
|
||||
|
@ -13,7 +13,7 @@ class WarehouseNotSet(frappe.ValidationError): pass
|
||||
|
||||
class Item(WebsiteGenerator):
|
||||
def onload(self):
|
||||
self.set("__sle_exists", self.check_if_sle_exists())
|
||||
self.get("__onload").sle_exists = self.check_if_sle_exists()
|
||||
|
||||
def autoname(self):
|
||||
if frappe.db.get_default("item_naming_by")=="Naming Series":
|
||||
|
@ -16,9 +16,8 @@ erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend
|
||||
this._super();
|
||||
|
||||
if(this.frm.doc.docstatus == 1) {
|
||||
if(!this.frm.doc.__billing_complete) {
|
||||
cur_frm.add_custom_button(__('Make Purchase Invoice'),
|
||||
this.make_purchase_invoice);
|
||||
if(this.frm.doc.__onload && !this.frm.doc.__onload.billing_complete) {
|
||||
cur_frm.add_custom_button(__('Make Purchase Invoice'), this.make_purchase_invoice);
|
||||
}
|
||||
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
|
||||
|
||||
|
@ -34,7 +34,7 @@ class PurchaseReceipt(BuyingController):
|
||||
where purchase_receipt=%s""", self.name)
|
||||
if billed_qty:
|
||||
total_qty = sum((item.qty for item in self.get("purchase_receipt_details")))
|
||||
self.set("__billing_complete", billed_qty[0][0] == total_qty)
|
||||
self.get("__onload").billing_complete = (billed_qty[0][0] == total_qty)
|
||||
|
||||
def validate(self):
|
||||
super(PurchaseReceipt, self).validate()
|
||||
|
@ -22,25 +22,25 @@ cur_frm.cscript.refresh = function(doc) {
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
cur_frm.cscript.setup_dashboard();
|
||||
|
||||
if(doc.__islocal && !doc.send_from) {
|
||||
cur_frm.set_value("send_from",
|
||||
cur_frm.set_value("send_from",
|
||||
repl("%(fullname)s <%(email)s>", frappe.user_info(doc.owner)));
|
||||
}
|
||||
}
|
||||
|
||||
cur_frm.cscript.setup_dashboard = function() {
|
||||
cur_frm.dashboard.reset();
|
||||
if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent) && cur_frm.doc.__status_count) {
|
||||
var stat = cur_frm.doc.__status_count;
|
||||
if(!cur_frm.doc.__islocal && cint(cur_frm.doc.email_sent) && cur_frm.doc.__onload && cur_frm.doc.__onload.status_count) {
|
||||
var stat = cur_frm.doc.__onload.status_count;
|
||||
var total = frappe.utils.sum($.map(stat, function(v) { return v; }));
|
||||
if(total) {
|
||||
$.each(stat, function(k, v) {
|
||||
stat[k] = flt(v * 100 / total, 2);
|
||||
});
|
||||
|
||||
|
||||
cur_frm.dashboard.add_progress("Status", [
|
||||
{
|
||||
title: stat["Sent"] + "% Sent",
|
||||
@ -60,4 +60,4 @@ cur_frm.cscript.setup_dashboard = function() {
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,16 +12,9 @@ from frappe.model.document import Document
|
||||
class Newsletter(Document):
|
||||
def onload(self):
|
||||
if self.email_sent:
|
||||
self.set("__status_count", dict(frappe.db.sql("""select status, count(*)
|
||||
self.get("__onload").status_count = dict(frappe.db.sql("""select status, count(*)
|
||||
from `tabBulk Email` where ref_doctype=%s and ref_docname=%s
|
||||
group by status""", (self.doctype, self.name))) or None)
|
||||
|
||||
def as_dict(self, no_nulls=False):
|
||||
doc = super(Newsletter, self).as_dict(no_nulls)
|
||||
if self.get("__status_count"):
|
||||
doc["__status_count"] = self.get("__status_count")
|
||||
|
||||
return doc
|
||||
group by status""", (self.doctype, self.name))) or None
|
||||
|
||||
def test_send(self, doctype="Lead"):
|
||||
self.recipients = self.test_email_id.split(",")
|
||||
|
Loading…
Reference in New Issue
Block a user