fix: incorrect gl if tax on multi currency payment entry
(cherry picked from commit f0ae77b23b)
This commit is contained in:
@@ -1111,7 +1111,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
|
|
||||||
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0; });
|
$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0; });
|
||||||
|
|
||||||
frm.doc.paid_amount_after_tax = frm.doc.paid_amount;
|
frm.doc.paid_amount_after_tax = frm.doc.base_paid_amount;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1202,7 +1202,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cumulated_tax_fraction += tax.tax_fraction_for_current_item;
|
cumulated_tax_fraction += tax.tax_fraction_for_current_item;
|
||||||
frm.doc.paid_amount_after_tax = flt(frm.doc.paid_amount/(1+cumulated_tax_fraction))
|
frm.doc.paid_amount_after_tax = flt(frm.doc.base_paid_amount/(1+cumulated_tax_fraction))
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -1234,6 +1234,7 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
frm.doc.total_taxes_and_charges = 0.0;
|
frm.doc.total_taxes_and_charges = 0.0;
|
||||||
frm.doc.base_total_taxes_and_charges = 0.0;
|
frm.doc.base_total_taxes_and_charges = 0.0;
|
||||||
|
|
||||||
|
let company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
|
||||||
let actual_tax_dict = {};
|
let actual_tax_dict = {};
|
||||||
|
|
||||||
// maintain actual tax rate based on idx
|
// maintain actual tax rate based on idx
|
||||||
@@ -1254,8 +1255,8 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tax.tax_amount = current_tax_amount;
|
// tax accounts are only in company currency
|
||||||
tax.base_tax_amount = tax.tax_amount * frm.doc.source_exchange_rate;
|
tax.base_tax_amount = current_tax_amount;
|
||||||
current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
|
current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
|
||||||
|
|
||||||
if(i==0) {
|
if(i==0) {
|
||||||
@@ -1264,9 +1265,29 @@ frappe.ui.form.on('Payment Entry', {
|
|||||||
tax.total = flt(frm.doc["taxes"][i-1].total + current_tax_amount, precision("total", tax));
|
tax.total = flt(frm.doc["taxes"][i-1].total + current_tax_amount, precision("total", tax));
|
||||||
}
|
}
|
||||||
|
|
||||||
tax.base_total = tax.total * frm.doc.source_exchange_rate;
|
// tac accounts are only in company currency
|
||||||
frm.doc.total_taxes_and_charges += current_tax_amount;
|
tax.base_total = tax.total
|
||||||
frm.doc.base_total_taxes_and_charges += current_tax_amount * frm.doc.source_exchange_rate;
|
|
||||||
|
// calculate total taxes and base total taxes
|
||||||
|
if(frm.doc.payment_type == "Pay") {
|
||||||
|
// tax accounts only have company currency
|
||||||
|
if(tax.currency != frm.doc.paid_to_account_currency) {
|
||||||
|
//total_taxes_and_charges has the target currency. so using target conversion rate
|
||||||
|
frm.doc.total_taxes_and_charges += flt(current_tax_amount / frm.doc.target_exchange_rate);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
frm.doc.total_taxes_and_charges += current_tax_amount;
|
||||||
|
}
|
||||||
|
} else if(frm.doc.payment_type == "Receive") {
|
||||||
|
if(tax.currency != frm.doc.paid_from_account_currency) {
|
||||||
|
//total_taxes_and_charges has the target currency. so using source conversion rate
|
||||||
|
frm.doc.total_taxes_and_charges += flt(current_tax_amount / frm.doc.source_exchange_rate);
|
||||||
|
} else {
|
||||||
|
frm.doc.total_taxes_and_charges += current_tax_amount;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
frm.doc.base_total_taxes_and_charges += tax.base_tax_amount;
|
||||||
|
|
||||||
frm.refresh_field('taxes');
|
frm.refresh_field('taxes');
|
||||||
frm.refresh_field('total_taxes_and_charges');
|
frm.refresh_field('total_taxes_and_charges');
|
||||||
|
|||||||
@@ -944,6 +944,13 @@ class PaymentEntry(AccountsController):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if not d.included_in_paid_amount:
|
if not d.included_in_paid_amount:
|
||||||
|
if get_account_currency(payment_account) != self.company_currency:
|
||||||
|
if self.payment_type == "Receive":
|
||||||
|
exchange_rate = self.target_exchange_rate
|
||||||
|
elif self.payment_type in ["Pay", "Internal Transfer"]:
|
||||||
|
exchange_rate = self.source_exchange_rate
|
||||||
|
base_tax_amount = flt((tax_amount / exchange_rate), self.precision("paid_amount"))
|
||||||
|
|
||||||
gl_entries.append(
|
gl_entries.append(
|
||||||
self.get_gl_dict(
|
self.get_gl_dict(
|
||||||
{
|
{
|
||||||
@@ -1059,7 +1066,7 @@ class PaymentEntry(AccountsController):
|
|||||||
for fieldname in tax_fields:
|
for fieldname in tax_fields:
|
||||||
tax.set(fieldname, 0.0)
|
tax.set(fieldname, 0.0)
|
||||||
|
|
||||||
self.paid_amount_after_tax = self.paid_amount
|
self.paid_amount_after_tax = self.base_paid_amount
|
||||||
|
|
||||||
def determine_exclusive_rate(self):
|
def determine_exclusive_rate(self):
|
||||||
if not any((cint(tax.included_in_paid_amount) for tax in self.get("taxes"))):
|
if not any((cint(tax.included_in_paid_amount) for tax in self.get("taxes"))):
|
||||||
@@ -1078,7 +1085,7 @@ class PaymentEntry(AccountsController):
|
|||||||
|
|
||||||
cumulated_tax_fraction += tax.tax_fraction_for_current_item
|
cumulated_tax_fraction += tax.tax_fraction_for_current_item
|
||||||
|
|
||||||
self.paid_amount_after_tax = flt(self.paid_amount / (1 + cumulated_tax_fraction))
|
self.paid_amount_after_tax = flt(self.base_paid_amount / (1 + cumulated_tax_fraction))
|
||||||
|
|
||||||
def calculate_taxes(self):
|
def calculate_taxes(self):
|
||||||
self.total_taxes_and_charges = 0.0
|
self.total_taxes_and_charges = 0.0
|
||||||
@@ -1101,7 +1108,7 @@ class PaymentEntry(AccountsController):
|
|||||||
current_tax_amount += actual_tax_dict[tax.idx]
|
current_tax_amount += actual_tax_dict[tax.idx]
|
||||||
|
|
||||||
tax.tax_amount = current_tax_amount
|
tax.tax_amount = current_tax_amount
|
||||||
tax.base_tax_amount = tax.tax_amount * self.source_exchange_rate
|
tax.base_tax_amount = current_tax_amount
|
||||||
|
|
||||||
if tax.add_deduct_tax == "Deduct":
|
if tax.add_deduct_tax == "Deduct":
|
||||||
current_tax_amount *= -1.0
|
current_tax_amount *= -1.0
|
||||||
@@ -1115,14 +1122,20 @@ class PaymentEntry(AccountsController):
|
|||||||
self.get("taxes")[i - 1].total + current_tax_amount, self.precision("total", tax)
|
self.get("taxes")[i - 1].total + current_tax_amount, self.precision("total", tax)
|
||||||
)
|
)
|
||||||
|
|
||||||
tax.base_total = tax.total * self.source_exchange_rate
|
tax.base_total = tax.total
|
||||||
|
|
||||||
if self.payment_type == "Pay":
|
if self.payment_type == "Pay":
|
||||||
self.base_total_taxes_and_charges += flt(current_tax_amount / self.source_exchange_rate)
|
if tax.currency != self.paid_to_account_currency:
|
||||||
self.total_taxes_and_charges += flt(current_tax_amount / self.target_exchange_rate)
|
self.total_taxes_and_charges += flt(current_tax_amount / self.target_exchange_rate)
|
||||||
else:
|
else:
|
||||||
self.base_total_taxes_and_charges += flt(current_tax_amount / self.target_exchange_rate)
|
self.total_taxes_and_charges += current_tax_amount
|
||||||
self.total_taxes_and_charges += flt(current_tax_amount / self.source_exchange_rate)
|
elif self.payment_type == "Receive":
|
||||||
|
if tax.currency != self.paid_from_account_currency:
|
||||||
|
self.total_taxes_and_charges += flt(current_tax_amount / self.source_exchange_rate)
|
||||||
|
else:
|
||||||
|
self.total_taxes_and_charges += current_tax_amount
|
||||||
|
|
||||||
|
self.base_total_taxes_and_charges += tax.base_tax_amount
|
||||||
|
|
||||||
if self.get("taxes"):
|
if self.get("taxes"):
|
||||||
self.paid_amount_after_tax = self.get("taxes")[-1].base_total
|
self.paid_amount_after_tax = self.get("taxes")[-1].base_total
|
||||||
|
|||||||
Reference in New Issue
Block a user