2014-12-23 12:35:13 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
|
|
|
import frappe
|
2015-01-02 07:16:49 +00:00
|
|
|
from frappe.utils import money_in_words
|
2014-12-23 12:35:13 +00:00
|
|
|
|
|
|
|
def execute():
|
2015-01-02 07:16:49 +00:00
|
|
|
company_currency = dict(frappe.db.sql("select name, default_currency from `tabCompany`"))
|
|
|
|
bank_or_cash_accounts = frappe.db.sql_list("""select name from `tabAccount`
|
|
|
|
where account_type in ('Bank', 'Cash') and docstatus < 2""")
|
|
|
|
|
|
|
|
for je in frappe.db.sql_list("""select name from `tabJournal Entry` where docstatus < 2"""):
|
|
|
|
total_amount = 0
|
|
|
|
total_amount_in_words = ""
|
|
|
|
|
|
|
|
je_doc = frappe.get_doc('Journal Entry', je)
|
|
|
|
for d in je_doc.get("accounts"):
|
|
|
|
if (d.party_type and d.party) or d.account in bank_or_cash_accounts:
|
|
|
|
total_amount = d.debit or d.credit
|
|
|
|
if total_amount:
|
|
|
|
total_amount_in_words = money_in_words(total_amount, company_currency.get(je_doc.company))
|
|
|
|
|
|
|
|
if total_amount:
|
|
|
|
frappe.db.sql("""update `tabJournal Entry` set total_amount=%s, total_amount_in_words=%s
|
|
|
|
where name = %s""", (total_amount, total_amount_in_words, je))
|