def rename_docs():
	_log = []
	def log(msg):
		_log.append(msg)
		print msg

	commit = False
	docs_to_rename = get_docs_to_rename()
	for doctype, list_of_names in docs_to_rename.items():
		naming_series_field = frappe.get_meta(doctype).get_field("naming_series")
		default_series = naming_series_field.default or filter(None, (naming_series_field.options or "").split("\n"))[0]

		print
		print "Rename", doctype, list_of_names, "using series", default_series
		confirm = raw_input("do it? (yes / anything else): ")

		if confirm == "yes":
			commit = True
			for name in list_of_names:
				fixed_name = _rename_doc(doctype, name, default_series)
				log("Renamed {doctype} {name} --> {fixed_name}".format(doctype=doctype, name=name, fixed_name=fixed_name))

	if commit:
		content = """These documents have been renamed in your ERPNext instance: {site}\n\n{_log}""".format(site=frappe.local.site, _log="\n".join(_log))

		print content

		frappe.db.commit()

		sendmail_to_system_managers("[Important] [ERPNext] Renamed Documents via Patch", content)
Example #2
0
def execute():
	wrong_records = []
	for dt in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice", 
		"Purchase Order", "Purchase Receipt", "Purchase Invoice"):
			records = frappe.db.sql_list("""select name from `tab{0}` 
				where apply_discount_on = 'Net Total' and ifnull(discount_amount, 0) != 0
				and modified >= '2015-02-17' and docstatus=1""".format(dt))
		
			if records:
				records = [get_link_to_form(dt, d) for d in records]
				wrong_records.append([dt, records])
				
	if wrong_records:
		content = """Dear System Manager,

Due to an error related to Discount Amount on Net Total, tax calculation might be wrong in the following records. We did not fix the tax amount automatically because it can corrupt the entries, so we request you to check these records and amend if you found the calculation wrong.

Please check following Entries:

%s


Regards,

Administrator""" % "\n".join([(d[0] + ": " + ", ".join(d[1])) for d in wrong_records])
		try:
			sendmail_to_system_managers("[Important] [dokos] Tax calculation might be wrong, please check.", content)
		except:
			pass
		
		print("="*50)
		print(content)
		print("="*50)
def execute():
	wrong_records = []
	for dt in ("Quotation", "Sales Order", "Delivery Note", "Sales Invoice", 
		"Purchase Order", "Purchase Receipt", "Purchase Invoice"):
			records = frappe.db.sql_list("""select name from `tab{0}` 
				where apply_discount_on = 'Net Total' and ifnull(discount_amount, 0) != 0
				and modified >= '2015-02-17' and docstatus=1""".format(dt))
		
			if records:
				records = [get_link_to_form(dt, d) for d in records]
				wrong_records.append([dt, records])
				
	if wrong_records:
		content = """Dear System Manager,

Due to an error related to Discount Amount on Net Total, tax calculation might be wrong in the following records. We did not fix the tax amount automatically because it can corrupt the entries, so we request you to check these records and amend if you found the calculation wrong.

Please check following Entries:

%s


Regards,

Administrator""" % "\n".join([(d[0] + ": " + ", ".join(d[1])) for d in wrong_records])
		try:
			sendmail_to_system_managers("[Important] [ERPNext] Tax calculation might be wrong, please check.", content)
		except:
			pass
		
		print("="*50)
		print(content)
		print("="*50)
Example #4
0
def send_mail(deferred_process):
	title = _("Error while processing deferred accounting for {0}").format(deferred_process)
	link = get_link_to_form("Process Deferred Accounting", deferred_process)
	content = _("Deferred accounting failed for some invoices:") + "\n"
	content += _(
		"Please check Process Deferred Accounting {0} and submit manually after resolving errors."
	).format(link)
	sendmail_to_system_managers(title, content)
def send_mail(deferred_process):
	title = _("Error while processing deferred accounting for {0}".format(deferred_process))
	content = _("""
		Deferred accounting failed for some invoices:
		Please check Process Deferred Accounting {0}
		and submit manually after resolving errors
	""").format(get_link_to_form('Process Deferred Accounting', deferred_process))
	sendmail_to_system_managers(title, content)
