diff --git a/frappe/core/doctype/communication/comment.py b/frappe/core/doctype/communication/comment.py index f934e3b0fd..2d5dfe5bb9 100644 --- a/frappe/core/doctype/communication/comment.py +++ b/frappe/core/doctype/communication/comment.py @@ -7,7 +7,6 @@ from frappe import _ import json from frappe.core.doctype.user.user import extract_mentions from frappe.utils import get_fullname, get_link_to_form -from frappe.model.db_schema import add_column from frappe.website.render import clear_cache def validate_comment(doc): @@ -107,25 +106,16 @@ def get_comments_from_parent(doc): try: _comments = frappe.db.get_value(doc.reference_doctype, doc.reference_name, "_comments") or "[]" - return json.loads(_comments) - except Exception, e: - - if e.args[0]==1054: - if frappe.flags.in_test: - return - - add_column(doc.reference_doctype, "_comments", "Text") - - return get_comments_from_parent(doc) - - elif e.args[0]==1146: + if e.args[0]==1146: # no table - pass + _comments = "[]" else: raise + return json.loads(_comments) + def update_comments_in_parent(doc, _comments): """Updates `_comments` property in parent Document with given dict. diff --git a/frappe/core/doctype/communication/email.py b/frappe/core/doctype/communication/email.py index 5863236c81..c657a23a11 100644 --- a/frappe/core/doctype/communication/email.py +++ b/frappe/core/doctype/communication/email.py @@ -190,7 +190,11 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) set_incoming_outgoing_accounts(doc) if not doc.sender or cint(doc.outgoing_email_account.always_use_account_email_id_as_sender): - doc.sender = formataddr([frappe.session.data.full_name or "Notification", doc.outgoing_email_account.email_id]) + sender_name = (frappe.session.data.full_name + or doc.outgoing_email_account.name + or _("Notification")) + sender_email_id = doc.outgoing_email_account.email_id + doc.sender = formataddr([sender_name, sender_email_id]) doc.attachments = [] @@ -222,7 +226,7 @@ def set_incoming_outgoing_accounts(doc): doc.outgoing_email_account = frappe.db.get_value("Email Account", {"append_to": doc.reference_doctype, "enable_outgoing": 1}, - ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) + ["email_id", "always_use_account_email_id_as_sender", "name"], as_dict=True) if not doc.incoming_email_account: doc.incoming_email_account = frappe.db.get_value("Email Account", @@ -231,7 +235,7 @@ def set_incoming_outgoing_accounts(doc): if not doc.outgoing_email_account: doc.outgoing_email_account = frappe.db.get_value("Email Account", {"default_outgoing": 1, "enable_outgoing": 1}, - ["email_id", "always_use_account_email_id_as_sender"], as_dict=True) or frappe._dict() + ["email_id", "always_use_account_email_id_as_sender", "name"], as_dict=True) or frappe._dict() def get_recipients(doc, fetched_from_email_account=False): """Build a list of email addresses for To""" diff --git a/frappe/core/doctype/communication/feed.py b/frappe/core/doctype/communication/feed.py index 9df2d72f3a..38b9219896 100644 --- a/frappe/core/doctype/communication/feed.py +++ b/frappe/core/doctype/communication/feed.py @@ -15,7 +15,7 @@ def update_feed(doc, method=None): if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_import: return - if doc._action!="save": + if doc._action!="save" or doc.flags.ignore_feed: return if doc.doctype == "Communication" or doc.meta.issingle: diff --git a/frappe/core/doctype/doctype/doctype.py b/frappe/core/doctype/doctype/doctype.py index 39a3bc6b6c..99a7647986 100644 --- a/frappe/core/doctype/doctype/doctype.py +++ b/frappe/core/doctype/doctype/doctype.py @@ -121,7 +121,7 @@ class DocType(Document): def on_update(self): """Update database schema, make controller templates if `custom` is not set and clear cache.""" from frappe.model.db_schema import updatedb - updatedb(self.name) + updatedb(self.name, self) self.change_modified_of_parent() make_module_and_roles(self) diff --git a/frappe/custom/doctype/custom_field/custom_field.py b/frappe/custom/doctype/custom_field/custom_field.py index c1d0346014..435ceb8d3f 100644 --- a/frappe/custom/doctype/custom_field/custom_field.py +++ b/frappe/custom/doctype/custom_field/custom_field.py @@ -92,9 +92,9 @@ class CustomField(Document): # Create new peroperty setter if order changed if _idx and not existing_property_setter: field_idx = (_idx.index(self.insert_after) + 1) if (self.insert_after in _idx) else len(_idx) - + _idx.insert(field_idx, self.fieldname) - + frappe.make_property_setter({ "doctype":self.dt, "doctype_or_field": "DocType", diff --git a/frappe/email/doctype/email_account/email_account.json b/frappe/email/doctype/email_account/email_account.json index e2a0ef04e3..ac90fd77eb 100644 --- a/frappe/email/doctype/email_account/email_account.json +++ b/frappe/email/doctype/email_account/email_account.json @@ -1,7 +1,7 @@ { "allow_copy": 0, "allow_import": 0, - "allow_rename": 0, + "allow_rename": 1, "autoname": "field:email_account_name", "creation": "2014-09-11 12:04:34.163728", "custom": 0, @@ -873,7 +873,7 @@ "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2015-12-02 02:27:34.031592", + "modified": "2016-02-08 02:39:33.273073", "modified_by": "Administrator", "module": "Email", "name": "Email Account", diff --git a/frappe/email/doctype/email_account/email_account.py b/frappe/email/doctype/email_account/email_account.py index d3fa01b159..39f1d43082 100644 --- a/frappe/email/doctype/email_account/email_account.py +++ b/frappe/email/doctype/email_account/email_account.py @@ -358,6 +358,9 @@ class EmailAccount(Document): """Clear communications where email account is linked""" frappe.db.sql("update `tabCommunication` set email_account='' where email_account=%s", self.name) + def after_rename(self, old, new, merge=False): + frappe.db.set_value("Email Account", new, "email_account_name", new) + @frappe.whitelist() def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): if not txt: txt = "" diff --git a/frappe/model/db_schema.py b/frappe/model/db_schema.py index ff35518a24..e2a77533db 100644 --- a/frappe/model/db_schema.py +++ b/frappe/model/db_schema.py @@ -46,10 +46,11 @@ type_map = { default_columns = ['name', 'creation', 'modified', 'modified_by', 'owner', 'docstatus', 'parent', 'parentfield', 'parenttype', 'idx'] +optional_columns = ["_user_tags", "_comments", "_assign", "_liked_by"] default_shortcuts = ['_Login', '__user', '_Full Name', 'Today', '__today', "now", "Now"] -def updatedb(dt): +def updatedb(dt, meta=None): """ Syncs a `DocType` to the table * creates if required @@ -61,7 +62,7 @@ def updatedb(dt): raise Exception, 'Wrong doctype "%s" in updatedb' % dt if not res[0][0]: - tab = DbTable(dt, 'tab') + tab = DbTable(dt, 'tab', meta) tab.validate() frappe.db.commit() @@ -69,12 +70,16 @@ def updatedb(dt): frappe.db.begin() class DbTable: - def __init__(self, doctype, prefix = 'tab'): + def __init__(self, doctype, prefix = 'tab', meta = None): self.doctype = doctype self.name = prefix + doctype self.columns = {} self.current_columns = {} + self.meta = meta + if not self.meta: + self.meta = frappe.get_meta(self.doctype) + # lists for change self.add_column = [] self.change_type = [] @@ -199,6 +204,14 @@ class DbTable: precisions = {} uniques = {} + # optional fields like _comments + if not self.meta.istable: + for fieldname in optional_columns: + fl.append({ + "fieldname": fieldname, + "fieldtype": "Text" + }) + if not frappe.flags.in_install_db and frappe.flags.in_install != "frappe": custom_fl = frappe.db.sql("""\ SELECT * FROM `tabCustom Field`