Skip to content

Commit

Permalink
Merge branch 'hotfix'
Browse files Browse the repository at this point in the history
  • Loading branch information
sahil28297 committed May 21, 2019
2 parents 7975118 + e4aedc3 commit 1a06bc2
Show file tree
Hide file tree
Showing 18 changed files with 700 additions and 482 deletions.
26 changes: 16 additions & 10 deletions frappe/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
reload(sys)
sys.setdefaultencoding("utf-8")

__version__ = '11.1.28'
__version__ = '11.1.29'
__title__ = "Frappe Framework"

local = Local()
Expand Down Expand Up @@ -187,15 +187,20 @@ def connect(site=None, db_name=None):
local.db = Database(user=db_name or local.conf.db_name)
set_user("Administrator")

def connect_read_only():
def connect_replica():
from frappe.database import Database
user = local.conf.db_name
password = local.conf.db_password

local.read_only_db = Database(local.conf.slave_host, local.conf.slave_db_name,
local.conf.slave_db_password)
if local.conf.different_credentials_for_replica:
user = local.conf.replica_db_name
password = local.conf.replica_db_password

local.replica_db = Database(host=local.conf.replica_host, user=user, password=password)

# swap db connections
local.master_db = local.db
local.db = local.read_only_db
local.primary_db = local.db
local.db = local.replica_db

