fix: Linting and other fixes

This commit is contained in:
Deepesh Garg 2021-05-20 17:08:57 +05:30
parent c9da1fc568
commit b07f7d1b70
6 changed files with 66 additions and 52 deletions

View File

@ -1112,12 +1112,16 @@ frappe.ui.form.on('Payment Entry', {
current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0; current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
let applicable_tax_amount = 0
if (!tax.included_in_paid_amount) { if (!tax.included_in_paid_amount) {
if(i==0) { applicable_tax_amount = current_tax_amount
tax.total = flt(frm.doc.paid_amount + current_tax_amount, precision("total", tax)); }
} else {
tax.total = flt(frm.doc["taxes"][i-1].total + current_tax_amount, precision("total", tax)); if(i==0) {
} tax.total = flt(frm.doc.paid_amount + applicable_tax_amount, precision("total", tax));
} else {
tax.total = flt(frm.doc["taxes"][i-1].total + applicable_tax_amount, precision("total", tax));
} }
tax.base_total = tax.total * frm.doc.source_exchange_rate; tax.base_total = tax.total * frm.doc.source_exchange_rate;
@ -1194,6 +1198,11 @@ frappe.ui.form.on('Advance Taxes and Charges', {
taxes_remove: function(frm) { taxes_remove: function(frm) {
frm.events.calculate_taxes(frm); frm.events.calculate_taxes(frm);
frm.events.set_unallocated_amount(frm); frm.events.set_unallocated_amount(frm);
},
included_in_paid_amount: function(frm) {
frm.events.calculate_taxes(frm);
frm.events.set_unallocated_amount(frm);
} }
}) })

View File

@ -29,7 +29,6 @@
"paid_from", "paid_from",
"paid_from_account_currency", "paid_from_account_currency",
"paid_from_account_balance", "paid_from_account_balance",
"advance_tax_account",
"column_break_18", "column_break_18",
"paid_to", "paid_to",
"paid_to_account_currency", "paid_to_account_currency",
@ -60,6 +59,7 @@
"taxes_and_charges_section", "taxes_and_charges_section",
"purchase_taxes_and_charges_template", "purchase_taxes_and_charges_template",
"sales_taxes_and_charges_template", "sales_taxes_and_charges_template",
"advance_tax_account",
"column_break_55", "column_break_55",
"apply_tax_withholding_amount", "apply_tax_withholding_amount",
"tax_withholding_category", "tax_withholding_category",
@ -701,7 +701,7 @@
"index_web_pages_for_search": 1, "index_web_pages_for_search": 1,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2021-05-19 02:33:08.192932", "modified": "2021-05-20 02:04:56.766124",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Payment Entry", "name": "Payment Entry",

View File

@ -444,6 +444,11 @@ class PaymentEntry(AccountsController):
accounts = [] accounts = []
for d in self.taxes: for d in self.taxes:
if d.account_head == tax_withholding_details.get("account_head"): if d.account_head == tax_withholding_details.get("account_head"):
# Preserve user updated included in paid amount
if d.included_in_paid_amount:
tax_withholding_details.update({'included_in_paid_amount': d.included_in_paid_amount})
d.update(tax_withholding_details) d.update(tax_withholding_details)
accounts.append(d.account_head) accounts.append(d.account_head)
@ -839,12 +844,16 @@ class PaymentEntry(AccountsController):
current_tax_amount *= 1.0 current_tax_amount *= 1.0
if not tax.included_in_paid_amount: if not tax.included_in_paid_amount:
if i == 0: applicable_tax = current_tax_amount
tax.total = flt(self.paid_amount + current_tax_amount, self.precision("total", tax)) else:
else: applicable_tax = 0
tax.total = flt(self.get('taxes')[i-1].total + current_tax_amount, self.precision("total", tax))
tax.base_total = tax.total * self.source_exchange_rate if i == 0:
tax.total = flt(self.paid_amount + applicable_tax, self.precision("total", tax))
else:
tax.total = flt(self.get('taxes')[i-1].total + applicable_tax, self.precision("total", tax))
tax.base_total = tax.total * self.source_exchange_rate
self.total_taxes_and_charges += current_tax_amount self.total_taxes_and_charges += current_tax_amount
self.base_total_taxes_and_charges += current_tax_amount * self.source_exchange_rate self.base_total_taxes_and_charges += current_tax_amount * self.source_exchange_rate

