brotherton-erpnext/erpnext/patches/v5_0/party_model_patch_fix.py

19 lines
842 B
Python
Raw Normal View History

2015-04-02 12:12:02 +00:00
from __future__ import unicode_literals
import frappe
def execute():
for company in frappe.get_all("Company",
["name", "default_receivable_account", "default_payable_account"]):
if company.default_receivable_account:
frappe.db.sql("""update `tabSales Invoice` invoice set `debit_to`=%(account)s
where company=%(company)s
and not exists (select name from `tabAccount` account where account.name=invoice.debit_to)""",
{"company": company.name, "account": company.default_receivable_account})
if company.default_payable_account:
frappe.db.sql("""update `tabPurchase Invoice` invoice set `credit_to`=%(account)s
where company=%(company)s
and not exists (select name from `tabAccount` account where account.name=invoice.credit_to)""",
{"company": company.name, "account": company.default_payable_account})