Browse Source

[fix] create optional columns during sync, use email account name if no sender full name

version-14
Anand Doshi 9 years ago
parent
commit
5b45450252
8 changed files with 36 additions and 26 deletions
  1. +4
    -14
      frappe/core/doctype/communication/comment.py
  2. +7
    -3
      frappe/core/doctype/communication/email.py
  3. +1
    -1
      frappe/core/doctype/communication/feed.py
  4. +1
    -1
      frappe/core/doctype/doctype/doctype.py
  5. +2
    -2
      frappe/custom/doctype/custom_field/custom_field.py
  6. +2
    -2
      frappe/email/doctype/email_account/email_account.json
  7. +3
    -0
      frappe/email/doctype/email_account/email_account.py
  8. +16
    -3
      frappe/model/db_schema.py

+ 4
- 14
frappe/core/doctype/communication/comment.py View File

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



+ 7
- 3
frappe/core/doctype/communication/email.py View File

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


+ 1
- 1
frappe/core/doctype/communication/feed.py View File

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


+ 1
- 1
frappe/core/doctype/doctype/doctype.py View File

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


+ 2
- 2
frappe/custom/doctype/custom_field/custom_field.py View File

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


+ 2
- 2
frappe/email/doctype/email_account/email_account.json View File

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


+ 3
- 0
frappe/email/doctype/email_account/email_account.py View File

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


+ 16
- 3
frappe/model/db_schema.py View File

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


Loading…
Cancel
Save