Merge pull request #2842 from nabinhait/foreign_currency_calc

Foreign currency calc
This commit is contained in:
Nabin Hait 2015-02-24 12:56:57 +05:30
commit 20256fa716
66 changed files with 2458 additions and 1651 deletions

View File

@ -3,7 +3,6 @@
frappe.provide("erpnext.accounts");
{% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
onload: function() {

View File

@ -263,6 +263,16 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"description": "Will be calculated automatically when you enter the details",
"fieldname": "base_net_total",
@ -280,6 +290,17 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -373,35 +394,10 @@
"read_only": 1
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Invoice.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break8",
"fieldname": "column_break_40",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"permlevel": 0,
"print_hide": 1,
"read_only": 0,
"width": "50%"
"precision": ""
},
{
"fieldname": "taxes_and_charges_added",
@ -433,6 +429,84 @@
"permlevel": 0,
"precision": ""
},
{
"fieldname": "section_break_44",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "column_break_46",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "base_discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "section_break_49",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Invoice.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break8",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"permlevel": 0,
"print_hide": 1,
"read_only": 0,
"width": "50%"
},
{
"fieldname": "grand_total",
"fieldtype": "Currency",
@ -888,7 +962,7 @@
"icon": "icon-file-text",
"idx": 1,
"is_submittable": 1,
"modified": "2015-02-20 05:16:22.693978",
"modified": "2015-02-23 15:33:28.554922",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",

View File

@ -275,36 +275,36 @@ class PurchaseInvoice(BuyingController):
# tax table gl entries
valuation_tax = {}
for tax in self.get("taxes"):
if tax.category in ("Total", "Valuation and Total") and flt(tax.tax_amount):
if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
gl_entries.append(
self.get_gl_dict({
"account": tax.account_head,
"against": self.credit_to,
"debit": tax.add_deduct_tax == "Add" and tax.tax_amount or 0,
"credit": tax.add_deduct_tax == "Deduct" and tax.tax_amount or 0,
"debit": tax.add_deduct_tax == "Add" and tax.base_tax_amount_after_discount_amount or 0,
"credit": tax.add_deduct_tax == "Deduct" and tax.base_tax_amount_after_discount_amount or 0,
"remarks": self.remarks,
"cost_center": tax.cost_center
})
)
# accumulate valuation tax
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
if auto_accounting_for_stock and not tax.cost_center:
frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
valuation_tax.setdefault(tax.cost_center, 0)
valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
# item gl entries
negative_expense_to_be_booked = 0.0
stock_items = self.get_stock_items()
for item in self.get("items"):
if flt(item.base_amount):
if flt(item.base_net_amount):
gl_entries.append(
self.get_gl_dict({
"account": item.expense_account,
"against": self.credit_to,
"debit": item.base_amount,
"debit": item.base_net_amount,
"remarks": self.remarks,
"cost_center": item.cost_center
})

View File

@ -194,6 +194,58 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_22",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_25",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "accounting",
"fieldtype": "Section Break",
@ -399,7 +451,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.060411",
"modified": "2015-02-23 15:35:32.895515",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice Item",

View File

@ -53,17 +53,13 @@
"read_only": 0
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"description": "If checked, the tax amount will be considered as already included in the Print Rate / Print Amount",
"fieldname": "included_in_print_rate",
"fieldtype": "Check",
"label": "Is this Tax included in Basic Rate?",
"permlevel": 0,
"print_width": "300px",
"read_only": 0,
"reqd": 1,
"width": "300px"
"precision": "",
"report_hide": 1
},
{
"fieldname": "col_break1",
@ -94,6 +90,19 @@
"permlevel": 0,
"read_only": 0
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_width": "300px",
"read_only": 0,
"reqd": 1,
"width": "300px"
},
{
"fieldname": "rate",
"fieldtype": "Float",
@ -105,6 +114,12 @@
"read_only": 0,
"reqd": 0
},
{
"fieldname": "section_break_9",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "tax_amount",
"fieldtype": "Currency",
@ -112,19 +127,65 @@
"label": "Amount",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"options": "currency",
"permlevel": 0,
"read_only": 1,
"reqd": 0
},
{
"fieldname": "tax_amount_after_discount_amount",
"fieldtype": "Currency",
"label": "Tax Amount After Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"oldfieldname": "total",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "column_break_14",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_tax_amount",
"fieldtype": "Currency",
"label": "Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"hidden": 1,
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "base_tax_amount_after_discount_amount",
"fieldtype": "Currency",
"label": "Tax Amount After Discount Amount",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
@ -155,7 +216,7 @@
"hide_heading": 1,
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.581115",
"modified": "2015-02-23 15:01:31.895131",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Taxes and Charges",

View File

@ -3,78 +3,7 @@
{% include "public/js/controllers/accounts.js" %}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
}
// For customizing print
cur_frm.pformat.net_total = function(doc) {
return '';
}
cur_frm.pformat.grand_total = function(doc) {
return '';
}
cur_frm.pformat.in_words = function(doc) {
return '';
}
cur_frm.pformat.taxes= function(doc) {
//function to make row of table
var make_row = function(title, val, bold) {
var bstart = '<b>'; var bend = '</b>';
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
+ '<td style="width:25%;text-align:right;"></td>'
+ '<td style="width:25%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
+ '</tr>';
}
function convert_rate(val) {
var new_val = flt(val)/flt(doc.conversion_rate);
return new_val;
}
function print_hide(fieldname) {
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
return doc_field.print_hide;
}
var cl = doc.taxes || [];
// outer table
var out='<div><table class="noborder" style="width:100%">\
<tr><td style="width: 60%"></td><td>';
// main table
out +='<table class="noborder" style="width:100%">';
if(!print_hide('net_total'))
out += make_row('Net Total', doc.net_total, 1);
// add rows
if(cl.length){
for(var i=0; i<cl.length; i++) {
out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
}
}
// grand total
if(!print_hide('grand_total'))
out += make_row('Grand Total', doc.grand_total, 1);
if(doc.in_words && !print_hide('in_words')) {
out += '</table></td></tr>';
out += '<tr><td colspan = "2">';
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
}
out +='</table></td></tr></table></div>';
return out;
}
cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) {
frappe.ui.form.on("Purchase Taxes and Charges", "add_deduct_tax", function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.category && d.add_deduct_tax) {
@ -85,96 +14,5 @@ cur_frm.cscript.add_deduct_tax = function(doc, cdt, cdn) {
msgprint(__("Cannot deduct when category is for 'Valuation' or 'Valuation and Total'"));
d.add_deduct_tax = '';
}
}
cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.category && d.charge_type) {
msgprint(__("Please select Category first"));
d.charge_type = '';
}
else if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
d.charge_type = '';
}
else if((d.category == 'Valuation' || d.category == 'Valuation and Total') && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for valuation. You can select only 'Total' option for previous row amount or previous row total"));
d.charge_type = '';
}
validated = false;
refresh_field('charge_type', d.name, 'taxes');
cur_frm.cscript.row_id(doc, cdt, cdn);
cur_frm.cscript.rate(doc, cdt, cdn);
cur_frm.cscript.tax_amount(doc, cdt, cdn);
}
cur_frm.cscript.row_id = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.row_id) {
msgprint(__("Please select charge type first"));
d.row_id = '';
}
else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
d.row_id = '';
}
else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
if(d.row_id >= d.idx){
msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
d.row_id = '';
}
}
validated = false;
refresh_field('row_id', d.name, 'taxes');
}
cur_frm.set_query("account_head", "taxes", function(doc) {
return {
query: "erpnext.controllers.queries.tax_account_query",
filters: {
"account_type": ["Tax", "Chargeable", "Expense Account"],
"company": doc.company
}
}
refresh_field('add_deduct_tax', d.name, 'taxes');
});
cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
return {
filters: {
'company': doc.company,
'group_or_ledger': "Ledger"
}
}
}
cur_frm.cscript.rate = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.rate) {
msgprint(__("Please select Charge Type first"));
d.rate = '';
}
validated = false;
refresh_field('rate', d.name, 'taxes');
}
cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.tax_amount) {
msgprint(__("Please select Charge Type first"));
d.tax_amount = '';
}
else if(d.charge_type && d.tax_amount) {
msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
d.tax_amount = '';
}
validated = false;
refresh_field('tax_amount', d.name, 'taxes');
}

View File

@ -2,8 +2,11 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.model.document import Document
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
class PurchaseTaxesandChargesMaster(Document):
pass
def validate(self):
for tax in self.get("taxes"):
validate_taxes_and_charges(tax)
validate_inclusive_tax(tax, self)

View File

@ -5,7 +5,6 @@
cur_frm.pformat.print_heading = 'Invoice';
{% include 'selling/sales_common.js' %};
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
frappe.provide("erpnext.accounts");
erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({

View File

@ -331,6 +331,16 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -348,6 +358,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -431,6 +451,12 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_47",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_total_taxes_and_charges",
"fieldtype": "Currency",
@ -443,7 +469,23 @@
"read_only": 1
},
{
"fieldname": "column_break_45",
"fieldname": "section_break_49",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "column_break_51",
"fieldtype": "Column Break",
"permlevel": 0
},
@ -1202,7 +1244,7 @@
"icon": "icon-file-text",
"idx": 1,
"is_submittable": 1,
"modified": "2015-02-20 05:16:19.256361",
"modified": "2015-02-23 15:53:37.894033",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@ -496,12 +496,12 @@ class SalesInvoice(SellingController):
def make_tax_gl_entries(self, gl_entries):
for tax in self.get("taxes"):
if flt(tax.tax_amount_after_discount_amount):
if flt(tax.base_tax_amount_after_discount_amount):
gl_entries.append(
self.get_gl_dict({
"account": tax.account_head,
"against": self.debit_to,
"credit": flt(tax.tax_amount_after_discount_amount),
"credit": flt(tax.base_tax_amount_after_discount_amount),
"remarks": self.remarks,
"cost_center": tax.cost_center
})
@ -510,12 +510,12 @@ class SalesInvoice(SellingController):
def make_item_gl_entries(self, gl_entries):
# income account gl entries
for item in self.get("items"):
if flt(item.base_amount):
if flt(item.base_net_amount):
gl_entries.append(
self.get_gl_dict({
"account": item.income_account,
"against": self.debit_to,
"credit": item.base_amount,
"credit": item.base_net_amount,
"remarks": self.remarks,
"cost_center": item.cost_center
})

View File

@ -201,6 +201,58 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_21",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_24",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "accounting",
"fieldtype": "Section Break",
@ -439,7 +491,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.862525",
"modified": "2015-02-23 15:55:23.143072",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice Item",

View File

@ -1,5 +1,5 @@
{
"autoname": "hash",
"autoname": "INVTD.######",
"creation": "2013-04-24 11:39:32",
"docstatus": 0,
"doctype": "DocType",
@ -25,24 +25,6 @@
"oldfieldtype": "Data",
"permlevel": 0
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_width": "300px",
"reqd": 1,
"width": "300px"
},
{
"fieldname": "col_break_1",
"fieldtype": "Column Break",
"permlevel": 0,
"width": "50%"
},
{
"fieldname": "account_head",
"fieldtype": "Link",
@ -77,26 +59,22 @@
"reqd": 1
},
{
"fieldname": "tax_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"fieldname": "col_break_1",
"fieldtype": "Column Break",
"permlevel": 0,
"read_only": 1,
"reqd": 0
"width": "50%"
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"oldfieldname": "total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"fieldname": "description",
"fieldtype": "Small Text",
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"permlevel": 0,
"read_only": 1
"print_width": "300px",
"reqd": 1,
"width": "300px"
},
{
"allow_on_submit": 0,
@ -112,11 +90,72 @@
"width": "150px"
},
{
"depends_on": "eval:parent.discount_amount",
"fieldname": "section_break_9",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "tax_amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount",
"options": "currency",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "tax_amount_after_discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"label": "Tax Amount After Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "column_break_13",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_tax_amount",
"fieldtype": "Currency",
"in_list_view": 0,
"label": "Amount (Company Currency)",
"oldfieldname": "tax_amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"read_only": 1,
"reqd": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"oldfieldname": "total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"read_only": 1
},
{
"depends_on": "eval:parent.discount_amount",
"fieldname": "base_tax_amount_after_discount_amount",
"fieldtype": "Currency",
"hidden": 0,
"label": "Tax Amount After Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"read_only": 1
@ -147,7 +186,7 @@
"hide_heading": 1,
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:02.165094",
"modified": "2015-02-23 12:36:02.213508",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Taxes and Charges",

View File

@ -7,168 +7,3 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
if(doc.doctype === "Sales Taxes and Charges Master")
erpnext.add_applicable_territory();
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.set_footnote(frappe.markdown(cur_frm.meta.description));
}
// For customizing print
cur_frm.pformat.net_total = function(doc) {
return '';
}
cur_frm.pformat.discount_amount = function(doc) {
return '';
}
cur_frm.pformat.grand_total = function(doc) {
return '';
}
cur_frm.pformat.rounded_total = function(doc) {
return '';
}
cur_frm.pformat.in_words = function(doc) {
return '';
}
cur_frm.pformat.taxes= function(doc){
//function to make row of table
var make_row = function(title, val, bold){
var bstart = '<b>'; var bend = '</b>';
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
+ '<td style="width:50%;text-align:right;">' + format_currency(val, doc.currency) + '</td>'
+ '</tr>';
}
function convert_rate(val) {
var new_val = flt(val)/flt(doc.conversion_rate);
return new_val;
}
function print_hide(fieldname) {
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
return doc_field.print_hide;
}
out ='';
if (!doc.print_without_amount) {
var cl = doc.taxes || [];
// outer table
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
// main table
out +='<table class="noborder" style="width:100%">';
if(!print_hide('net_total')) {
out += make_row('Net Total', doc.net_total, 1);
}
// add rows
if(cl.length){
for(var i=0;i<cl.length;i++) {
if(convert_rate(cl[i].tax_amount)!=0 && !cl[i].included_in_print_rate)
out += make_row(cl[i].description, convert_rate(cl[i].tax_amount), 0);
}
}
// Discount Amount
if(!print_hide('discount_amount') && doc.discount_amount)
out += make_row('Discount Amount', doc.discount_amount, 0);
// grand total
if(!print_hide('grand_total'))
out += make_row('Grand Total', doc.grand_total, 1);
if(!print_hide('rounded_total'))
out += make_row('Rounded Total', doc.rounded_total, 1);
if(doc.in_words && !print_hide('in_words')) {
out +='</table></td></tr>';
out += '<tr><td colspan = "2">';
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
}
out += '</table></td></tr></table></div>';
}
return out;
}
cur_frm.cscript.charge_type = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(d.idx == 1 && (d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total')) {
msgprint(__("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"));
d.charge_type = '';
}
validated = false;
refresh_field('charge_type', d.name, 'taxes');
cur_frm.cscript.row_id(doc, cdt, cdn);
cur_frm.cscript.rate(doc, cdt, cdn);
cur_frm.cscript.tax_amount(doc, cdt, cdn);
}
cur_frm.cscript.row_id = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.row_id) {
msgprint(__("Please select Charge Type first"));
d.row_id = '';
}
else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
d.row_id = '';
}
else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
if(d.row_id >= d.idx){
msgprint(__("Cannot refer row number greater than or equal to current row number for this Charge type"));
d.row_id = '';
}
}
validated = false;
refresh_field('row_id', d.name, 'taxes');
}
/*---------------------- Get rate if account_head has account_type as TAX or CHARGEABLE-------------------------------------*/
cur_frm.fields_dict['taxes'].grid.get_field("account_head").get_query = function(doc,cdt,cdn) {
return{
query: "erpnext.controllers.queries.tax_account_query",
filters: {
"account_type": ["Tax", "Chargeable", "Income Account"],
"company": doc.company
}
}
}
cur_frm.fields_dict['taxes'].grid.get_field("cost_center").get_query = function(doc) {
return{
'company': doc.company,
'group_or_ledger': "Ledger"
}
}
cur_frm.cscript.rate = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.rate) {
msgprint(__("Please select Charge Type first"));
d.rate = '';
}
validated = false;
refresh_field('rate', d.name, 'taxes');
}
cur_frm.cscript.tax_amount = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
if(!d.charge_type && d.tax_amount) {
msgprint(__("Please select Charge Type first"));
d.tax_amount = '';
}
else if(d.charge_type && d.tax_amount) {
msgprint(__("Cannot directly set amount. For 'Actual' charge type, use the rate field"));
d.tax_amount = '';
}
validated = false;
refresh_field('tax_amount', d.name, 'taxes');
};

