From 5402451b35068a791ef9c97067757838d221ca30 Mon Sep 17 00:00:00 2001 From: Anurag Mishra Date: Fri, 29 Mar 2019 19:25:11 +0530 Subject: [PATCH 01/75] feat: Loan repayment report Co-authored-by: crescent28 --- erpnext/hr/report/loan_repayment/__init__.py | 0 .../report/loan_repayment/loan_repayment.js | 9 ++ .../report/loan_repayment/loan_repayment.json | 28 ++++++ .../report/loan_repayment/loan_repayment.py | 95 +++++++++++++++++++ 4 files changed, 132 insertions(+) create mode 100644 erpnext/hr/report/loan_repayment/__init__.py create mode 100644 erpnext/hr/report/loan_repayment/loan_repayment.js create mode 100644 erpnext/hr/report/loan_repayment/loan_repayment.json create mode 100644 erpnext/hr/report/loan_repayment/loan_repayment.py diff --git a/erpnext/hr/report/loan_repayment/__init__.py b/erpnext/hr/report/loan_repayment/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/erpnext/hr/report/loan_repayment/loan_repayment.js b/erpnext/hr/report/loan_repayment/loan_repayment.js new file mode 100644 index 00000000000..21aa2061603 --- /dev/null +++ b/erpnext/hr/report/loan_repayment/loan_repayment.js @@ -0,0 +1,9 @@ +// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors +// For license information, please see license.txt +/* eslint-disable */ + +frappe.query_reports["Loan Repayment"] = { + "filters": [ + + ] +} diff --git a/erpnext/hr/report/loan_repayment/loan_repayment.json b/erpnext/hr/report/loan_repayment/loan_repayment.json new file mode 100644 index 00000000000..23b6977db89 --- /dev/null +++ b/erpnext/hr/report/loan_repayment/loan_repayment.json @@ -0,0 +1,28 @@ +{ + "add_total_row": 0, + "creation": "2019-03-29 18:58:00.166032", + "disable_prepared_report": 0, + "disabled": 0, + "docstatus": 0, + "doctype": "Report", + "idx": 0, + "is_standard": "Yes", + "letter_head": "Gadgets International", + "modified": "2019-03-29 18:58:00.166032", + "modified_by": "Administrator", + "module": "HR", + "name": "Loan Repayment", + "owner": "Administrator", + "prepared_report": 0, + "ref_doctype": "Loan", + "report_name": "Loan Repayment", + "report_type": "Script Report", + "roles": [ + { + "role": "HR Manager" + }, + { + "role": "Employee" + } + ] +} \ No newline at end of file diff --git a/erpnext/hr/report/loan_repayment/loan_repayment.py b/erpnext/hr/report/loan_repayment/loan_repayment.py new file mode 100644 index 00000000000..9e310de48c9 --- /dev/null +++ b/erpnext/hr/report/loan_repayment/loan_repayment.py @@ -0,0 +1,95 @@ +# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe import _ + +def execute(filters=None): + + columns = create_columns() + data = get_record() + return columns, data + +def create_columns(): + return [ + { + "label": _("Employee"), + "fieldtype": "Data", + "fieldname": "employee", + "options": "Employee", + "width": 200 + }, + { + "label": _("Loan"), + "fieldtype": "Link", + "fieldname": "loan_name", + "options": "Loan", + "width": 200 + }, + { + "label": _("Loan Amount"), + "fieldtype": "Currency", + "fieldname": "loan_amount", + "options": "currency", + "width": 100 + }, + { + "label": _("Interest"), + "fieldtype": "Data", + "fieldname": "interest", + "width": 100 + }, + { + "label": _("Payable Amount"), + "fieldtype": "Currency", + "fieldname": "payable_amount", + "options": "currency", + "width": 100 + }, + { + "label": _("EMI"), + "fieldtype": "Currency", + "fieldname": "emi", + "options": "currency", + "width": 100 + }, + { + "label": _("Paid Amount"), + "fieldtype": "Currency", + "fieldname": "paid_amount", + "options": "currency", + "width": 100 + }, + { + "label": _("Outstanding Amount"), + "fieldtype": "Currency", + "fieldname": "out_amt", + "options": "currency", + "width": 100 + }, + ] + +def get_record(): + data = [] + loans = frappe.get_all("Loan", + filters=[("status", "=", "Fully Disbursed")], + fields=["applicant", "applicant_name", "name", "loan_amount", "rate_of_interest", + "total_payment", "monthly_repayment_amount", "total_amount_paid"] + ) + + for loan in loans: + row = { + "employee": loan.applicant + ": " + loan.applicant_name, + "loan_name": loan.name, + "loan_amount": loan.loan_amount, + "interest": str(loan.rate_of_interest) + "%", + "payable_amount": loan.total_payment, + "emi": loan.monthly_repayment_amount, + "paid_amount": loan.total_amount_paid, + "out_amt": loan.total_payment - loan.total_amount_paid + } + + data.append(row) + + return data From 593242fa5ca2cb18dfb1cf0155a6297f8d85053a Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 5 Apr 2019 19:35:02 +0530 Subject: [PATCH 02/75] fix: Calculate rate based on discount on server side only if not rate or pricing rule applied --- erpnext/controllers/taxes_and_totals.py | 23 +++++++++++--------- erpnext/public/js/controllers/buying.js | 2 ++ erpnext/public/js/controllers/transaction.js | 1 + erpnext/selling/sales_common.js | 2 ++ 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index b3880be2c6d..fe12cf2316c 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -59,19 +59,22 @@ class calculate_taxes_and_totals(object): if item.discount_percentage == 100: item.rate = 0.0 - elif (not item.rate or item.discount_percentage > 0) and item.price_list_rate: - item.rate = flt(item.price_list_rate * - (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) - item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0) - elif item.discount_amount and item.price_list_rate: - item.rate = item.price_list_rate - item.discount_amount + elif item.price_list_rate: + if not item.rate or (item.pricing_rules and item.discount_percentage > 0): + item.rate = flt(item.price_list_rate * + (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) + item.discount_amount = item.price_list_rate * (item.discount_percentage / 100.0) + elif item.discount_amount and item.pricing_rules: + item.rate = item.price_list_rate - item.discount_amount if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) - - if flt(item.rate_with_margin) > 0: - item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) - item.discount_amount = item.rate_with_margin - item.rate + if item.discount_percentage: + if flt(item.rate_with_margin) > 0: + item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) + item.discount_amount = item.rate_with_margin - item.rate + elif flt(item.price_list_rate) > 0: + item.discount_amount = item.price_list_rate - item.rate elif flt(item.price_list_rate) > 0 and not item.discount_amount: item.discount_amount = item.price_list_rate - item.rate diff --git a/erpnext/public/js/controllers/buying.js b/erpnext/public/js/controllers/buying.js index 3ec27fcc7f9..f2fe3fe72b4 100644 --- a/erpnext/public/js/controllers/buying.js +++ b/erpnext/public/js/controllers/buying.js @@ -147,6 +147,8 @@ erpnext.buying.BuyingController = erpnext.TransactionController.extend({ }, discount_amount: function(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + item.discount_percentage = 0.0; this.price_list_rate(doc, cdt, cdn); }, diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js index 5291d4ff6f6..cb01c525d59 100644 --- a/erpnext/public/js/controllers/transaction.js +++ b/erpnext/public/js/controllers/transaction.js @@ -23,6 +23,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({ } else { item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item)); + item.discount_amount = flt(item.price_list_rate) - flt(item.rate); item.margin_type = ''; item.margin_rate_or_amount = 0; item.rate_with_margin = 0; diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js index 965d2b0219c..23dcaa152de 100644 --- a/erpnext/selling/sales_common.js +++ b/erpnext/selling/sales_common.js @@ -145,6 +145,8 @@ erpnext.selling.SellingController = erpnext.TransactionController.extend({ }, discount_amount: function(doc, cdt, cdn) { + var item = frappe.get_doc(cdt, cdn); + item.discount_percentage = 0.0; this.apply_discount_on_item(doc, cdt, cdn, 'discount_amount'); }, From 64bfdd95967e2682752bad5546fbf0e9e078c143 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 23 Apr 2019 13:37:19 +0530 Subject: [PATCH 03/75] fix: test cases --- erpnext/controllers/taxes_and_totals.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py index fe12cf2316c..b75b8b825c0 100644 --- a/erpnext/controllers/taxes_and_totals.py +++ b/erpnext/controllers/taxes_and_totals.py @@ -69,12 +69,11 @@ class calculate_taxes_and_totals(object): if item.doctype in ['Quotation Item', 'Sales Order Item', 'Delivery Note Item', 'Sales Invoice Item']: item.rate_with_margin, item.base_rate_with_margin = self.calculate_margin(item) - if item.discount_percentage: - if flt(item.rate_with_margin) > 0: - item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) - item.discount_amount = item.rate_with_margin - item.rate - elif flt(item.price_list_rate) > 0: - item.discount_amount = item.price_list_rate - item.rate + if flt(item.rate_with_margin) > 0: + item.rate = flt(item.rate_with_margin * (1.0 - (item.discount_percentage / 100.0)), item.precision("rate")) + item.discount_amount = item.rate_with_margin - item.rate + elif flt(item.price_list_rate) > 0: + item.discount_amount = item.price_list_rate - item.rate elif flt(item.price_list_rate) > 0 and not item.discount_amount: item.discount_amount = item.price_list_rate - item.rate From 691e03a36b9ba68aad6a0686c831fb209afd732d Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Tue, 23 Apr 2019 17:26:01 +0530 Subject: [PATCH 04/75] fix: Straight line asset depreciation not working if Expected Value After Useful Life is defined --- erpnext/assets/doctype/asset/asset.js | 6 ++++++ erpnext/assets/doctype/asset/asset.py | 15 +++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/erpnext/assets/doctype/asset/asset.js b/erpnext/assets/doctype/asset/asset.js index e9a0f70b332..2d78d2693d0 100644 --- a/erpnext/assets/doctype/asset/asset.js +++ b/erpnext/assets/doctype/asset/asset.js @@ -296,6 +296,12 @@ frappe.ui.form.on('Asset', { frm.toggle_reqd("finance_books", frm.doc.calculate_depreciation); }, + gross_purchase_amount: function(frm) { + frm.doc.finance_books.forEach(d => { + frm.events.set_depreciation_rate(frm, d); + }) + }, + set_depreciation_rate: function(frm, row) { if (row.total_number_of_depreciations && row.frequency_of_depreciation) { frappe.call({ diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 8011038b1b1..72f5c627a71 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -101,7 +101,7 @@ class Asset(AccountsController): def set_depreciation_rate(self): for d in self.get("finance_books"): - d.rate_of_depreciation = self.get_depreciation_rate(d) + d.rate_of_depreciation = self.get_depreciation_rate(d, on_validate=True) def make_depreciation_schedule(self): depreciation_method = [d.depreciation_method for d in self.finance_books] @@ -125,7 +125,7 @@ class Asset(AccountsController): no_of_depreciations * cint(d.frequency_of_depreciation)) total_days = date_diff(end_date, self.available_for_use_date) - rate_per_day = value_after_depreciation / total_days + rate_per_day = (value_after_depreciation - d.get("expected_value_after_useful_life")) / total_days number_of_pending_depreciations = cint(d.total_number_of_depreciations) - \ cint(self.number_of_depreciations_booked) @@ -291,8 +291,8 @@ class Asset(AccountsController): def validate_expected_value_after_useful_life(self): for row in self.get('finance_books'): - accumulated_depreciation_after_full_schedule = \ - max([d.accumulated_depreciation_amount for d in self.get("schedules") if d.finance_book_id == row.idx]) + accumulated_depreciation_after_full_schedule = max([d.accumulated_depreciation_amount + for d in self.get("schedules") if cint(d.finance_book_id) == row.idx]) asset_value_after_full_schedule = flt(flt(self.gross_purchase_amount) - flt(accumulated_depreciation_after_full_schedule), @@ -403,7 +403,7 @@ class Asset(AccountsController): make_gl_entries(gl_entries) self.db_set('booked_fixed_asset', 1) - def get_depreciation_rate(self, args): + def get_depreciation_rate(self, args, on_validate=False): if isinstance(args, string_types): args = json.loads(args) @@ -420,7 +420,10 @@ class Asset(AccountsController): if args.get("depreciation_method") == 'Double Declining Balance': return 200.0 / args.get("total_number_of_depreciations") - if args.get("depreciation_method") == "Written Down Value" and not args.get("rate_of_depreciation"): + if args.get("depreciation_method") == "Written Down Value": + if args.get("rate_of_depreciation") and on_validate: + return args.get("rate_of_depreciation") + no_of_years = flt(args.get("total_number_of_depreciations") * flt(args.get("frequency_of_depreciation"))) / 12 value = flt(args.get("expected_value_after_useful_life")) / flt(self.gross_purchase_amount) From 9c1fa77f4ecdcfc063fe401e425147be4c0cd263 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Thu, 25 Apr 2019 01:26:27 +0530 Subject: [PATCH 05/75] fixed test cases --- erpnext/assets/doctype/asset/test_asset.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 985097b447d..ef85ffa1cb8 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -102,9 +102,9 @@ class TestAsset(unittest.TestCase): asset.save() self.assertEqual(asset.status, "Draft") expected_schedules = [ - ["2020-06-06", 163.93, 163.93], - ["2021-04-06", 49836.07, 50000.0], - ["2022-02-06", 40000.0, 90000.00] + ["2020-06-06", 147.54, 147.54], + ["2021-04-06", 44852.46, 45000.0], + ["2022-02-06", 45000.0, 90000.00] ] schedules = [[cstr(d.schedule_date), d.depreciation_amount, d.accumulated_depreciation_amount] @@ -130,8 +130,8 @@ class TestAsset(unittest.TestCase): self.assertEqual(asset.status, "Draft") asset.save() expected_schedules = [ - ["2020-06-06", 197.37, 40197.37], - ["2021-04-06", 49802.63, 90000.00] + ["2020-06-06", 164.47, 40164.47], + ["2021-04-06", 49835.53, 90000.00] ] schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), d.accumulated_depreciation_amount] for d in asset.get("schedules")] @@ -266,8 +266,8 @@ class TestAsset(unittest.TestCase): self.assertEqual(asset.get("schedules")[0].journal_entry[:4], "DEPR") expected_gle = ( - ("_Test Accumulated Depreciations - _TC", 0.0, 35699.15), - ("_Test Depreciations - _TC", 35699.15, 0.0) + ("_Test Accumulated Depreciations - _TC", 0.0, 32129.24), + ("_Test Depreciations - _TC", 32129.24, 0.0) ) gle = frappe.db.sql("""select account, debit, credit from `tabGL Entry` From 37a55345fdaebb2266be6fe85eb42c62ad07759e Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 25 Apr 2019 19:29:56 +0530 Subject: [PATCH 06/75] feat: removed home page for lms role --- erpnext/hooks.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/hooks.py b/erpnext/hooks.py index ecc961186ad..47d205692c2 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -169,10 +169,6 @@ default_roles = [ {'role': 'Student', 'doctype':'Student', 'email_field': 'student_email_id'}, ] -role_home_page = { - "LMS User": "/lms" -} - has_website_permission = { "Sales Order": "erpnext.controllers.website_list_for_contact.has_website_permission", "Quotation": "erpnext.controllers.website_list_for_contact.has_website_permission", From 2428485ebb5a866a4a3283d17284b1b320c27984 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 25 Apr 2019 19:33:22 +0530 Subject: [PATCH 07/75] fix (ui): Card layout --- erpnext/public/js/education/lms/components/CourseCard.vue | 2 +- erpnext/public/js/education/lms/components/ProgramCard.vue | 2 +- erpnext/public/js/education/lms/components/ProgressCard.vue | 2 +- erpnext/public/js/education/lms/components/ScoreCard.vue | 2 +- erpnext/public/js/education/lms/components/TopicCard.vue | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/erpnext/public/js/education/lms/components/CourseCard.vue b/erpnext/public/js/education/lms/components/CourseCard.vue index 223654f27e8..16f8873bd1b 100644 --- a/erpnext/public/js/education/lms/components/CourseCard.vue +++ b/erpnext/public/js/education/lms/components/CourseCard.vue @@ -1,5 +1,5 @@