Merge pull request #2576 from nabinhait/fix1

Discount amount in party currency
This commit is contained in:
Nabin Hait 2015-01-14 11:27:30 +05:30
commit 56e04e0727
12 changed files with 132 additions and 71 deletions

View File

@ -422,6 +422,15 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Total Taxes and Charges",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "other_charges_total",
"fieldtype": "Currency",
@ -438,23 +447,24 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Total Taxes and Charges",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "Company:company:default_currency",
"options": "currency",
"permlevel": 0,
"print_hide": 0
},
{
"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",
"fieldtype": "Section Break",
@ -1192,7 +1202,7 @@
"icon": "icon-file-text",
"idx": 1,
"is_submittable": 1,
"modified": "2014-12-11 16:26:12.402110",
"modified": "2015-01-12 17:34:36.353241",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",

View File

@ -46,17 +46,17 @@ cur_frm.pformat.other_charges= function(doc){
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.other_charges || [];
// outer table
// outer table
var out='<div><table class="noborder" style="width:100%"><tr><td style="width: 60%"></td><td>';
// main table
@ -77,12 +77,12 @@ cur_frm.pformat.other_charges= function(doc){
// Discount Amount
if(!print_hide('discount_amount') && doc.discount_amount)
out += make_row('Discount Amount', convert_rate(doc.discount_amount), 0);
out += make_row('Discount Amount', doc.discount_amount, 0);
// grand total
if(!print_hide('grand_total_export'))
out += make_row('Grand Total', doc.grand_total_export, 1);
if(!print_hide('rounded_total_export'))
out += make_row('Rounded Total', doc.rounded_total_export, 1);
@ -92,7 +92,7 @@ cur_frm.pformat.other_charges= function(doc){
out += '<table><tr><td style="width:25%;"><b>In Words</b></td>';
out += '<td style="width:50%;">' + doc.in_words_export + '</td></tr>';
}
out += '</table></td></tr></table></div>';
out += '</table></td></tr></table></div>';
}
return out;
}
@ -139,14 +139,14 @@ cur_frm.fields_dict['other_charges'].grid.get_field("account_head").get_query =
"account_type": ["Tax", "Chargeable", "Income Account"],
"company": doc.company
}
}
}
}
cur_frm.fields_dict['other_charges'].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) {

View File

@ -295,7 +295,7 @@ class AccountsController(TransactionBase):
self.precision("tax_amount", tax))
def adjust_discount_amount_loss(self, tax):
discount_amount_loss = self.grand_total - flt(self.discount_amount) - tax.total
discount_amount_loss = self.grand_total - flt(self.base_discount_amount) - tax.total
tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
discount_amount_loss, self.precision("tax_amount", tax))
tax.total = flt(tax.total + discount_amount_loss, self.precision("total", tax))

View File

@ -218,8 +218,7 @@ class SellingController(StockController):
def calculate_totals(self):
self.grand_total = flt(self.tax_doclist[-1].total if self.tax_doclist else self.net_total)
self.grand_total_export = flt(self.grand_total / self.conversion_rate) \
if self.tax_doclist else self.net_total_export
self.grand_total_export = flt(self.grand_total / self.conversion_rate)
self.other_charges_total = flt(self.grand_total - self.net_total, self.precision("other_charges_total"))
@ -234,16 +233,20 @@ class SellingController(StockController):
def apply_discount_amount(self):
if self.discount_amount:
self.base_discount_amount = flt(self.discount_amount * self.conversion_rate, self.precision("base_discount_amount"))
grand_total_for_discount_amount = self.get_grand_total_for_discount_amount()
if grand_total_for_discount_amount:
# calculate item amount after Discount Amount
for item in self.item_doclist:
distributed_amount = flt(self.discount_amount) * item.base_amount / grand_total_for_discount_amount
distributed_amount = flt(self.base_discount_amount) * item.base_amount / grand_total_for_discount_amount
item.base_amount = flt(item.base_amount - distributed_amount, self.precision("base_amount", item))
self.discount_amount_applied = True
self._calculate_taxes_and_totals()
else:
self.base_discount_amount = 0
def get_grand_total_for_discount_amount(self):
actual_taxes_dict = {}

View File

@ -90,3 +90,4 @@ erpnext.patches.v4_2.fix_gl_entries_for_stock_transactions
erpnext.patches.v4_2.update_requested_and_ordered_qty
execute:frappe.delete_doc("DocType", "Contact Control")
erpnext.patches.v4_2.recalculate_bom_costs
erpnext.patches.v4_2.discount_amount

View File

@ -0,0 +1,12 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe
from frappe.modules import scrub, get_doctype_module
def execute():
for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales invoice"]:
frappe.reload_doc(get_doctype_module(dt), "doctype", scrub(dt))
frappe.db.sql("""update `tab{0}` set base_discount_amount=discount_amount,
discount_amount=discount_amount/conversion_rate""".format(dt))

View File

