From 819ced4cb3feca1535182cde98b7a8ae3aeee131 Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Tue, 5 Mar 2024 17:24:17 +0530 Subject: [PATCH 01/21] fix: Add to Cart button width for Mobile/Tablet --- erpnext/public/scss/shopping_cart.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/public/scss/shopping_cart.scss b/erpnext/public/scss/shopping_cart.scss index 6ae464d2c21..36e2cf9cd0a 100644 --- a/erpnext/public/scss/shopping_cart.scss +++ b/erpnext/public/scss/shopping_cart.scss @@ -444,7 +444,7 @@ body.product-page { width: 30%; @media (max-width: 992px) { - width: 40%; + width: 50%; } } } @@ -1378,4 +1378,4 @@ body.product-page { .mt-minus-1 { margin-top: -1rem; -} \ No newline at end of file +} From 649c192abe17dcbe576a3f27ffd6c3984803d81d Mon Sep 17 00:00:00 2001 From: rohitwaghchaure Date: Thu, 23 May 2024 15:37:00 +0530 Subject: [PATCH 02/21] fix: dict can not be used as parameter (#41598) --- erpnext/stock/stock_ledger.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 4e624c9acb0..0cd2ecdaaf5 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1196,7 +1196,11 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc order by posting_datetime desc, creation desc limit 1 for update""", - args, + { + "item_code": args.get("item_code"), + "warehouse": args.get("warehouse"), + "posting_datetime": args.get("posting_datetime"), + }, as_dict=1, ) From 50f6afd588e08b75a22989fe85d31ba72fe0052f Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 9 Apr 2024 15:25:36 +0530 Subject: [PATCH 03/21] fix: Fetch outstanding and total amount for reference journal entry (cherry picked from commit f331f9b15cd219ecafddb71ffd8e3367d731ae3b) # Conflicts: # erpnext/accounts/doctype/payment_entry/payment_entry.js # erpnext/accounts/doctype/payment_entry/payment_entry.py --- .../doctype/payment_entry/payment_entry.js | 9 +++ .../doctype/payment_entry/payment_entry.py | 63 ++++++++++++------- .../payment_entry/test_payment_entry.py | 4 +- .../payment_request/payment_request.py | 6 +- 4 files changed, 58 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index c0716ff19ae..6909ca2b04b 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -1395,8 +1395,17 @@ frappe.ui.form.on('Payment Entry Reference', { args: { reference_doctype: row.reference_doctype, reference_name: row.reference_name, +<<<<<<< HEAD party_account_currency: frm.doc.payment_type=="Receive" ? frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency +======= + party_account_currency: + frm.doc.payment_type == "Receive" + ? frm.doc.paid_from_account_currency + : frm.doc.paid_to_account_currency, + party_type: frm.doc.party_type, + party: frm.doc.party, +>>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry) }, callback: function(r, rt) { if(r.message) { diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 370e1deaa40..0182e80c59d 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -348,7 +348,11 @@ class PaymentEntry(AccountsController): continue ref_details = get_reference_details( - d.reference_doctype, d.reference_name, self.party_account_currency + d.reference_doctype, + d.reference_name, + self.party_account_currency, + self.party_type, + self.party, ) # Only update exchange rate when the reference is Journal Entry @@ -1883,34 +1887,48 @@ def get_company_defaults(company): return frappe.get_cached_value("Company", company, fields, as_dict=1) -def get_outstanding_on_journal_entry(name): - gl = frappe.qb.DocType("GL Entry") - res = ( - frappe.qb.from_(gl) - .select( - Case() - .when( - gl.party_type == "Customer", - Coalesce(Sum(gl.debit_in_account_currency - gl.credit_in_account_currency), 0), - ) - .else_(Coalesce(Sum(gl.credit_in_account_currency - gl.debit_in_account_currency), 0)) - .as_("outstanding_amount") - ) +def get_outstanding_on_journal_entry(voucher_no, party_type, party): + ple = frappe.qb.DocType("Payment Ledger Entry") + + outstanding = ( + frappe.qb.from_(ple) + .select(Sum(ple.amount_in_account_currency)) .where( - (Coalesce(gl.party_type, "") != "") - & (gl.is_cancelled == 0) - & ((gl.voucher_no == name) | (gl.against_voucher == name)) + (ple.against_voucher_no == voucher_no) + & (ple.party_type == party_type) + & (ple.party == party) + & (ple.delinked == 0) ) - ).run(as_dict=True) + ).run() - outstanding_amount = res[0].get("outstanding_amount", 0) if res else 0 + outstanding_amount = outstanding[0][0] if outstanding else 0 - return outstanding_amount + total = ( + frappe.qb.from_(ple) + .select(Sum(ple.amount_in_account_currency)) + .where( + (ple.voucher_no == voucher_no) + & (ple.party_type == party_type) + & (ple.party == party) + & (ple.delinked == 0) + ) + ).run() + + total_amount = total[0][0] if total else 0 + + return outstanding_amount, total_amount @frappe.whitelist() +<<<<<<< HEAD def get_reference_details(reference_doctype, reference_name, party_account_currency): total_amount = outstanding_amount = exchange_rate = None +======= +def get_reference_details( + reference_doctype, reference_name, party_account_currency, party_type=None, party=None +): + total_amount = outstanding_amount = exchange_rate = account = None +>>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry) ref_doc = frappe.get_doc(reference_doctype, reference_name) company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(ref_doc.company) @@ -1920,12 +1938,13 @@ def get_reference_details(reference_doctype, reference_name, party_account_curre exchange_rate = 1 elif reference_doctype == "Journal Entry" and ref_doc.docstatus == 1: - total_amount = ref_doc.get("total_amount") if ref_doc.multi_currency: exchange_rate = get_exchange_rate(party_account_currency, company_currency, ref_doc.posting_date) else: exchange_rate = 1 - outstanding_amount = get_outstanding_on_journal_entry(reference_name) + outstanding_amount, total_amount = get_outstanding_on_journal_entry( + reference_name, party_type, party + ) elif reference_doctype != "Journal Entry": if not total_amount: diff --git a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py index c600198999e..28dfae29966 100644 --- a/erpnext/accounts/doctype/payment_entry/test_payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/test_payment_entry.py @@ -1087,7 +1087,9 @@ class TestPaymentEntry(FrappeTestCase): pe.source_exchange_rate = 50 pe.save() - ref_details = get_reference_details(so.doctype, so.name, pe.paid_from_account_currency) + ref_details = get_reference_details( + so.doctype, so.name, pe.paid_from_account_currency, "Customer", so.customer + ) expected_response = { "total_amount": 5000.0, "outstanding_amount": 5000.0, diff --git a/erpnext/accounts/doctype/payment_request/payment_request.py b/erpnext/accounts/doctype/payment_request/payment_request.py index 583735b1cc6..0fa2e7835eb 100644 --- a/erpnext/accounts/doctype/payment_request/payment_request.py +++ b/erpnext/accounts/doctype/payment_request/payment_request.py @@ -596,7 +596,11 @@ def update_payment_req_status(doc, method): if payment_request_name: ref_details = get_reference_details( - ref.reference_doctype, ref.reference_name, doc.party_account_currency + ref.reference_doctype, + ref.reference_name, + doc.party_account_currency, + doc.party_type, + doc.party, ) pay_req_doc = frappe.get_doc("Payment Request", payment_request_name) status = pay_req_doc.status From a6bf7c1ebdfbb9ca46db2284ebc4561759c44473 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 15:06:05 +0530 Subject: [PATCH 04/21] chore: remove unused imports --- erpnext/accounts/doctype/payment_entry/payment_entry.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 0182e80c59d..5218f0ea344 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -9,8 +9,7 @@ import frappe from frappe import ValidationError, _, qb, scrub, throw from frappe.utils import cint, comma_or, flt, getdate, nowdate from frappe.utils.data import comma_and, fmt_money -from pypika import Case -from pypika.functions import Coalesce, Sum +from pypika.functions import Sum import erpnext from erpnext.accounts.doctype.accounting_dimension.accounting_dimension import get_dimensions From 5230d411bf30ce2f168a7dca1fbf4f8087a7fd39 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 15:05:58 +0530 Subject: [PATCH 05/21] chore: resolve conflicts --- .../accounts/doctype/payment_entry/payment_entry.js | 10 +--------- .../accounts/doctype/payment_entry/payment_entry.py | 7 +------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js index 6909ca2b04b..e184a3e00fd 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.js +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js @@ -1395,17 +1395,9 @@ frappe.ui.form.on('Payment Entry Reference', { args: { reference_doctype: row.reference_doctype, reference_name: row.reference_name, -<<<<<<< HEAD - party_account_currency: frm.doc.payment_type=="Receive" ? - frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency -======= - party_account_currency: - frm.doc.payment_type == "Receive" - ? frm.doc.paid_from_account_currency - : frm.doc.paid_to_account_currency, + party_account_currency: frm.doc.payment_type == "Receive" ? frm.doc.paid_from_account_currency : frm.doc.paid_to_account_currency, party_type: frm.doc.party_type, party: frm.doc.party, ->>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry) }, callback: function(r, rt) { if(r.message) { diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 5218f0ea344..fa5aabe1268 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1919,15 +1919,10 @@ def get_outstanding_on_journal_entry(voucher_no, party_type, party): @frappe.whitelist() -<<<<<<< HEAD -def get_reference_details(reference_doctype, reference_name, party_account_currency): - total_amount = outstanding_amount = exchange_rate = None -======= def get_reference_details( reference_doctype, reference_name, party_account_currency, party_type=None, party=None ): - total_amount = outstanding_amount = exchange_rate = account = None ->>>>>>> f331f9b15c (fix: Fetch outstanding and total amount for reference journal entry) + total_amount = outstanding_amount = exchange_rate = None ref_doc = frappe.get_doc(reference_doctype, reference_name) company_currency = ref_doc.get("company_currency") or erpnext.get_company_currency(ref_doc.company) From c834a9de855ceaff128a96b74cbe006f2e1d1037 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 17:01:24 +0530 Subject: [PATCH 06/21] refactor: remove 'format:' based naming in internal doctypes (cherry picked from commit e2ec3e453a4995cacabb676165b135cf43e07315) # Conflicts: # erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json # erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json --- .../repost_accounting_ledger/repost_accounting_ledger.json | 7 ++++--- .../repost_payment_ledger/repost_payment_ledger.json | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json index 5b7cd2b0b20..cef88965f6b 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json +++ b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json @@ -1,7 +1,5 @@ { "actions": [], - "allow_rename": 1, - "autoname": "format:ACC-REPOST-{#####}", "creation": "2023-07-04 13:07:32.923675", "default_view": "List", "doctype": "DocType", @@ -55,11 +53,14 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-09-26 14:21:27.362567", +======= + "modified": "2024-05-23 17:00:42.984798", +>>>>>>> e2ec3e453a (refactor: remove 'format:' based naming in internal doctypes) "modified_by": "Administrator", "module": "Accounts", "name": "Repost Accounting Ledger", - "naming_rule": "Expression", "owner": "Administrator", "permissions": [ { diff --git a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json index ed8d395a0ec..84205990dda 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json +++ b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json @@ -1,6 +1,5 @@ { "actions": [], - "allow_rename": 1, "creation": "2022-10-19 21:59:33.553852", "doctype": "DocType", "editable_grid": 1, @@ -99,7 +98,11 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-09-26 14:21:35.719727", +======= + "modified": "2024-05-23 17:00:31.540640", +>>>>>>> e2ec3e453a (refactor: remove 'format:' based naming in internal doctypes) "modified_by": "Administrator", "module": "Accounts", "name": "Repost Payment Ledger", From 0dc2f78a2ed55677f837da4de3544935220c4910 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 11:52:11 +0530 Subject: [PATCH 07/21] refactor: query payment ledger for payments (cherry picked from commit cb3c20dcd3704afc9d02539ca931e2bdd6fe4e4b) --- .../payment_period_based_on_invoice_date.py | 76 ++++++++++++------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py index 834eb5f519c..c78424cfab6 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py @@ -3,7 +3,8 @@ import frappe -from frappe import _ +from frappe import _, qb +from frappe.query_builder import Criterion from frappe.utils import flt, getdate from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport @@ -129,51 +130,68 @@ def get_columns(filters): def get_conditions(filters): + ple = qb.DocType("Payment Ledger Entry") conditions = [] - if not filters.party_type: - if filters.payment_type == _("Outgoing"): - filters.party_type = "Supplier" - else: - filters.party_type = "Customer" - - if filters.party_type: - conditions.append("party_type=%(party_type)s") + conditions.append(ple.delinked.eq(0)) + if filters.payment_type == _("Outgoing"): + conditions.append(ple.party_type.eq("Supplier")) + conditions.append(ple.against_voucher_type.eq("Purchase Invoice")) + else: + conditions.append(ple.party_type.eq("Customer")) + conditions.append(ple.against_voucher_type.eq("Sales Invoice")) if filters.party: - conditions.append("party=%(party)s") - - if filters.party_type: - conditions.append("against_voucher_type=%(reference_type)s") - filters["reference_type"] = ( - "Sales Invoice" if filters.party_type == "Customer" else "Purchase Invoice" - ) + conditions.append(ple.party.eq(filters.party)) if filters.get("from_date"): - conditions.append("posting_date >= %(from_date)s") + conditions.append(ple.posting_date.gte(filters.get("from_date"))) if filters.get("to_date"): - conditions.append("posting_date <= %(to_date)s") + conditions.append(ple.posting_date.lte(filters.get("to_date"))) - return "and " + " and ".join(conditions) if conditions else "" + if filters.get("company"): + conditions.append(ple.company.eq(filters.get("company"))) + + return conditions def get_entries(filters): - return frappe.db.sql( - """select - voucher_type, voucher_no, party_type, party, posting_date, debit, credit, remarks, against_voucher - from `tabGL Entry` - where company=%(company)s and voucher_type in ('Journal Entry', 'Payment Entry') and is_cancelled = 0 {} - """.format(get_conditions(filters)), - filters, - as_dict=1, + ple = qb.DocType("Payment Ledger Entry") + conditions = get_conditions(filters) + + query = ( + qb.from_(ple) + .select( + ple.voucher_type, + ple.voucher_no, + ple.party_type, + ple.party, + ple.posting_date, + ple.amount, + ple.remarks, + ple.against_voucher_no, + ) + .where(Criterion.all(conditions)) ) + res = query.run(as_dict=True) + return res def get_invoice_posting_date_map(filters): invoice_details = {} - dt = "Sales Invoice" if filters.get("payment_type") == _("Incoming") else "Purchase Invoice" - for t in frappe.db.sql(f"select name, posting_date, due_date from `tab{dt}`", as_dict=1): + dt = ( + qb.DocType("Sales Invoice") + if filters.get("payment_type") == _("Incoming") + else qb.DocType("Purchase Invoice") + ) + res = ( + qb.from_(dt) + .select(dt.name, dt.posting_date, dt.due_date) + .where((dt.docstatus.eq(1)) & (dt.company.eq(filters.get("company")))) + .run(as_dict=1) + ) + for t in res: invoice_details[t.name] = t return invoice_details From 3512f7d528533cf8204b74ece9083d14af013ca5 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 11:59:57 +0530 Subject: [PATCH 08/21] refactor: remove debit and credit (cherry picked from commit 014b542cf3aacba93f87f380470cd692598c14e3) --- .../payment_period_based_on_invoice_date.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py index c78424cfab6..04626bc528f 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py @@ -23,11 +23,7 @@ def execute(filters=None): data = [] for d in entries: invoice = invoice_details.get(d.against_voucher) or frappe._dict() - - if d.reference_type == "Purchase Invoice": - payment_amount = flt(d.debit) or -1 * flt(d.credit) - else: - payment_amount = flt(d.credit) or -1 * flt(d.debit) + payment_amount = d.amount d.update({"range1": 0, "range2": 0, "range3": 0, "range4": 0, "outstanding": payment_amount}) @@ -43,8 +39,7 @@ def execute(filters=None): d.against_voucher, invoice.posting_date, invoice.due_date, - d.debit, - d.credit, + d.amount, d.remarks, d.age, d.range1, @@ -112,8 +107,7 @@ def get_columns(filters): "width": 100, }, {"fieldname": "due_date", "label": _("Payment Due Date"), "fieldtype": "Date", "width": 100}, - {"fieldname": "debit", "label": _("Debit"), "fieldtype": "Currency", "width": 140}, - {"fieldname": "credit", "label": _("Credit"), "fieldtype": "Currency", "width": 140}, + {"fieldname": "amount", "label": _("Amount"), "fieldtype": "Currency", "width": 140}, {"fieldname": "remarks", "label": _("Remarks"), "fieldtype": "Data", "width": 200}, {"fieldname": "age", "label": _("Age"), "fieldtype": "Int", "width": 50}, {"fieldname": "range1", "label": _("0-30"), "fieldtype": "Currency", "width": 140}, From 190900cd1bcaec3aebe7a2d757caa6da79ab93ef Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 12:08:51 +0530 Subject: [PATCH 09/21] refactor: replace against_voucher with against_voucher_no (cherry picked from commit c4e2abb9739da20be3409cde87c014d0d689e1b6) --- .../payment_period_based_on_invoice_date.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py index 04626bc528f..f3f30d38a04 100644 --- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py +++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py @@ -5,6 +5,7 @@ import frappe from frappe import _, qb from frappe.query_builder import Criterion +from frappe.query_builder.functions import Abs from frappe.utils import flt, getdate from erpnext.accounts.report.accounts_receivable.accounts_receivable import ReceivablePayableReport @@ -22,12 +23,12 @@ def execute(filters=None): data = [] for d in entries: - invoice = invoice_details.get(d.against_voucher) or frappe._dict() + invoice = invoice_details.get(d.against_voucher_no) or frappe._dict() payment_amount = d.amount d.update({"range1": 0, "range2": 0, "range3": 0, "range4": 0, "outstanding": payment_amount}) - if d.against_voucher: + if d.against_voucher_no: ReceivablePayableReport(filters).get_ageing_data(invoice.posting_date, d) row = [ @@ -36,7 +37,7 @@ def execute(filters=None): d.party_type, d.party, d.posting_date, - d.against_voucher, + d.against_voucher_no, invoice.posting_date, invoice.due_date, d.amount, @@ -162,7 +163,7 @@ def get_entries(filters): ple.party_type, ple.party, ple.posting_date, - ple.amount, + Abs(ple.amount).as_("amount"), ple.remarks, ple.against_voucher_no, ) From 0f9b5074a6a4b02b1a3e3bdf56e6c8c1c62cca06 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Thu, 23 May 2024 17:46:23 +0530 Subject: [PATCH 10/21] chore: resolve conflicts --- .../repost_accounting_ledger/repost_accounting_ledger.json | 4 ---- .../doctype/repost_payment_ledger/repost_payment_ledger.json | 4 ---- 2 files changed, 8 deletions(-) diff --git a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json index cef88965f6b..f9344ce4f3a 100644 --- a/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json +++ b/erpnext/accounts/doctype/repost_accounting_ledger/repost_accounting_ledger.json @@ -53,11 +53,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], -<<<<<<< HEAD - "modified": "2023-09-26 14:21:27.362567", -======= "modified": "2024-05-23 17:00:42.984798", ->>>>>>> e2ec3e453a (refactor: remove 'format:' based naming in internal doctypes) "modified_by": "Administrator", "module": "Accounts", "name": "Repost Accounting Ledger", diff --git a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json index 84205990dda..4ecff8cac3b 100644 --- a/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json +++ b/erpnext/accounts/doctype/repost_payment_ledger/repost_payment_ledger.json @@ -98,11 +98,7 @@ "index_web_pages_for_search": 1, "is_submittable": 1, "links": [], -<<<<<<< HEAD - "modified": "2023-09-26 14:21:35.719727", -======= "modified": "2024-05-23 17:00:31.540640", ->>>>>>> e2ec3e453a (refactor: remove 'format:' based naming in internal doctypes) "modified_by": "Administrator", "module": "Accounts", "name": "Repost Payment Ledger", From 459d13636823cf9faef760b1fd7f1f303e6b3d8d Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Fri, 10 May 2024 12:31:15 +0530 Subject: [PATCH 11/21] fix: cost center filter according to the company in project (cherry picked from commit 249e8264ddde2f3397a65b19492560069e18a02b) --- erpnext/projects/doctype/project/project.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 3ea8189feec..271fe4e36e2 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -57,6 +57,14 @@ frappe.ui.form.on("Project", { filters: filters, }; }); + + frm.set_query("cost_center", () => { + return { + filters: { + company: frm.doc.company, + } + } + }); }, refresh: function (frm) { From 0cf97f255982c921d528747b6daa6d96a12e265d Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Fri, 10 May 2024 12:35:24 +0530 Subject: [PATCH 12/21] fix: cost center filter according to the company in project (cherry picked from commit cfde8088b43d884858dbfaec5ce1937a4ccf9eb3) --- erpnext/projects/doctype/project/project.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 271fe4e36e2..8d320e84713 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -62,8 +62,8 @@ frappe.ui.form.on("Project", { return { filters: { company: frm.doc.company, - } - } + }, + }, }); }, From 7035969db7563061b2df89349eed8c22dc365150 Mon Sep 17 00:00:00 2001 From: "Nihantra C. Patel" <141945075+Nihantra-Patel@users.noreply.github.com> Date: Fri, 10 May 2024 12:40:01 +0530 Subject: [PATCH 13/21] fix: cost center filter according to the company in project (cherry picked from commit 501c6aa1267a11109ca47bb9bfeab3d4ead0d794) --- erpnext/projects/doctype/project/project.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/projects/doctype/project/project.js b/erpnext/projects/doctype/project/project.js index 8d320e84713..6ac6d1f88a6 100644 --- a/erpnext/projects/doctype/project/project.js +++ b/erpnext/projects/doctype/project/project.js @@ -63,7 +63,7 @@ frappe.ui.form.on("Project", { filters: { company: frm.doc.company, }, - }, + }; }); }, From c16c41ee593bfafa4c5563f527babdb4c16b309a Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 23 May 2024 16:36:41 +0530 Subject: [PATCH 14/21] fix: add in some indices to speed up Purchase Order deletion `tabSales Order`.`inter_company_order_reference` `tabSales Invoice Item`.`purchase_order` Signed-off-by: Akhil Narang (cherry picked from commit 0303d7dbdc7a84679034e5ba793a13823a7c8f24) # Conflicts: # erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json # erpnext/selling/doctype/sales_order/sales_order.json --- .../doctype/sales_invoice_item/sales_invoice_item.json | 7 ++++++- erpnext/selling/doctype/sales_order/sales_order.json | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index 87cf1ae80d6..29261e47627 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -867,7 +867,8 @@ "label": "Purchase Order", "options": "Purchase Order", "print_hide": 1, - "read_only": 1 + "read_only": 1, + "search_index": 1 }, { "fieldname": "column_break_92", @@ -892,7 +893,11 @@ "idx": 1, "istable": 1, "links": [], +<<<<<<< HEAD "modified": "2023-11-14 18:34:10.479329", +======= + "modified": "2024-05-23 16:36:18.970862", +>>>>>>> 0303d7dbdc (fix: add in some indices to speed up Purchase Order deletion) "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json index 09b73878aa2..b3fb51c4fb8 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.json +++ b/erpnext/selling/doctype/sales_order/sales_order.json @@ -1138,7 +1138,8 @@ "hide_seconds": 1, "label": "Inter Company Order Reference", "options": "Purchase Order", - "read_only": 1 + "read_only": 1, + "search_index": 1 }, { "fieldname": "project", @@ -1631,7 +1632,11 @@ "idx": 105, "is_submittable": 1, "links": [], +<<<<<<< HEAD "modified": "2024-03-20 16:04:43.627183", +======= + "modified": "2024-05-23 16:35:54.905804", +>>>>>>> 0303d7dbdc (fix: add in some indices to speed up Purchase Order deletion) "modified_by": "Administrator", "module": "Selling", "name": "Sales Order", From f1f2f6e3388df52cc883805d4b8d0195728abf81 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Fri, 24 May 2024 11:05:45 +0530 Subject: [PATCH 15/21] chore: resolve conflicts --- .../doctype/sales_invoice_item/sales_invoice_item.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json index 29261e47627..5e7a75b8a3f 100644 --- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json +++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json @@ -893,11 +893,7 @@ "idx": 1, "istable": 1, "links": [], -<<<<<<< HEAD - "modified": "2023-11-14 18:34:10.479329", -======= "modified": "2024-05-23 16:36:18.970862", ->>>>>>> 0303d7dbdc (fix: add in some indices to speed up Purchase Order deletion) "modified_by": "Administrator", "module": "Accounts", "name": "Sales Invoice Item", From 220ae118e816a2a1a1f0a1fbc387315fca5d68af Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Fri, 24 May 2024 11:08:53 +0530 Subject: [PATCH 16/21] chore: resolve conflicts --- erpnext/selling/doctype/sales_order/sales_order.json | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/erpnext/selling/doctype/sales_order/sales_order.json b/erpnext/selling/doctype/sales_order/sales_order.json index b3fb51c4fb8..43e8e41f7f3 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.json +++ b/erpnext/selling/doctype/sales_order/sales_order.json @@ -1632,11 +1632,7 @@ "idx": 105, "is_submittable": 1, "links": [], -<<<<<<< HEAD - "modified": "2024-03-20 16:04:43.627183", -======= "modified": "2024-05-23 16:35:54.905804", ->>>>>>> 0303d7dbdc (fix: add in some indices to speed up Purchase Order deletion) "modified_by": "Administrator", "module": "Selling", "name": "Sales Order", @@ -1715,4 +1711,4 @@ "title_field": "customer_name", "track_changes": 1, "track_seen": 1 -} \ No newline at end of file +} From 518dad8ecba61acd80ce6eb0bd3e050b0f585024 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 17 Apr 2024 12:49:01 +0530 Subject: [PATCH 17/21] ci: dont auto apply fixes I've personally encountered ~5 instances of bad auto fixes, let developers apply the fixes. (cherry picked from commit 3b4913ec810bcee60537380bdc721c04a4e823c6) --- .pre-commit-config.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f670f2bec3..14bd9e8f0c4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,8 +69,7 @@ repos: rev: v0.2.0 hooks: - id: ruff - name: "Run ruff linter and apply fixes" - args: ["--fix"] + name: "Run ruff linter" - id: ruff-format name: "Format Python code" From 76b7884fb7a8d60e1282f58e652b73f597439bce Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Tue, 21 May 2024 16:05:16 +0530 Subject: [PATCH 18/21] ci: ruff only fix imports (cherry picked from commit 85b1a8001b30429800ca5c6bef960c885368819b) --- .pre-commit-config.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 14bd9e8f0c4..56bcb22c9bb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -68,12 +68,15 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.2.0 hooks: + - id: ruff + name: "Run ruff import sorter" + args: ["--select=I", "--fix"] + - id: ruff name: "Run ruff linter" - id: ruff-format - name: "Format Python code" - + name: "Run ruff formatter" ci: autoupdate_schedule: weekly From 5b2c13dacf32c80ca1cf444f2bf98829d59850e1 Mon Sep 17 00:00:00 2001 From: Akhil Narang Date: Thu, 23 May 2024 19:30:42 +0530 Subject: [PATCH 19/21] refactor: use `json` directly instead of using `frappe.json` (#41609) (cherry picked from commit 3f06f1905f6c86eaa5eb4d33765a46470892f576) Signed-off-by: Akhil Narang --- .../doctype/pos_invoice_merge_log/pos_invoice_merge_log.py | 2 +- .../process_payment_reconciliation.py | 4 +++- erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py | 5 +++-- .../doctype/unreconcile_payment/unreconcile_payment.py | 4 +++- erpnext/accounts/utils.py | 2 +- erpnext/selling/doctype/customer/test_customer.py | 4 +++- 6 files changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 1302a0c386c..0d02172226e 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -441,7 +441,7 @@ def create_merge_logs(invoice_by_customer, closing_entry=None): if closing_entry: closing_entry.set_status(update=True, status="Failed") if isinstance(error_message, list): - error_message = frappe.json.dumps(error_message) + error_message = json.dumps(error_message) closing_entry.db_set("error_message", error_message) raise diff --git a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py index c7535e76d7e..b1419020f0f 100644 --- a/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py +++ b/erpnext/accounts/doctype/process_payment_reconciliation/process_payment_reconciliation.py @@ -1,6 +1,8 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt +import json + import frappe from frappe import _, qb from frappe.model.document import Document @@ -479,7 +481,7 @@ def is_any_doc_running(for_filter: str | dict | None = None) -> str | None: running_doc = None if for_filter: if isinstance(for_filter, str): - for_filter = frappe.json.loads(for_filter) + for_filter = json.loads(for_filter) running_doc = frappe.db.get_value( "Process Payment Reconciliation", diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 87d297f4aa1..9c7cfa4387e 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2,6 +2,7 @@ # License: GNU General Public License v3. See license.txt import copy +import json import frappe from frappe.model.dynamic_links import get_dynamic_link_map @@ -3479,9 +3480,9 @@ class TestSalesInvoice(FrappeTestCase): map_docs( method="erpnext.stock.doctype.delivery_note.delivery_note.make_sales_invoice", - source_names=frappe.json.dumps([dn1.name, dn2.name]), + source_names=json.dumps([dn1.name, dn2.name]), target_doc=si, - args=frappe.json.dumps({"customer": dn1.customer, "merge_taxes": 1, "filtered_children": []}), + args=json.dumps({"customer": dn1.customer, "merge_taxes": 1, "filtered_children": []}), ) si.save().submit() diff --git a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py index 091bccf5099..6ba1de35238 100644 --- a/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py +++ b/erpnext/accounts/doctype/unreconcile_payment/unreconcile_payment.py @@ -1,6 +1,8 @@ # Copyright (c) 2023, Frappe Technologies Pvt. Ltd. and contributors # For license information, please see license.txt +import json + import frappe from frappe import _, qb from frappe.model.document import Document @@ -142,7 +144,7 @@ def get_linked_payments_for_doc( @frappe.whitelist() def create_unreconcile_doc_for_selection(selections=None): if selections: - selections = frappe.json.loads(selections) + selections = json.loads(selections) # assuming each row is a unique voucher for row in selections: unrecon = frappe.new_doc("Unreconcile Payment") diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 377eeae7cff..7e67085f5dd 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -56,7 +56,7 @@ def get_fiscal_year( date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False, boolean=False ): if isinstance(boolean, str): - boolean = frappe.json.loads(boolean) + boolean = loads(boolean) fiscal_years = get_fiscal_years( date, fiscal_year, label, verbose, company, as_dict=as_dict, boolean=boolean diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py index 61e5d5e457c..23052299330 100644 --- a/erpnext/selling/doctype/customer/test_customer.py +++ b/erpnext/selling/doctype/customer/test_customer.py @@ -2,6 +2,8 @@ # License: GNU General Public License v3. See license.txt +import json + import frappe from frappe.custom.doctype.property_setter.property_setter import make_property_setter from frappe.test_runner import make_test_records @@ -322,7 +324,7 @@ class TestCustomer(FrappeTestCase): frappe.ValidationError, update_child_qty_rate, so.doctype, - frappe.json.dumps([modified_item]), + json.dumps([modified_item]), so.name, ) From 014486de39dd7da6fe79bf803adcf1b66d890876 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 May 2024 10:46:06 +0530 Subject: [PATCH 20/21] fix: set expense account as Assets RBNB only if it is booked in linked PR (#41368) * fix: set expense account as Assets RBNB only if it is booked in linked PR * fix: broken translations --- .../pos_closing_entry/pos_closing_entry.py | 2 +- .../pos_invoice_merge_log.py | 2 +- .../purchase_invoice/purchase_invoice.py | 52 ++++++++++++------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py index f61bfdb58ab..4e4a7492a00 100644 --- a/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py +++ b/erpnext/accounts/doctype/pos_closing_entry/pos_closing_entry.py @@ -33,7 +33,7 @@ class POSClosingEntry(StatusUpdater): for key, value in pos_occurences.items(): if len(value) > 1: error_list.append( - _(f"{frappe.bold(key)} is added multiple times on rows: {frappe.bold(value)}") + _("{0} is added multiple times on rows: {1}").format(frappe.bold(key), frappe.bold(value)) ) if error_list: diff --git a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py index 0d02172226e..a183a5ee6aa 100644 --- a/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py +++ b/erpnext/accounts/doctype/pos_invoice_merge_log/pos_invoice_merge_log.py @@ -29,7 +29,7 @@ class POSInvoiceMergeLog(Document): for key, value in pos_occurences.items(): if len(value) > 1: error_list.append( - _(f"{frappe.bold(key)} is added multiple times on rows: {frappe.bold(value)}") + _("{0} is added multiple times on rows: {1}").format(frappe.bold(key), frappe.bold(value)) ) if error_list: diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 77f879a1f42..c5f089fd24d 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -284,7 +284,7 @@ class PurchaseInvoice(BuyingController): stock_not_billed_account = self.get_company_default("stock_received_but_not_billed") stock_items = self.get_stock_items() - asset_received_but_not_billed = None + asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed") if self.update_stock: self.validate_item_code() @@ -367,26 +367,40 @@ class PurchaseInvoice(BuyingController): frappe.msgprint(msg, title=_("Expense Head Changed")) item.expense_account = stock_not_billed_account - elif item.is_fixed_asset and item.pr_detail: - if not asset_received_but_not_billed: - asset_received_but_not_billed = self.get_company_default("asset_received_but_not_billed") - item.expense_account = asset_received_but_not_billed elif item.is_fixed_asset: - account_type = ( - "capital_work_in_progress_account" - if is_cwip_accounting_enabled(item.asset_category) - else "fixed_asset_account" - ) - asset_category_account = get_asset_category_account( - account_type, item=item.item_code, company=self.company - ) - if not asset_category_account: - form_link = get_link_to_form("Asset Category", item.asset_category) - throw( - _("Please set Fixed Asset Account in {} against {}.").format(form_link, self.company), - title=_("Missing Account"), + account = None + if item.pr_detail: + # check if 'Asset Received But Not Billed' account is credited in Purchase receipt or not + arbnb_booked_in_pr = frappe.db.get_value( + "GL Entry", + { + "voucher_type": "Purchase Receipt", + "voucher_no": item.purchase_receipt, + "account": asset_received_but_not_billed, + }, + "name", ) - item.expense_account = asset_category_account + if arbnb_booked_in_pr: + account = asset_received_but_not_billed + + if not account: + account_type = ( + "capital_work_in_progress_account" + if is_cwip_accounting_enabled(item.asset_category) + else "fixed_asset_account" + ) + account = get_asset_category_account( + account_type, item=item.item_code, company=self.company + ) + if not account: + form_link = get_link_to_form("Asset Category", item.asset_category) + throw( + _("Please set Fixed Asset Account in {} against {}.").format( + form_link, self.company + ), + title=_("Missing Account"), + ) + item.expense_account = account elif not item.expense_account and for_validate: throw(_("Expense account is mandatory for item {0}").format(item.item_code or item.item_name)) From eb418e865945a208338db65e7fb1f259cc7f94b5 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 29 May 2024 11:07:03 +0530 Subject: [PATCH 21/21] fix: Update depreciation schedule via asset repair (#41344) * fix: Update depreciation schedule via asset repair * fix: test cases related to modified depreciation schedule --- .../sales_invoice/test_sales_invoice.py | 4 +--- erpnext/assets/doctype/asset/asset.py | 22 +++++++++++++------ erpnext/assets/doctype/asset/test_asset.py | 4 ++-- .../test_asset_value_adjustment.py | 11 +++++----- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py index 9c7cfa4387e..f22218fcd33 100644 --- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py @@ -2979,10 +2979,8 @@ class TestSalesInvoice(FrappeTestCase): ["2021-06-30", 20000.0, 21366.12, True], ["2022-06-30", 20000.0, 41366.12, False], ["2023-06-30", 20000.0, 61366.12, False], - ["2024-06-30", 20000.0, 81366.12, False], - ["2025-06-06", 18633.88, 100000.0, False], + ["2024-06-06", 38633.88, 100000.0, False], ] - for i, schedule in enumerate(asset.schedules): self.assertEqual(getdate(expected_values[i][0]), schedule.schedule_date) self.assertEqual(expected_values[i][1], schedule.depreciation_amount) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index fd00a495030..405eda8d09f 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -12,6 +12,7 @@ from frappe.utils import ( add_months, add_years, cint, + cstr, date_diff, flt, get_datetime, @@ -361,9 +362,11 @@ class Asset(AccountsController): final_number_of_depreciations = cint(finance_book.total_number_of_depreciations) - cint( self.number_of_depreciations_booked ) - has_pro_rata = self.check_is_pro_rata(finance_book) - if has_pro_rata: + depr_already_booked = any( + [d.journal_entry for d in self.get("schedules") if d.finance_book == finance_book.finance_book] + ) + if has_pro_rata and not depr_already_booked: final_number_of_depreciations += 1 has_wdv_or_dd_non_yearly_pro_rata = False @@ -543,7 +546,7 @@ class Asset(AccountsController): "depreciation_amount": depreciation_amount, "depreciation_method": finance_book.depreciation_method, "finance_book": finance_book.finance_book, - "finance_book_id": finance_book.idx, + "finance_book_id": cstr(finance_book.idx), "shift": shift, }, ) @@ -749,7 +752,6 @@ class Asset(AccountsController): ): straight_line_idx = [] finance_books = [] - for i, d in enumerate(self.get("schedules")): if ignore_booked_entry and d.journal_entry: continue @@ -771,7 +773,10 @@ class Asset(AccountsController): finance_books.append(int(d.finance_book_id)) depreciation_amount = flt(d.depreciation_amount, d.precision("depreciation_amount")) - value_after_depreciation -= flt(depreciation_amount) + if not d.journal_entry: + value_after_depreciation = flt( + flt(value_after_depreciation) - depreciation_amount, d.precision("depreciation_amount") + ) # for the last row, if depreciation method = Straight Line if ( @@ -783,10 +788,13 @@ class Asset(AccountsController): book = self.get("finance_books")[cint(d.finance_book_id) - 1] if not book.shift_based: - depreciation_amount += flt( + adjustment_amount = flt( value_after_depreciation - flt(book.expected_value_after_useful_life), d.precision("depreciation_amount"), ) + depreciation_amount = flt( + depreciation_amount + adjustment_amount, d.precision("depreciation_amount") + ) d.depreciation_amount = depreciation_amount accumulated_depreciation += d.depreciation_amount @@ -1433,7 +1441,7 @@ def get_straight_line_or_manual_depr_amount(asset, row, schedule_idx, number_of_ # if the Depreciation Schedule is being modified after Asset Repair due to increase in asset value elif asset.flags.increase_in_asset_value_due_to_repair: return (flt(row.value_after_depreciation) - flt(row.expected_value_after_useful_life)) / flt( - row.total_number_of_depreciations + number_of_pending_depreciations ) # if the Depreciation Schedule is being modified after Asset Value Adjustment due to decrease in asset value elif asset.flags.decrease_in_asset_value_due_to_value_adjustment: diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 00a53aa80d2..dc58222008a 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -1355,9 +1355,9 @@ class TestDepreciationBasics(AssetSetup): for schedule in asset.schedules: if schedule.idx <= 3: - self.assertEqual(schedule.finance_book_id, 1) + self.assertEqual(schedule.finance_book_id, "1") else: - self.assertEqual(schedule.finance_book_id, 2) + self.assertEqual(schedule.finance_book_id, "2") def test_depreciation_entry_cancellation(self): asset = create_asset( diff --git a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py index 7661e70fd17..f3583b0768d 100644 --- a/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py +++ b/erpnext/assets/doctype/asset_value_adjustment/test_asset_value_adjustment.py @@ -103,12 +103,11 @@ class TestAssetValueAdjustment(unittest.TestCase): ["2023-05-31", 9983.33, 45408.05], ["2023-06-30", 9983.33, 55391.38], ["2023-07-31", 9983.33, 65374.71], - ["2023-08-31", 8300.0, 73674.71], - ["2023-09-30", 8300.0, 81974.71], - ["2023-10-31", 8300.0, 90274.71], - ["2023-11-30", 8300.0, 98574.71], - ["2023-12-31", 8300.0, 106874.71], - ["2024-01-15", 8300.0, 115174.71], + ["2023-08-31", 9960.0, 75334.71], + ["2023-09-30", 9960.0, 85294.71], + ["2023-10-31", 9960.0, 95254.71], + ["2023-11-30", 9960.0, 105214.71], + ["2023-12-15", 9960.0, 115174.71], ] schedules = [