View File

@ -3,8 +3,8 @@
from __future__ import unicode_literals
import frappe
from frappe.utils import cint
from frappe.model.document import Document
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
class SalesTaxesandChargesMaster(Document):
def validate(self):
@ -15,3 +15,8 @@ class SalesTaxesandChargesMaster(Document):
# at least one territory
self.validate_table_has_rows("territories")
for tax in self.get("taxes"):
validate_taxes_and_charges(tax)
validate_inclusive_tax(tax, self)

View File

@ -95,7 +95,7 @@ class GrossProfitGenerator(object):
if self.skip_row(row, self.sales_boms):
continue
row.selling_amount = flt(row.base_amount)
row.selling_amount = flt(row.base_net_amount)
sales_boms = self.sales_boms.get(row.parenttype, {}).get(row.name, frappe._dict())
@ -175,7 +175,7 @@ class GrossProfitGenerator(object):
# sorted by posting_date desc, posting_time desc
if item_code in self.non_stock_items:
# average purchasing rate for non-stock items
item_rate = frappe.db.sql("""select sum(base_amount) / sum(qty)
item_rate = frappe.db.sql("""select sum(base_net_amount) / sum(qty)
from `tabPurchase Invoice Item`
where item_code = %s and docstatus=1""", item_code)
@ -211,7 +211,7 @@ class GrossProfitGenerator(object):
si.customer, si.customer_group, si.territory,
item.item_code, item.item_name, item.description, item.warehouse,
item.item_group, item.brand, item.dn_detail, item.delivery_note,
item.qty, item.base_rate, item.base_amount, item.name as "item_row",
item.qty, item.base_net_rate, item.base_net_amount, item.name as "item_row",
sales.sales_person, sales.sales_designation, sales.allocated_amount,
sales.incentives
from `tabSales Invoice` si

View File

@ -28,13 +28,13 @@ def execute(filters=None):
expense_account = d.expense_account or aii_account_map.get(d.company)
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.supplier,
d.supplier_name, d.credit_to, d.project_name, d.company, d.purchase_order,
purchase_receipt, expense_account, d.qty, d.base_rate, d.base_amount]
purchase_receipt, expense_account, d.qty, d.base_net_rate, d.base_net_amount]
for tax in tax_accounts:
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
total_tax = sum(row[last_col:])
row += [total_tax, d.base_amount + total_tax]
row += [total_tax, d.base_net_amount + total_tax]
data.append(row)
@ -70,7 +70,7 @@ def get_items(filters):
return frappe.db.sql("""select pi_item.parent, pi.posting_date, pi.credit_to, pi.company,
pi.supplier, pi.remarks, pi.base_net_total, pi_item.item_code, pi_item.item_name, pi_item.item_group,
pi_item.project_name, pi_item.purchase_order, pi_item.purchase_receipt, pi_item.po_detail
pi_item.expense_account, pi_item.qty, pi_item.base_rate, pi_item.base_amount, pi.supplier_name
pi_item.expense_account, pi_item.qty, pi_item.base_net_rate, pi_item.base_net_amount, pi.supplier_name
from `tabPurchase Invoice` pi, `tabPurchase Invoice Item` pi_item
where pi.name = pi_item.parent and pi.docstatus = 1 %s %s
order by pi.posting_date desc, pi_item.item_code desc""" % (conditions, match_conditions), filters, as_dict=1)
@ -86,7 +86,7 @@ def get_tax_accounts(item_list, columns):
for d in item_list:
invoice_wise_items.setdefault(d.parent, []).append(d)
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, base_tax_amount_after_discount_amount
from `tabPurchase Taxes and Charges` where parenttype = 'Purchase Invoice'
and docstatus = 1 and ifnull(account_head, '') != '' and category in ('Total', 'Valuation and Total')
and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)), tuple(invoice_wise_items.keys()))
@ -107,7 +107,7 @@ def get_tax_accounts(item_list, columns):
elif charge_type == "Actual" and tax_amount:
for d in invoice_wise_items.get(parent, []):
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
(tax_amount * d.base_amount) / d.base_net_total
(tax_amount * d.base_net_amount) / d.base_net_total
tax_accounts.sort()
columns += [account_head + ":Currency:80" for account_head in tax_accounts]

View File

@ -26,13 +26,13 @@ def execute(filters=None):
row = [d.item_code, d.item_name, d.item_group, d.parent, d.posting_date, d.customer, d.customer_name,
d.customer_group, d.debit_to, d.territory, d.project_name, d.company, d.sales_order,
delivery_note, d.income_account, d.qty, d.base_rate, d.base_amount]
delivery_note, d.income_account, d.qty, d.base_net_rate, d.base_net_amount]
for tax in tax_accounts:
row.append(item_tax.get(d.parent, {}).get(d.item_code, {}).get(tax, 0))
total_tax = sum(row[last_col:])
row += [total_tax, d.base_amount + total_tax]
row += [total_tax, d.base_net_amount + total_tax]
data.append(row)
@ -69,7 +69,7 @@ def get_items(filters):
return frappe.db.sql("""select si_item.parent, si.posting_date, si.debit_to, si.project_name,
si.customer, si.remarks, si.territory, si.company, si.base_net_total, si_item.item_code, si_item.item_name,
si_item.item_group, si_item.sales_order, si_item.delivery_note, si_item.income_account,
si_item.qty, si_item.base_rate, si_item.base_amount, si.customer_name,
si_item.qty, si_item.base_net_rate, si_item.base_net_amount, si.customer_name,
si.customer_group, si_item.so_detail
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
where si.name = si_item.parent and si.docstatus = 1 %s
@ -83,7 +83,8 @@ def get_tax_accounts(item_list, columns):
for d in item_list:
invoice_wise_items.setdefault(d.parent, []).append(d)
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail, charge_type, tax_amount
tax_details = frappe.db.sql("""select parent, account_head, item_wise_tax_detail,
charge_type, base_tax_amount_after_discount_amount
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
and docstatus = 1 and ifnull(account_head, '') != ''
and parent in (%s)""" % ', '.join(['%s']*len(invoice_wise_items)),
@ -104,7 +105,7 @@ def get_tax_accounts(item_list, columns):
elif charge_type == "Actual" and tax_amount:
for d in invoice_wise_items.get(parent, []):
item_tax.setdefault(parent, {}).setdefault(d.item_code, {})[account_head] = \
flt((tax_amount * d.base_amount) / d.base_net_total)
flt((tax_amount * d.base_net_amount) / d.base_net_total)
tax_accounts.sort()
columns += [account_head + ":Currency:80" for account_head in tax_accounts]

View File

@ -114,7 +114,7 @@ def get_invoices(filters):
def get_invoice_expense_map(invoice_list):
expense_details = frappe.db.sql("""select parent, expense_account, sum(base_amount) as amount
expense_details = frappe.db.sql("""select parent, expense_account, sum(base_net_amount) as amount
from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_account""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
@ -126,7 +126,7 @@ def get_invoice_expense_map(invoice_list):
return invoice_expense_map
def get_invoice_tax_map(invoice_list, invoice_expense_map, expense_accounts):
tax_details = frappe.db.sql("""select parent, account_head, sum(tax_amount) as tax_amount
tax_details = frappe.db.sql("""select parent, account_head, sum(base_tax_amount_after_discount_amount) as tax_amount
from `tabPurchase Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)

View File

@ -78,7 +78,7 @@ def get_columns(invoice_list):
tax_accounts = frappe.db.sql_list("""select distinct account_head
from `tabSales Taxes and Charges` where parenttype = 'Sales Invoice'
and docstatus = 1 and ifnull(tax_amount_after_discount_amount, 0) != 0
and docstatus = 1 and ifnull(base_tax_amount_after_discount_amount, 0) != 0
and parent in (%s) order by account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]))
@ -113,7 +113,7 @@ def get_invoices(filters):
conditions, filters, as_dict=1)
def get_invoice_income_map(invoice_list):
income_details = frappe.db.sql("""select parent, income_account, sum(base_amount) as amount
income_details = frappe.db.sql("""select parent, income_account, sum(base_net_amount) as amount
from `tabSales Invoice Item` where parent in (%s) group by parent, income_account""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)
@ -126,7 +126,7 @@ def get_invoice_income_map(invoice_list):
def get_invoice_tax_map(invoice_list, invoice_income_map, income_accounts):
tax_details = frappe.db.sql("""select parent, account_head,
sum(tax_amount_after_discount_amount) as tax_amount
sum(base_tax_amount_after_discount_amount) as tax_amount
from `tabSales Taxes and Charges` where parent in (%s) group by parent, account_head""" %
', '.join(['%s']*len(invoice_list)), tuple([inv.name for inv in invoice_list]), as_dict=1)

View File

@ -2,9 +2,11 @@
// License: GNU General Public License v3. See license.txt
frappe.provide("erpnext.buying");
frappe.require("assets/erpnext/js/controllers/transaction.js");
{% include "public/js/controllers/accounts.js" %};
cur_frm.cscript.tax_table = "Purchase Taxes and Charges";
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
frappe.require("assets/erpnext/js/controllers/transaction.js");
cur_frm.email_field = "contact_email";
@ -90,20 +92,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
this.price_list_rate(doc, cdt, cdn);
},
rate: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["rate", "discount_percentage"]);
if(item.price_list_rate) {
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
precision("discount_percentage", item));
} else {
item.discount_percentage = 0.0;
}
this.calculate_taxes_and_totals();
},
uom: function(doc, cdt, cdn) {
var me = this;
var item = frappe.get_doc(cdt, cdn);
@ -180,97 +168,6 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({
this.frm.doc.outstanding_amount = flt(this.frm.doc.total_amount_to_pay - this.frm.doc.total_advance,
precision("outstanding_amount"));
}
},
change_form_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency) {
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[fname] = label.trim() + " (" + currency + ")";
}
});
};
setup_field_label_map(["base_net_total", "base_total_taxes_and_charges", "base_grand_total", "base_in_words",
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
"outstanding_amount", "total_advance", "total_amount_to_pay", "base_rounded_total"],
company_currency);
setup_field_label_map(["net_total", "grand_total", "in_words",
"taxes_and_charges_added", "taxes_and_charges_deducted"], this.frm.doc.currency);
cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
+ " = [?] " + company_currency);
if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
+ " = [?] " + company_currency);
}
// toggle fields
this.frm.toggle_display(["conversion_rate", "base_net_total", "base_grand_total",
"base_in_words", "base_taxes_and_charges_added", "base_taxes_and_charges_deducted"],
this.frm.doc.currency !== company_currency);
this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
this.frm.doc.price_list_currency !== company_currency);
// set labels
$.each(field_label_map, function(fname, label) {
me.frm.fields_dict[fname].set_label(label);
});
},
change_grid_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency, parentfield) {
var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[grid_doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[grid_doctype + "-" + fname] =
label.trim() + " (" + currency + ")";
}
});
};
setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"],
company_currency, "items");
setup_field_label_map(["rate", "price_list_rate", "amount"], this.frm.doc.currency, "items");
if(this.frm.fields_dict["taxes"]) {
setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
}
if(this.frm.fields_dict["advances"]) {
setup_field_label_map(["advance_amount", "allocated_amount"], company_currency,
"advances");
}
// toggle columns
var item_grid = this.frm.fields_dict["items"].grid;
var fieldnames = $.map(["base_rate", "base_price_list_rate", "base_amount", "base_rate"], function(fname) {
return frappe.meta.get_docfield(item_grid.doctype, fname, me.frm.docname) ? fname : null;
});
item_grid.set_column_disp(fieldnames, this.frm.doc.currency != company_currency);
// set labels
var $wrapper = $(this.frm.wrapper);
$.each(field_label_map, function(fname, label) {
$wrapper.find('[data-grid-fieldname="'+fname+'"]').text(label);
});
}
});
cur_frm.add_fetch('project_name', 'cost_center', 'cost_center');

View File

@ -4,7 +4,6 @@
frappe.provide("erpnext.buying");
{% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend({
refresh: function(doc, cdt, cdn) {

View File

@ -224,11 +224,29 @@
"options": "Purchase Order Item",
"permlevel": 0
},
{
"fieldname": "get_last_purchase_rate",
"fieldtype": "Button",
"label": "Get Last Purchase Rate",
"oldfieldtype": "Button",
"permlevel": 0,
"print_hide": 0
},
{
"fieldname": "sb_last_purchase",
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -247,6 +265,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -259,14 +287,6 @@
"print_hide": 0,
"read_only": 1
},
{
"fieldname": "get_last_purchase_rate",
"fieldtype": "Button",
"label": "Get Last Purchase Rate",
"oldfieldtype": "Button",
"permlevel": 0,
"print_hide": 0
},
{
"fieldname": "taxes_section",
"fieldtype": "Section Break",
@ -351,6 +371,93 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_39",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "taxes_and_charges_added",
"fieldtype": "Currency",
"label": "Taxes and Charges Added",
"no_copy": 0,
"oldfieldname": "other_charges_added_import",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 0
},
{
"fieldname": "taxes_and_charges_deducted",
"fieldtype": "Currency",
"label": "Taxes and Charges Deducted",
"no_copy": 0,
"oldfieldname": "other_charges_deducted_import",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 0
},
{
"fieldname": "total_taxes_and_charges",
"fieldtype": "Currency",
"label": "Total Taxes and Charges",
"options": "currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "discount_section",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "column_break_45",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "base_discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "totals_section",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
@ -400,40 +507,6 @@
"permlevel": 0,
"print_hide": 0
},
{
"fieldname": "taxes_and_charges_added",
"fieldtype": "Currency",
"label": "Taxes and Charges Added",
"no_copy": 0,
"oldfieldname": "other_charges_added_import",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 0
},
{
"fieldname": "taxes_and_charges_deducted",
"fieldtype": "Currency",
"label": "Taxes and Charges Deducted",
"no_copy": 0,
"oldfieldname": "other_charges_deducted_import",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 0
},
{
"fieldname": "total_taxes_and_charges",
"fieldtype": "Currency",
"label": "Total Taxes and Charges",
"options": "currency",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "grand_total",
"fieldtype": "Currency",
@ -783,7 +856,7 @@
"icon": "icon-file-text",
"idx": 1,
"is_submittable": 1,
"modified": "2015-02-20 05:16:19.990723",
"modified": "2015-02-23 15:10:05.156787",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order",

View File

@ -281,6 +281,58 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_29",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_32",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
@ -484,7 +536,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.224244",
"modified": "2015-02-23 12:21:53.399279",
"modified_by": "Administrator",
"module": "Buying",
"name": "Purchase Order Item",

View File

@ -3,7 +3,6 @@
// attach required files
{% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
erpnext.buying.SupplierQuotationController = erpnext.buying.BuyingController.extend({
refresh: function() {

View File

@ -228,6 +228,16 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -246,6 +256,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -342,45 +362,10 @@
"read_only": 1
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"no_copy": 1,
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_rounded_total",
"fieldtype": "Currency",
"label": "Rounded Total (Company Currency)",
"oldfieldname": "rounded_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Order.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break4",
"fieldname": "column_break_37",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"permlevel": 0,
"print_hide": 0
"precision": ""
},
{
"fieldname": "taxes_and_charges_added",
@ -414,8 +399,97 @@
"label": "Total Taxes and Charges",
"options": "currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "section_break_41",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "column_break_43",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "base_discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "section_break_46",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"no_copy": 1,
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Order.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_rounded_total",
"fieldtype": "Currency",
"label": "Rounded Total (Company Currency)",
"oldfieldname": "rounded_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break4",
"fieldtype": "Column Break",
"oldfieldtype": "Column Break",
"permlevel": 0,
"print_hide": 0
},
{
"fieldname": "grand_total",
"fieldtype": "Currency",
@ -583,7 +657,7 @@
"icon": "icon-shopping-cart",
"idx": 1,
"is_submittable": 1,
"modified": "2015-02-20 05:16:21.307774",
"modified": "2015-02-23 15:24:02.428061",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier Quotation",
@ -673,7 +747,7 @@
}
],
"read_only_onload": 1,
"search_fields": "status, transaction_date, supplier,base_grand_total",
"search_fields": "status, transaction_date, supplier,grand_total",
"sort_field": "modified",
"sort_order": "DESC",
"title_field": "supplier_name"

View File

@ -225,6 +225,57 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_24",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_27",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
@ -360,7 +411,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:02.403267",
"modified": "2015-02-23 15:28:03.712608",
"modified_by": "Administrator",
"module": "Buying",
"name": "Supplier Quotation Item",

View File

@ -209,7 +209,7 @@ erpnext.PurchaseAnalytics = frappe.views.TreeGridReport.extend({
if (posting_date >= from_date && posting_date <= to_date) {
var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty);
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
}
}
});

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _, throw
from frappe.utils import today, flt
from frappe.utils import today, flt, cint
from erpnext.setup.utils import get_company_currency, get_exchange_rate
from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year
from erpnext.utilities.transaction_base import TransactionBase
@ -357,3 +357,32 @@ def validate_conversion_rate(currency, conversion_rate, conversion_rate_label, c
if not conversion_rate:
throw(_("{0} is mandatory. Maybe Currency Exchange record is not created for {1} to {2}.").format(
conversion_rate_label, currency, company_currency))
def validate_taxes_and_charges(tax):
if tax.charge_type in ['Actual', 'On Net Total'] and tax.row_id:
frappe.throw(_("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"))
elif tax.charge_type in ['On Previous Row Amount', 'On Previous Row Total']:
if cint(tax.idx) == 1:
frappe.throw(_("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row"))
elif not tax.row_id:
frappe.throw(_("Please specify a valid Row ID for row {0} in table {1}".format(tax.idx, _(tax.doctype))))
elif tax.row_id and cint(tax.row_id) >= cint(tax.idx):
frappe.throw(_("Cannot refer row number greater than or equal to current row number for this Charge type"))
def validate_inclusive_tax(tax, doc):
def _on_previous_row_error(row_range):
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx,
row_range))
if cint(getattr(tax, "included_in_print_rate", None)):
if tax.charge_type == "Actual":
# inclusive tax cannot be of type Actual
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
elif tax.charge_type == "On Previous Row Amount" and \
not cint(doc.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
# referred row should also be inclusive
_on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_print_rate) for t in doc.get("taxes")[:cint(tax.row_id) - 1]]):
# all rows about the reffered tax should be inclusive
_on_previous_row_error("1 - %d" % (tax.row_id,))

View File

@ -14,7 +14,7 @@ from erpnext.controllers.stock_controller import StockController
class BuyingController(StockController):
def __setup__(self):
if hasattr(self, "items"):
if hasattr(self, "taxes"):
self.print_templates = {
"taxes": "templates/print_formats/includes/taxes.html"
}
@ -94,16 +94,16 @@ class BuyingController(StockController):
for d in self.get(parentfield):
if d.item_code and d.item_code in stock_items:
stock_items_qty += flt(d.qty)
stock_items_amount += flt(d.base_amount)
stock_items_amount += flt(d.base_net_amount)
last_stock_item_idx = d.idx
total_valuation_amount = sum([flt(d.tax_amount) for d in self.get("taxes")
total_valuation_amount = sum([flt(d.base_tax_amount_after_discount_amount) for d in self.get("taxes")
if d.category in ["Valuation", "Valuation and Total"]])
valuation_amount_adjustment = total_valuation_amount
for i, item in enumerate(self.get(parentfield)):
if item.item_code and item.qty and item.item_code in stock_items:
item_proportion = flt(item.base_amount) / stock_items_amount if stock_items_amount \
item_proportion = flt(item.base_net_amount) / stock_items_amount if stock_items_amount \
else flt(item.qty) / stock_items_qty
if i == (last_stock_item_idx - 1):
@ -124,7 +124,7 @@ class BuyingController(StockController):
landed_cost_voucher_amount = flt(item.landed_cost_voucher_amount) \
if self.doctype == "Purchase Receipt" else 0.0
item.valuation_rate = ((item.base_amount + item.item_tax_amount + rm_supp_cost
item.valuation_rate = ((item.base_net_amount + item.item_tax_amount + rm_supp_cost
+ landed_cost_voucher_amount) / qty_in_stock_uom)
else:
item.valuation_rate = 0.0

View File

@ -12,7 +12,7 @@ from erpnext.controllers.stock_controller import StockController
class SellingController(StockController):
def __setup__(self):
if hasattr(self, "items"):
if hasattr(self, "taxes"):
self.print_templates = {
"taxes": "templates/print_formats/includes/taxes.html"
}

View File

@ -3,15 +3,16 @@
from __future__ import unicode_literals
import json
from frappe import _, throw
import frappe
from frappe import _
from frappe.utils import cint, flt, rounded
from erpnext.setup.utils import get_company_currency
from erpnext.controllers.accounts_controller import validate_conversion_rate
from erpnext.controllers.accounts_controller import validate_conversion_rate, \
validate_taxes_and_charges, validate_inclusive_tax
class calculate_taxes_and_totals(object):
def __init__(self, doc):
self.doc = doc
self.calculate()
def calculate(self):
@ -25,6 +26,15 @@ class calculate_taxes_and_totals(object):
self.calculate_total_advance()
def _calculate(self):
self.calculate_item_values()
self.initialize_taxes()
self.determine_exclusive_rate()
self.calculate_net_total()
self.calculate_taxes()
self.calculate_totals()
self._cleanup()
def validate_conversion_rate(self):
# validate conversion rate
company_currency = get_company_currency(self.doc.company)
if not self.doc.currency or self.doc.currency == company_currency:
@ -36,17 +46,6 @@ class calculate_taxes_and_totals(object):
self.doc.conversion_rate = flt(self.doc.conversion_rate)
self.calculate_item_values()
self.initialize_taxes()
if self.doc.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
self.determine_exclusive_rate()
self.calculate_net_total()
self.calculate_taxes()
self.calculate_totals()
self._cleanup()
def calculate_item_values(self):
if not self.discount_amount_applied:
for item in self.doc.get("items"):
@ -55,69 +54,44 @@ class calculate_taxes_and_totals(object):
if item.discount_percentage == 100:
item.rate = 0.0
elif not item.rate:
item.rate = flt(item.price_list_rate * (1.0 - (item.discount_percentage / 100.0)),
self.doc.precision("rate", item))
item.rate = flt(item.price_list_rate *
(1.0 - (item.discount_percentage / 100.0)), item.precision("rate"))
item.amount = flt(item.rate * item.qty, self.doc.precision("amount", item))
item.item_tax_amount = 0.0;
item.net_rate = item.rate
item.amount = flt(item.rate * item.qty, item.precision("amount"))
item.net_amount = item.amount
self._set_in_company_currency(item, "price_list_rate", "base_price_list_rate")
self._set_in_company_currency(item, "rate", "base_rate")
self._set_in_company_currency(item, "amount", "base_amount")
self._set_in_company_currency(item, ["price_list_rate", "rate", "net_rate", "amount", "net_amount"])
def _set_in_company_currency(self, item, print_field, base_field):
item.item_tax_amount = 0.0
def _set_in_company_currency(self, doc, fields):
"""set values in base currency"""
value_in_company_currency = flt(self.doc.conversion_rate *
flt(item.get(print_field), self.doc.precision(print_field, item)), self.doc.precision(base_field, item))
item.set(base_field, value_in_company_currency)
for f in fields:
val = flt(flt(doc.get(f), doc.precision(f)) * self.doc.conversion_rate, doc.precision("base_" + f))
doc.set("base_" + f, val)
def initialize_taxes(self):
for tax in self.doc.get("taxes"):
validate_taxes_and_charges(tax)
validate_inclusive_tax(tax, self.doc)
tax.item_wise_tax_detail = {}
tax_fields = ["total", "tax_amount_after_discount_amount",
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
if not self.discount_amount_applied:
tax_fields.append("tax_amount")
if tax.charge_type != "Actual" and \
not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"):
tax_fields.append("tax_amount")
for fieldname in tax_fields:
tax.set(fieldname, 0.0)
self.validate_on_previous_row(tax)
self.validate_inclusive_tax(tax)
self.doc.round_floats_in(tax)
def validate_on_previous_row(self, tax):
"""
validate if a valid row id is mentioned in case of
On Previous Row Amount and On Previous Row Total
"""
if tax.charge_type in ["On Previous Row Amount", "On Previous Row Total"] and \
(not tax.row_id or cint(tax.row_id) >= tax.idx):
throw(_("Please specify a valid Row ID for {0} in row {1}").format(_(tax.doctype), tax.idx))
def validate_inclusive_tax(self, tax):
def _on_previous_row_error(row_range):
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx,
row_range))
if cint(getattr(tax, "included_in_print_rate", None)):
if tax.charge_type == "Actual":
# inclusive tax cannot be of type Actual
throw(_("Charge of type 'Actual' in row {0} cannot be included in Item Rate").format(tax.idx))
elif tax.charge_type == "On Previous Row Amount" and \
not cint(self.doc.get("taxes")[cint(tax.row_id) - 1].included_in_print_rate):
# referred row should also be inclusive
_on_previous_row_error(tax.row_id)
elif tax.charge_type == "On Previous Row Total" and \
not all([cint(t.included_in_print_rate) for t in self.doc.get("taxes")[:cint(tax.row_id) - 1]]):
# all rows about the reffered tax should be inclusive
_on_previous_row_error("1 - %d" % (tax.row_id,))
def determine_exclusive_rate(self):
if not any((cint(tax.included_in_print_rate) for tax in self.doc.get("taxes"))):
# no inclusive tax
return
for item in self.doc.get("items"):
@ -136,18 +110,24 @@ class calculate_taxes_and_totals(object):
cumulated_tax_fraction += tax.tax_fraction_for_current_item
if cumulated_tax_fraction and not self.discount_amount_applied and item.qty:
item.base_amount = flt((item.amount * self.doc.conversion_rate) /
(1 + cumulated_tax_fraction), self.doc.precision("base_amount", item))
item.net_amount = flt(item.amount / (1 + cumulated_tax_fraction), item.precision("net_amount"))
item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
item.discount_percentage = flt(item.discount_percentage, item.precision("discount_percentage"))
item.base_rate = flt(item.base_amount / item.qty, self.doc.precision("base_rate", item))
item.discount_percentage = flt(item.discount_percentage, self.doc.precision("discount_percentage", item))
if item.discount_percentage == 100:
item.base_price_list_rate = item.base_rate
item.base_rate = 0.0
else:
item.base_price_list_rate = flt(item.base_rate / (1 - (item.discount_percentage / 100.0)),
self.doc.precision("base_price_list_rate", item))
self._set_in_company_currency(item, ["net_rate", "net_amount"])
# below part need to be fixed???
# if item.discount_percentage == 100:
# item.price_list_rate = item.net_rate
# item.base_price_list_rate = flt(item.price_list_rate*self.doc.conversion_rate,
# self.doc.precision("base_price_list_rate", item))
# item.rate = item.base_rate = item.net_rate = item.base_net_rate = 0.0
# else:
# item.base_price_list_rate = flt(item.net_rate / (1 - (item.discount_percentage / 100.0)),
# self.doc.precision("price_list_rate", item))
def _load_item_tax_rate(self, item_tax_rate):
return json.loads(item_tax_rate) if item_tax_rate else {}
@ -182,17 +162,19 @@ class calculate_taxes_and_totals(object):
return tax.rate
def calculate_net_total(self):
self.doc.base_net_total = self.doc.net_total = 0.0
self.doc.total = self.doc.base_total = self.doc.net_total = self.doc.base_net_total = 0.0
for item in self.doc.get("items"):
self.doc.base_net_total += item.base_amount
self.doc.net_total += item.amount
self.doc.total += item.amount
self.doc.base_total += item.base_amount
self.doc.net_total += item.net_amount
self.doc.base_net_total += item.base_net_amount
self.doc.round_floats_in(self.doc, ["base_net_total", "net_total"])
self.doc.round_floats_in(self.doc, ["total", "base_total", "net_total", "base_net_total"])
def calculate_taxes(self):
# maintain actual tax rate based on idx
actual_tax_dict = dict([[tax.idx, flt(tax.rate, self.doc.precision("tax_amount", tax))]
actual_tax_dict = dict([[tax.idx, flt(tax.tax_amount, tax.precision("tax_amount"))]
for tax in self.doc.get("taxes") if tax.charge_type == "Actual"])
for n, item in enumerate(self.doc.get("items")):
@ -208,14 +190,16 @@ class calculate_taxes_and_totals(object):
if n == len(self.doc.get("items")) - 1:
current_tax_amount += actual_tax_dict[tax.idx]
# accumulate tax amount into tax.tax_amount
if tax.charge_type != "Actual" and \
not (self.discount_amount_applied and self.doc.apply_discount_on=="Grand Total"):
tax.tax_amount += current_tax_amount
# store tax_amount for current item as it will be used for
# charge type = 'On Previous Row Amount'
tax.tax_amount_for_current_item = current_tax_amount
# accumulate tax amount into tax.tax_amount
if not self.discount_amount_applied:
tax.tax_amount += current_tax_amount
# set tax after discount
tax.tax_amount_after_discount_amount += current_tax_amount
if getattr(tax, "category", None):
@ -230,12 +214,10 @@ class calculate_taxes_and_totals(object):
# note: grand_total_for_current_item contains the contribution of
# item's amount, previously applied tax and the current tax on that item
if i==0:
tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount,
self.doc.precision("total", tax))
tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount)
else:
tax.grand_total_for_current_item = \
flt(self.doc.get("taxes")[i-1].grand_total_for_current_item +
current_tax_amount, self.doc.precision("total", tax))
self.doc.get("taxes")[i-1].grand_total_for_current_item + current_tax_amount
# in tax.total, accumulate grand total of each item
tax.total += tax.grand_total_for_current_item
@ -245,8 +227,9 @@ class calculate_taxes_and_totals(object):
self.round_off_totals(tax)
# adjust Discount Amount loss in last tax iteration
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied:
self.adjust_discount_amount_loss(tax)
if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
and self.doc.apply_discount_on == "Grand Total":
self.adjust_discount_amount_loss(tax)
def get_current_tax_amount(self, item, tax, item_tax_map):
tax_rate = self._get_tax_rate(tax, item_tax_map)
@ -254,12 +237,11 @@ class calculate_taxes_and_totals(object):
if tax.charge_type == "Actual":
# distribute the tax amount proportionally to each item row
actual = flt(tax.rate, self.doc.precision("tax_amount", tax))
current_tax_amount = (self.doc.base_net_total
and ((item.base_amount / self.doc.base_net_total) * actual)
or 0)
actual = flt(tax.tax_amount, tax.precision("tax_amount"))
current_tax_amount = item.net_amount*actual / self.doc.net_total if self.doc.net_total else 0.0
elif tax.charge_type == "On Net Total":
current_tax_amount = (tax_rate / 100.0) * item.base_amount
current_tax_amount = (tax_rate / 100.0) * item.net_amount
elif tax.charge_type == "On Previous Row Amount":
current_tax_amount = (tax_rate / 100.0) * \
self.doc.get("taxes")[cint(tax.row_id) - 1].tax_amount_for_current_item
@ -267,72 +249,68 @@ class calculate_taxes_and_totals(object):
current_tax_amount = (tax_rate / 100.0) * \
self.doc.get("taxes")[cint(tax.row_id) - 1].grand_total_for_current_item
current_tax_amount = flt(current_tax_amount, self.doc.precision("tax_amount", tax))
# current_tax_amount = flt(current_tax_amount, tax.precision("tax_amount", tax))
# store tax breakup for each item
key = item.item_code or item.item_name
if tax.item_wise_tax_detail.get(key):
item_wise_tax_amount = tax.item_wise_tax_detail[key][1] + current_tax_amount
tax.item_wise_tax_detail[key] = [tax_rate,item_wise_tax_amount]
else:
tax.item_wise_tax_detail[key] = [tax_rate,current_tax_amount]
self.set_item_wise_tax(item, tax, tax_rate, current_tax_amount)
return current_tax_amount
def set_item_wise_tax(self, item, tax, tax_rate, current_tax_amount):
# store tax breakup for each item
key = item.item_code or item.item_name
item_wise_tax_amount = current_tax_amount*self.doc.conversion_rate
if tax.item_wise_tax_detail.get(key):
item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, tax.precision("base_tax_amount"))]
def round_off_totals(self, tax):
tax.total = flt(tax.total, self.doc.precision("total", tax))
tax.tax_amount = flt(tax.tax_amount, self.doc.precision("tax_amount", tax))
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
self.doc.precision("tax_amount", tax))
tax.total = flt(tax.total, tax.precision("total"))
tax.tax_amount = flt(tax.tax_amount, tax.precision("tax_amount"))
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, tax.precision("tax_amount"))
self._set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"])
def adjust_discount_amount_loss(self, tax):
discount_amount_loss = self.doc.base_grand_total - flt(self.doc.base_discount_amount) - tax.total
discount_amount_loss = self.doc.grand_total - flt(self.doc.discount_amount) - tax.total
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
discount_amount_loss, self.doc.precision("tax_amount", tax))
tax.total = flt(tax.total + discount_amount_loss, self.doc.precision("total", tax))
def calculate_totals(self):
self.doc.base_grand_total = flt(self.doc.get("taxes")[-1].total
if self.doc.get("taxes") else self.doc.base_net_total)
self.doc.base_total_taxes_and_charges = flt(self.doc.base_grand_total - self.doc.base_net_total,
self.doc.precision("base_total_taxes_and_charges"))
self.doc.grand_total = flt(self.doc.get("taxes")[-1].total
if self.doc.get("taxes") else self.doc.net_total)
if self.doc.doctype in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]:
self.doc.grand_total = flt(self.doc.base_grand_total / self.doc.conversion_rate) \
if (self.doc.base_total_taxes_and_charges or self.doc.discount_amount) else self.doc.net_total
self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total +
flt(self.doc.discount_amount), self.doc.precision("total_taxes_and_charges"))
self.doc.base_grand_total = flt(self.doc.grand_total * self.doc.conversion_rate) \
if self.doc.total_taxes_and_charges else self.doc.base_net_total
else:
self.doc.base_taxes_and_charges_added, self.doc.base_taxes_and_charges_deducted = 0.0, 0.0
self.doc.taxes_and_charges_added, self.taxes_and_charges_deducted = 0.0, 0.0
for tax in self.doc.get("taxes"):
if tax.category in ["Valuation and Total", "Total"]:
if tax.add_deduct_tax == "Add":
self.doc.base_taxes_and_charges_added += flt(tax.tax_amount)
self.doc.taxes_and_charges_added += flt(tax.tax_amount)
else:
self.doc.base_taxes_and_charges_deducted += flt(tax.tax_amount)
self.doc.taxes_and_charges_deducted += flt(tax.tax_amount)
self.doc.round_floats_in(self.doc, ["base_taxes_and_charges_added", "base_taxes_and_charges_deducted"])
self.doc.round_floats_in(self.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"])
self.doc.grand_total = flt(self.doc.base_grand_total / self.doc.conversion_rate) \
if (self.doc.base_taxes_and_charges_added or self.doc.base_taxes_and_charges_deducted) else self.doc.net_total
self.doc.base_grand_total = flt(self.doc.grand_total * self.doc.conversion_rate) \
if (self.doc.taxes_and_charges_added or self.doc.taxes_and_charges_deducted) \
else self.doc.base_net_total
self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total,
self.doc.precision("total_taxes_and_charges"))
self._set_in_company_currency(self.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"])
self.doc.taxes_and_charges_added = flt(self.doc.base_taxes_and_charges_added / self.doc.conversion_rate,
self.doc.precision("taxes_and_charges_added"))
self.doc.taxes_and_charges_deducted = flt(self.doc.base_taxes_and_charges_deducted / self.doc.conversion_rate,
self.doc.precision("taxes_and_charges_deducted"))
self.doc.total_taxes_and_charges = flt(self.doc.grand_total - self.doc.net_total,
self.doc.precision("total_taxes_and_charges"))
self.doc.base_grand_total = flt(self.doc.base_grand_total, self.doc.precision("base_grand_total"))
self.doc.grand_total = flt(self.doc.grand_total, self.doc.precision("grand_total"))
self._set_in_company_currency(self.doc, ["total_taxes_and_charges"])
self.doc.round_floats_in(self.doc, ["grand_total", "base_grand_total"])
if self.doc.meta.get_field("base_rounded_total"):
self.doc.base_rounded_total = rounded(self.doc.base_grand_total)
if self.doc.meta.get_field("rounded_total"):
self.doc.rounded_total = rounded(self.doc.grand_total)
if self.doc.meta.get_field("base_rounded_total"):
self.doc.base_rounded_total = rounded(self.doc.base_grand_total)
def _cleanup(self):
for tax in self.doc.get("taxes"):
@ -340,43 +318,50 @@ class calculate_taxes_and_totals(object):
def apply_discount_amount(self):
if self.doc.discount_amount:
if not self.doc.apply_discount_on:
frappe.throw(_("Please select Apply Discount On"))
self.doc.base_discount_amount = flt(self.doc.discount_amount * self.doc.conversion_rate,
self.doc.precision("base_discount_amount"))
grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
total_for_discount_amount = self.get_total_for_discount_amount()
if grand_total_for_discount_amount:
if total_for_discount_amount:
# calculate item amount after Discount Amount
for item in self.doc.get("items"):
distributed_amount = flt(self.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount
item.base_amount = flt(item.base_amount - distributed_amount, self.doc.precision("base_amount", item))
distributed_amount = flt(self.doc.discount_amount) * item.net_amount / total_for_discount_amount
item.net_amount = flt(item.net_amount - distributed_amount, item.precision("net_amount"))
item.net_rate = flt(item.net_amount / item.qty, item.precision("net_rate"))
self._set_in_company_currency(item, ["net_rate", "net_amount"])
self.discount_amount_applied = True
self._calculate()
else:
self.doc.base_discount_amount = 0
def get_grand_total_for_discount_amount(self):
actual_taxes_dict = {}
def get_total_for_discount_amount(self):
if self.doc.apply_discount_on == "Net Total":
return self.doc.net_total
else:
actual_taxes_dict = {}
for tax in self.doc.get("taxes"):
if tax.charge_type == "Actual":
actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
elif tax.row_id in actual_taxes_dict:
actual_tax_amount = flt(actual_taxes_dict.get(tax.row_id, 0)) * flt(tax.rate) / 100
actual_taxes_dict.setdefault(tax.idx, actual_tax_amount)
for tax in self.doc.get("taxes"):
if tax.charge_type == "Actual":
actual_taxes_dict.setdefault(tax.idx, tax.tax_amount)
elif tax.row_id in actual_taxes_dict:
actual_tax_amount = flt(actual_taxes_dict.get(tax.row_id, 0)) * flt(tax.rate) / 100
actual_taxes_dict.setdefault(tax.idx, actual_tax_amount)
grand_total_for_discount_amount = flt(self.doc.base_grand_total - sum(actual_taxes_dict.values()),
self.doc.precision("base_grand_total"))
return grand_total_for_discount_amount
return flt(self.doc.grand_total - sum(actual_taxes_dict.values()), self.doc.precision("grand_total"))
def calculate_total_advance(self):
if self.doc.docstatus < 2:
sum_of_allocated_amount = sum([flt(adv.allocated_amount, self.doc.precision("allocated_amount", adv))
total_allocated_amount = sum([flt(adv.allocated_amount, adv.precision("allocated_amount"))
for adv in self.doc.get("advances")])
self.doc.total_advance = flt(sum_of_allocated_amount, self.doc.precision("total_advance"))
self.doc.total_advance = flt(total_allocated_amount, self.doc.precision("total_advance"))
if self.doc.docstatus == 0:
self.calculate_outstanding_amount()

View File

@ -132,9 +132,9 @@ def period_wise_columns_query(filters, trans):
else:
pwc = [_(filters.get("fiscal_year")) + " ("+_("Qty") + "):Float:120",
_(filters.get("fiscal_year")) + " ("+ _("Amt") + "):Currency:120"]
query_details = " SUM(t2.qty), SUM(t2.base_amount),"
query_details = " SUM(t2.qty), SUM(t2.base_net_amount),"
query_details += 'SUM(t2.qty), SUM(t2.base_amount)'
query_details += 'SUM(t2.qty), SUM(t2.base_net_amount)'
return pwc, query_details
def get_period_wise_columns(bet_dates, period, pwc):
@ -147,7 +147,7 @@ def get_period_wise_columns(bet_dates, period, pwc):
def get_period_wise_query(bet_dates, trans_date, query_details):
query_details += """SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.qty, NULL)),
SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_amount, NULL)),
SUM(IF(t1.%(trans_date)s BETWEEN '%(sd)s' AND '%(ed)s', t2.base_net_amount, NULL)),
""" % {"trans_date": trans_date, "sd": bet_dates[0],"ed": bet_dates[1]}
return query_details

View File

@ -112,7 +112,6 @@ erpnext.patches.v5_0.remove_birthday_events
erpnext.patches.v5_0.update_item_name_in_bom
erpnext.patches.v5_0.rename_customer_issue
erpnext.patches.v5_0.rename_total_fields
erpnext.patches.v5_0.replace_renamed_fields_in_custom_script_and_print_formats
erpnext.patches.v5_0.new_crm_module
erpnext.patches.v5_0.rename_customer_issue
erpnext.patches.v5_0.update_material_transfer_for_manufacture
@ -124,3 +123,5 @@ erpnext.patches.v5_0.convert_stock_reconciliation
erpnext.patches.v5_0.update_projects
erpnext.patches.v5_0.item_patches
erpnext.patches.v5_0.update_journal_entry_title
erpnext.patches.v5_0.taxes_and_totals_in_party_currency
erpnext.patches.v5_0.replace_renamed_fields_in_custom_scripts_and_print_formats

View File

@ -35,7 +35,6 @@ doctype_series_map = {
def execute():
series_to_set = get_series_to_set()
for doctype, opts in series_to_set.items():
print "Setting naming series", doctype, opts
set_series(doctype, opts["options"], opts["default"])
def set_series(doctype, options, default):

View File

@ -21,9 +21,10 @@ def get_all_renamed_fields():
from erpnext.patches.v5_0.rename_table_fieldnames import rename_map
renamed_fields = (
("base_amount", "base_net_amount"),
("net_total", "base_net_total"),
("net_total_export", "net_total"),
("net_total_import", "net_total"),
("net_total_export", "total"),
("net_total_import", "total"),
("other_charges_total", "base_total_taxes_and_charges"),
("other_charges_total_export", "total_taxes_and_charges"),
("other_charges_added", "base_taxes_and_charges_added"),
@ -39,7 +40,9 @@ def get_all_renamed_fields():
("rounded_total_import", "rounded_total"),
("in_words", "base_in_words"),
("in_words_export", "in_words"),
("in_words_import", "in_words")
("in_words_import", "in_words"),
("tax_amount", "base_tax_amount"),
("tax_amount_after_discount_amount", "base_tax_amount_after_discount_amount"),
)
for fields in rename_map.values():

View File

@ -0,0 +1,66 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
import frappe
def execute():
selling_doctypes = ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]
buying_doctypes = ["Supplier Quotation", "Purchase Order", "Purchase Receipt", "Purchase Invoice"]
for dt in selling_doctypes:
update_values(dt, "Sales Taxes and Charges")
for dt in buying_doctypes:
update_values(dt, "Purchase Taxes and Charges")
def update_values(dt, tax_table):
frappe.reload_doctype(dt)
frappe.reload_doctype(dt + " Item")
frappe.reload_doctype(tax_table)
# update net_total, discount_on
frappe.db.sql("""
UPDATE
`tab{0}`
SET
total = net_total,
base_total = net_total*conversion_rate,
net_total = base_net_total / conversion_rate,
apply_discount_on = "Grand Total"
WHERE
docstatus < 2
""".format(dt))
# update net_amount
frappe.db.sql("""
UPDATE
`tab{0}` par, `tab{1}` item
SET
item.base_net_amount = item.base_amount,
item.base_net_rate = item.base_rate,
item.net_amount = item.base_net_amount / par.conversion_rate,
item.net_rate = item.base_net_rate / par.conversion_rate,
item.base_amount = item.amount * par.conversion_rate,
item.base_rate = item.rate * par.conversion_rate
WHERE
par.name = item.parent
and par.docstatus < 2
""".format(dt, dt + " Item"))
# update tax in party currency
frappe.db.sql("""
UPDATE
`tab{0}` par, `tab{1}` tax
SET
tax.base_tax_amount = tax.tax_amount,
tax.tax_amount = tax.base_tax_amount / par.conversion_rate,
tax.base_total = tax.total,
tax.total = tax.base_total / conversion_rate,
tax.base_tax_amount_after_discount_amount = tax.tax_amount_after_discount_amount,
tax.tax_amount_after_discount_amount = tax.base_tax_amount_after_discount_amount / conversion_rate
WHERE
par.name = tax.parent
and par.docstatus < 2
""".format(dt, tax_table))

View File

@ -77,7 +77,6 @@ $.extend(cur_frm.cscript, {
},
callback: function(r) {
if(!r.exc) {
console.log(r.message)
cur_frm.set_value("workstation", r.message)
}
}

View File

@ -13,19 +13,19 @@ def execute(filters=None):
data = []
for project in proj_details:
data.append([project.name, pr_item_map.get(project.name, 0),
se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0),
project.project_name, project.status, project.company,
project.customer, project.project_value, project.project_start_date,
data.append([project.name, pr_item_map.get(project.name, 0),
se_item_map.get(project.name, 0), dn_item_map.get(project.name, 0),
project.project_name, project.status, project.company,
project.customer, project.project_value, project.project_start_date,
project.completion_date])
return columns, data
return columns, data
def get_columns():
return [_("Project Id") + ":Link/Project:140", _("Cost of Purchased Items") + ":Currency:160",
_("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160",
_("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100",
_("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120",
_("Cost of Issued Items") + ":Currency:160", _("Cost of Delivered Items") + ":Currency:160",
_("Project Name") + "::120", _("Project Status") + "::120", _("Company") + ":Link/Company:100",
_("Customer") + ":Link/Customer:140", _("Project Value") + ":Currency:120",
_("Project Start Date") + ":Date:120", _("Completion Date") + ":Date:120"]
def get_project_details():
@ -33,8 +33,8 @@ def get_project_details():
project_start_date, completion_date from tabProject where docstatus < 2""", as_dict=1)
def get_purchased_items_cost():
pr_items = frappe.db.sql("""select project_name, sum(base_amount) as amount
from `tabPurchase Receipt Item` where ifnull(project_name, '') != ''
pr_items = frappe.db.sql("""select project_name, sum(base_net_amount) as amount
from `tabPurchase Receipt Item` where ifnull(project_name, '') != ''
and docstatus = 1 group by project_name""", as_dict=1)
pr_item_map = {}
@ -46,7 +46,7 @@ def get_purchased_items_cost():
def get_issued_items_cost():
se_items = frappe.db.sql("""select se.project_name, sum(se_item.amount) as amount
from `tabStock Entry` se, `tabStock Entry Detail` se_item
where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = ''
where se.name = se_item.parent and se.docstatus = 1 and ifnull(se_item.t_warehouse, '') = ''
and ifnull(se.project_name, '') != '' group by se.project_name""", as_dict=1)
se_item_map = {}
@ -56,14 +56,14 @@ def get_issued_items_cost():
return se_item_map
def get_delivered_items_cost():
dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_amount) as amount
dn_items = frappe.db.sql("""select dn.project_name, sum(dn_item.base_net_amount) as amount
from `tabDelivery Note` dn, `tabDelivery Note Item` dn_item
where dn.name = dn_item.parent and dn.docstatus = 1 and ifnull(dn.project_name, '') != ''
group by dn.project_name""", as_dict=1)
si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_amount) as amount
si_items = frappe.db.sql("""select si.project_name, sum(si_item.base_net_amount) as amount
from `tabSales Invoice` si, `tabSales Invoice Item` si_item
where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1
where si.name = si_item.parent and si.docstatus = 1 and ifnull(si.update_stock, 0) = 1
and ifnull(si.is_pos, 0) = 1 and ifnull(si.project_name, '') != ''
group by si.project_name""", as_dict=1)
@ -75,4 +75,4 @@ def get_delivered_items_cost():
for item in si_items:
dn_item_map.setdefault(item.project_name, item.amount)
return dn_item_map
return dn_item_map

View File

@ -1,3 +1,5 @@
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
// get tax rate
cur_frm.cscript.account_head = function(doc, cdt, cdn) {
@ -8,7 +10,7 @@ cur_frm.cscript.account_head = function(doc, cdt, cdn) {
} else if(d.account_head && d.charge_type!=="Actual") {
frappe.call({
type:"GET",
method: "erpnext.controllers.accounts_controller.get_tax_rate",
method: "erpnext.controllers.accounts_controller.get_tax_rate",
args: {"account_head":d.account_head},
callback: function(r) {
frappe.model.set_value(cdt, cdn, "rate", r.message || 0);
@ -16,3 +18,187 @@ cur_frm.cscript.account_head = function(doc, cdt, cdn) {
})
}
}
cur_frm.cscript.validate_taxes_and_charges = function(cdt, cdn) {
var d = locals[cdt][cdn];
var msg = "";
if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
msg = __("Please select Charge Type first");
d.row_id = "";
d.rate = d.tax_amount = 0.0;
} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
msg = __("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'");
d.row_id = "";
} else if((d.charge_type == 'On Previous Row Amount' || d.charge_type == 'On Previous Row Total') && d.row_id) {
if (d.idx == 1) {
msg = __("Cannot select charge type as 'On Previous Row Amount' or 'On Previous Row Total' for first row");
d.charge_type = '';
} else if (!d.row_id) {
msg = __("Please specify a valid Row ID for row {0} in table {1}", [d.idx, __(d.doctype)]);
d.row_id = "";
} else if(d.row_id && d.row_id >= d.idx) {
msg = __("Cannot refer row number greater than or equal to current row number for this Charge type");
d.row_id = "";
}
}
if(msg) {
validated = false;
refresh_field("taxes");
frappe.throw(msg);
}
}
cur_frm.cscript.validate_inclusive_tax = function(tax) {
var actual_type_error = function() {
var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
frappe.throw(msg);
};
var on_previous_row_error = function(row_range) {
var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included",
[tax.idx, __(tax.doctype), tax.charge_type, row_range])
frappe.throw(msg);
};
if(cint(tax.included_in_print_rate)) {
if(tax.charge_type == "Actual") {
// inclusive tax cannot be of type Actual
actual_type_error();
} else if(tax.charge_type == "On Previous Row Amount" &&
!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)) {
// referred row should also be an inclusive tax
on_previous_row_error(tax.row_id);
} else if(tax.charge_type == "On Previous Row Total") {
var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
function(t) { return cint(t.included_in_print_rate) ? null : t; });
if(taxes_not_included.length > 0) {
// all rows above this tax should be inclusive
on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
}
}
}
}
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
});
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
});
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
});
frappe.ui.form.on(cur_frm.cscript.tax_table, "charge_type", function(frm, cdt, cdn) {
cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
});
frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
var tax = frappe.get_doc(cdt, cdn);
try {
cur_frm.cscript.validate_taxes_and_charges(cdt, cdn);
cur_frm.cscript.validate_inclusive_tax(tax);
} catch(e) {
tax.included_in_print_rate = 0;
refresh_field("included_in_print_rate", tax.name, tax.parentfield);
throw e;
}
});
cur_frm.set_query("account_head", "taxes", function(doc) {
if(cur_frm.cscript.tax_table == "Sales Taxes and Charges") {
var account_type = ["Tax", "Chargeable", "Expense Account"];
} else {
var account_type = ["Tax", "Chargeable", "Income Account"];
}
return {
query: "erpnext.controllers.queries.tax_account_query",
filters: {
"account_type": account_type,
"company": doc.company
}
}
});
cur_frm.set_query("cost_center", "taxes", function(doc) {
return {
filters: {
'company': doc.company,
'group_or_ledger': "Ledger"
}
}
});
// For customizing print
cur_frm.pformat.total = function(doc) { return ''; }
cur_frm.pformat.discount_amount = function(doc) { return ''; }
cur_frm.pformat.grand_total = function(doc) { return ''; }
cur_frm.pformat.rounded_total = function(doc) { return ''; }
cur_frm.pformat.in_words = function(doc) { return ''; }
cur_frm.pformat.taxes= function(doc){
//function to make row of table
var make_row = function(title, val, bold, is_negative) {
var bstart = '<b>'; var bend = '</b>';
return '<tr><td style="width:50%;">' + (bold?bstart:'') + title + (bold?bend:'') + '</td>'
+ '<td style="width:50%;text-align:right;">' + (is_negative ? '- ' : '')
+ format_currency(val, doc.currency) + '</td></tr>';
}
function print_hide(fieldname) {
var doc_field = frappe.meta.get_docfield(doc.doctype, fieldname, doc.name);
return doc_field.print_hide;
}
out ='';
if (!doc.print_without_amount) {
var cl = doc.taxes || [];
// outer table
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
// main table
out +='<table class="noborder" style="width:100%">';
if(!print_hide('total')) {
out += make_row('Total', doc.total, 1);
}
// Discount Amount on net total
if(!print_hide('discount_amount') && doc.apply_discount_on == "Net Total" && doc.discount_amount)
out += make_row('Discount Amount', doc.discount_amount, 0, 1);
// add rows
if(cl.length){
for(var i=0;i<cl.length;i++) {
if(cl[i].tax_amount!=0 && !cl[i].included_in_print_rate)
out += make_row(cl[i].description, cl[i].tax_amount, 0);
}
}
// Discount Amount on grand total
if(!print_hide('discount_amount') && doc.apply_discount_on == "Grand Total" && doc.discount_amount)
out += make_row('Discount Amount', doc.discount_amount, 0, 1);
// grand total
if(!print_hide('grand_total'))
out += make_row('Grand Total', doc.grand_total, 1);
if(!print_hide('rounded_total'))
out += make_row('Rounded Total', doc.rounded_total, 1);
if(doc.in_words && !print_hide('in_words')) {
out +='</table></td></tr>';
out += '<tr><td colspan = "2">';
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
out += '<td style="width:50%;">' + doc.in_words + '</td></tr>';
}
out += '</table></td></tr></table></div>';
}
return out;
}

View File

@ -38,22 +38,47 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
this.show_item_wise_taxes();
},
validate_conversion_rate: function() {
this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
this.frm.doc.name);
var company_currency = this.get_company_currency();
if(!this.frm.doc.conversion_rate) {
frappe.throw(repl('%(conversion_rate_label)s' +
__(' is mandatory. Maybe Currency Exchange record is not created for ') +
'%(from_currency)s' + __(" to ") + '%(to_currency)s',
{
"conversion_rate_label": conversion_rate_label,
"from_currency": this.frm.doc.currency,
"to_currency": company_currency
}));
}
},
calculate_item_values: function() {
var me = this;
if (!this.discount_amount_applied) {
$.each(this.frm.doc["items"] || [], function(i, item) {
frappe.model.round_floats_in(item);
item.net_rate = item.rate;
item.amount = flt(item.rate * item.qty, precision("amount", item));
item.net_amount = item.amount;
item.item_tax_amount = 0.0;
$.each(["price_list_rate", "rate", "amount"], function(i, f) {
item["base_" + f] = flt(item[f] * me.frm.doc.conversion_rate, precision("base_" + f, item));
})
me.set_in_company_currency(item, ["price_list_rate", "rate", "amount", "net_rate", "net_amount"]);
});
}
},
set_in_company_currency: function(doc, fields) {
var me = this;
$.each(fields, function(i, f) {
doc["base_"+f] = flt(flt(doc[f], precision(f, doc)) * me.frm.doc.conversion_rate, precision("base_" + f, doc));
})
},
initialize_taxes: function() {
var me = this;
@ -63,21 +88,27 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
"tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
if (!me.discount_amount_applied)
tax_fields.push("tax_amount");
if (cstr(tax.charge_type) != "Actual" &&
!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
tax_fields.push("tax_amount");
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
me.validate_on_previous_row(tax);
cur_frm.cscript.validate_taxes_and_charges(tax.doctype, tax.name);
me.validate_inclusive_tax(tax);
frappe.model.round_floats_in(tax);
});
},
determine_exclusive_rate: function() {
if(!in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) return;
var me = this;
var has_inclusive_tax = false;
$.each(me.frm.doc["taxes"] || [], function(i, row) {
if(cint(row.included_in_print_rate)) has_inclusive_tax = true;
})
if(has_inclusive_tax==false) return;
$.each(me.frm.doc["items"] || [], function(n, item) {
var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
var cumulated_tax_fraction = 0.0;
@ -97,19 +128,18 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
});
if(cumulated_tax_fraction && !me.discount_amount_applied) {
item.base_amount = flt(
(item.amount * me.frm.doc.conversion_rate) / (1 + cumulated_tax_fraction),
precision("base_amount", item));
item.net_amount = flt(item.amount / (1 + cumulated_tax_fraction), precision("net_amount", item));
item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
item.base_rate = flt(item.base_amount / item.qty, precision("base_rate", item));
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
if(item.discount_percentage == 100) {
item.base_price_list_rate = item.base_rate;
item.base_rate = 0.0;
} else {
item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
precision("base_price_list_rate", item));
}
// if(item.discount_percentage == 100) {
// item.base_price_list_rate = item.base_rate;
// item.base_rate = 0.0;
// } else {
// item.base_price_list_rate = flt(item.base_rate / (1 - item.discount_percentage / 100.0),
// precision("base_price_list_rate", item));
// }
}
});
},
@ -140,20 +170,21 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
_get_tax_rate: function(tax, item_tax_map) {
return (keys(item_tax_map).indexOf(tax.account_head) != -1) ?
flt(item_tax_map[tax.account_head], precision("rate", tax)) :
tax.rate;
flt(item_tax_map[tax.account_head], precision("rate", tax)) : tax.rate;
},
calculate_net_total: function() {
var me = this;
this.frm.doc.base_net_total = this.frm.doc.net_total = 0.0;
this.frm.doc.total = this.frm.doc.base_total = this.frm.doc.net_total = this.frm.doc.base_net_total = 0.0;
$.each(this.frm.doc["items"] || [], function(i, item) {
me.frm.doc.base_net_total += item.base_amount;
me.frm.doc.net_total += item.amount;
me.frm.doc.total += item.amount;
me.frm.doc.base_total += item.base_amount;
me.frm.doc.net_total += item.net_amount;
me.frm.doc.base_net_total += item.base_net_amount;
});
frappe.model.round_floats_in(this.frm.doc, ["base_net_total", "net_total"]);
frappe.model.round_floats_in(this.frm.doc, ["total", "base_total", "net_total", "base_net_total"]);
},
calculate_taxes: function() {
@ -163,7 +194,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
// maintain actual tax rate based on idx
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
if (tax.charge_type == "Actual") {
actual_tax_dict[tax.idx] = flt(tax.rate, precision("tax_amount", tax));
actual_tax_dict[tax.idx] = flt(tax.tax_amount, precision("tax_amount", tax));
}
});
@ -182,14 +213,16 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
}
}
// accumulate tax amount into tax.tax_amount
if (tax.charge_type != "Actual" &&
!(me.discount_amount_applied && me.frm.doc.apply_discount_on=="Grand Total"))
tax.tax_amount += current_tax_amount;
// store tax_amount for current item as it will be used for
// charge type = 'On Previous Row Amount'
tax.tax_amount_for_current_item = current_tax_amount;
// accumulate tax amount into tax.tax_amount
if (!me.discount_amount_applied)
tax.tax_amount += current_tax_amount;
// tax amount after discount amount
tax.tax_amount_after_discount_amount += current_tax_amount;
// for buying
@ -205,12 +238,10 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
// note: grand_total_for_current_item contains the contribution of
// item's amount, previously applied tax and the current tax on that item
if(i==0) {
tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount,
precision("total", tax));
tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
} else {
tax.grand_total_for_current_item =
flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount,
precision("total", tax));
flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount);
}
// in tax.total, accumulate grand total for each item
@ -221,7 +252,7 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
me.round_off_totals(tax);
// adjust Discount Amount loss in last tax iteration
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied)
if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
me.adjust_discount_amount_loss(tax);
}
});
@ -238,12 +269,12 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
if(tax.charge_type == "Actual") {
// distribute the tax amount proportionally to each item row
var actual = flt(tax.rate, precision("tax_amount", tax));
current_tax_amount = this.frm.doc.base_net_total ?
((item.base_amount / this.frm.doc.base_net_total) * actual) : 0.0;
var actual = flt(tax.tax_amount, precision("tax_amount", tax));
current_tax_amount = this.frm.doc.net_total ?
((item.net_amount / this.frm.doc.net_total) * actual) : 0.0;
} else if(tax.charge_type == "On Net Total") {
current_tax_amount = (tax_rate / 100.0) * item.base_amount;
current_tax_amount = (tax_rate / 100.0) * item.net_amount;
} else if(tax.charge_type == "On Previous Row Amount") {
current_tax_amount = (tax_rate / 100.0) *
@ -254,31 +285,90 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
this.frm.doc["taxes"][cint(tax.row_id) - 1].grand_total_for_current_item;
}
current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
// current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
// store tax breakup for each item
tax.item_wise_tax_detail[item.item_code || item.item_name] = [tax_rate, current_tax_amount];
this.set_item_wise_tax(item, tax, tax_rate, current_tax_amount);
return current_tax_amount;
},
set_item_wise_tax: function(item, tax, tax_rate, current_tax_amount) {
// store tax breakup for each item
var key = item.item_code || item.item_name;
var item_wise_tax_amount = current_tax_amount * this.frm.doc.conversion_rate;
if (tax.item_wise_tax_detail && tax.item_wise_tax_detail[key])
item_wise_tax_amount += tax.item_wise_tax_detail[key][1]
tax.item_wise_tax_detail[key] = [tax_rate,flt(item_wise_tax_amount, precision("base_tax_amount", tax))]
},
round_off_totals: function(tax) {
tax.total = flt(tax.total, precision("total", tax));
tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax));
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount,
precision("tax_amount", tax));
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, precision("tax_amount", tax));
this.set_in_company_currency(tax, ["total", "tax_amount", "tax_amount_after_discount_amount"]);
},
adjust_discount_amount_loss: function(tax) {
var discount_amount_loss = this.frm.doc.base_grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
discount_amount_loss, precision("tax_amount", tax));
tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
},
calculate_totals: function() {
// Changing sequence can cause roundiing issue and on-screen discrepency
var me = this;
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ?
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total;
} else {
// other charges added/deducted
this.frm.doc.taxes_and_charges_added = this.frm.doc.taxes_and_charges_deducted = 0.0;
if(tax_count) {
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
if (in_list(["Valuation and Total", "Total"], tax.category)) {
if(tax.add_deduct_tax == "Add") {
me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount);
} else {
me.frm.doc.taxes_and_charges_deducted += flt(tax.tax_amount);
}
}
})
frappe.model.round_floats_in(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
}
this.frm.doc.base_grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total);
this.set_in_company_currency(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
}
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
precision("total_taxes_and_charges"));
this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
// Round grand total as per precision
frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
// rounded totals
if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
}
if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
this.frm.doc.base_rounded_total = Math.round(this.frm.doc.base_grand_total);
}
},
_cleanup: function() {
this.frm.doc.base_in_words = this.frm.doc.in_words = this.frm.doc.in_words = "";
this.frm.doc.base_in_words = this.frm.doc.in_words = "";
if(this.frm.doc["items"] && this.frm.doc["items"].length) {
if(!frappe.meta.get_docfield(this.frm.doc["items"][0].doctype, "item_tax_amount", this.frm.doctype)) {
@ -288,7 +378,6 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
}
}
if(this.frm.doc["taxes"] && this.frm.doc["taxes"].length) {
var temporary_fields = ["tax_amount_for_current_item", "grand_total_for_current_item",
"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
@ -307,79 +396,26 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
}
},
calculate_totals: function() {
// Changing sequence can cause roundiing issue and on-screen discrepency
var tax_count = this.frm.doc["taxes"] ? this.frm.doc["taxes"].length : 0;
this.frm.doc.base_grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.base_net_total);
this.frm.doc.base_total_taxes_and_charges = flt(this.frm.doc.base_grand_total - this.frm.doc.base_net_total,
precision("base_total_taxes_and_charges"));
if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
this.frm.doc.grand_total = (this.frm.doc.base_total_taxes_and_charges || this.frm.doc.discount_amount) ?
flt(this.frm.doc.base_grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total;
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total
+ flt(this.frm.doc.discount_amount), precision("total_taxes_and_charges"));
} else {
// other charges added/deducted
this.frm.doc.base_taxes_and_charges_added = 0.0
this.frm.doc.base_taxes_and_charges_deducted = 0.0
if(tax_count) {
this.frm.doc.base_taxes_and_charges_added = frappe.utils.sum($.map(this.frm.doc["taxes"],
function(tax) { return (tax.add_deduct_tax == "Add"
&& in_list(["Valuation and Total", "Total"], tax.category)) ?
tax.tax_amount : 0.0; }));
this.frm.doc.base_taxes_and_charges_deducted = frappe.utils.sum($.map(this.frm.doc["taxes"],
function(tax) { return (tax.add_deduct_tax == "Deduct"
&& in_list(["Valuation and Total", "Total"], tax.category)) ?
tax.tax_amount : 0.0; }));
frappe.model.round_floats_in(this.frm.doc,
["base_taxes_and_charges_added", "base_taxes_and_charges_deducted"]);
}
this.frm.doc.grand_total = flt((this.frm.doc.base_taxes_and_charges_added || this.frm.doc.base_taxes_and_charges_deducted) ?
flt(this.frm.doc.base_grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total);
this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
precision("total_taxes_and_charges"));
this.frm.doc.taxes_and_charges_added = flt(this.frm.doc.base_taxes_and_charges_added /
this.frm.doc.conversion_rate, precision("taxes_and_charges_added"));
this.frm.doc.taxes_and_charges_deducted = flt(this.frm.doc.base_taxes_and_charges_deducted /
this.frm.doc.conversion_rate, precision("taxes_and_charges_deducted"));
}
// Round grand total as per precision
this.frm.doc.base_grand_total = flt(this.frm.doc.base_grand_total, precision("base_grand_total"));
this.frm.doc.grand_total = flt(this.frm.doc.grand_total, precision("grand_total"));
// rounded totals
if(frappe.meta.get_docfield(this.frm.doc.doctype, "base_rounded_total", this.frm.doc.name)) {
this.frm.doc.base_rounded_total = Math.round(this.frm.doc.base_grand_total);
}
if(frappe.meta.get_docfield(this.frm.doc.doctype, "rounded_total", this.frm.doc.name)) {
this.frm.doc.rounded_total = Math.round(this.frm.doc.grand_total);
}
},
apply_discount_amount: function() {
var me = this;
var distributed_amount = 0.0;
if (this.frm.doc.discount_amount) {
if(!this.frm.doc.apply_discount_on)
frappe.throw(__("Please select Apply Discount On"));
this.frm.set_value("base_discount_amount",
flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
var grand_total_for_discount_amount = this.get_grand_total_for_discount_amount();
var total_for_discount_amount = this.get_total_for_discount_amount();
// calculate item amount after Discount Amount
if (grand_total_for_discount_amount) {
if (total_for_discount_amount) {
$.each(this.frm.doc["items"] || [], function(i, item) {
distributed_amount = flt(me.frm.doc.base_discount_amount) * item.base_amount / grand_total_for_discount_amount;
item.base_amount = flt(item.base_amount - distributed_amount, precision("base_amount", item));
distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
item.net_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
me.set_in_company_currency(item, ["net_rate", "net_amount"]);
});
this.discount_amount_applied = true;
@ -390,34 +426,37 @@ erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
}
},
get_grand_total_for_discount_amount: function() {
get_total_for_discount_amount: function() {
var me = this;
var total_actual_tax = 0.0;
var actual_taxes_dict = {};
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
if (tax.charge_type == "Actual")
actual_taxes_dict[tax.idx] = tax.tax_amount;
else if (actual_taxes_dict[tax.row_id] !== null) {
actual_tax_amount = flt(actual_taxes_dict[tax.row_id]) * flt(tax.rate) / 100;
actual_taxes_dict[tax.idx] = actual_tax_amount;
}
});
if(this.frm.doc.apply_discount_on == "Net Total") {
return this.frm.doc.net_total
} else {
var total_actual_tax = 0.0;
var actual_taxes_dict = {};
$.each(actual_taxes_dict, function(key, value) {
if (value)
total_actual_tax += value;
});
$.each(this.frm.doc["taxes"] || [], function(i, tax) {
if (tax.charge_type == "Actual")
actual_taxes_dict[tax.idx] = tax.tax_amount;
else if (actual_taxes_dict[tax.row_id] !== null) {
actual_tax_amount = flt(actual_taxes_dict[tax.row_id]) * flt(tax.rate) / 100;
actual_taxes_dict[tax.idx] = actual_tax_amount;
}
});
grand_total_for_discount_amount = flt(this.frm.doc.base_grand_total - total_actual_tax,
precision("base_grand_total"));
return grand_total_for_discount_amount;
$.each(actual_taxes_dict, function(key, value) {
if (value) total_actual_tax += value;
});
return flt(this.frm.doc.grand_total - total_actual_tax, precision("grand_total"));
}
},
calculate_total_advance: function(update_paid_amount) {
this.frm.doc.total_advance = flt(frappe.utils.sum(
$.map(this.frm.doc["advances"] || [], function(adv) { return adv.allocated_amount })
), precision("total_advance"));
var total_allocated_amount = frappe.utils.sum($.map(this.frm.doc["advances"] || [], function(adv) {
return flt(adv.allocated_amount, precision("allocated_amount", adv))
}));
this.frm.doc.total_advance = flt(total_allocated_amount, precision("total_advance"));
this.calculate_outstanding_amount(update_paid_amount);
}

View File

@ -274,23 +274,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
},
// tax rate
rate: function(doc, cdt, cdn) {
this.calculate_taxes_and_totals();
},
row_id: function(doc, cdt, cdn) {
var tax = frappe.get_doc(cdt, cdn);
try {
this.validate_on_previous_row(tax);
this.calculate_taxes_and_totals();
} catch(e) {
tax.row_id = null;
refresh_field("row_id", tax.name, tax.parentfield);
throw e;
}
},
set_dynamic_labels: function() {
// What TODO? should we make price list system non-mandatory?
this.frm.toggle_reqd("plc_conversion_rate",
@ -302,6 +285,113 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
this.frm.refresh_fields();
},
change_form_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency) {
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[fname] = label.trim() + " (" + currency + ")";
}
});
};
setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
"base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency);
setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
"grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted",
"rounded_total", "in_words"], this.frm.doc.currency);
cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
+ " = [?] " + company_currency)
if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
+ " = [?] " + company_currency)
}
// toggle fields
this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", "base_total_taxes_and_charges",
"base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
"base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
this.frm.doc.currency != company_currency);
this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
this.frm.doc.price_list_currency != company_currency);
// set labels
$.each(field_label_map, function(fname, label) {
me.frm.fields_dict[fname].set_label(label);
});
},
change_grid_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency, parentfield) {
var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[grid_doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[grid_doctype + "-" + fname] =
label.trim() + " (" + currency + ")";
}
});
}
setup_field_label_map(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
company_currency, "items");
setup_field_label_map(["rate", "net_rate", "price_list_rate", "amount", "net_amount"],
this.frm.doc.currency, "items");
if(this.frm.fields_dict["taxes"]) {
setup_field_label_map(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes");
setup_field_label_map(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes");
}
if(this.frm.fields_dict["advances"]) {
setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances");
}
// toggle columns
var item_grid = this.frm.fields_dict["items"].grid;
$.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
if(frappe.meta.get_docfield(item_grid.doctype, fname))
item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency);
});
var show = (cint(cur_frm.doc.discount_amount)) ||
((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
$.each(["net_rate", "net_amount"], function(i, fname) {
if(frappe.meta.get_docfield(item_grid.doctype, fname))
item_grid.set_column_disp(fname, show);
});
$.each(["base_net_rate", "base_net_amount"], function(i, fname) {
if(frappe.meta.get_docfield(item_grid.doctype, fname))
item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency)));
});
// set labels
var $wrapper = $(this.frm.wrapper);
$.each(field_label_map, function(fname, label) {
fname = fname.split("-");
var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
if(df) df.label = label;
});
},
recalculate: function() {
this.calculate_taxes_and_totals();
},
@ -409,9 +499,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
apply_price_list: function(item) {
var me = this;
var args = this._get_args(item);
if(!args.item_list.length) {
return;
}
return this.frm.call({
method: "erpnext.stock.get_item_details.apply_price_list",
args: { args: args },
@ -421,66 +509,15 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
me.frm.set_value("price_list_currency", r.message.parent.price_list_currency);
me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate);
me.in_apply_price_list = false;
me._set_values_for_item_list(r.message.children);
if(args.item_list.length) {
me._set_values_for_item_list(r.message.children);
}
}
}
});
},
included_in_print_rate: function(doc, cdt, cdn) {
var tax = frappe.get_doc(cdt, cdn);
try {
this.validate_on_previous_row(tax);
this.validate_inclusive_tax(tax);
this.calculate_taxes_and_totals();
} catch(e) {
tax.included_in_print_rate = 0;
refresh_field("included_in_print_rate", tax.name, tax.parentfield);
throw e;
}
},
validate_on_previous_row: function(tax) {
// validate if a valid row id is mentioned in case of
// On Previous Row Amount and On Previous Row Total
if((["On Previous Row Amount", "On Previous Row Total"].indexOf(tax.charge_type) != -1) &&
(!tax.row_id || cint(tax.row_id) >= tax.idx)) {
var msg = __("Please specify a valid Row ID for row {0} in table {1}", [tax.idx, __(tax.doctype)])
frappe.throw(msg);
}
},
validate_inclusive_tax: function(tax) {
var actual_type_error = function() {
var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx])
frappe.throw(msg);
};
var on_previous_row_error = function(row_range) {
var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included",
[tax.idx, __(tax.doctype), tax.charge_type, row_range])
frappe.throw(msg);
};
if(cint(tax.included_in_print_rate)) {
if(tax.charge_type == "Actual") {
// inclusive tax cannot be of type Actual
actual_type_error();
} else if(tax.charge_type == "On Previous Row Amount" &&
!cint(this.frm.doc["taxes"][tax.row_id - 1].included_in_print_rate)) {
// referred row should also be an inclusive tax
on_previous_row_error(tax.row_id);
} else if(tax.charge_type == "On Previous Row Total") {
var taxes_not_included = $.map(this.frm.doc["taxes"].slice(0, tax.row_id),
function(t) { return cint(t.included_in_print_rate) ? null : t; });
if(taxes_not_included.length > 0) {
// all rows above this tax should be inclusive
on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
}
}
}
},
get_item_wise_taxes_html: function() {
var item_tax = {};
var tax_accounts = [];
@ -560,24 +597,6 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
return valid;
},
validate_conversion_rate: function() {
this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate",
this.frm.doc.name);
var company_currency = this.get_company_currency();
if(!this.frm.doc.conversion_rate) {
frappe.throw(repl('%(conversion_rate_label)s' +
__(' is mandatory. Maybe Currency Exchange record is not created for ') +
'%(from_currency)s' + __(" to ") + '%(to_currency)s',
{
"conversion_rate_label": conversion_rate_label,
"from_currency": this.frm.doc.currency,
"to_currency": company_currency
}));
}
},
get_terms: function() {
var me = this;
if(this.frm.doc.tc_name) {
@ -656,3 +675,40 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
}
}
});
frappe.ui.form.on(cur_frm.doctype + "Item", "rate", function(frm, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
if(item.price_list_rate) {
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
} else {
item.discount_percentage = 0.0;
}
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
cur_frm.cscript.calculate_taxes_and_totals();
})
frappe.ui.form.on(cur_frm.doctype, "discount_amount", function(frm) {
cur_frm.cscript.calculate_taxes_and_totals();
})

View File

@ -111,34 +111,54 @@ erpnext.feature_setup.feature_dict = {
'Sales Order': {'items':['page_break']}
},
'fs_exports': {
'Delivery Note': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
'Delivery Note': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'POS Setting': {'fields':['conversion_rate','currency']},
'Quotation': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
'Sales Invoice': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']},
'Quotation': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Sales Invoice': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Sales BOM': {'fields':['currency']},
'Sales Order': {'fields':['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total'],'items':['base_price_list_rate','base_amount','base_rate']}
'Sales Order': {
'fields': ['conversion_rate','currency','base_grand_total','base_in_words','base_rounded_total',
'base_total', 'base_net_total', 'base_discount_amount', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}
},
'fs_imports': {
'Purchase Invoice': {
'fields': ['conversion_rate', 'currency', 'base_grand_total',
'base_in_words', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted'],
'items': ['base_price_list_rate', 'base_amount','base_rate']
'fields': ['conversion_rate', 'currency', 'base_grand_total', 'base_discount_amount',
'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Purchase Order': {
'fields': ['conversion_rate','currency', 'base_grand_total',
'base_in_words', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted'],
'items': ['base_price_list_rate', 'base_amount','base_rate']
'fields': ['conversion_rate','currency', 'base_grand_total', 'base_discount_amount',
'base_in_words', 'base_total', 'base_net_total', 'base_taxes_and_charges_added',
'base_taxes_and_charges_deducted', 'base_total_taxes_and_charges'],
'items': ['base_price_list_rate', 'base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Purchase Receipt': {
'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words',
'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted'],
'items': ['base_price_list_rate','base_amount','base_rate']
'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
'base_total_taxes_and_charges', 'base_discount_amount'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
},
'Supplier Quotation': {
'fields':['conversion_rate','currency']
'fields': ['conversion_rate', 'currency','base_grand_total', 'base_in_words', 'base_total',
'base_net_total', 'base_taxes_and_charges_added', 'base_taxes_and_charges_deducted',
'base_total_taxes_and_charges', 'base_discount_amount'],
'items': ['base_price_list_rate','base_amount','base_rate', 'base_net_rate', 'base_net_amount']
}
},

View File

@ -3,7 +3,6 @@
{% include 'selling/sales_common.js' %}
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
onload: function(doc, dt, dn) {
@ -25,7 +24,7 @@ erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({
cur_frm.add_custom_button(__('Set as Lost'),
cur_frm.cscript['Declare Order Lost'], "icon-exclamation", "btn-default");
}
}
if (this.frm.doc.docstatus===0) {
@ -159,4 +158,6 @@ cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
cur_frm.email_doc(frappe.boot.notification_settings.quotation_message);
}
frappe.ui.form.on("Quotation Item", "items_on_form_rendered", function(frm, cdt, cdn) {
// enable tax_amount field if Actual
})

View File

@ -312,9 +312,20 @@
"permlevel": 0,
"read_only": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Total (Company Currency)",
"no_copy": 0,
"oldfieldname": "net_total",
@ -331,12 +342,23 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Total",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
@ -389,6 +411,7 @@
"oldfieldtype": "Table",
"options": "Sales Taxes and Charges",
"permlevel": 0,
"print_hide": 0,
"read_only": 0
},
{
@ -430,12 +453,23 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0
"permlevel": 0,
"print_hide": 1
},
{
"fieldname": "base_discount_amount",
@ -810,7 +844,7 @@
"idx": 1,
"is_submittable": 1,
"max_attachments": 1,
"modified": "2015-02-20 05:16:20.664025",
"modified": "2015-02-23 01:18:17.421144",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation",

View File

@ -1,5 +1,5 @@
{
"autoname": "hash",
"autoname": "QUOD/.#####",
"creation": "2013-03-07 11:42:57",
"docstatus": 0,
"doctype": "DocType",
@ -187,6 +187,16 @@
"search_index": 0,
"width": "100px"
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"hidden": 0,
"label": "Net Rate",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "amount",
"fieldtype": "Currency",
@ -204,6 +214,16 @@
"search_index": 0,
"width": "100px"
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "col_break3",
"fieldtype": "Column Break",
@ -213,7 +233,7 @@
"fieldname": "base_rate",
"fieldtype": "Currency",
"in_filter": 0,
"label": "Basic Rate (Company Currency)",
"label": "Rate (Company Currency)",
"oldfieldname": "basic_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
@ -225,6 +245,15 @@
"search_index": 0,
"width": "100px"
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_amount",
"fieldtype": "Currency",
@ -241,6 +270,16 @@
"search_index": 0,
"width": "100px"
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "pricing_rule",
"fieldtype": "Link",
@ -349,7 +388,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.742936",
"modified": "2015-02-23 00:48:08.477241",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation Item",

View File

@ -2,7 +2,6 @@
// License: GNU General Public License v3. See license.txt
{% include 'selling/sales_common.js' %}
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend({
refresh: function(doc, dt, dn) {

View File

@ -325,6 +325,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -343,6 +353,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -420,6 +440,12 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_46",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_total_taxes_and_charges",
"fieldtype": "Currency",
@ -433,7 +459,23 @@
"width": "150px"
},
{
"fieldname": "column_break_46",
"fieldname": "section_break_48",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "column_break_50",
"fieldtype": "Column Break",
"permlevel": 0
},
@ -1034,7 +1076,7 @@
"idx": 1,
"is_submittable": 1,
"issingle": 0,
"modified": "2015-02-20 05:16:18.207123",
"modified": "2015-02-23 15:40:17.414233",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order",

View File

@ -1,455 +1,507 @@
{
"autoname": "hash",
"creation": "2013-03-07 11:42:58",
"docstatus": 0,
"doctype": "DocType",
"autoname": "hash",
"creation": "2013-03-07 11:42:58",
"docstatus": 0,
"doctype": "DocType",
"fields": [
{
"fieldname": "item_code",
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"label": "Item Code",
"oldfieldname": "item_code",
"oldfieldtype": "Link",
"options": "Item",
"permlevel": 0,
"print_width": "150px",
"read_only": 0,
"reqd": 1,
"search_index": 1,
"fieldname": "item_code",
"fieldtype": "Link",
"in_filter": 1,
"in_list_view": 1,
"label": "Item Code",
"oldfieldname": "item_code",
"oldfieldtype": "Link",
"options": "Item",
"permlevel": 0,
"print_width": "150px",
"read_only": 0,
"reqd": 1,
"search_index": 1,
"width": "150px"
},
},
{
"fieldname": "customer_item_code",
"fieldtype": "Data",
"hidden": 1,
"label": "Customer's Item Code",
"permlevel": 0,
"print_hide": 1,
"fieldname": "customer_item_code",
"fieldtype": "Data",
"hidden": 1,
"label": "Customer's Item Code",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
},
{
"fieldname": "col_break1",
"fieldtype": "Column Break",
"fieldname": "col_break1",
"fieldtype": "Column Break",
"permlevel": 0
},
},
{
"fieldname": "item_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Item Name",
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"print_width": "150",
"read_only": 0,
"reqd": 1,
"fieldname": "item_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Item Name",
"oldfieldname": "item_name",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"print_width": "150",
"read_only": 0,
"reqd": 1,
"width": "150"
},
},
{
"fieldname": "section_break_5",
"fieldtype": "Section Break",
"permlevel": 0,
"fieldname": "section_break_5",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
},
{
"fieldname": "description",
"fieldtype": "Small Text",
"in_filter": 1,
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_width": "300px",
"read_only": 0,
"reqd": 1,
"search_index": 1,
"fieldname": "description",
"fieldtype": "Small Text",
"in_filter": 1,
"in_list_view": 1,
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_width": "300px",
"read_only": 0,
"reqd": 1,
"search_index": 1,
"width": "300px"
},
},
{
"fieldname": "column_break_7",
"fieldtype": "Column Break",
"permlevel": 0,
"fieldname": "column_break_7",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
},
{
"fieldname": "image",
"fieldtype": "Attach",
"hidden": 1,
"label": "Image",
"permlevel": 0,
"precision": "",
"fieldname": "image",
"fieldtype": "Attach",
"hidden": 1,
"label": "Image",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
},
{
"fieldname": "image_view",
"fieldtype": "Image",
"label": "Image View",
"options": "image",
"permlevel": 0,
"fieldname": "image_view",
"fieldtype": "Image",
"label": "Image View",
"options": "image",
"permlevel": 0,
"precision": ""
},
},
{
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate",
"fieldname": "quantity_and_rate",
"fieldtype": "Section Break",
"label": "Quantity and Rate",
"permlevel": 0
},
},
{
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Quantity",
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"fieldname": "qty",
"fieldtype": "Float",
"in_list_view": 1,
"label": "Quantity",
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 1,
"width": "100px"
},
},
{
"fieldname": "price_list_rate",
"fieldtype": "Currency",
"label": "Price List Rate",
"oldfieldname": "ref_rate",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"reqd": 0,
"fieldname": "price_list_rate",
"fieldtype": "Currency",
"label": "Price List Rate",
"oldfieldname": "ref_rate",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"reqd": 0,
"width": "70px"
},
},
{
"fieldname": "discount_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Discount(%)",
"oldfieldname": "adj_rate",
"oldfieldtype": "Float",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 0,
"fieldname": "discount_percentage",
"fieldtype": "Percent",
"in_list_view": 1,
"label": "Discount(%)",
"oldfieldname": "adj_rate",
"oldfieldtype": "Float",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 0,
"width": "70px"
},
},
{
"fieldname": "col_break2",
"fieldtype": "Column Break",
"fieldname": "col_break2",
"fieldtype": "Column Break",
"permlevel": 0
},
},
{
"fieldname": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"permlevel": 0,
"print_width": "70px",
"read_only": 1,
"reqd": 0,
"fieldname": "stock_uom",
"fieldtype": "Link",
"hidden": 0,
"in_list_view": 1,
"label": "UOM",
"oldfieldname": "stock_uom",
"oldfieldtype": "Data",
"options": "UOM",
"permlevel": 0,
"print_width": "70px",
"read_only": 1,
"reqd": 0,
"width": "70px"
},
},
{
"fieldname": "base_price_list_rate",
"fieldtype": "Currency",
"label": "Price List Rate (Company Currency)",
"oldfieldname": "base_ref_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"fieldname": "base_price_list_rate",
"fieldtype": "Currency",
"label": "Price List Rate (Company Currency)",
"oldfieldname": "base_ref_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"width": "100px"
},
},
{
"fieldname": "section_break_simple1",
"fieldtype": "Section Break",
"fieldname": "section_break_simple1",
"fieldtype": "Section Break",
"permlevel": 0
},
},
{
"fieldname": "rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Rate",
"oldfieldname": "export_rate",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 0,
"fieldname": "rate",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Rate",
"oldfieldname": "export_rate",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 0,
"reqd": 0,
"width": "100px"
},
},
{
"fieldname": "amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount",
"no_copy": 0,
"oldfieldname": "export_amount",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"fieldname": "amount",
"fieldtype": "Currency",
"in_list_view": 1,
"label": "Amount",
"no_copy": 0,
"oldfieldname": "export_amount",
"oldfieldtype": "Currency",
"options": "currency",
"permlevel": 0,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"width": "100px"
},
},
{
"fieldname": "col_break3",
"fieldtype": "Column Break",
"fieldname": "col_break3",
"fieldtype": "Column Break",
"permlevel": 0
},
},
{
"fieldname": "base_rate",
"fieldtype": "Currency",
"label": "Basic Rate (Company Currency)",
"oldfieldname": "basic_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"fieldname": "base_rate",
"fieldtype": "Currency",
"label": "Basic Rate (Company Currency)",
"oldfieldname": "basic_rate",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"width": "100px"
},
},
{
"fieldname": "base_amount",
"fieldtype": "Currency",
"label": "Amount (Company Currency)",
"no_copy": 0,
"oldfieldname": "amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"fieldname": "base_amount",
"fieldtype": "Currency",
"label": "Amount (Company Currency)",
"no_copy": 0,
"oldfieldname": "amount",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"reqd": 0,
"width": "100px"
},
},
{
"fieldname": "pricing_rule",
"fieldtype": "Link",
"label": "Pricing Rule",
"options": "Pricing Rule",
"permlevel": 0,
"fieldname": "pricing_rule",
"fieldtype": "Link",
"label": "Pricing Rule",
"options": "Pricing Rule",
"permlevel": 0,
"read_only": 1
},
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
"label": "Warehouse and Reference",
"fieldname": "section_break_24",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_27",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
"label": "Warehouse and Reference",
"permlevel": 0
},
},
{
"fieldname": "warehouse",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Reserved Warehouse",
"no_copy": 0,
"oldfieldname": "reserved_warehouse",
"oldfieldtype": "Link",
"options": "Warehouse",
"permlevel": 0,
"print_hide": 1,
"print_width": "150px",
"read_only": 0,
"reqd": 0,
"fieldname": "warehouse",
"fieldtype": "Link",
"in_list_view": 1,
"label": "Reserved Warehouse",
"no_copy": 0,
"oldfieldname": "reserved_warehouse",
"oldfieldtype": "Link",
"options": "Warehouse",
"permlevel": 0,
"print_hide": 1,
"print_width": "150px",
"read_only": 0,
"reqd": 0,
"width": "150px"
},
},
{
"fieldname": "prevdoc_docname",
"fieldtype": "Link",
"hidden": 0,
"in_filter": 1,
"label": "Quotation",
"no_copy": 1,
"oldfieldname": "prevdoc_docname",
"oldfieldtype": "Link",
"options": "Quotation",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"fieldname": "prevdoc_docname",
"fieldtype": "Link",
"hidden": 0,
"in_filter": 1,
"label": "Quotation",
"no_copy": 1,
"oldfieldname": "prevdoc_docname",
"oldfieldtype": "Link",
"options": "Quotation",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
},
{
"fieldname": "brand",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Brand Name",
"oldfieldname": "brand",
"oldfieldtype": "Link",
"options": "Brand",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"fieldname": "brand",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Brand Name",
"oldfieldname": "brand",
"oldfieldtype": "Link",
"options": "Brand",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
},
{
"description": "",
"fieldname": "item_group",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Item Group",
"oldfieldname": "item_group",
"oldfieldtype": "Link",
"options": "Item Group",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"description": "",
"fieldname": "item_group",
"fieldtype": "Link",
"hidden": 1,
"in_filter": 1,
"label": "Item Group",
"oldfieldname": "item_group",
"oldfieldtype": "Link",
"options": "Item Group",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"search_index": 1
},
},
{
"allow_on_submit": 1,
"fieldname": "page_break",
"fieldtype": "Check",
"label": "Page Break",
"oldfieldname": "page_break",
"oldfieldtype": "Check",
"permlevel": 0,
"print_hide": 1,
"read_only": 0,
"allow_on_submit": 1,
"fieldname": "page_break",
"fieldtype": "Check",
"label": "Page Break",
"oldfieldname": "page_break",
"oldfieldtype": "Check",
"permlevel": 0,
"print_hide": 1,
"read_only": 0,
"report_hide": 1
},
},
{
"fieldname": "col_break4",
"fieldtype": "Column Break",
"fieldname": "col_break4",
"fieldtype": "Column Break",
"permlevel": 0
},
},
{
"allow_on_submit": 1,
"fieldname": "projected_qty",
"fieldtype": "Float",
"hidden": 0,
"label": "Projected Qty",
"no_copy": 1,
"oldfieldname": "projected_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"allow_on_submit": 1,
"fieldname": "projected_qty",
"fieldtype": "Float",
"hidden": 0,
"label": "Projected Qty",
"no_copy": 1,
"oldfieldname": "projected_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"width": "70px"
},
},
{
"allow_on_submit": 1,
"fieldname": "actual_qty",
"fieldtype": "Float",
"label": "Actual Qty",
"no_copy": 1,
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"allow_on_submit": 1,
"fieldname": "actual_qty",
"fieldtype": "Float",
"label": "Actual Qty",
"no_copy": 1,
"permlevel": 0,
"print_hide": 1,
"print_width": "70px",
"read_only": 1,
"width": "70px"
},
},
{
"fieldname": "delivered_qty",
"fieldtype": "Float",
"hidden": 0,
"in_filter": 0,
"label": "Delivered Qty",
"no_copy": 1,
"oldfieldname": "delivered_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"search_index": 0,
"fieldname": "delivered_qty",
"fieldtype": "Float",
"hidden": 0,
"in_filter": 0,
"label": "Delivered Qty",
"no_copy": 1,
"oldfieldname": "delivered_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "100px",
"read_only": 1,
"search_index": 0,
"width": "100px"
},
},
{
"fieldname": "billed_amt",
"fieldtype": "Currency",
"label": "Billed Amt",
"no_copy": 1,
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"fieldname": "billed_amt",
"fieldtype": "Currency",
"label": "Billed Amt",
"no_copy": 1,
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
},
{
"description": "For Production",
"fieldname": "planned_qty",
"fieldtype": "Float",
"hidden": 1,
"label": "Planned Quantity",
"no_copy": 1,
"oldfieldname": "planned_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "50px",
"read_only": 1,
"report_hide": 1,
"description": "For Production",
"fieldname": "planned_qty",
"fieldtype": "Float",
"hidden": 1,
"label": "Planned Quantity",
"no_copy": 1,
"oldfieldname": "planned_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "50px",
"read_only": 1,
"report_hide": 1,
"width": "50px"
},
},
{
"description": "For Production",
"fieldname": "produced_qty",
"fieldtype": "Float",
"hidden": 1,
"label": "Produced Quantity",
"oldfieldname": "produced_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "50px",
"read_only": 1,
"report_hide": 1,
"description": "For Production",
"fieldname": "produced_qty",
"fieldtype": "Float",
"hidden": 1,
"label": "Produced Quantity",
"oldfieldname": "produced_qty",
"oldfieldtype": "Currency",
"permlevel": 0,
"print_hide": 1,
"print_width": "50px",
"read_only": 1,
"report_hide": 1,
"width": "50px"
},
},
{
"fieldname": "item_tax_rate",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Item Tax Rate",
"oldfieldname": "item_tax_rate",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"fieldname": "item_tax_rate",
"fieldtype": "Small Text",
"hidden": 1,
"label": "Item Tax Rate",
"oldfieldname": "item_tax_rate",
"oldfieldtype": "Small Text",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 1
},
},
{
"description": "Used for Production Plan",
"fieldname": "transaction_date",
"fieldtype": "Date",
"hidden": 1,
"in_filter": 0,
"label": "Sales Order Date",
"oldfieldname": "transaction_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 1,
"description": "Used for Production Plan",
"fieldname": "transaction_date",
"fieldtype": "Date",
"hidden": 1,
"in_filter": 0,
"label": "Sales Order Date",
"oldfieldname": "transaction_date",
"oldfieldtype": "Date",
"permlevel": 0,
"print_hide": 1,
"read_only": 1,
"report_hide": 1,
"search_index": 0
}
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:02.025024",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
],
"idx": 1,
"istable": 1,
"modified": "2015-02-23 15:43:08.156543",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
}
}

View File

@ -204,7 +204,7 @@ erpnext.SalesAnalytics = frappe.views.TreeGridReport.extend({
if (posting_date >= from_date && posting_date <= to_date) {
var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
me.item_by_name['Not Set'];
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_amount : tl.qty);
item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
}
}
});

View File

@ -82,7 +82,7 @@ def get_target_distribution_details(filters):
def get_achieved_details(filters):
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date,
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
st.sales_person, MONTHNAME(so.transaction_date) as month_name
from `tabSales Order Item` soi, `tabSales Order` so, `tabSales Team` st
where soi.parent=so.name and so.docstatus=1 and
@ -125,7 +125,7 @@ def get_salesperson_item_month_map(filters):
if (filters["target_on"] == "Amount"):
tav_dict.target = flt(sd.target_amount) * month_percentage / 100
if ad.month_name == month:
tav_dict.achieved += ad.base_amount
tav_dict.achieved += ad.base_net_amount
return sim_map

View File

@ -16,7 +16,7 @@ def execute(filters=None):
data.append([
d.name, d.customer, d.territory, d.posting_date, d.item_code,
item_details.get(d.item_code, {}).get("item_group"), item_details.get(d.item_code, {}).get("brand"),
d.qty, d.base_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
d.qty, d.base_net_amount, d.sales_person, d.allocated_percentage, d.contribution_amt
])
return columns, data
@ -36,8 +36,8 @@ def get_entries(filters):
date_field = filters["doc_type"] == "Sales Order" and "transaction_date" or "posting_date"
conditions, items = get_conditions(filters, date_field)
entries = frappe.db.sql("""select dt.name, dt.customer, dt.territory, dt.%s as posting_date,
dt_item.item_code, dt_item.qty, dt_item.base_amount, st.sales_person,
st.allocated_percentage, dt_item.base_amount*st.allocated_percentage/100 as contribution_amt
dt_item.item_code, dt_item.qty, dt_item.base_net_amount, st.sales_person,
st.allocated_percentage, dt_item.base_net_amount*st.allocated_percentage/100 as contribution_amt
from `tab%s` dt, `tab%s Item` dt_item, `tabSales Team` st
where st.parent = dt.name and dt.name = dt_item.parent and st.parenttype = %s
and dt.docstatus = 1 %s order by st.sales_person, dt.name desc""" %

View File

@ -5,7 +5,6 @@ from __future__ import unicode_literals
import frappe
from frappe import _, msgprint
from frappe.utils import flt
import time
from erpnext.accounts.utils import get_fiscal_year
from erpnext.controllers.trends import get_period_date_ranges, get_period_month_ranges
@ -81,7 +80,7 @@ def get_target_distribution_details(filters):
def get_achieved_details(filters):
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_amount, so.transaction_date,
item_details = frappe.db.sql("""select soi.item_code, soi.qty, soi.base_net_amount, so.transaction_date,
so.territory, MONTHNAME(so.transaction_date) as month_name
from `tabSales Order Item` soi, `tabSales Order` so
where soi.parent=so.name and so.docstatus=1 and so.transaction_date>=%s and
@ -125,7 +124,7 @@ def get_territory_item_month_map(filters):
if (filters["target_on"] == "Amount"):
tav_dict.target = flt(td.target_amount) * month_percentage / 100
if ad.month_name == month:
tav_dict.achieved += ad.base_amount
tav_dict.achieved += ad.base_net_amount
return tim_map

View File

@ -2,11 +2,12 @@
// License: GNU General Public License v3. See license.txt
cur_frm.cscript.tax_table = "Sales Taxes and Charges";
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
frappe.provide("erpnext.selling");
frappe.require("assets/erpnext/js/controllers/transaction.js");
{% include "public/js/controllers/accounts.js" %};
cur_frm.email_field = "contact_email";
erpnext.selling.SellingController = erpnext.TransactionController.extend({
@ -16,10 +17,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
this.toggle_editable_price_list_rate();
},
onload_post_render: function() {
cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
},
setup_queries: function() {
var me = this;
@ -154,24 +151,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
},
rate: function(doc, cdt, cdn) {
var item = frappe.get_doc(cdt, cdn);
frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
if(item.price_list_rate) {
item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0,
precision("discount_percentage", item));
} else {
item.discount_percentage = 0.0;
}
this.calculate_taxes_and_totals();
},
discount_amount: function() {
this.calculate_taxes_and_totals();
},
commission_rate: function() {
this.calculate_commission();
refresh_field("total_commission");
@ -321,98 +300,6 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
}
refresh_field('sales_bom_help');
},
change_form_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency) {
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[fname] = label.trim() + " (" + currency + ")";
}
});
};
setup_field_label_map(["base_net_total", "base_total_taxes_and_charges", "base_discount_amount", "base_grand_total",
"base_rounded_total", "base_in_words",
"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"],
company_currency);
setup_field_label_map(["net_total", "total_taxes_and_charges", "discount_amount", "grand_total",
"rounded_total", "in_words"], this.frm.doc.currency);
cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
+ " = [?] " + company_currency)
if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
+ " = [?] " + company_currency)
}
// toggle fields
this.frm.toggle_display(["conversion_rate", "base_net_total", "base_total_taxes_and_charges",
"base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
this.frm.doc.currency != company_currency);
this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
this.frm.doc.price_list_currency != company_currency);
// set labels
$.each(field_label_map, function(fname, label) {
me.frm.fields_dict[fname].set_label(label);
});
},
change_grid_labels: function(company_currency) {
var me = this;
var field_label_map = {};
var setup_field_label_map = function(fields_list, currency, parentfield) {
var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
$.each(fields_list, function(i, fname) {
var docfield = frappe.meta.docfield_map[grid_doctype][fname];
if(docfield) {
var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
field_label_map[grid_doctype + "-" + fname] =
label.trim() + " (" + currency + ")";
}
});
}
setup_field_label_map(["base_rate", "base_price_list_rate", "base_amount"],
company_currency, "items");
setup_field_label_map(["rate", "price_list_rate", "amount"],
this.frm.doc.currency, "items");
setup_field_label_map(["tax_amount", "total"], company_currency, "taxes");
if(this.frm.fields_dict["advances"]) {
setup_field_label_map(["advance_amount", "allocated_amount"], company_currency,
"advances");
}
// toggle columns
var item_grid = this.frm.fields_dict["items"].grid;
var show = (this.frm.doc.currency != company_currency) ||
((cur_frm.doc.taxes || []).filter(
function(d) { return d.included_in_print_rate===1}).length);
$.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
if(frappe.meta.get_docfield(item_grid.doctype, fname))
item_grid.set_column_disp(fname, show);
});
// set labels
var $wrapper = $(this.frm.wrapper);
$.each(field_label_map, function(fname, label) {
fname = fname.split("-");
var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
if(df) df.label = label;
});
}
});

View File

@ -8,11 +8,8 @@ import unittest
class TestCompany(unittest.TestCase):
def atest_coa(self):
for country, chart_name in frappe.db.sql("""select country, chart_name
for country, chart_name in frappe.db.sql("""select country, chart_name
from `tabChart of Accounts` where name = 'Deutscher Kontenplan SKR03'""", as_list=1):
print "Country: ", country
print "Chart Name: ", chart_name
company_doc = frappe.get_doc({
"doctype": "Company",
"company_name": "_Test Company 2",
@ -23,10 +20,10 @@ class TestCompany(unittest.TestCase):
})
company_doc.insert()
self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
where company='_Test Company 2'""")[0][0] > 10)
frappe.delete_doc("Company", "_Test Company 2")
test_records = frappe.get_test_records('Company')
frappe.delete_doc("Company", "_Test Company 2")
test_records = frappe.get_test_records('Company')

View File

@ -141,7 +141,7 @@ def decorate_quotation_doc(quotation_doc):
d["formatted_amount"] = fmt_money(d.get("amount"), currency=doc.currency)
for d in doc.get("taxes", []):
d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount")) / doc.conversion_rate,
d["formatted_tax_amount"] = fmt_money(flt(d.get("tax_amount_after_discount_amount")),
currency=doc.currency)
doc.formatted_grand_total_export = fmt_money(doc.grand_total,

View File

@ -174,7 +174,7 @@ data_map = {
}
},
"Sales Invoice Item": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
@ -192,7 +192,7 @@ data_map = {
}
},
"Sales Order Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
@ -210,7 +210,7 @@ data_map = {
}
},
"Delivery Note Item[Sales Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
@ -242,7 +242,7 @@ data_map = {
}
},
"Purchase Invoice Item": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
@ -260,7 +260,7 @@ data_map = {
}
},
"Purchase Order Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {
@ -278,7 +278,7 @@ data_map = {
}
},
"Purchase Receipt Item[Purchase Analytics]": {
"columns": ["name", "parent", "item_code", "qty", "base_amount"],
"columns": ["name", "parent", "item_code", "qty", "base_net_amount"],
"conditions": ["docstatus=1", "ifnull(parent, '')!=''"],
"order_by": "parent",
"links": {

View File

@ -2,7 +2,6 @@
// License: GNU General Public License v3. See license.txt
{% include 'selling/sales_common.js' %};
{% include 'accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js' %}
frappe.provide("erpnext.stock");
frappe.provide("erpnext.stock.delivery_note");
@ -25,7 +24,7 @@ erpnext.stock.DeliveryNoteController = erpnext.selling.SellingController.extend(
cur_frm.add_custom_button(__('Make Installation Note'), this.make_installation_note);
if (doc.docstatus==1) {
this.show_stock_ledger();
this.show_general_ledger();
}
@ -131,6 +130,7 @@ erpnext.stock.delivery_note.set_print_hide = function(doc, cdt, cdn){
dn_item_fields['discount_percentage'].print_hide = 1;
dn_item_fields['price_list_rate'].print_hide = 1;
dn_item_fields['amount'].print_hide = 1;
dn_fields['taxes'].print_hide = 1;
} else {
if (dn_fields_copy['currency'].print_hide != 1)
dn_fields['currency'].print_hide = 0;
@ -138,6 +138,8 @@ erpnext.stock.delivery_note.set_print_hide = function(doc, cdt, cdn){
dn_item_fields['rate'].print_hide = 0;
if (dn_item_fields_copy['amount'].print_hide != 1)
dn_item_fields['amount'].print_hide = 0;
if (dn_fields_copy['taxes'].print_hide != 1)
dn_fields['taxes'].print_hide = 0;
}
}

View File

@ -340,6 +340,16 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -360,6 +370,16 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -443,6 +463,12 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_47",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_total_taxes_and_charges",
"fieldtype": "Currency",
@ -457,7 +483,22 @@
"width": "150px"
},
{
"fieldname": "column_break_47",
"fieldname": "section_break_49",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "column_break_51",
"fieldtype": "Column Break",
"permlevel": 0
},
@ -1024,7 +1065,7 @@
"idx": 1,
"in_create": 0,
"is_submittable": 1,
"modified": "2015-02-20 05:16:21.997931",
"modified": "2015-02-23 15:49:10.972483",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note",

View File

@ -254,6 +254,58 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_25",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_28",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
@ -442,17 +494,6 @@
"read_only": 1,
"width": "150px"
},
{
"fieldname": "buying_amount",
"fieldtype": "Currency",
"hidden": 1,
"label": "Buying Amount",
"no_copy": 1,
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"allow_on_submit": 1,
"fieldname": "page_break",
@ -467,7 +508,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:06:59.675246",
"modified": "2015-02-23 15:51:20.772564",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note Item",

View File

@ -2,7 +2,6 @@
// License: GNU General Public License v3. See license.txt
{% include 'buying/doctype/purchase_common/purchase_common.js' %};
{% include 'accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js' %}
frappe.provide("erpnext.stock");
erpnext.stock.PurchaseReceiptController = erpnext.buying.BuyingController.extend({

View File

@ -222,12 +222,31 @@
"print_hide": 0,
"reqd": 0
},
{
"fieldname": "get_current_stock",
"fieldtype": "Button",
"label": "Get Current Stock",
"oldfieldtype": "Button",
"options": "get_current_stock",
"permlevel": 0,
"print_hide": 1
},
{
"fieldname": "section_break0",
"fieldtype": "Section Break",
"oldfieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "base_total",
"fieldtype": "Currency",
"label": "Total (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_total",
"fieldtype": "Currency",
@ -242,20 +261,22 @@
"reqd": 1,
"width": "150px"
},
{
"fieldname": "get_current_stock",
"fieldtype": "Button",
"label": "Get Current Stock",
"oldfieldtype": "Button",
"options": "get_current_stock",
"permlevel": 0,
"print_hide": 1
},
{
"fieldname": "column_break_27",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "total",
"fieldtype": "Currency",
"hidden": 0,
"label": "Total",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_total",
"fieldtype": "Currency",
@ -346,39 +367,6 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_rounded_total",
"fieldtype": "Currency",
"label": "Rounded Total (Company Currency)",
"oldfieldname": "rounded_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Receipt.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break3",
"fieldtype": "Column Break",
@ -416,6 +404,92 @@
"permlevel": 0,
"precision": ""
},
{
"fieldname": "section_break_42",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"default": "Grand Total",
"fieldname": "apply_discount_on",
"fieldtype": "Select",
"label": "Apply Discount On",
"options": "\nGrand Total\nNet Total",
"permlevel": 0,
"precision": "",
"print_hide": 1
},
{
"fieldname": "column_break_44",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 0
},
{
"fieldname": "base_discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"read_only": 1
},
{
"fieldname": "section_break_46",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_grand_total",
"fieldtype": "Currency",
"label": "Grand Total (Company Currency)",
"oldfieldname": "grand_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"description": "In Words will be visible once you save the Purchase Receipt.",
"fieldname": "base_in_words",
"fieldtype": "Data",
"label": "In Words (Company Currency)",
"oldfieldname": "in_words",
"oldfieldtype": "Data",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_rounded_total",
"fieldtype": "Currency",
"label": "Rounded Total (Company Currency)",
"oldfieldname": "rounded_total",
"oldfieldtype": "Currency",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_50",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "grand_total",
"fieldtype": "Currency",
@ -775,7 +849,7 @@
"icon": "icon-truck",
"idx": 1,
"is_submittable": 1,
"modified": "2015-02-20 05:16:24.035630",
"modified": "2015-02-23 15:16:36.617354",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt",

View File

@ -295,7 +295,7 @@ class PurchaseReceipt(BuyingController):
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"debit": flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
self.precision("base_amount", d))
self.precision("base_net_amount", d))
}))
# stock received but not billed
@ -304,7 +304,7 @@ class PurchaseReceipt(BuyingController):
"against": warehouse_account[d.warehouse],
"cost_center": d.cost_center,
"remarks": self.get("remarks") or _("Accounting Entry for Stock"),
"credit": flt(d.base_amount, self.precision("base_amount", d))
"credit": flt(d.base_net_amount, self.precision("base_net_amount", d))
}))
negative_expense_to_be_booked += flt(d.item_tax_amount)
@ -330,14 +330,14 @@ class PurchaseReceipt(BuyingController):
}))
# divisional loss adjustment
if not self.get("other_charges"):
if not self.get("taxes"):
sle_valuation_amount = flt(flt(d.valuation_rate, val_rate_db_precision) * flt(d.qty) * flt(d.conversion_factor),
self.precision("base_amount", d))
self.precision("base_net_amount", d))
distributed_amount = flt(flt(d.base_amount, self.precision("base_amount", d))) + \
distributed_amount = flt(flt(d.base_net_amount, self.precision("base_net_amount", d))) + \
flt(d.landed_cost_voucher_amount) + flt(d.rm_supp_cost)
divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_amount", d))
divisional_loss = flt(distributed_amount - sle_valuation_amount, self.precision("base_net_amount", d))
if divisional_loss:
gl_entries.append(self.get_gl_dict({
"account": stock_rbnb,
@ -354,12 +354,12 @@ class PurchaseReceipt(BuyingController):
# Cost center-wise amount breakup for other charges included for valuation
valuation_tax = {}
for tax in self.get("taxes"):
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.tax_amount):
if tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
if not tax.cost_center:
frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
valuation_tax.setdefault(tax.cost_center, 0)
valuation_tax[tax.cost_center] += \
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.tax_amount)
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
if negative_expense_to_be_booked and valuation_tax:
# Backward compatibility:

View File

@ -283,6 +283,58 @@
"permlevel": 0,
"read_only": 1
},
{
"fieldname": "section_break_29",
"fieldtype": "Section Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "net_rate",
"fieldtype": "Currency",
"label": "Net Rate",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "net_amount",
"fieldtype": "Currency",
"label": "Net Amount",
"options": "currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_32",
"fieldtype": "Column Break",
"permlevel": 0,
"precision": ""
},
{
"fieldname": "base_net_rate",
"fieldtype": "Currency",
"label": "Net Rate (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "base_net_amount",
"fieldtype": "Currency",
"label": "Net Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "warehouse_and_reference",
"fieldtype": "Section Break",
@ -588,7 +640,7 @@
],
"idx": 1,
"istable": 1,
"modified": "2015-02-19 01:07:01.405923",
"modified": "2015-02-23 15:19:26.294450",
"modified_by": "Administrator",
"module": "Stock",
"name": "Purchase Receipt Item",

View File

@ -53,7 +53,7 @@ class StockLedgerEntry(Document):
def validate_item(self):
item_det = frappe.db.sql("""select name, has_batch_no, docstatus,
is_stock_item, has_variants
is_stock_item, has_variants, stock_uom
from tabItem where name=%s""", self.item_code, as_dict=True)[0]
if item_det.is_stock_item != 'Yes':

View File

@ -170,6 +170,8 @@ def get_basic_details(args, item):
"base_rate": 0.0,
"amount": 0.0,
"base_amount": 0.0,
"net_rate": 0.0,
"net_amount": 0.0,
"discount_percentage": 0.0
})

View File

@ -1,6 +1,21 @@
{%- macro render_discount_amount(doc) -%}
{%- if doc.discount_amount -%}
<div class="row">
<div class="col-xs-5 text-right">
<label>{{ "Discount Amount" }}</label></div>
<div class="col-xs-7 text-right">
- {{ doc.get_formatted("discount_amount", doc) }}
</div>
</div>
{%- endif -%}
{%- endmacro -%}
<div class="row">
<div class="col-xs-6"></div>
<div class="col-xs-6">
{%- if doc.apply_discount_on == "Net Total" -%}
{{ render_discount_amount(doc) }}
{%- endif -%}
{%- for charge in data -%}
{%- if not charge.included_in_print_rate -%}
<div class="row">
@ -13,5 +28,8 @@
</div>
{%- endif -%}
{%- endfor -%}
{%- if doc.apply_discount_on == "Grand Total" -%}
{{ render_discount_amount(doc) }}
{%- endif -%}
</div>
</div>