def make_gl_entries(doc, credit_account, debit_account, against, amount,
                    base_amount, posting_date, project, account_currency,
                    cost_center, item):
    # GL Entry for crediting the amount in the deferred expense
    from erpnext.accounts.general_ledger import make_gl_entries

    if amount == 0: return

    gl_entries = []
    gl_entries.append(
        doc.get_gl_dict(
            {
                "account": credit_account,
                "against": against,
                "credit": base_amount,
                "credit_in_account_currency": amount,
                "cost_center": cost_center,
                "voucher_detail_no": item.name,
                'posting_date': posting_date,
                'project': project
            },
            account_currency,
            item=item))
    # GL Entry to debit the amount from the expense
    gl_entries.append(
        doc.get_gl_dict(
            {
                "account": debit_account,
                "against": against,
                "debit": base_amount,
                "debit_in_account_currency": amount,
                "cost_center": cost_center,
                "voucher_detail_no": item.name,
                'posting_date': posting_date,
                'project': project
            },
            account_currency,
            item=item))

    if gl_entries:
        try:
            make_gl_entries(gl_entries,
                            cancel=(doc.docstatus == 2),
                            merge_entries=True)
            frappe.db.commit()
        except:
            frappe.db.rollback()
            title = _(
                "Error while processing deferred accounting for {0}").format(
                    doc.name)
            traceback = frappe.get_traceback()
            frappe.log_error(message=traceback, title=title)
            sendmail_to_system_managers(title, traceback)
Example #7
0
def notify_failure(log):
	try:
		content = """
			Dear System Manager,
			Razorpay webhook for creating renewing membership subscription failed due to some reason.
			Please check the following error log linked below
			Error Log: {0}
			Regards, Administrator
		""".format(get_link_to_form("Error Log", log.name))

		sendmail_to_system_managers("[Important] [ERPNext] Razorpay membership webhook failed , please check.", content)
	except:
		pass
Example #8
0
def notify_failure(log):
	try:
		content = '''
			Dear System Manager,
			Razorpay webhook for creating donation failed due to some reason.
			Please check the error log linked below
			Error Log: {0}
			Regards, Administrator
		'''.format(get_link_to_form('Error Log', log.name))

		sendmail_to_system_managers(_('[Important] [ERPNext] Razorpay donation webhook failed, please check.'), content)
	except Exception:
		pass
Example #9
0
def notify_errors(exceptions_list):
	subject = _("[Important] [ERPV] Auto Reorder Errors")
	content = _("Dear System Manager,") + "<br>" + _("An error occured for certain Items while creating Material Requests based on Re-order level. \
		Please rectify these issues :") + "<br>"

	for exception in exceptions_list:
		exception = json.loads(exception)
		error_message = """<div class='small text-muted'>{0}</div><br>""".format(_(exception.get("message")))
		content += error_message

	content += _("Regards,") + "<br>" + _("Administrator")

	from frappe.email import sendmail_to_system_managers
	sendmail_to_system_managers(subject, content)
def notify_errors(exceptions_list):
	subject = "[Important] [ERPNext] Auto Reorder Errors"
	content = """Dear System Manager,
An error occured for certain Items while creating Material Requests based on Re-order level.
Please rectify these issues:
---
<pre>
%s
</pre>
---
Regards,
Administrator""" % ("\n\n".join(exceptions_list),)

	from frappe.email import sendmail_to_system_managers
	sendmail_to_system_managers(subject, content)
Example #11
0
def notify_errors(exceptions_list):
	subject = "[Important] [ERPNext] Auto Reorder Errors"
	content = """Dear System Manager,

An error occured for certain Items while creating Material Requests based on Re-order level.

Please rectify these issues:
---
<pre>
%s
</pre>
---
Regards,
Administrator""" % ("\n\n".join(exceptions_list),)

	from frappe.email import sendmail_to_system_managers
	sendmail_to_system_managers(subject, content)
Example #12
0
def make_gl_entries(doc, credit_account, debit_account, against,
	amount, base_amount, posting_date, project, account_currency, cost_center, voucher_detail_no):
	# GL Entry for crediting the amount in the deferred expense
	from erpnext.accounts.general_ledger import make_gl_entries

	gl_entries = []
	gl_entries.append(
		doc.get_gl_dict({
			"account": credit_account,
			"against": against,
			"credit": base_amount,
			"credit_in_account_currency": amount,
			"cost_center": cost_center,
			"voucher_detail_no": voucher_detail_no,
			'posting_date': posting_date,
			'project': project
		}, account_currency)
	)
	# GL Entry to debit the amount from the expense
	gl_entries.append(
		doc.get_gl_dict({
			"account": debit_account,
			"against": against,
			"debit": base_amount,
			"debit_in_account_currency": amount,
			"cost_center": cost_center,
			"voucher_detail_no": voucher_detail_no,
			'posting_date': posting_date,
			'project': project
		}, account_currency)
	)

	if gl_entries:
		try:
			make_gl_entries(gl_entries, cancel=(doc.docstatus == 2), merge_entries=True)
			frappe.db.commit()
		except:
			frappe.db.rollback()
			title = _("Error while processing deferred accounting for {0}").format(doc.name)
			traceback = frappe.get_traceback()
			frappe.log_error(message=traceback , title=title)
			sendmail_to_system_managers(title, traceback)
