mirror of
https://github.com/frappe/erpnext.git
synced 2026-09-01 23:53:21 +00:00
Replaced doc, doc.fields frappe/frappe#478
This commit is contained in:
@@ -14,20 +14,20 @@ from erpnext.utilities.transaction_base import TransactionBase
|
||||
class CustomerIssue(TransactionBase):
|
||||
|
||||
def validate(self):
|
||||
if session['user'] != 'Guest' and not self.doc.customer:
|
||||
if session['user'] != 'Guest' and not self.customer:
|
||||
msgprint("Please select Customer from whom issue is raised",
|
||||
raise_exception=True)
|
||||
|
||||
if self.doc.status=="Closed" and \
|
||||
frappe.db.get_value("Customer Issue", self.doc.name, "status")!="Closed":
|
||||
self.doc.resolution_date = today()
|
||||
self.doc.resolved_by = frappe.session.user
|
||||
if self.status=="Closed" and \
|
||||
frappe.db.get_value("Customer Issue", self.name, "status")!="Closed":
|
||||
self.resolution_date = today()
|
||||
self.resolved_by = frappe.session.user
|
||||
|
||||
def on_cancel(self):
|
||||
lst = frappe.db.sql("""select t1.name
|
||||
from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2
|
||||
where t2.parent = t1.name and t2.prevdoc_docname = %s and t1.docstatus!=2""",
|
||||
(self.doc.name))
|
||||
(self.name))
|
||||
if lst:
|
||||
lst1 = ','.join([x[0] for x in lst])
|
||||
msgprint("Maintenance Visit No. "+lst1+" already created against this customer issue. So can not be Cancelled")
|
||||
|
||||
@@ -24,7 +24,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
def generate_schedule(self):
|
||||
self.set('maintenance_schedule_detail', [])
|
||||
frappe.db.sql("""delete from `tabMaintenance Schedule Detail`
|
||||
where parent=%s""", (self.doc.name))
|
||||
where parent=%s""", (self.name))
|
||||
count = 1
|
||||
for d in self.get('item_maintenance_detail'):
|
||||
self.validate_maintenance_detail()
|
||||
@@ -63,21 +63,21 @@ class MaintenanceSchedule(TransactionBase):
|
||||
|
||||
scheduled_date = frappe.db.sql("""select scheduled_date from
|
||||
`tabMaintenance Schedule Detail` where sales_person=%s and item_code=%s and
|
||||
parent=%s""", (d.sales_person, d.item_code, self.doc.name), as_dict=1)
|
||||
parent=%s""", (d.sales_person, d.item_code, self.name), as_dict=1)
|
||||
|
||||
for key in scheduled_date:
|
||||
if email_map[d.sales_person]:
|
||||
description = "Reference: %s, Item Code: %s and Customer: %s" % \
|
||||
(self.doc.name, d.item_code, self.doc.customer)
|
||||
(self.name, d.item_code, self.customer)
|
||||
frappe.bean({
|
||||
"doctype": "Event",
|
||||
"owner": email_map[d.sales_person] or self.doc.owner,
|
||||
"owner": email_map[d.sales_person] or self.owner,
|
||||
"subject": description,
|
||||
"description": description,
|
||||
"starts_on": key["scheduled_date"] + " 10:00:00",
|
||||
"event_type": "Private",
|
||||
"ref_type": self.doc.doctype,
|
||||
"ref_name": self.doc.name
|
||||
"ref_type": self.doctype,
|
||||
"ref_name": self.name
|
||||
}).insert(ignore_permissions=1)
|
||||
|
||||
frappe.db.set(self.doc, 'status', 'Submitted')
|
||||
@@ -204,7 +204,7 @@ class MaintenanceSchedule(TransactionBase):
|
||||
def update_amc_date(self, serial_nos, amc_expiry_date=None):
|
||||
for serial_no in serial_nos:
|
||||
serial_no_bean = frappe.bean("Serial No", serial_no)
|
||||
serial_no_bean.doc.amc_expiry_date = amc_expiry_date
|
||||
serial_no_bean.amc_expiry_date = amc_expiry_date
|
||||
serial_no_bean.save()
|
||||
|
||||
def validate_serial_no(self, serial_nos, amc_start_date):
|
||||
@@ -262,10 +262,10 @@ class MaintenanceSchedule(TransactionBase):
|
||||
serial_nos = get_valid_serial_nos(d.serial_no)
|
||||
self.update_amc_date(serial_nos)
|
||||
frappe.db.set(self.doc, 'status', 'Cancelled')
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
delete_events(self.doctype, self.name)
|
||||
|
||||
def on_trash(self):
|
||||
delete_events(self.doc.doctype, self.doc.name)
|
||||
delete_events(self.doctype, self.name)
|
||||
|
||||
@frappe.whitelist()
|
||||
def make_maintenance_visit(source_name, target_doclist=None):
|
||||
|
||||
@@ -34,15 +34,15 @@ class MaintenanceVisit(TransactionBase):
|
||||
for d in self.get('maintenance_visit_details'):
|
||||
if d.prevdoc_docname and d.prevdoc_doctype == 'Customer Issue' :
|
||||
if flag==1:
|
||||
mntc_date = self.doc.mntc_date
|
||||
mntc_date = self.mntc_date
|
||||
service_person = d.service_person
|
||||
work_done = d.work_done
|
||||
if self.doc.completion_status == 'Fully Completed':
|
||||
if self.completion_status == 'Fully Completed':
|
||||
status = 'Closed'
|
||||
elif self.doc.completion_status == 'Partially Completed':
|
||||
elif self.completion_status == 'Partially Completed':
|
||||
status = 'Work In Progress'
|
||||
else:
|
||||
nm = frappe.db.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.doc.name))
|
||||
nm = frappe.db.sql("select t1.name, t1.mntc_date, t2.service_person, t2.work_done from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.completion_status = 'Partially Completed' and t2.prevdoc_docname = %s and t1.name!=%s and t1.docstatus = 1 order by t1.name desc limit 1", (d.prevdoc_docname, self.name))
|
||||
|
||||
if nm:
|
||||
status = 'Work In Progress'
|
||||
@@ -67,7 +67,7 @@ class MaintenanceVisit(TransactionBase):
|
||||
check_for_doctype = d.prevdoc_doctype
|
||||
|
||||
if check_for_docname:
|
||||
check = frappe.db.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.name!=%s and t2.prevdoc_docname=%s and t1.docstatus = 1 and (t1.mntc_date > %s or (t1.mntc_date = %s and t1.mntc_time > %s))", (self.doc.name, check_for_docname, self.doc.mntc_date, self.doc.mntc_date, self.doc.mntc_time))
|
||||
check = frappe.db.sql("select t1.name from `tabMaintenance Visit` t1, `tabMaintenance Visit Purpose` t2 where t2.parent = t1.name and t1.name!=%s and t2.prevdoc_docname=%s and t1.docstatus = 1 and (t1.mntc_date > %s or (t1.mntc_date = %s and t1.mntc_time > %s))", (self.name, check_for_docname, self.mntc_date, self.mntc_date, self.mntc_time))
|
||||
|
||||
if check:
|
||||
check_lst = [x[0] for x in check]
|
||||
|
||||
@@ -12,23 +12,23 @@ from frappe.model.document import Document
|
||||
class Newsletter(Document):
|
||||
|
||||
def onload(self):
|
||||
if self.doc.email_sent:
|
||||
self.doc.fields["__status_count"] = dict(frappe.db.sql("""select status, count(*)
|
||||
if self.email_sent:
|
||||
self.set("__status_count", dict(frappe.db.sql("""select status, count(*))
|
||||
from `tabBulk Email` where ref_doctype=%s and ref_docname=%s
|
||||
group by status""", (self.doc.doctype, self.doc.name))) or None
|
||||
group by status""", (self.doctype, self.name))) or None
|
||||
|
||||
def test_send(self, doctype="Lead"):
|
||||
self.recipients = self.doc.test_email_id.split(",")
|
||||
self.recipients = self.test_email_id.split(",")
|
||||
self.send_to_doctype = "Lead"
|
||||
self.send_bulk()
|
||||
msgprint("{send} {email}".format**{
|
||||
"send": _("Scheduled to send to"),
|
||||
"email": self.doc.test_email_id
|
||||
"email": self.test_email_id
|
||||
})
|
||||
|
||||
def send_emails(self):
|
||||
"""send emails to leads and customers"""
|
||||
if self.doc.email_sent:
|
||||
if self.email_sent:
|
||||
throw(_("Newsletter has already been sent"))
|
||||
|
||||
self.recipients = self.get_recipients()
|
||||
@@ -44,23 +44,23 @@ class Newsletter(Document):
|
||||
|
||||
def get_recipients(self):
|
||||
self.email_field = None
|
||||
if self.doc.send_to_type=="Contact":
|
||||
if self.send_to_type=="Contact":
|
||||
self.send_to_doctype = "Contact"
|
||||
if self.doc.contact_type == "Customer":
|
||||
if self.contact_type == "Customer":
|
||||
return frappe.db.sql_list("""select email_id from tabContact
|
||||
where ifnull(email_id, '') != '' and ifnull(customer, '') != ''""")
|
||||
|
||||
elif self.doc.contact_type == "Supplier":
|
||||
elif self.contact_type == "Supplier":
|
||||
return frappe.db.sql_list("""select email_id from tabContact
|
||||
where ifnull(email_id, '') != '' and ifnull(supplier, '') != ''""")
|
||||
|
||||
elif self.doc.send_to_type=="Lead":
|
||||
elif self.send_to_type=="Lead":
|
||||
self.send_to_doctype = "Lead"
|
||||
conditions = []
|
||||
if self.doc.lead_source and self.doc.lead_source != "All":
|
||||
conditions.append(" and source='%s'" % self.doc.lead_source.replace("'", "\'"))
|
||||
if self.doc.lead_status and self.doc.lead_status != "All":
|
||||
conditions.append(" and status='%s'" % self.doc.lead_status.replace("'", "\'"))
|
||||
if self.lead_source and self.lead_source != "All":
|
||||
conditions.append(" and source='%s'" % self.lead_source.replace("'", "\'"))
|
||||
if self.lead_status and self.lead_status != "All":
|
||||
conditions.append(" and status='%s'" % self.lead_status.replace("'", "\'"))
|
||||
|
||||
if conditions:
|
||||
conditions = "".join(conditions)
|
||||
@@ -68,7 +68,7 @@ class Newsletter(Document):
|
||||
return frappe.db.sql_list("""select email_id from tabLead
|
||||
where ifnull(email_id, '') != '' %s""" % (conditions or ""))
|
||||
|
||||
elif self.doc.send_to_type=="Employee":
|
||||
elif self.send_to_type=="Employee":
|
||||
self.send_to_doctype = "Employee"
|
||||
self.email_field = "company_email"
|
||||
|
||||
@@ -76,8 +76,8 @@ class Newsletter(Document):
|
||||
if(ifnull(company_email, '')!='', company_email, personal_email) as email_id
|
||||
from `tabEmployee` where status='Active'""")
|
||||
|
||||
elif self.doc.email_list:
|
||||
email_list = [cstr(email).strip() for email in self.doc.email_list.split(",")]
|
||||
elif self.email_list:
|
||||
email_list = [cstr(email).strip() for email in self.email_list.split(",")]
|
||||
for email in email_list:
|
||||
create_lead(email)
|
||||
|
||||
@@ -87,7 +87,7 @@ class Newsletter(Document):
|
||||
def send_bulk(self):
|
||||
self.validate_send()
|
||||
|
||||
sender = self.doc.send_from or frappe.utils.get_formatted_email(self.doc.owner)
|
||||
sender = self.send_from or frappe.utils.get_formatted_email(self.owner)
|
||||
|
||||
from frappe.utils.email_lib.bulk import send
|
||||
|
||||
@@ -95,15 +95,15 @@ class Newsletter(Document):
|
||||
frappe.db.auto_commit_on_many_writes = True
|
||||
|
||||
send(recipients = self.recipients, sender = sender,
|
||||
subject = self.doc.subject, message = self.doc.message,
|
||||
subject = self.subject, message = self.message,
|
||||
doctype = self.send_to_doctype, email_field = self.email_field or "email_id",
|
||||
ref_doctype = self.doc.doctype, ref_docname = self.doc.name)
|
||||
ref_doctype = self.doctype, ref_docname = self.name)
|
||||
|
||||
if not frappe.flags.in_test:
|
||||
frappe.db.auto_commit_on_many_writes = False
|
||||
|
||||
def validate_send(self):
|
||||
if self.doc.fields.get("__islocal"):
|
||||
if self.get("__islocal"):
|
||||
throw(_("Please save the Newsletter before sending."))
|
||||
|
||||
from frappe import conf
|
||||
|
||||
@@ -14,7 +14,7 @@ class TestNewsletter(unittest.TestCase):
|
||||
|
||||
def test_get_recipients_lead_by_status(self):
|
||||
w = frappe.bean(test_records[0])
|
||||
w.doc.lead_status="Converted"
|
||||
w.lead_status="Converted"
|
||||
w.insert()
|
||||
self.assertTrue("test_lead3@example.com" in w.controller.get_recipients())
|
||||
|
||||
@@ -25,7 +25,7 @@ class TestNewsletter(unittest.TestCase):
|
||||
|
||||
def test_get_recipients_contact_supplier(self):
|
||||
w = frappe.bean(test_records[1])
|
||||
w.doc.contact_type="Supplier"
|
||||
w.contact_type="Supplier"
|
||||
w.insert()
|
||||
self.assertTrue("test_contact_supplier@example.com" in w.controller.get_recipients())
|
||||
|
||||
|
||||
@@ -14,20 +14,20 @@ class SupportEmailSettings(Document):
|
||||
"""
|
||||
Checks support ticket email settings
|
||||
"""
|
||||
if self.doc.sync_support_mails and self.doc.mail_server:
|
||||
if self.sync_support_mails and self.mail_server:
|
||||
from frappe.utils.email_lib.receive import POP3Mailbox
|
||||
import _socket, poplib
|
||||
|
||||
inc_email = frappe.get_doc('Incoming Email Settings')
|
||||
# inc_email.encode()
|
||||
inc_email.host = self.doc.mail_server
|
||||
inc_email.use_ssl = self.doc.use_ssl
|
||||
inc_email.host = self.mail_server
|
||||
inc_email.use_ssl = self.use_ssl
|
||||
try:
|
||||
err_msg = 'User Name or Support Password missing. Please enter and try again.'
|
||||
if not (self.doc.mail_login and self.doc.mail_password):
|
||||
if not (self.mail_login and self.mail_password):
|
||||
raise AttributeError, err_msg
|
||||
inc_email.username = self.doc.mail_login
|
||||
inc_email.password = self.doc.mail_password
|
||||
inc_email.username = self.mail_login
|
||||
inc_email.password = self.mail_password
|
||||
except AttributeError, e:
|
||||
frappe.msgprint(err_msg)
|
||||
raise
|
||||
|
||||
@@ -19,7 +19,7 @@ class SupportMailbox(POP3Mailbox):
|
||||
})
|
||||
|
||||
def process_message(self, mail):
|
||||
if mail.from_email == self.email_settings.fields.get('support_email'):
|
||||
if mail.from_email == self.email_settings.get('support_email'):
|
||||
return
|
||||
thread_id = mail.get_thread_id()
|
||||
new_ticket = False
|
||||
@@ -35,8 +35,8 @@ class SupportMailbox(POP3Mailbox):
|
||||
self.send_auto_reply(ticket.doc)
|
||||
|
||||
def send_auto_reply(self, d):
|
||||
signature = self.email_settings.fields.get('support_signature') or ''
|
||||
response = self.email_settings.fields.get('support_autoreply') or ("""
|
||||
signature = self.email_settings.get('support_signature') or ''
|
||||
response = self.email_settings.get('support_autoreply') or ("""
|
||||
A new Ticket has been raised for your query. If you have any additional information, please
|
||||
reply back to this mail.
|
||||
|
||||
@@ -48,7 +48,7 @@ Original Query:
|
||||
|
||||
sendmail(\
|
||||
recipients = [cstr(d.raised_by)], \
|
||||
sender = cstr(self.email_settings.fields.get('support_email')), \
|
||||
sender = cstr(self.email_settings.get('support_email')), \
|
||||
subject = '['+cstr(d.name)+'] ' + cstr(d.subject), \
|
||||
msg = cstr(response))
|
||||
|
||||
@@ -59,9 +59,9 @@ def get_support_mails():
|
||||
def add_support_communication(subject, content, sender, docname=None, mail=None):
|
||||
if docname:
|
||||
ticket = frappe.bean("Support Ticket", docname)
|
||||
ticket.doc.status = 'Open'
|
||||
ticket.status = 'Open'
|
||||
ticket.ignore_permissions = True
|
||||
ticket.doc.save()
|
||||
ticket.save()
|
||||
else:
|
||||
ticket = frappe.bean([decode_dict({
|
||||
"doctype":"Support Ticket",
|
||||
@@ -76,7 +76,7 @@ def add_support_communication(subject, content, sender, docname=None, mail=None)
|
||||
ticket.insert()
|
||||
|
||||
_make(content=content, sender=sender, subject = subject,
|
||||
doctype="Support Ticket", name=ticket.doc.name,
|
||||
doctype="Support Ticket", name=ticket.name,
|
||||
date=mail.date if mail else today(), sent_or_received="Received")
|
||||
|
||||
if mail:
|
||||
|
||||
@@ -13,7 +13,7 @@ class SupportTicket(TransactionBase):
|
||||
return frappe.db.get_value('Support Email Settings',None,'support_email')
|
||||
|
||||
def get_subject(self, comm):
|
||||
return '[' + self.doc.name + '] ' + (comm.subject or 'No Subject Specified')
|
||||
return '[' + self.name + '] ' + (comm.subject or 'No Subject Specified')
|
||||
|
||||
def get_content(self, comm):
|
||||
signature = frappe.db.get_value('Support Email Settings',None,'support_signature')
|
||||
@@ -27,38 +27,38 @@ class SupportTicket(TransactionBase):
|
||||
|
||||
def validate(self):
|
||||
self.update_status()
|
||||
self.set_lead_contact(self.doc.raised_by)
|
||||
self.set_lead_contact(self.raised_by)
|
||||
|
||||
if self.doc.status == "Closed":
|
||||
if self.status == "Closed":
|
||||
from frappe.widgets.form.assign_to import clear
|
||||
clear(self.doc.doctype, self.doc.name)
|
||||
clear(self.doctype, self.name)
|
||||
|
||||
def set_lead_contact(self, email_id):
|
||||
import email.utils
|
||||
email_id = email.utils.parseaddr(email_id)
|
||||
if email_id:
|
||||
if not self.doc.lead:
|
||||
self.doc.lead = frappe.db.get_value("Lead", {"email_id": email_id})
|
||||
if not self.doc.contact:
|
||||
self.doc.contact = frappe.db.get_value("Contact", {"email_id": email_id})
|
||||
if not self.lead:
|
||||
self.lead = frappe.db.get_value("Lead", {"email_id": email_id})
|
||||
if not self.contact:
|
||||
self.contact = frappe.db.get_value("Contact", {"email_id": email_id})
|
||||
|
||||
if not self.doc.company:
|
||||
self.doc.company = frappe.db.get_value("Lead", self.doc.lead, "company") or \
|
||||
if not self.company:
|
||||
self.company = frappe.db.get_value("Lead", self.lead, "company") or \
|
||||
frappe.db.get_default("company")
|
||||
|
||||
def update_status(self):
|
||||
status = frappe.db.get_value("Support Ticket", self.doc.name, "status")
|
||||
if self.doc.status!="Open" and status =="Open" and not self.doc.first_responded_on:
|
||||
self.doc.first_responded_on = now()
|
||||
if self.doc.status=="Closed" and status !="Closed":
|
||||
self.doc.resolution_date = now()
|
||||
if self.doc.status=="Open" and status !="Open":
|
||||
self.doc.resolution_date = ""
|
||||
status = frappe.db.get_value("Support Ticket", self.name, "status")
|
||||
if self.status!="Open" and status =="Open" and not self.first_responded_on:
|
||||
self.first_responded_on = now()
|
||||
if self.status=="Closed" and status !="Closed":
|
||||
self.resolution_date = now()
|
||||
if self.status=="Open" and status !="Open":
|
||||
self.resolution_date = ""
|
||||
|
||||
@frappe.whitelist()
|
||||
def set_status(name, status):
|
||||
st = frappe.bean("Support Ticket", name)
|
||||
st.doc.status = status
|
||||
st.status = status
|
||||
st.save()
|
||||
|
||||
def auto_close_tickets():
|
||||
|
||||
Reference in New Issue
Block a user