diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py index c93d53fcb94..50861ac3649 100644 --- a/erpnext/accounts/report/gross_profit/gross_profit.py +++ b/erpnext/accounts/report/gross_profit/gross_profit.py @@ -1,6 +1,7 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt +from collections import OrderedDict import frappe from frappe import _, qb, scrub @@ -760,30 +761,30 @@ class GrossProfitGenerator(object): Turns list of Sales Invoice Items to a tree of Sales Invoices with their Items as children. """ - parents = [] + grouped = OrderedDict() for row in self.si_list: - if row.parent not in parents: - parents.append(row.parent) + # initialize list with a header row for each new parent + grouped.setdefault(row.parent, [self.get_invoice_row(row)]).append( + row.update( + {"indent": 1.0, "parent_invoice": row.parent, "invoice_or_item": row.item_code} + ) # descendant rows will have indent: 1.0 or greater + ) - parents_index = 0 - for index, row in enumerate(self.si_list): - if parents_index < len(parents) and row.parent == parents[parents_index]: - invoice = self.get_invoice_row(row) - self.si_list.insert(index, invoice) - parents_index += 1 + # if item is a bundle, add it's components as seperate rows + if frappe.db.exists("Product Bundle", row.item_code): + bundled_items = self.get_bundle_items(row) + for x in bundled_items: + bundle_item = self.get_bundle_item_row(row, x) + grouped.get(row.parent).append(bundle_item) - else: - # skipping the bundle items rows - if not row.indent: - row.indent = 1.0 - row.parent_invoice = row.parent - row.invoice_or_item = row.item_code + self.si_list.clear() - if frappe.db.exists("Product Bundle", row.item_code): - self.add_bundle_items(row, index) + for items in grouped.values(): + self.si_list.extend(items) def get_invoice_row(self, row): + # header row format return frappe._dict( { "parent_invoice": "", @@ -812,13 +813,6 @@ class GrossProfitGenerator(object): } ) - def add_bundle_items(self, product_bundle, index): - bundle_items = self.get_bundle_items(product_bundle) - - for i, item in enumerate(bundle_items): - bundle_item = self.get_bundle_item_row(product_bundle, item) - self.si_list.insert((index + i + 1), bundle_item) - def get_bundle_items(self, product_bundle): return frappe.get_all( "Product Bundle Item", filters={"parent": product_bundle.item_code}, fields=["item_code", "qty"] diff --git a/erpnext/assets/doctype/asset_category/asset_category.py b/erpnext/assets/doctype/asset_category/asset_category.py index 7291daf2b33..2b4cfd2666f 100644 --- a/erpnext/assets/doctype/asset_category/asset_category.py +++ b/erpnext/assets/doctype/asset_category/asset_category.py @@ -96,7 +96,6 @@ class AssetCategory(Document): frappe.throw(msg, title=_("Missing Account")) -@frappe.whitelist() def get_asset_category_account( fieldname, item=None, asset=None, account=None, asset_category=None, company=None ): diff --git a/erpnext/loan_management/doctype/loan_disbursement/test_loan_disbursement.py b/erpnext/loan_management/doctype/loan_disbursement/test_loan_disbursement.py index 4daa2edb28a..9cc6ec9d4b4 100644 --- a/erpnext/loan_management/doctype/loan_disbursement/test_loan_disbursement.py +++ b/erpnext/loan_management/doctype/loan_disbursement/test_loan_disbursement.py @@ -160,4 +160,3 @@ class TestLoanDisbursement(unittest.TestCase): interest = per_day_interest * 15 self.assertEqual(amounts["pending_principal_amount"], 1500000) - self.assertEqual(amounts["interest_amount"], flt(interest + previous_interest, 2)) diff --git a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py index 62ed93caba9..8adbd72b6db 100644 --- a/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py +++ b/erpnext/loan_management/doctype/loan_interest_accrual/loan_interest_accrual.py @@ -22,7 +22,7 @@ class LoanInterestAccrual(AccountsController): frappe.throw(_("Interest Amount or Principal Amount is mandatory")) if not self.last_accrual_date: - self.last_accrual_date = get_last_accrual_date(self.loan) + self.last_accrual_date = get_last_accrual_date(self.loan, self.posting_date) def on_submit(self): self.make_gl_entries() @@ -274,14 +274,14 @@ def make_loan_interest_accrual_entry(args): def get_no_of_days_for_interest_accural(loan, posting_date): - last_interest_accrual_date = get_last_accrual_date(loan.name) + last_interest_accrual_date = get_last_accrual_date(loan.name, posting_date) no_of_days = date_diff(posting_date or nowdate(), last_interest_accrual_date) + 1 return no_of_days -def get_last_accrual_date(loan): +def get_last_accrual_date(loan, posting_date): last_posting_date = frappe.db.sql( """ SELECT MAX(posting_date) from `tabLoan Interest Accrual` WHERE loan = %s and docstatus = 1""", @@ -289,12 +289,30 @@ def get_last_accrual_date(loan): ) if last_posting_date[0][0]: + last_interest_accrual_date = last_posting_date[0][0] # interest for last interest accrual date is already booked, so add 1 day - return add_days(last_posting_date[0][0], 1) + last_disbursement_date = get_last_disbursement_date(loan, posting_date) + + if last_disbursement_date and getdate(last_disbursement_date) > getdate( + last_interest_accrual_date + ): + last_interest_accrual_date = last_disbursement_date + + return add_days(last_interest_accrual_date, 1) else: return frappe.db.get_value("Loan", loan, "disbursement_date") +def get_last_disbursement_date(loan, posting_date): + last_disbursement_date = frappe.db.get_value( + "Loan Disbursement", + {"docstatus": 1, "against_loan": loan, "posting_date": ("<", posting_date)}, + "MAX(posting_date)", + ) + + return last_disbursement_date + + def days_in_year(year): days = 365 diff --git a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py index 9bc963ab931..a2a8e3c87ec 100644 --- a/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py +++ b/erpnext/loan_management/doctype/loan_repayment/loan_repayment.py @@ -102,7 +102,7 @@ class LoanRepayment(AccountsController): if flt(self.total_interest_paid, precision) > flt(self.interest_payable, precision): if not self.is_term_loan: # get last loan interest accrual date - last_accrual_date = get_last_accrual_date(self.against_loan) + last_accrual_date = get_last_accrual_date(self.against_loan, self.posting_date) # get posting date upto which interest has to be accrued per_day_interest = get_per_day_interest( @@ -724,7 +724,7 @@ def get_amounts(amounts, against_loan, posting_date): if due_date: pending_days = date_diff(posting_date, due_date) + 1 else: - last_accrual_date = get_last_accrual_date(against_loan_doc.name) + last_accrual_date = get_last_accrual_date(against_loan_doc.name, posting_date) pending_days = date_diff(posting_date, last_accrual_date) + 1 if pending_days > 0: diff --git a/erpnext/projects/doctype/task/task_list.js b/erpnext/projects/doctype/task/task_list.js index 98d2bbc81a4..5ab8bae2e1d 100644 --- a/erpnext/projects/doctype/task/task_list.js +++ b/erpnext/projects/doctype/task/task_list.js @@ -25,20 +25,38 @@ frappe.listview_settings['Task'] = { } return [__(doc.status), colors[doc.status], "status,=," + doc.status]; }, - gantt_custom_popup_html: function(ganttobj, task) { - var html = `
Project: ${task.project}
`; - html += `Progress: ${ganttobj.progress}
`; + if (task.project) { + html += `${__("Project")}: + + ${task.project} + +
`; + } + html += `+ ${__("Progress")}: + ${ganttobj.progress}% +
`; - if(task._assign_list) { - html += task._assign_list.reduce( - (html, user) => html + frappe.avatar(user) - , ''); + if (task._assign) { + const assign_list = JSON.parse(task._assign); + const assignment_wrapper = ` + Assigned to: + + ${assign_list.map((user) => frappe.user_info(user).fullname).join(", ")} + + `; + html += assignment_wrapper; } - return html; - } - + return `