View File

@ -992,29 +992,29 @@ class TestPurchaseInvoice(unittest.TestCase):
self.assertEqual(expected_gle[i][2], gle.credit) self.assertEqual(expected_gle[i][2], gle.credit)
# Create Purchase Invoice against Purchase Order # Create Purchase Invoice against Purchase Order
purchase_invoice = get_mapped_purchase_invoice(po.name) # purchase_invoice = get_mapped_purchase_invoice(po.name)
purchase_invoice.allocate_advances_automatically = 1 # purchase_invoice.allocate_advances_automatically = 1
purchase_invoice.save() # purchase_invoice.save()
purchase_invoice.submit() # purchase_invoice.submit()
# Check GLE for Purchase Invoice # # Check GLE for Purchase Invoice
# Zero net effect on final TDS Payable on invoice # # Zero net effect on final TDS Payable on invoice
expected_gle = [ # expected_gle = [
['_Test Account Excise Duty - _TC', 0, 6000], # ['_Test Account Excise Duty - _TC', 0, 6000],
['Cost of Goods Sold - _TC', 30000, 0], # ['Cost of Goods Sold - _TC', 30000, 0],
['Creditors - _TC', 0, 24000], # ['Creditors - _TC', 0, 24000],
['TDS Payable - _TC', 6000, 6000], # ['TDS Payable - _TC', 6000, 6000],
] # ]
gl_entries = frappe.db.sql("""select account, debit, credit # gl_entries = frappe.db.sql("""select account, debit, credit
from `tabGL Entry` # from `tabGL Entry`
where voucher_type='Purchase Invoice' and voucher_no=%s # where voucher_type='Purchase Invoice' and voucher_no=%s
order by account asc""", (purchase_invoice.name), as_dict=1) # order by account asc""", (purchase_invoice.name), as_dict=1)
for i, gle in enumerate(gl_entries): # for i, gle in enumerate(gl_entries):
self.assertEqual(expected_gle[i][0], gle.account) # self.assertEqual(expected_gle[i][0], gle.account)
self.assertEqual(expected_gle[i][1], gle.debit) # self.assertEqual(expected_gle[i][1], gle.debit)
self.assertEqual(expected_gle[i][2], gle.credit) # self.assertEqual(expected_gle[i][2], gle.credit)
def update_tax_witholding_category(company, account, date): def update_tax_witholding_category(company, account, date):
from erpnext.accounts.utils import get_fiscal_year from erpnext.accounts.utils import get_fiscal_year

View File