def get_site_config(sites_path=None, site_path=None):
"""Returns `site_config.json` combined with `sites/common_site_config.json`.
Expand Down Expand Up @@ -495,16 +500,17 @@ def innerfn(fn):
def read_only():
def innfn(fn):
def wrapper_fn(*args, **kwargs):
if conf.use_slave_for_read_only:
connect_read_only()
if conf.read_from_replica:
connect_replica()

try:
retval = fn(*args, **get_newargs(fn, kwargs))
except:
raise
finally:
if local and hasattr(local, 'master_db'):
if local and hasattr(local, 'primary_db'):
local.db.close()
local.db = local.master_db
local.db = local.primary_db

return retval
return wrapper_fn
Expand Down
8 changes: 8 additions & 0 deletions frappe/contacts/address_and_contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,11 @@ def filter_dynamic_link_doctypes(doctype, txt, searchfield, start, page_len, fil
valid_doctypes = [[doctype] for doctype in valid_doctypes]

return valid_doctypes

def set_link_title(doc):
if not doc.links:
return
for link in doc.links:
if not link.link_title:
linked_doc = frappe.get_doc(link.link_doctype, link.link_name)
link.link_title = linked_doc.get("title_field") or linked_doc.get("name")
2 changes: 2 additions & 0 deletions frappe/contacts/doctype/address/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
from six import iteritems, string_types
from past.builtins import cmp
from frappe.contacts.address_and_contact import set_link_title

import functools

Expand All @@ -39,6 +40,7 @@ def autoname(self):
def validate(self):
self.link_address()
self.validate_reference()
set_link_title(self)
deduplicate_dynamic_links(self)

def link_address(self):
Expand Down
2 changes: 2 additions & 0 deletions frappe/contacts/doctype/contact/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from six import iteritems
from past.builtins import cmp
from frappe.model.naming import append_number_if_name_exists
from frappe.contacts.address_and_contact import set_link_title

import functools

Expand All @@ -31,6 +32,7 @@ def validate(self):
if self.email_id:
self.email_id = self.email_id.strip()
self.set_user()
set_link_title(self)
if self.email_id and not self.image:
self.image = has_gravatar(self.email_id)

Expand Down
4 changes: 2 additions & 2 deletions frappe/core/doctype/prepared_report/prepared_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ def run_background(prepared_report):
instance.status = "Completed"
instance.columns = json.dumps(result["columns"])
instance.report_end_time = frappe.utils.now()
instance.save()
instance.save(ignore_permissions=True)

except Exception:
frappe.log_error(frappe.get_traceback())
instance = frappe.get_doc("Prepared Report", prepared_report)
instance.status = "Error"
instance.error_message = frappe.get_traceback()
instance.save()
instance.save(ignore_permissions=True)

frappe.publish_realtime(
'report_generated',
Expand Down
11 changes: 9 additions & 2 deletions frappe/desk/doctype/auto_repeat/auto_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,15 @@ def validate(self):
validate_template(self.message or "")

def before_submit(self):
start_date_copy = self.start_date
today_copy = add_days(today(), -1)

if start_date_copy <= today_copy:
start_date_copy = today_copy

if not self.next_schedule_date:
self.next_schedule_date = get_next_schedule_date(
self.start_date, self.frequency, self.repeat_on_day)
start_date_copy, self.frequency, self.repeat_on_day)

def on_submit(self):
self.update_auto_repeat_id()
Expand Down Expand Up @@ -116,14 +122,15 @@ def get_auto_repeat_schedule(self):
days = 60 if self.frequency in ['Daily', 'Weekly'] else 365
end_date_copy = add_days(today_copy, days)

start_date_copy = get_next_schedule_date(start_date_copy, self.frequency, self.repeat_on_day)
while (getdate(start_date_copy) < getdate(end_date_copy)):
start_date_copy = get_next_schedule_date(start_date_copy, self.frequency, self.repeat_on_day)
row = {
"reference_document" : self.reference_document,
"frequency" : self.frequency,
"next_scheduled_date" : start_date_copy
}
schedule_details.append(row)
start_date_copy = get_next_schedule_date(start_date_copy, self.frequency, self.repeat_on_day)

return schedule_details

Expand Down
8 changes: 4 additions & 4 deletions frappe/desk/doctype/auto_repeat/test_auto_repeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import frappe
from frappe.custom.doctype.custom_field.custom_field import create_custom_field
from frappe.desk.doctype.auto_repeat.auto_repeat import get_auto_repeat_entries, create_repeated_entries, disable_auto_repeat
from frappe.utils import today, add_days, getdate
from frappe.utils import today, add_days, getdate, add_months


def add_custom_fields():
Expand Down Expand Up @@ -44,8 +44,8 @@ def test_daily_auto_repeat(self):
self.assertEqual(todo.get('description'), new_todo.get('description'))

def test_monthly_auto_repeat(self):
start_date = '2018-01-01'
end_date = '2018-12-31'
start_date = today()
end_date = add_months(start_date, 12)

todo = frappe.get_doc(
dict(doctype='ToDo', description='test recurring todo', assigned_by='Administrator')).insert()
Expand Down Expand Up @@ -103,7 +103,7 @@ def make_auto_repeat(**args):
'reference_document': args.reference_document or frappe.db.get_value('ToDo', {'docstatus': 1}, 'name'),
'frequency': args.frequency or 'Daily',
'start_date': args.start_date or add_days(today(), -1),
'end_date': args.end_date or add_days(today(), 1),
'end_date': args.end_date or add_days(today(), 2),
'submit_on_creation': args.submit_on_creation or 0,
'notify_by_email': args.notify or 0,
'recipients': args.recipients or "",
Expand Down
2 changes: 1 addition & 1 deletion frappe/desk/moduleview.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ def get_report_list(module, is_standard="No"):
out.append({
"type": "report",
"doctype": r.ref_doctype,
"is_query_report": 1 if r.report_type in ("Query Report", "Script Report") else 0,
"is_query_report": 1 if r.report_type in ("Query Report", "Script Report", "Custom Report") else 0,
"label": _(r.name),
"name": r.name
})
Expand Down
1 change: 1 addition & 0 deletions frappe/geo/country_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2329,6 +2329,7 @@
},
"Suriname": {
"code": "sr",
"currency": "SRD",
"currency_fraction": "Cent",
"currency_fraction_units": 100,
"currency_symbol": "$",
Expand Down
Loading

0 comments on commit 1a06bc2

Please sign in to comment.