def send_gst_update_email():
	message = """Hello,

<p>ERPNext is now GST Ready!</p>

<p>To start making GST Invoices from 1st of July, you just need to create new Tax Accounts,
Templates and update your Customer's and Supplier's GST Numbers.</p>

<p>Please refer {gst_document_link} to know more about how to setup and implement GST in ERPNext.</p>

<p>Please contact us at [email protected], if you have any questions.</p>

<p>Thanks,</p>
ERPNext Team.
	""".format(gst_document_link="<a href='http://frappe.github.io/erpnext/user/manual/en/regional/india/'> ERPNext GST Document </a>")

	try:
		sendmail_to_system_managers("[Important] ERPNext GST updates", message)
	except Exception as e:
		pass
Example #14
0
def rename_docs():
    _log = []

    def log(msg):
        _log.append(msg)
        print msg

    commit = False
    docs_to_rename = get_docs_to_rename()
    for doctype, list_of_names in docs_to_rename.items():
        naming_series_field = frappe.get_meta(doctype).get_field(
            "naming_series")
        default_series = naming_series_field.default or filter(
            None, (naming_series_field.options or "").split("\n"))[0]

        print
        print "Rename", doctype, list_of_names, "using series", default_series
        confirm = raw_input("do it? (yes / anything else): ")

        if confirm == "yes":
            commit = True
            for name in list_of_names:
                fixed_name = _rename_doc(doctype, name, default_series)
                log("Renamed {doctype} {name} --> {fixed_name}".format(
                    doctype=doctype, name=name, fixed_name=fixed_name))

    if commit:
        content = """These documents have been renamed in your letzERP instance: {site}\n\n{_log}""".format(
            site=frappe.local.site, _log="\n".join(_log))

        print content

        frappe.db.commit()

        sendmail_to_system_managers(
            "[Important] [letzERP] Renamed Documents via Patch", content)
Example #15
0
    def make_gl_entries_for_rebate(self, si_list):

        default_currency = frappe.get_value('Company', self.company,
                                            'default_currency')
        cost_center = self.cost_center or frappe.get_cached_value(
            'Company', self.company, "cost_center")
        date_format = frappe.db.get_single_value('System Settings',
                                                 'date_format')
        jv_main = {
            "company":
            self.company,
            "voucher_type":
            "Journal Entry",
            "is_opening":
            "No",
            "remark":
            " Customer rebate paid against period {from_date} to {to_date}.".
            format(from_date=formatdate(self.from_date, date_format),
                   to_date=formatdate(self.to_date, date_format)) +
            "\n List of updated sales invoices are:\n" + si_list,
            "title":
            "Rebate from {from_date} to {to_date}".format(
                from_date=formatdate(self.from_date, date_format),
                to_date=formatdate(self.to_date, date_format)),
            "total_debit":
            self.total_discount,
            "total_credit":
            self.total_discount,
            "posting_date":
            getdate(nowdate()),
            "account_currency":
            default_currency,
        }

        credit_account = self.default_receivable_account or frappe.get_cached_value(
            'Company', self.company, "default_receivable_account")
        debit_account = self.expense_account
        try:
            je = frappe.new_doc("Journal Entry")
            je.update(jv_main)
            for row in self.customer_rebate_detail:
                credit_party_balance = get_balance_on(party=row.customer,
                                                      party_type="Customer")
                credit_account_balance = get_balance_on(
                    account=credit_account, cost_center=cost_center)
                jv_credit_row = {
                    "account": credit_account,
                    "account_type": 'Receivable',
                    "account_balance": credit_account_balance,
                    "is_advance": "No",
                    "party_type": "Customer",
                    "party": row.customer,
                    "against_account": self.expense_account,
                    "credit": row.rebate_amount,
                    "credit_in_account_currency": row.rebate_amount,
                    "party_balance": credit_party_balance,
                }
                debit_account_balance = get_balance_on(
                    account=debit_account, cost_center=self.cost_center)
                jv_debit_row = {
                    "account": debit_account,
                    "account_type": 'Expense Account',
                    "account_balance": debit_account_balance,
                    "is_advance": "No",
                    "party": "",
                    "party_type": "",
                    "debit": row.rebate_amount,
                    "debit_in_account_currency": row.rebate_amount,
                    "cost_center": cost_center,
                }
                je.append("accounts", jv_credit_row)
                je.append("accounts", jv_debit_row)
            je.save()
            je.submit()
            frappe.db.commit()
            return je.name
        except:
            frappe.db.rollback()
            title = _("Error while processing customer rebate for {0}").format(
                self.name)
            traceback = frappe.get_traceback()
            frappe.log_error(message=traceback, title=title)
            sendmail_to_system_managers(title, traceback)
            return False