From 0a32b7a6eb78c94f4aa69a83423cc239bf5ad08f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 12 Jul 2017 15:45:32 +0530 Subject: [PATCH] Set company address while making invoice from SO, don't show taxes in print if amount is zero, fixed state code --- erpnext/accounts/party.py | 13 ++++++++----- erpnext/controllers/taxes_and_totals.py | 2 +- erpnext/public/js/controllers/taxes_and_totals.js | 2 +- erpnext/regional/india/__init__.py | 7 ++++--- erpnext/selling/doctype/sales_order/sales_order.py | 10 ++++++++-- .../stock/doctype/delivery_note/delivery_note.py | 12 ++++++++++-- erpnext/templates/print_formats/includes/taxes.html | 2 +- 7 files changed, 33 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py index 355803bd55..ba0f0d3c4a 100644 --- a/erpnext/accounts/party.py +++ b/erpnext/accounts/party.py @@ -8,9 +8,10 @@ import datetime from frappe import _, msgprint, scrub from frappe.defaults import get_user_permissions from frappe.model.utils import get_fetch_values -from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, \ - add_years, get_timestamp, nowdate, flt -from frappe.contacts.doctype.address.address import get_address_display, get_default_address +from frappe.utils import (add_days, getdate, formatdate, get_first_day, date_diff, + add_years, get_timestamp, nowdate, flt) +from frappe.contacts.doctype.address.address import (get_address_display, + get_default_address, get_company_address) from frappe.contacts.doctype.contact.contact import get_contact_details, get_default_contact from erpnext.exceptions import PartyFrozen, PartyDisabled, InvalidAccountCurrency from erpnext.accounts.utils import get_fiscal_year @@ -77,8 +78,10 @@ def set_address_details(out, party, party_type, doctype=None, company=None): out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name)) if doctype and doctype in ['Sales Invoice']: - out.company_address = get_default_address('Company', company) - out.update(get_fetch_values(doctype, 'company_address', out.company_address)) + out.update(get_company_address(company)) + if out.company_address: + out.update(get_fetch_values(doctype, 'company_address', out.company_address)) + def set_contact_details(out, party, party_type): out.contact_person = get_default_contact(party_type, party.name) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index 72785da563..8b96152bb2 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -559,7 +559,7 @@ class calculate_taxes_and_totals(object): item_tax[item_code][tax.name] = [tax_rate, tax_amount] else: - item_tax[item_code][tax.name] = [cstr(flt(tax_data, tax_rate_precision)) + "%", ""] + item_tax[item_code][tax.name] = [cstr(flt(tax_data, tax_rate_precision)) + "%", "0.00"] tax_accounts.append([tax.name, tax.account_head]) return item_tax, tax_accounts diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index e09925d059..837097b490 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -675,7 +675,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({ item_tax[item_code][tax.name] = [tax_rate, tax_amount]; } else { - item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", ""]; + item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", "0.00"]; } }); tax_accounts.push([tax.name, tax.account_head]); diff --git a/erpnext/regional/india/__init__.py b/erpnext/regional/india/__init__.py index 3c0dd07e59..de5f1ab7ab 100644 --- a/erpnext/regional/india/__init__.py +++ b/erpnext/regional/india/__init__.py @@ -6,7 +6,7 @@ states = [ 'Assam', 'Bihar', 'Chandigarh', - 'Chattisgarh', + 'Chhattisgarh', 'Dadra and Nagar Haveli', 'Daman and Diu', 'Delhi', @@ -45,7 +45,7 @@ state_numbers = { "Assam": "18", "Bihar": "10", "Chandigarh": "04", - "Chattisgarh": "22", + "Chhattisgarh": "22", "Dadra and Nagar Haveli": "26", "Daman and Diu": "25", "Delhi": "07", @@ -65,6 +65,7 @@ state_numbers = { "Mizoram": "15", "Nagaland": "13", "Odisha": "21", + "Other Territory": "98", "Pondicherry": "34", "Punjab": "03", "Rajasthan": "08", @@ -74,5 +75,5 @@ state_numbers = { "Tripura": "16", "Uttar Pradesh": "09", "Uttarakhand": "05", - "West Bengal": "19" + "West Bengal": "19", } \ No newline at end of file diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index ccaa07c194..2df52ac649 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -7,11 +7,12 @@ import json import frappe.utils from frappe.utils import cstr, flt, getdate, comma_and, cint from frappe import _ +from frappe.model.utils import get_fetch_values from frappe.model.mapper import get_mapped_doc from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty from frappe.desk.notifications import clear_doctype_notifications from erpnext.controllers.recurring_document import month_map, get_next_date - +from frappe.contacts.doctype.address.address import get_company_address from erpnext.controllers.selling_controller import SellingController form_grid_templates = { @@ -503,7 +504,12 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False): target.flags.ignore_permissions = True target.run_method("set_missing_values") target.run_method("calculate_taxes_and_totals") - + + # set company address + target.update(get_company_address(target.company)) + if target.company_address: + target.update(get_fetch_values("Sales Invoice", 'company_address', target.company_address)) + def update_item(source, target, source_parent): target.amount = flt(source.amount) - flt(source.billed_amt) target.base_amount = target.amount * flt(source_parent.conversion_rate) diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.py b/erpnext/stock/doctype/delivery_note/delivery_note.py index 7523409950..3bf0384e7d 100644 --- a/erpnext/stock/doctype/delivery_note/delivery_note.py +++ b/erpnext/stock/doctype/delivery_note/delivery_note.py @@ -8,10 +8,12 @@ from frappe.utils import flt, cint from frappe import msgprint, _ import frappe.defaults +from frappe.model.utils import get_fetch_values from frappe.model.mapper import get_mapped_doc from erpnext.controllers.selling_controller import SellingController from frappe.desk.notifications import clear_doctype_notifications from erpnext.stock.doctype.batch.batch import set_batch_nos +from frappe.contacts.doctype.address.address import get_company_address form_grid_templates = { "items": "templates/form_grid/item_grid.html" @@ -371,7 +373,7 @@ def get_invoiced_qty_map(delivery_note): def make_sales_invoice(source_name, target_doc=None): invoiced_qty_map = get_invoiced_qty_map(source_name) - def update_accounts(source, target): + def set_missing_values(source, target): target.is_pos = 0 target.ignore_pricing_rule = 1 target.run_method("set_missing_values") @@ -380,6 +382,12 @@ def make_sales_invoice(source_name, target_doc=None): frappe.throw(_("All these items have already been invoiced")) target.run_method("calculate_taxes_and_totals") + + # set company address + target.update(get_company_address(target.company)) + if target.company_address: + target.update(get_fetch_values("Sales Invoice", 'company_address', target.company_address)) + def update_item(source_doc, target_doc, source_parent): target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0) @@ -415,7 +423,7 @@ def make_sales_invoice(source_name, target_doc=None): }, "add_if_empty": True } - }, target_doc, update_accounts) + }, target_doc, set_missing_values) return doc diff --git a/erpnext/templates/print_formats/includes/taxes.html b/erpnext/templates/print_formats/includes/taxes.html index b0bd1d4b5b..b180c1c923 100644 --- a/erpnext/templates/print_formats/includes/taxes.html +++ b/erpnext/templates/print_formats/includes/taxes.html @@ -17,7 +17,7 @@ {{ render_discount_amount(doc) }} {%- endif -%} {%- for charge in data -%} - {%- if not charge.included_in_print_rate -%} + {%- if charge.tax_amount and not charge.included_in_print_rate -%}