@ -734,7 +734,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
},
adjust_discount_amount_loss: function(tax) {
var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.base_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));
@ -748,8 +748,7 @@ erpnext.TransactionController = erpnext.stock.StockController.extend({
// distribute the tax amount proportionally to each item row
var actual = flt(tax.rate, precision("tax_amount", tax));
current_tax_amount = this.frm.doc.net_total ?
((item.base_amount / this.frm.doc.net_total) * actual) :
0.0;
((item.base_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;

View File

@ -405,6 +405,15 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Taxes and Charges Total",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "other_charges_total",
"fieldtype": "Currency",
@ -421,22 +430,23 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Taxes and Charges Total",
"options": "currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "Company:company:default_currency",
"options": "currency",
"permlevel": 0
},
{
"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",
"fieldtype": "Section Break",
@ -832,7 +842,7 @@
"idx": 1,
"is_submittable": 1,
"max_attachments": 1,
"modified": "2014-09-09 05:35:33.413559",
"modified": "2015-01-12 16:57:14.706270",
"modified_by": "Administrator",
"module": "Selling",
"name": "Quotation",

View File

@ -420,11 +420,6 @@
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break_46",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total",
"fieldtype": "Currency",
@ -437,12 +432,28 @@
"read_only": 1,
"width": "150px"
},
{
"fieldname": "column_break_46",
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "currency",
"permlevel": 0,
"print_hide": 0
},
{
"fieldname": "base_discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount (Company Currency)",
"options": "Company:company:default_currency",
"permlevel": 0
"permlevel": 0,
"precision": "",
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "totals",
@ -490,14 +501,6 @@
"read_only": 1,
"width": "200px"
},
{
"fieldname": "advance_paid",
"fieldtype": "Currency",
"label": "Advance Paid",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "column_break3",
"fieldtype": "Column Break",
@ -542,6 +545,15 @@
"read_only": 1,
"width": "200px"
},
{
"fieldname": "advance_paid",
"fieldtype": "Currency",
"label": "Advance Paid",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "view_details",
"fieldtype": "Fold",
@ -1021,7 +1033,7 @@
"idx": 1,
"is_submittable": 1,
"issingle": 0,
"modified": "2014-12-16 10:36:47.295144",
"modified": "2015-01-12 15:16:51.611467",
"modified_by": "Administrator",
"module": "Selling",
"name": "Sales Order",

View File

@ -342,8 +342,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
var tax_count = this.frm.tax_doclist.length;
this.frm.doc.grand_total = flt(tax_count ? this.frm.tax_doclist[tax_count - 1].total : this.frm.doc.net_total);
this.frm.doc.grand_total_export = flt(tax_count ?
flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate) : this.frm.doc.net_total_export);
this.frm.doc.grand_total_export = flt(this.frm.doc.grand_total / this.frm.doc.conversion_rate);
this.frm.doc.other_charges_total = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
precision("other_charges_total"));
@ -363,17 +362,22 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
var distributed_amount = 0.0;
if (this.frm.doc.discount_amount) {
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();
// calculate item amount after Discount Amount
if (grand_total_for_discount_amount) {
$.each(this.frm.item_doclist, function(i, item) {
distributed_amount = flt(me.frm.doc.discount_amount) * item.base_amount / grand_total_for_discount_amount;
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));
});
this.discount_amount_applied = true;
this._calculate_taxes_and_totals();
}
} else {
this.frm.set_value("base_discount_amount", 0);
}
},
@ -507,12 +511,12 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
}
});
};
setup_field_label_map(["net_total", "other_charges_total", "grand_total",
setup_field_label_map(["net_total", "other_charges_total", "base_discount_amount", "grand_total",
"rounded_total", "in_words",
"outstanding_amount", "total_advance", "paid_amount", "write_off_amount"],
company_currency);
setup_field_label_map(["net_total_export", "other_charges_total_export", "grand_total_export",
setup_field_label_map(["net_total_export", "other_charges_total_export", "discount_amount", "grand_total_export",
"rounded_total_export", "in_words_export"], this.frm.doc.currency);
cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
@ -525,7 +529,7 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({
// toggle fields
this.frm.toggle_display(["conversion_rate", "net_total", "other_charges_total",
"grand_total", "rounded_total", "in_words"],
"grand_total", "rounded_total", "in_words", "base_discount_amount"],
this.frm.doc.currency != company_currency);
this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],

View File

@ -434,6 +434,15 @@
"fieldtype": "Section Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Taxes and Charges Total",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "other_charges_total",
"fieldtype": "Currency",
@ -452,22 +461,23 @@
"fieldtype": "Column Break",
"permlevel": 0
},
{
"fieldname": "other_charges_total_export",
"fieldtype": "Currency",
"label": "Taxes and Charges Total",
"options": "Company:company:default_currency",
"permlevel": 0,
"print_hide": 1,
"read_only": 1
},
{
"fieldname": "discount_amount",
"fieldtype": "Currency",
"label": "Discount Amount",
"options": "Company:company:default_currency",
"options": "currency",
"permlevel": 0
},
{
"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",
"fieldtype": "Section Break",
@ -1013,7 +1023,7 @@
"idx": 1,
"in_create": 0,
"is_submittable": 1,
"modified": "2014-12-22 14:58:19.575566",
"modified": "2015-01-12 16:56:39.975961",
"modified_by": "Administrator",
"module": "Stock",
"name": "Delivery Note",

View File

@ -4,7 +4,7 @@
from __future__ import unicode_literals
import frappe
from frappe import _, throw
from frappe.utils import flt, cint, add_days
from frappe.utils import flt, cint, add_days, cstr
import json
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
from erpnext.setup.utils import get_exchange_rate
@ -140,7 +140,7 @@ def get_basic_details(args, item_doc):
"item_code": item.name,
"item_name": item.item_name,
"description": item.description_html or item.description,
"description": cstr(item.description_html).strip() or cstr(item.description).strip(),
"warehouse": user_default_warehouse or args.warehouse or item.default_warehouse,
"income_account": (item.income_account
or args.income_account