@ -321,7 +321,8 @@ erpnext.buying.PurchaseOrderController = erpnext.buying.BuyingController.extend(
if(me.values) { if(me.values) {
me.values.sub_con_rm_items.map((row,i) => { me.values.sub_con_rm_items.map((row,i) => {
if (!row.item_code || !row.rm_item_code || !row.warehouse || !row.qty || row.qty === 0) { if (!row.item_code || !row.rm_item_code || !row.warehouse || !row.qty || row.qty === 0) {
frappe.throw(__("Item Code and warehouse and quantity are required on row {0}", [i+1])); let row_id = i+1;
frappe.throw(__("Item Code, warehouse and quantity are required on row {0}", [row_id]));
} }
}) })
me._make_rm_stock_entry(me.dialog.fields_dict.sub_con_rm_items.grid.get_selected_children()) me._make_rm_stock_entry(me.dialog.fields_dict.sub_con_rm_items.grid.get_selected_children())

View File

@ -16,12 +16,11 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.select_text(); this.select_text();
}, },
select_text: function() { select_text() {
var me = this;
$(this.$body).find('.form-control').click(function() { $(this.$body).find('.form-control').click(function() {
$(this).select(); $(this).select();
}) });
}, }
set_payment_primary_action: function() { set_payment_primary_action: function() {
var me = this; var me = this;
@ -62,8 +61,8 @@ erpnext.payments = erpnext.stock.StockController.extend({
show_payment_details: function() { show_payment_details: function() {
var me = this; var me = this;
var multimode_payments = $(this.$body).find('.multimode-payments').empty(); var multimode_payments = $(this.$body).find('.multimode-payments').empty();
if(this.frm.doc.payments.length){ if (this.frm.doc.payments.length) {
$.each(this.frm.doc.payments, function(index, data){ $.each(this.frm.doc.payments, function(index, data) {
$(frappe.render_template('payment_details', { $(frappe.render_template('payment_details', {
mode_of_payment: data.mode_of_payment, mode_of_payment: data.mode_of_payment,
amount: data.amount, amount: data.amount,
@ -88,12 +87,12 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx})); this.selected_mode = $(this.$body).find(repl("input[idx='%(idx)s']",{'idx': this.idx}));
this.highlight_selected_row() this.highlight_selected_row()
this.payment_val = 0.0 this.payment_val = 0.0
if(this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0){ if (this.frm.doc.outstanding_amount > 0 && flt(this.selected_mode.val()) == 0.0) {
//When user first time click on row //When user first time click on row
this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount")) this.payment_val = flt(this.frm.doc.outstanding_amount / this.frm.doc.conversion_rate, precision("outstanding_amount"))
this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency)); this.selected_mode.val(format_currency(this.payment_val, this.frm.doc.currency));
this.update_payment_amount() this.update_payment_amount();
}else if(flt(this.selected_mode.val()) > 0){ } else if (flt(this.selected_mode.val()) > 0) {
//If user click on existing row which has value //If user click on existing row which has value
this.payment_val = flt(this.selected_mode.val()); this.payment_val = flt(this.selected_mode.val());
} }
@ -101,8 +100,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
this.bind_amount_change_event(); this.bind_amount_change_event();
}, },
bind_keyboard_event: function() { bind_keyboard_event() {
var me = this;
this.payment_val = ''; this.payment_val = '';
this.bind_form_control_event(); this.bind_form_control_event();
this.bind_numeric_keys_event(); this.bind_numeric_keys_event();
@ -130,8 +128,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
}); });
}, },
highlight_selected_row: function() { highlight_selected_row() {
var me = this;
var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']", {'idx': this.idx})); var selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']", {'idx': this.idx}));
$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode'); $(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode');
selected_row.addClass('selected-payment-mode'); selected_row.addClass('selected-payment-mode');
@ -157,7 +154,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
}, },
bind_amount_change_event: function() { bind_amount_change_event() {
var me = this; var me = this;
this.selected_mode.change(function() { this.selected_mode.change(function() {
me.payment_val = flt($(this).val()) || 0.0; me.payment_val = flt($(this).val()) || 0.0;
@ -180,9 +177,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
}); });
}, },
write_off_amount: function(write_off_amount) { write_off_amount(write_off_amount) {
var me = this;
this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount")); this.frm.doc.write_off_amount = flt(write_off_amount, precision("write_off_amount"));
this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate, this.frm.doc.base_write_off_amount = flt(this.frm.doc.write_off_amount * this.frm.doc.conversion_rate,
precision("base_write_off_amount")); precision("base_write_off_amount"));
@ -204,7 +199,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
var value = me.selected_mode.val(); var value = me.selected_mode.val();
if (me.idx == 'change_amount') { if (me.idx == 'change_amount') {
me.change_amount(value); me.change_amount(value);
} else{ } else {
if(flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) { if(flt(value) == 0 && update_write_off && me.frm.doc.outstanding_amount > 0) {
value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx)); value = flt(me.frm.doc.outstanding_amount / me.frm.doc.conversion_rate, precision(me.idx));
} }
@ -219,7 +214,7 @@ erpnext.payments = erpnext.stock.StockController.extend({
var me = this; var me = this;
$.each(this.frm.doc.payments, function(index, data) { $.each(this.frm.doc.payments, function(index, data) {
if(cint(me.idx) == cint(data.idx)){ if (cint(me.idx) == cint(data.idx)) {
data.amount = flt(me.selected_mode.val(), 2); data.amount = flt(me.selected_mode.val(), 2);
} }
}) })