Set company address while making invoice from SO, don't show taxes in print if amount is zero, fixed state code

This commit is contained in:
Nabin Hait 2017-07-12 15:45:32 +05:30
parent c1a1e62c0d
commit 0a32b7a6eb
7 changed files with 33 additions and 15 deletions

View File

@ -8,9 +8,10 @@ import datetime
from frappe import _, msgprint, scrub from frappe import _, msgprint, scrub
from frappe.defaults import get_user_permissions from frappe.defaults import get_user_permissions
from frappe.model.utils import get_fetch_values from frappe.model.utils import get_fetch_values
from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, \ from frappe.utils import (add_days, getdate, formatdate, get_first_day, date_diff,
add_years, get_timestamp, nowdate, flt add_years, get_timestamp, nowdate, flt)
from frappe.contacts.doctype.address.address import get_address_display, get_default_address 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 frappe.contacts.doctype.contact.contact import get_contact_details, get_default_contact
from erpnext.exceptions import PartyFrozen, PartyDisabled, InvalidAccountCurrency from erpnext.exceptions import PartyFrozen, PartyDisabled, InvalidAccountCurrency
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year
@ -77,9 +78,11 @@ 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)) out.update(get_fetch_values(doctype, 'shipping_address_name', out.shipping_address_name))
if doctype and doctype in ['Sales Invoice']: if doctype and doctype in ['Sales Invoice']:
out.company_address = get_default_address('Company', company) out.update(get_company_address(company))
if out.company_address:
out.update(get_fetch_values(doctype, 'company_address', out.company_address)) out.update(get_fetch_values(doctype, 'company_address', out.company_address))
def set_contact_details(out, party, party_type): def set_contact_details(out, party, party_type):
out.contact_person = get_default_contact(party_type, party.name) out.contact_person = get_default_contact(party_type, party.name)

View File

@ -559,7 +559,7 @@ class calculate_taxes_and_totals(object):
item_tax[item_code][tax.name] = [tax_rate, tax_amount] item_tax[item_code][tax.name] = [tax_rate, tax_amount]
else: 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]) tax_accounts.append([tax.name, tax.account_head])
return item_tax, tax_accounts return item_tax, tax_accounts

View File

@ -675,7 +675,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
item_tax[item_code][tax.name] = [tax_rate, tax_amount]; item_tax[item_code][tax.name] = [tax_rate, tax_amount];
} else { } 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]); tax_accounts.push([tax.name, tax.account_head]);

View File

@ -6,7 +6,7 @@ states = [
'Assam', 'Assam',
'Bihar', 'Bihar',
'Chandigarh', 'Chandigarh',
'Chattisgarh', 'Chhattisgarh',
'Dadra and Nagar Haveli', 'Dadra and Nagar Haveli',
'Daman and Diu', 'Daman and Diu',
'Delhi', 'Delhi',
@ -45,7 +45,7 @@ state_numbers = {
"Assam": "18", "Assam": "18",
"Bihar": "10", "Bihar": "10",
"Chandigarh": "04", "Chandigarh": "04",
"Chattisgarh": "22", "Chhattisgarh": "22",
"Dadra and Nagar Haveli": "26", "Dadra and Nagar Haveli": "26",
"Daman and Diu": "25", "Daman and Diu": "25",
"Delhi": "07", "Delhi": "07",
@ -65,6 +65,7 @@ state_numbers = {
"Mizoram": "15", "Mizoram": "15",
"Nagaland": "13", "Nagaland": "13",
"Odisha": "21", "Odisha": "21",
"Other Territory": "98",
"Pondicherry": "34", "Pondicherry": "34",
"Punjab": "03", "Punjab": "03",
"Rajasthan": "08", "Rajasthan": "08",
@ -74,5 +75,5 @@ state_numbers = {
"Tripura": "16", "Tripura": "16",
"Uttar Pradesh": "09", "Uttar Pradesh": "09",
"Uttarakhand": "05", "Uttarakhand": "05",
"West Bengal": "19" "West Bengal": "19",
} }

View File

@ -7,11 +7,12 @@ import json
import frappe.utils import frappe.utils
from frappe.utils import cstr, flt, getdate, comma_and, cint from frappe.utils import cstr, flt, getdate, comma_and, cint
from frappe import _ from frappe import _
from frappe.model.utils import get_fetch_values
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty from erpnext.stock.stock_balance import update_bin_qty, get_reserved_qty
from frappe.desk.notifications import clear_doctype_notifications from frappe.desk.notifications import clear_doctype_notifications
from erpnext.controllers.recurring_document import month_map, get_next_date 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 from erpnext.controllers.selling_controller import SellingController
form_grid_templates = { form_grid_templates = {
@ -504,6 +505,11 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
target.run_method("set_missing_values") target.run_method("set_missing_values")
target.run_method("calculate_taxes_and_totals") 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): def update_item(source, target, source_parent):
target.amount = flt(source.amount) - flt(source.billed_amt) target.amount = flt(source.amount) - flt(source.billed_amt)
target.base_amount = target.amount * flt(source_parent.conversion_rate) target.base_amount = target.amount * flt(source_parent.conversion_rate)

View File

@ -8,10 +8,12 @@ from frappe.utils import flt, cint
from frappe import msgprint, _ from frappe import msgprint, _
import frappe.defaults import frappe.defaults
from frappe.model.utils import get_fetch_values
from frappe.model.mapper import get_mapped_doc from frappe.model.mapper import get_mapped_doc
from erpnext.controllers.selling_controller import SellingController from erpnext.controllers.selling_controller import SellingController
from frappe.desk.notifications import clear_doctype_notifications from frappe.desk.notifications import clear_doctype_notifications
from erpnext.stock.doctype.batch.batch import set_batch_nos from erpnext.stock.doctype.batch.batch import set_batch_nos
from frappe.contacts.doctype.address.address import get_company_address
form_grid_templates = { form_grid_templates = {
"items": "templates/form_grid/item_grid.html" "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): def make_sales_invoice(source_name, target_doc=None):
invoiced_qty_map = get_invoiced_qty_map(source_name) 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.is_pos = 0
target.ignore_pricing_rule = 1 target.ignore_pricing_rule = 1
target.run_method("set_missing_values") target.run_method("set_missing_values")
@ -381,6 +383,12 @@ def make_sales_invoice(source_name, target_doc=None):
target.run_method("calculate_taxes_and_totals") 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): def update_item(source_doc, target_doc, source_parent):
target_doc.qty = source_doc.qty - invoiced_qty_map.get(source_doc.name, 0) 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 "add_if_empty": True
} }
}, target_doc, update_accounts) }, target_doc, set_missing_values)
return doc return doc

View File

@ -17,7 +17,7 @@
{{ render_discount_amount(doc) }} {{ render_discount_amount(doc) }}
{%- endif -%} {%- endif -%}
{%- for charge in data -%} {%- for charge in data -%}
{%- if not charge.included_in_print_rate -%} {%- if charge.tax_amount and not charge.included_in_print_rate -%}
<div class="row"> <div class="row">
<div class="col-xs-5 {%- if not doc._align_labels_left %} text-right{%- endif -%}"> <div class="col-xs-5 {%- if not doc._align_labels_left %} text-right{%- endif -%}">
<label>{{ charge.get_formatted("description") }}</label></div> <label>{{ charge.get_formatted("description") }}</label></div>