From a378619c9a4dd94bf5fcc59831342c193251e68e Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Wed, 23 Nov 2022 17:52:12 +0530 Subject: [PATCH 1/4] fix(pos): partial return amount update Signed-off-by: Sabu Siyad --- .../public/js/controllers/taxes_and_totals.js | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index 4c3e9dcf0a7..ebb7120e91c 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -47,29 +47,36 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { await this.calculate_shipping_charges(); - // Advance calculation applicable to Sales /Purchase Invoice - if(in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype) - && this.frm.doc.docstatus < 2 && !this.frm.doc.is_return) { + // Advance calculation applicable to Sales/Purchase Invoice + if ( + in_list(["Sales Invoice", "POS Invoice", "Purchase Invoice"], this.frm.doc.doctype) + && this.frm.doc.docstatus < 2 + && !this.frm.doc.is_return + ) { this.calculate_total_advance(update_paid_amount); } - if (in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) && this.frm.doc.is_pos && - this.frm.doc.is_return) { - if (this.frm.doc.doctype == "Sales Invoice") { - this.set_total_amount_to_default_mop(); - } + if ( + in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) + && this.frm.doc.is_pos + && this.frm.doc.is_return + ) { + this.set_total_amount_to_default_mop(); this.calculate_paid_amount(); } // Sales person's commission - if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) { + if (in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) { this.calculate_commission(); this.calculate_contribution(); } // Update paid amount on return/debit note creation - if(this.frm.doc.doctype === "Purchase Invoice" && this.frm.doc.is_return - && (this.frm.doc.grand_total > this.frm.doc.paid_amount)) { + if ( + this.frm.doc.doctype === "Purchase Invoice" + && this.frm.doc.is_return + && (this.frm.doc.grand_total > this.frm.doc.paid_amount) + ) { this.frm.doc.paid_amount = flt(this.frm.doc.grand_total, precision("grand_total")); } @@ -775,21 +782,30 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { let grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total; let base_grand_total = this.frm.doc.base_rounded_total || this.frm.doc.base_grand_total; - if(this.frm.doc.party_account_currency == this.frm.doc.currency) { - var total_amount_to_pay = flt((grand_total - this.frm.doc.total_advance - - this.frm.doc.write_off_amount), precision("grand_total")); + if (this.frm.doc.party_account_currency == this.frm.doc.currency) { + var total_amount_to_pay = flt( + grand_total - this.frm.doc.total_advance - this.frm.doc.write_off_amount, + precision("grand_total") + ); } else { var total_amount_to_pay = flt( - (flt(base_grand_total, precision("base_grand_total")) - - this.frm.doc.total_advance - this.frm.doc.base_write_off_amount), + ( + flt( + base_grand_total, + precision("base_grand_total") + ) + - this.frm.doc.total_advance - this.frm.doc.base_write_off_amount + ), precision("base_grand_total") ); } + this.frm.doc.payments.find(pay => { if (pay.default) { pay.amount = total_amount_to_pay; } }); + this.frm.refresh_fields(); } From c5edbe2e2fb8e3c74d71ad91b4200d900d2f79c8 Mon Sep 17 00:00:00 2001 From: Sabu Siyad Date: Wed, 30 Nov 2022 17:12:06 +0530 Subject: [PATCH 2/4] fix(lint): trailing whitespace Signed-off-by: Sabu Siyad --- erpnext/public/js/controllers/taxes_and_totals.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js index ebb7120e91c..74810005ed9 100644 --- a/erpnext/public/js/controllers/taxes_and_totals.js +++ b/erpnext/public/js/controllers/taxes_and_totals.js @@ -58,7 +58,7 @@ erpnext.taxes_and_totals = class TaxesAndTotals extends erpnext.payments { if ( in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) - && this.frm.doc.is_pos + && this.frm.doc.s_pos && this.frm.doc.is_return ) { this.set_total_amount_to_default_mop(); From 25522444b8e404af2c2ec328ac38aebf243ef92e Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Wed, 30 Nov 2022 23:25:40 +0530 Subject: [PATCH 3/4] fix: use is_last_day_of_the_month in test_scrap_asset --- erpnext/assets/doctype/asset/test_asset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 136a033b7db..feace84df4f 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -13,6 +13,7 @@ from frappe.utils import ( get_last_day, getdate, nowdate, + is_last_day_of_the_month, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice @@ -264,7 +265,7 @@ class TestAsset(AssetSetup): asset.gross_purchase_amount - asset.finance_books[0].value_after_depreciation, asset.precision("gross_purchase_amount"), ) - this_month_depr_amount = 9000.0 if get_last_day(date) == date else 0 + this_month_depr_amount = 9000.0 if is_last_day_of_the_month(date) else 0 self.assertEquals(accumulated_depr_amount, 18000.0 + this_month_depr_amount) From 827ad01d4fe024282cd2afce9c5f09cdfa11d89a Mon Sep 17 00:00:00 2001 From: anandbaburajan Date: Wed, 30 Nov 2022 23:56:37 +0530 Subject: [PATCH 4/4] chore: style --- erpnext/assets/doctype/asset/test_asset.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index feace84df4f..2bec27371b5 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -12,8 +12,8 @@ from frappe.utils import ( get_first_day, get_last_day, getdate, - nowdate, is_last_day_of_the_month, + nowdate, ) from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice