From 1279f1d4303894837ebbb1ab5a8db4aa6027b631 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Aug 2014 13:04:50 +0530 Subject: [PATCH 1/2] Fixes for customer / supplier renaming --- erpnext/accounts/utils.py | 34 +++++++++++-------- erpnext/buying/doctype/supplier/supplier.py | 2 +- erpnext/selling/doctype/customer/customer.py | 2 +- .../doctype/customer_issue/customer_issue.py | 6 +--- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 25a8adfca1..5062578b61 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -325,32 +325,38 @@ def get_actual_expense(args): and fiscal_year='%(fiscal_year)s' and company='%(company)s' %(condition)s """ % (args))[0][0] -def rename_account_for(dt, olddn, newdn, merge, company): - old_account = get_account_for(dt, olddn) - if old_account: - new_account = None - if not merge: - if old_account == add_abbr_if_missing(olddn, company): - new_account = frappe.rename_doc("Account", old_account, newdn) - else: - existing_new_account = get_account_for(dt, newdn) - new_account = frappe.rename_doc("Account", old_account, - existing_new_account or newdn, merge=True if existing_new_account else False) +def rename_account_for(dt, olddn, newdn, merge, company=None): + if not company: + companies = [d[0] for d in frappe.db.sql("select name from tabCompany")] + else: + companies = [company] - frappe.db.set_value("Account", new_account or old_account, "master_name", newdn) + for company in companies: + old_account = get_account_for(dt, olddn, company) + if old_account: + new_account = None + if not merge: + if old_account == add_abbr_if_missing(olddn, company): + new_account = frappe.rename_doc("Account", old_account, newdn) + else: + existing_new_account = get_account_for(dt, newdn, company) + new_account = frappe.rename_doc("Account", old_account, + existing_new_account or newdn, merge=True if existing_new_account else False) + + frappe.db.set_value("Account", new_account or old_account, "master_name", newdn) def add_abbr_if_missing(dn, company): from erpnext.setup.doctype.company.company import get_name_with_abbr return get_name_with_abbr(dn, company) -def get_account_for(account_for_doctype, account_for): +def get_account_for(account_for_doctype, account_for, company): if account_for_doctype in ["Customer", "Supplier"]: account_for_field = "master_type" elif account_for_doctype == "Warehouse": account_for_field = "account_type" return frappe.db.get_value("Account", {account_for_field: account_for_doctype, - "master_name": account_for}) + "master_name": account_for, "company": company}) def get_currency_precision(currency=None): if not currency: diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py index 6828845690..240762eb2c 100644 --- a/erpnext/buying/doctype/supplier/supplier.py +++ b/erpnext/buying/doctype/supplier/supplier.py @@ -88,7 +88,7 @@ class Supplier(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from erpnext.accounts.utils import rename_account_for - rename_account_for("Supplier", olddn, newdn, merge, self.company) + rename_account_for("Supplier", olddn, newdn, merge) def after_rename(self, olddn, newdn, merge=False): set_field = '' diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py index c065b54dbb..362542e55a 100644 --- a/erpnext/selling/doctype/customer/customer.py +++ b/erpnext/selling/doctype/customer/customer.py @@ -121,7 +121,7 @@ class Customer(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from erpnext.accounts.utils import rename_account_for - rename_account_for("Customer", olddn, newdn, merge, self.company) + rename_account_for("Customer", olddn, newdn, merge) def after_rename(self, olddn, newdn, merge=False): set_field = '' diff --git a/erpnext/support/doctype/customer_issue/customer_issue.py b/erpnext/support/doctype/customer_issue/customer_issue.py index 6f368a8b04..45adb0b8d2 100644 --- a/erpnext/support/doctype/customer_issue/customer_issue.py +++ b/erpnext/support/doctype/customer_issue/customer_issue.py @@ -52,11 +52,7 @@ def make_maintenance_visit(source_name, target_doc=None): target_doc = get_mapped_doc("Customer Issue", source_name, { "Customer Issue": { "doctype": "Maintenance Visit", - "field_map": { - "complaint": "description", - "doctype": "prevdoc_doctype", - "name": "prevdoc_docname" - } + "field_map": {} } }, target_doc) From 4d18b3f96d7684b1c6bc307b741702f9adf4f0bc Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 4 Aug 2014 17:01:01 +0530 Subject: [PATCH 2/2] Fixes for standard print formats --- erpnext/templates/print_formats/includes/item_grid.html | 4 ++-- erpnext/templates/print_formats/includes/taxes.html | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/erpnext/templates/print_formats/includes/item_grid.html b/erpnext/templates/print_formats/includes/item_grid.html index 3cc3034f3a..d6ab347c92 100644 --- a/erpnext/templates/print_formats/includes/item_grid.html +++ b/erpnext/templates/print_formats/includes/item_grid.html @@ -22,12 +22,12 @@ {%- endif %} {% if (not row.meta.is_print_hide("item_name") and (row.meta.is_print_hide("item_code") or row.item_code != row.item_name)) -%} -
{{ row.item_name }}
+
{{ row.get_formatted("item_name",as_html=True) }}
{%- endif %} {% if (not row.meta.is_print_hide("description") and row.description and ((row.meta.is_print_hide("item_code") and row.meta.is_print_hide("item_name")) or not (row.item_code == row.item_name == row.description))) -%} -

{{ row.description }}

+

{{ row.get_formatted("description", as_html=True) }}

{%- endif %} {%- for field in visible_columns -%} {%- if (field.fieldname not in std_fields) and diff --git a/erpnext/templates/print_formats/includes/taxes.html b/erpnext/templates/print_formats/includes/taxes.html index 5d9aaace7f..50f9d86a38 100644 --- a/erpnext/templates/print_formats/includes/taxes.html +++ b/erpnext/templates/print_formats/includes/taxes.html @@ -5,10 +5,10 @@ {%- if not charge.included_in_print_rate -%}
-
+
{{ frappe.format_value(charge.tax_amount / doc.conversion_rate, - table_meta.get_field("tax_amount"), doc) }} + table_meta.get_field("tax_amount"), doc, currency=doc.currency) }}
{%- endif -%}