@@ -7,7 +7,6 @@ from frappe import _ | |||||
import json | import json | ||||
from frappe.core.doctype.user.user import extract_mentions | from frappe.core.doctype.user.user import extract_mentions | ||||
from frappe.utils import get_fullname, get_link_to_form | 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 | from frappe.website.render import clear_cache | ||||
def validate_comment(doc): | def validate_comment(doc): | ||||
@@ -107,25 +106,16 @@ def get_comments_from_parent(doc): | |||||
try: | try: | ||||
_comments = frappe.db.get_value(doc.reference_doctype, doc.reference_name, "_comments") or "[]" | _comments = frappe.db.get_value(doc.reference_doctype, doc.reference_name, "_comments") or "[]" | ||||
return json.loads(_comments) | |||||
except Exception, e: | 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 | # no table | ||||
pass | |||||
_comments = "[]" | |||||
else: | else: | ||||
raise | raise | ||||
return json.loads(_comments) | |||||
def update_comments_in_parent(doc, _comments): | def update_comments_in_parent(doc, _comments): | ||||
"""Updates `_comments` property in parent Document with given dict. | """Updates `_comments` property in parent Document with given dict. | ||||
@@ -190,7 +190,11 @@ def prepare_to_notify(doc, print_html=None, print_format=None, attachments=None) | |||||
set_incoming_outgoing_accounts(doc) | set_incoming_outgoing_accounts(doc) | ||||
if not doc.sender or cint(doc.outgoing_email_account.always_use_account_email_id_as_sender): | 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 = [] | doc.attachments = [] | ||||
@@ -222,7 +226,7 @@ def set_incoming_outgoing_accounts(doc): | |||||
doc.outgoing_email_account = frappe.db.get_value("Email Account", | doc.outgoing_email_account = frappe.db.get_value("Email Account", | ||||
{"append_to": doc.reference_doctype, "enable_outgoing": 1}, | {"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: | if not doc.incoming_email_account: | ||||
doc.incoming_email_account = frappe.db.get_value("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: | if not doc.outgoing_email_account: | ||||
doc.outgoing_email_account = frappe.db.get_value("Email Account", | doc.outgoing_email_account = frappe.db.get_value("Email Account", | ||||
{"default_outgoing": 1, "enable_outgoing": 1}, | {"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): | def get_recipients(doc, fetched_from_email_account=False): | ||||
"""Build a list of email addresses for To""" | """Build a list of email addresses for To""" | ||||
@@ -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: | if frappe.flags.in_patch or frappe.flags.in_install or frappe.flags.in_import: | ||||
return | return | ||||
if doc._action!="save": | |||||
if doc._action!="save" or doc.flags.ignore_feed: | |||||
return | return | ||||
if doc.doctype == "Communication" or doc.meta.issingle: | if doc.doctype == "Communication" or doc.meta.issingle: | ||||
@@ -121,7 +121,7 @@ class DocType(Document): | |||||
def on_update(self): | def on_update(self): | ||||
"""Update database schema, make controller templates if `custom` is not set and clear cache.""" | """Update database schema, make controller templates if `custom` is not set and clear cache.""" | ||||
from frappe.model.db_schema import updatedb | from frappe.model.db_schema import updatedb | ||||
updatedb(self.name) | |||||
updatedb(self.name, self) | |||||
self.change_modified_of_parent() | self.change_modified_of_parent() | ||||
make_module_and_roles(self) | make_module_and_roles(self) | ||||
@@ -92,9 +92,9 @@ class CustomField(Document): | |||||
# Create new peroperty setter if order changed | # Create new peroperty setter if order changed | ||||
if _idx and not existing_property_setter: | if _idx and not existing_property_setter: | ||||
field_idx = (_idx.index(self.insert_after) + 1) if (self.insert_after in _idx) else len(_idx) | field_idx = (_idx.index(self.insert_after) + 1) if (self.insert_after in _idx) else len(_idx) | ||||
_idx.insert(field_idx, self.fieldname) | _idx.insert(field_idx, self.fieldname) | ||||
frappe.make_property_setter({ | frappe.make_property_setter({ | ||||
"doctype":self.dt, | "doctype":self.dt, | ||||
"doctype_or_field": "DocType", | "doctype_or_field": "DocType", | ||||
@@ -1,7 +1,7 @@ | |||||
{ | { | ||||
"allow_copy": 0, | "allow_copy": 0, | ||||
"allow_import": 0, | "allow_import": 0, | ||||
"allow_rename": 0, | |||||
"allow_rename": 1, | |||||
"autoname": "field:email_account_name", | "autoname": "field:email_account_name", | ||||
"creation": "2014-09-11 12:04:34.163728", | "creation": "2014-09-11 12:04:34.163728", | ||||
"custom": 0, | "custom": 0, | ||||
@@ -873,7 +873,7 @@ | |||||
"issingle": 0, | "issingle": 0, | ||||
"istable": 0, | "istable": 0, | ||||
"max_attachments": 0, | "max_attachments": 0, | ||||
"modified": "2015-12-02 02:27:34.031592", | |||||
"modified": "2016-02-08 02:39:33.273073", | |||||
"modified_by": "Administrator", | "modified_by": "Administrator", | ||||
"module": "Email", | "module": "Email", | ||||
"name": "Email Account", | "name": "Email Account", | ||||
@@ -358,6 +358,9 @@ class EmailAccount(Document): | |||||
"""Clear communications where email account is linked""" | """Clear communications where email account is linked""" | ||||
frappe.db.sql("update `tabCommunication` set email_account='' where email_account=%s", self.name) | 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() | @frappe.whitelist() | ||||
def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): | def get_append_to(doctype=None, txt=None, searchfield=None, start=None, page_len=None, filters=None): | ||||
if not txt: txt = "" | if not txt: txt = "" | ||||
@@ -46,10 +46,11 @@ type_map = { | |||||
default_columns = ['name', 'creation', 'modified', 'modified_by', 'owner', | default_columns = ['name', 'creation', 'modified', 'modified_by', 'owner', | ||||
'docstatus', 'parent', 'parentfield', 'parenttype', 'idx'] | 'docstatus', 'parent', 'parentfield', 'parenttype', 'idx'] | ||||
optional_columns = ["_user_tags", "_comments", "_assign", "_liked_by"] | |||||
default_shortcuts = ['_Login', '__user', '_Full Name', 'Today', '__today', "now", "Now"] | default_shortcuts = ['_Login', '__user', '_Full Name', 'Today', '__today', "now", "Now"] | ||||
def updatedb(dt): | |||||
def updatedb(dt, meta=None): | |||||
""" | """ | ||||
Syncs a `DocType` to the table | Syncs a `DocType` to the table | ||||
* creates if required | * creates if required | ||||
@@ -61,7 +62,7 @@ def updatedb(dt): | |||||
raise Exception, 'Wrong doctype "%s" in updatedb' % dt | raise Exception, 'Wrong doctype "%s" in updatedb' % dt | ||||
if not res[0][0]: | if not res[0][0]: | ||||
tab = DbTable(dt, 'tab') | |||||
tab = DbTable(dt, 'tab', meta) | |||||
tab.validate() | tab.validate() | ||||
frappe.db.commit() | frappe.db.commit() | ||||
@@ -69,12 +70,16 @@ def updatedb(dt): | |||||
frappe.db.begin() | frappe.db.begin() | ||||
class DbTable: | class DbTable: | ||||
def __init__(self, doctype, prefix = 'tab'): | |||||
def __init__(self, doctype, prefix = 'tab', meta = None): | |||||
self.doctype = doctype | self.doctype = doctype | ||||
self.name = prefix + doctype | self.name = prefix + doctype | ||||
self.columns = {} | self.columns = {} | ||||
self.current_columns = {} | self.current_columns = {} | ||||
self.meta = meta | |||||
if not self.meta: | |||||
self.meta = frappe.get_meta(self.doctype) | |||||
# lists for change | # lists for change | ||||
self.add_column = [] | self.add_column = [] | ||||
self.change_type = [] | self.change_type = [] | ||||
@@ -199,6 +204,14 @@ class DbTable: | |||||
precisions = {} | precisions = {} | ||||
uniques = {} | 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": | if not frappe.flags.in_install_db and frappe.flags.in_install != "frappe": | ||||
custom_fl = frappe.db.sql("""\ | custom_fl = frappe.db.sql("""\ | ||||
SELECT * FROM `tabCustom Field` | SELECT * FROM `tabCustom Field` | ||||