From 725a7f90e9a873335caaa588d73ddb3de7383c33 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 19:45:19 +0530 Subject: [PATCH 01/35] fix: use dynamic link for against field --- erpnext/accounts/doctype/gl_entry/gl_entry.json | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index 5063ec6076..1adeaa54d8 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -17,6 +17,7 @@ "account_currency", "debit_in_account_currency", "credit_in_account_currency", + "against_type", "against", "against_voucher_type", "against_voucher", @@ -128,13 +129,21 @@ "label": "Credit Amount in Account Currency", "options": "account_currency" }, + { + "fieldname": "against_type", + "fieldtype": "Link", + "in_filter": 1, + "label": "Against Type", + "options": "DocType" + }, { "fieldname": "against", - "fieldtype": "Text", + "fieldtype": "Dynamic Link", "in_filter": 1, "label": "Against", "oldfieldname": "against", - "oldfieldtype": "Text" + "oldfieldtype": "Text", + "options": "against_type" }, { "fieldname": "against_voucher_type", @@ -286,7 +295,7 @@ "idx": 1, "in_create": 1, "links": [], - "modified": "2023-08-16 21:38:44.072267", + "modified": "2023-09-25 12:03:23.031733", "modified_by": "Administrator", "module": "Accounts", "name": "GL Entry", From 19b220f39ca3596e416d99f3aef7c2485019b9fd Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 19:49:17 +0530 Subject: [PATCH 02/35] fix: set against type in inv gl dict --- .../purchase_invoice/purchase_invoice.py | 29 +++++++++++++++++++ .../doctype/sales_invoice/sales_invoice.py | 14 +++++++++ 2 files changed, 43 insertions(+) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 55972719f8..1dc67ef689 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -623,6 +623,7 @@ class PurchaseInvoice(BuyingController): "party_type": "Supplier", "party": self.supplier, "due_date": self.due_date, + "against_type": "Account", "against": self.against_expense_account, "credit": base_grand_total, "credit_in_account_currency": base_grand_total @@ -692,6 +693,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": warehouse_account[item.warehouse]["account"], + "against_type": "Account", "against": warehouse_account[item.from_warehouse]["account"], "cost_center": item.cost_center, "project": item.project or self.project, @@ -712,6 +714,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": warehouse_account[item.from_warehouse]["account"], + "against_type": "Account", "against": warehouse_account[item.warehouse]["account"], "cost_center": item.cost_center, "project": item.project or self.project, @@ -729,6 +732,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": item.expense_account, + "against_type": "Supplier", "against": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -746,6 +750,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": item.expense_account, + "against_type": "Supplier", "against": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -765,6 +770,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": account, + "against_type": "Account", "against": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -785,6 +791,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": supplier_warehouse_account, + "against_type": "Account", "against": item.expense_account, "cost_center": item.cost_center, "project": item.project or self.project, @@ -842,6 +849,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": expense_account, + "against_type": "Supplier", "against": self.supplier, "debit": amount, "cost_center": item.cost_center, @@ -868,6 +876,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": expense_account, + "against_type": "Supplier", "against": self.supplier, "debit": discrepancy_caused_by_exchange_rate_difference, "cost_center": item.cost_center, @@ -881,6 +890,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": self.get_company_default("exchange_gain_loss_account"), + "against_type": "Supplier", "against": self.supplier, "credit": discrepancy_caused_by_exchange_rate_difference, "cost_center": item.cost_center, @@ -901,6 +911,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": expenses_included_in_asset_valuation, + "against_type": "Account", "against": expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -915,6 +926,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": expense_account, + "against_type": "Account", "against": expenses_included_in_asset_valuation, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -954,6 +966,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": self.stock_received_but_not_billed, + "against_type": "Supplier", "against": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or _("Accounting Entry for Stock"), @@ -993,6 +1006,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": item.expense_account, + "against_type": "Supplier", "against": self.supplier, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "debit": base_asset_amount, @@ -1015,6 +1029,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": eiiav_account, + "against_type": "Supplier", "against": self.supplier, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "cost_center": item.cost_center, @@ -1039,6 +1054,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": cwip_account, + "against_type": "Supplier", "against": self.supplier, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "debit": base_asset_amount, @@ -1061,6 +1077,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": eiiav_account, + "against_type": "Supplier", "against": self.supplier, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "cost_center": item.cost_center, @@ -1085,6 +1102,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": eiiav_account, + "against_type": "Account", "against": cwip_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -1099,6 +1117,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": cwip_account, + "against_type": "Account", "against": eiiav_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -1146,6 +1165,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": cost_of_goods_sold_account, + "against_type": "Account", "against": item.expense_account, "debit": stock_adjustment_amt, "remarks": self.get("remarks") or _("Stock Adjustment"), @@ -1176,6 +1196,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": tax.account_head, + "against_type": "Supplier", "against": self.supplier, dr_or_cr: base_amount, dr_or_cr + "_in_account_currency": base_amount @@ -1224,6 +1245,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": tax.account_head, + "against_type": "Supplier", "cost_center": tax.cost_center, "against": self.supplier, "credit": applicable_amount, @@ -1243,6 +1265,7 @@ class PurchaseInvoice(BuyingController): { "account": tax.account_head, "cost_center": tax.cost_center, + "against_type": "Supplier", "against": self.supplier, "credit": valuation_tax[tax.name], "remarks": self.remarks or _("Accounting Entry for Stock"), @@ -1258,6 +1281,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": self.unrealized_profit_loss_account, + "against_type": "Supplier", "against": self.supplier, "credit": flt(self.total_taxes_and_charges), "credit_in_account_currency": flt(self.base_total_taxes_and_charges), @@ -1279,6 +1303,7 @@ class PurchaseInvoice(BuyingController): "account": self.credit_to, "party_type": "Supplier", "party": self.supplier, + "against_type": "Account", "against": self.cash_bank_account, "debit": self.base_paid_amount, "debit_in_account_currency": self.base_paid_amount @@ -1300,6 +1325,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": self.cash_bank_account, + "against_type": "Supplier", "against": self.supplier, "credit": self.base_paid_amount, "credit_in_account_currency": self.base_paid_amount @@ -1324,6 +1350,7 @@ class PurchaseInvoice(BuyingController): "account": self.credit_to, "party_type": "Supplier", "party": self.supplier, + "against_type": "Account", "against": self.write_off_account, "debit": self.base_write_off_amount, "debit_in_account_currency": self.base_write_off_amount @@ -1344,6 +1371,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": self.write_off_account, + "against_type": "Supplier", "against": self.supplier, "credit": flt(self.base_write_off_amount), "credit_in_account_currency": self.base_write_off_amount @@ -1371,6 +1399,7 @@ class PurchaseInvoice(BuyingController): self.get_gl_dict( { "account": round_off_account, + "against_type": "Supplier", "against": self.supplier, "debit_in_account_currency": self.rounding_adjustment, "debit": self.base_rounding_adjustment, diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 7bdb2b49ce..db3d5c666f 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1101,6 +1101,7 @@ class SalesInvoice(SellingController): "party_type": "Customer", "party": self.customer, "due_date": self.due_date, + "against_type": "Account", "against": self.against_income_account, "debit": base_grand_total, "debit_in_account_currency": base_grand_total @@ -1130,6 +1131,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": tax.account_head, + "against_type": "Customer", "against": self.customer, "credit": flt(base_amount, tax.precision("tax_amount_after_discount_amount")), "credit_in_account_currency": ( @@ -1151,6 +1153,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": self.unrealized_profit_loss_account, + "against_type": "Customer", "against": self.customer, "debit": flt(self.total_taxes_and_charges), "debit_in_account_currency": flt(self.base_total_taxes_and_charges), @@ -1219,6 +1222,7 @@ class SalesInvoice(SellingController): add_asset_activity(asset.name, _("Asset sold")) for gle in fixed_asset_gl_entries: + gle["against_type"] = "Customer" gle["against"] = self.customer gl_entries.append(self.get_gl_dict(gle, item=item)) @@ -1240,6 +1244,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": income_account, + "against_type": "Customer", "against": self.customer, "credit": flt(base_amount, item.precision("base_net_amount")), "credit_in_account_currency": ( @@ -1294,6 +1299,7 @@ class SalesInvoice(SellingController): "account": self.debit_to, "party_type": "Customer", "party": self.customer, + "against_type": "Account", "against": "Expense account - " + cstr(self.loyalty_redemption_account) + " for the Loyalty Program", @@ -1310,6 +1316,7 @@ class SalesInvoice(SellingController): { "account": self.loyalty_redemption_account, "cost_center": self.cost_center or self.loyalty_redemption_cost_center, + "against_type": "Customer", "against": self.customer, "debit": self.loyalty_amount, "remark": "Loyalty Points redeemed by the customer", @@ -1337,6 +1344,7 @@ class SalesInvoice(SellingController): "account": self.debit_to, "party_type": "Customer", "party": self.customer, + "against_type": "Account", "against": payment_mode.account, "credit": payment_mode.base_amount, "credit_in_account_currency": payment_mode.base_amount @@ -1358,6 +1366,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": payment_mode.account, + "against_type": "Customer", "against": self.customer, "debit": payment_mode.base_amount, "debit_in_account_currency": payment_mode.base_amount @@ -1382,6 +1391,7 @@ class SalesInvoice(SellingController): "account": self.debit_to, "party_type": "Customer", "party": self.customer, + "against_type": "Account", "against": self.account_for_change_amount, "debit": flt(self.base_change_amount), "debit_in_account_currency": flt(self.base_change_amount) @@ -1403,6 +1413,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": self.account_for_change_amount, + "against_type": "Customer", "against": self.customer, "credit": self.base_change_amount, "cost_center": self.cost_center, @@ -1429,6 +1440,7 @@ class SalesInvoice(SellingController): "account": self.debit_to, "party_type": "Customer", "party": self.customer, + "against_type": "Account", "against": self.write_off_account, "credit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")), "credit_in_account_currency": ( @@ -1449,6 +1461,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": self.write_off_account, + "against_type": "Customer", "against": self.customer, "debit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")), "debit_in_account_currency": ( @@ -1477,6 +1490,7 @@ class SalesInvoice(SellingController): self.get_gl_dict( { "account": round_off_account, + "against_type": "Customer", "against": self.customer, "credit_in_account_currency": flt( self.rounding_adjustment, self.precision("rounding_adjustment") From 82774f89b106a56c4754536b1c0cf5eb695a3c15 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 19:50:47 +0530 Subject: [PATCH 03/35] fix: set against type in deferred revenue --- erpnext/accounts/deferred_revenue.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index d0940c7df2..00d5ea3245 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -358,9 +358,11 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None): account_currency = get_account_currency(item.expense_account or item.income_account) if doc.doctype == "Sales Invoice": + against_type = "Customer" against, project = doc.customer, doc.project credit_account, debit_account = item.income_account, item.deferred_revenue_account else: + against_type = "Supplier" against, project = doc.supplier, item.project credit_account, debit_account = item.deferred_expense_account, item.expense_account @@ -413,6 +415,7 @@ def book_deferred_income_or_expense(doc, deferred_process, posting_date=None): doc, credit_account, debit_account, + against_type, against, amount, base_amount, @@ -494,6 +497,7 @@ def make_gl_entries( doc, credit_account, debit_account, + against_type, against, amount, base_amount, @@ -515,6 +519,7 @@ def make_gl_entries( doc.get_gl_dict( { "account": credit_account, + "against_type": against_type, "against": against, "credit": base_amount, "credit_in_account_currency": amount, @@ -534,6 +539,7 @@ def make_gl_entries( doc.get_gl_dict( { "account": debit_account, + "against_type": against_type, "against": against, "debit": base_amount, "debit_in_account_currency": amount, From 4c5a83d6cf7e4b39a403b1e99a2b1c443f854ac9 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 19:55:40 +0530 Subject: [PATCH 04/35] fix: set against type in controllers --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 1 + erpnext/accounts/doctype/payment_entry/payment_entry.py | 7 +++++++ erpnext/controllers/accounts_controller.py | 7 +++++++ 3 files changed, 15 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 85ef6f76d2..0616643a68 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -906,6 +906,7 @@ class JournalEntry(AccountsController): "party_type": d.party_type, "due_date": self.due_date, "party": d.party, + "against_type": "Account", "against": d.against_account, "debit": flt(d.debit, d.precision("debit")), "credit": flt(d.credit, d.precision("credit")), diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index 38a520996c..6cfc072aea 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1074,6 +1074,7 @@ class PaymentEntry(AccountsController): "account": self.party_account, "party_type": self.party_type, "party": self.party, + "against_type": "Account", "against": against_account, "account_currency": self.party_account_currency, "cost_center": self.cost_center, @@ -1232,6 +1233,7 @@ class PaymentEntry(AccountsController): { "account": self.paid_from, "account_currency": self.paid_from_account_currency, + "against_type": self.party_type if self.payment_type == "Pay" else "Account", "against": self.party if self.payment_type == "Pay" else self.paid_to, "credit_in_account_currency": self.paid_amount, "credit": self.base_paid_amount, @@ -1247,6 +1249,7 @@ class PaymentEntry(AccountsController): { "account": self.paid_to, "account_currency": self.paid_to_account_currency, + "against_type": self.party_type if self.payment_type == "Receive" else "Account", "against": self.party if self.payment_type == "Receive" else self.paid_from, "debit_in_account_currency": self.received_amount, "debit": self.base_received_amount, @@ -1271,6 +1274,7 @@ class PaymentEntry(AccountsController): rev_dr_or_cr = "credit" if dr_or_cr == "debit" else "debit" against = self.party or self.paid_to + against_type = self.party_type or "Account" payment_account = self.get_party_account_for_taxes() tax_amount = d.tax_amount base_tax_amount = d.base_tax_amount @@ -1279,6 +1283,7 @@ class PaymentEntry(AccountsController): self.get_gl_dict( { "account": d.account_head, + "against_type": against_type, "against": against, dr_or_cr: tax_amount, dr_or_cr + "_in_account_currency": base_tax_amount @@ -1304,6 +1309,7 @@ class PaymentEntry(AccountsController): self.get_gl_dict( { "account": payment_account, + "against_type": against_type, "against": against, rev_dr_or_cr: tax_amount, rev_dr_or_cr + "_in_account_currency": base_tax_amount @@ -1329,6 +1335,7 @@ class PaymentEntry(AccountsController): { "account": d.account, "account_currency": account_currency, + "against_type": self.party_type or "Account", "against": self.party or self.paid_from, "debit_in_account_currency": d.amount, "debit": d.amount, diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e635aa7924..d77b8a3c7f 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1040,6 +1040,7 @@ class AccountsController(TransactionBase): ) credit_or_debit = "credit" if self.doctype == "Purchase Invoice" else "debit" + against_type = "Supplier" if self.doctype == "Purchase Invoice" else "Customer" against = self.supplier if self.doctype == "Purchase Invoice" else self.customer if precision_loss: @@ -1047,6 +1048,7 @@ class AccountsController(TransactionBase): self.get_gl_dict( { "account": round_off_account, + "against_type": against_type, "against": against, credit_or_debit: precision_loss, "cost_center": round_off_cost_center @@ -1394,11 +1396,13 @@ class AccountsController(TransactionBase): if self.doctype == "Purchase Invoice": dr_or_cr = "credit" rev_dr_cr = "debit" + against_type = "Supplier" supplier_or_customer = self.supplier else: dr_or_cr = "debit" rev_dr_cr = "credit" + against_type = "Customer" supplier_or_customer = self.customer if enable_discount_accounting: @@ -1423,6 +1427,7 @@ class AccountsController(TransactionBase): self.get_gl_dict( { "account": item.discount_account, + "against_type": against_type, "against": supplier_or_customer, dr_or_cr: flt( discount_amount * self.get("conversion_rate"), item.precision("discount_amount") @@ -1441,6 +1446,7 @@ class AccountsController(TransactionBase): self.get_gl_dict( { "account": income_or_expense_account, + "against_type": against_type, "against": supplier_or_customer, rev_dr_cr: flt( discount_amount * self.get("conversion_rate"), item.precision("discount_amount") @@ -1464,6 +1470,7 @@ class AccountsController(TransactionBase): self.get_gl_dict( { "account": self.additional_discount_account, + "against_type": against_type, "against": supplier_or_customer, dr_or_cr: self.base_discount_amount, "cost_center": self.cost_center, From f292a0cc4c89814607fec0bb66d1c458d6624750 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 19:58:12 +0530 Subject: [PATCH 05/35] fix: set against type in utils --- .../accounts/doctype/invoice_discounting/invoice_discounting.py | 2 ++ erpnext/regional/united_arab_emirates/utils.py | 1 + erpnext/stock/doctype/stock_entry/stock_entry.py | 2 ++ 3 files changed, 5 insertions(+) diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py index 5bd4585a9a..744dff4670 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py @@ -125,6 +125,7 @@ class InvoiceDiscounting(AccountsController): "account": inv.debit_to, "party_type": "Customer", "party": d.customer, + "against_type": "Account", "against": self.accounts_receivable_credit, "credit": outstanding_in_company_currency, "credit_in_account_currency": outstanding_in_company_currency @@ -145,6 +146,7 @@ class InvoiceDiscounting(AccountsController): "account": self.accounts_receivable_credit, "party_type": "Customer", "party": d.customer, + "against_type": "Account", "against": inv.debit_to, "debit": outstanding_in_company_currency, "debit_in_account_currency": outstanding_in_company_currency diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py index a910af6a1d..d70d5466e0 100644 --- a/erpnext/regional/united_arab_emirates/utils.py +++ b/erpnext/regional/united_arab_emirates/utils.py @@ -153,6 +153,7 @@ def make_gl_entry(tax, gl_entries, doc, tax_accounts): "account": tax.account_head, "cost_center": tax.cost_center, "posting_date": doc.posting_date, + "against_type": "Supplier", "against": doc.supplier, dr_or_cr: tax.base_tax_amount_after_discount_amount, dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index a2cae7ff8d..2124168b62 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1360,6 +1360,7 @@ class StockEntry(StockController): self.get_gl_dict( { "account": account, + "against_type": "Account", "against": d.expense_account, "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -1374,6 +1375,7 @@ class StockEntry(StockController): self.get_gl_dict( { "account": d.expense_account, + "against_type": "Account", "against": account, "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), From 4ea43ebc5dadc35e66cec30d36a9578118f01622 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 20:01:13 +0530 Subject: [PATCH 06/35] fix: set against type in stock controller --- erpnext/controllers/stock_controller.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index ae54b801f1..5a04f71002 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -164,6 +164,7 @@ class StockController(AccountsController): self.get_gl_dict( { "account": warehouse_account[sle.warehouse]["account"], + "against_type": "Account", "against": expense_account, "cost_center": item_row.cost_center, "project": item_row.project or self.get("project"), @@ -180,6 +181,7 @@ class StockController(AccountsController): self.get_gl_dict( { "account": expense_account, + "against_type": "Account", "against": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -212,6 +214,7 @@ class StockController(AccountsController): self.get_gl_dict( { "account": expense_account, + "against_type": "Account", "against": warehouse_asset_account, "cost_center": item_row.cost_center, "project": item_row.project or self.get("project"), @@ -228,6 +231,7 @@ class StockController(AccountsController): self.get_gl_dict( { "account": warehouse_asset_account, + "against_type": "Account", "against": expense_account, "cost_center": item_row.cost_center, "remarks": _("Rounding gain/loss Entry for Stock Transfer"), @@ -834,6 +838,7 @@ class StockController(AccountsController): "cost_center": cost_center, "debit": debit, "credit": credit, + "against_type": "Account", "against": against_account, "remarks": remarks, } From 6e1565c32c41a5d8bb5cffc4a74c861b0592ece6 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 20:08:42 +0530 Subject: [PATCH 07/35] fix: set against type in asset --- erpnext/assets/doctype/asset/asset.py | 2 ++ erpnext/assets/doctype/asset_repair/asset_repair.py | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 0dbed87cf2..a732dec08b 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -606,6 +606,7 @@ class Asset(AccountsController): self.get_gl_dict( { "account": cwip_account, + "against_type": "Account", "against": fixed_asset_account, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "posting_date": self.available_for_use_date, @@ -621,6 +622,7 @@ class Asset(AccountsController): self.get_gl_dict( { "account": fixed_asset_account, + "against_type": "Account", "against": cwip_account, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "posting_date": self.available_for_use_date, diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 7e95cb2a1b..30c0371ae6 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -241,6 +241,7 @@ class AssetRepair(AccountsController): "account": fixed_asset_account, "debit": self.repair_cost, "debit_in_account_currency": self.repair_cost, + "against_type": "Account", "against": pi_expense_account, "voucher_type": self.doctype, "voucher_no": self.name, @@ -260,6 +261,7 @@ class AssetRepair(AccountsController): "account": pi_expense_account, "credit": self.repair_cost, "credit_in_account_currency": self.repair_cost, + "against_type": "Account", "against": fixed_asset_account, "voucher_type": self.doctype, "voucher_no": self.name, @@ -294,6 +296,7 @@ class AssetRepair(AccountsController): "account": item.expense_account or default_expense_account, "credit": item.amount, "credit_in_account_currency": item.amount, + "against_type": "Account", "against": fixed_asset_account, "voucher_type": self.doctype, "voucher_no": self.name, @@ -311,6 +314,7 @@ class AssetRepair(AccountsController): "account": fixed_asset_account, "debit": item.amount, "debit_in_account_currency": item.amount, + "against_type": "Account", "against": item.expense_account or default_expense_account, "voucher_type": self.doctype, "voucher_no": self.name, From f705bf2efe7bf079bb9b8af200f4c8cadfddd4ee Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 25 Sep 2023 20:10:01 +0530 Subject: [PATCH 08/35] fix: remove multiple accounts from against in capitalization --- .../asset_capitalization.py | 62 ++++++++++--------- 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index 662e4b983b..ad91edc038 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -390,6 +390,7 @@ class AssetCapitalization(StockController): self.get_gl_dict( { "account": account, + "against_type": "Account", "against": target_account, "cost_center": item_row.cost_center, "project": item_row.get("project") or self.get("project"), @@ -431,6 +432,7 @@ class AssetCapitalization(StockController): self.set_consumed_asset_status(asset) for gle in fixed_asset_gl_entries: + gle["against_type"] = "Account" gle["against"] = target_account gl_entries.append(self.get_gl_dict(gle, item=item)) target_against.add(gle["account"]) @@ -447,6 +449,7 @@ class AssetCapitalization(StockController): self.get_gl_dict( { "account": item_row.expense_account, + "against_type": "Account", "against": target_account, "cost_center": item_row.cost_center, "project": item_row.get("project") or self.get("project"), @@ -458,41 +461,44 @@ class AssetCapitalization(StockController): ) def get_gl_entries_for_target_item(self, gl_entries, target_against, precision): - if self.target_is_fixed_asset: - # Capitalization - gl_entries.append( - self.get_gl_dict( - { - "account": self.target_fixed_asset_account, - "against": ", ".join(target_against), - "remarks": self.get("remarks") or _("Accounting Entry for Asset"), - "debit": flt(self.total_value, precision), - "cost_center": self.get("cost_center"), - }, - item=self, - ) - ) - else: - # Target Stock Item - sle_list = self.sle_map.get(self.name) - for sle in sle_list: - stock_value_difference = flt(sle.stock_value_difference, precision) - account = self.warehouse_account[sle.warehouse]["account"] - + for target_account in target_against: + if self.target_is_fixed_asset: + # Capitalization gl_entries.append( self.get_gl_dict( { - "account": account, - "against": ", ".join(target_against), - "cost_center": self.cost_center, - "project": self.get("project"), - "remarks": self.get("remarks") or "Accounting Entry for Stock", - "debit": stock_value_difference, + "account": self.target_fixed_asset_account, + "against_type": "Account", + "against": target_account, + "remarks": self.get("remarks") or _("Accounting Entry for Asset"), + "debit": flt(self.total_value, precision) / len(target_against), + "cost_center": self.get("cost_center"), }, - self.warehouse_account[sle.warehouse]["account_currency"], item=self, ) ) + else: + # Target Stock Item + sle_list = self.sle_map.get(self.name) + for sle in sle_list: + stock_value_difference = flt(sle.stock_value_difference, precision) + account = self.warehouse_account[sle.warehouse]["account"] + + gl_entries.append( + self.get_gl_dict( + { + "account": account, + "against_type": "Account", + "against": target_account, + "cost_center": self.cost_center, + "project": self.get("project"), + "remarks": self.get("remarks") or "Accounting Entry for Stock", + "debit": stock_value_difference / len(target_against), + }, + self.warehouse_account[sle.warehouse]["account_currency"], + item=self, + ) + ) def create_target_asset(self): total_target_asset_value = flt(self.total_value, self.precision("total_value")) From fcfdb9b5667755b2846e834d70d3f9b444743d2b Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 3 Oct 2023 15:19:33 +0530 Subject: [PATCH 09/35] fix: purchase receipt tests --- erpnext/controllers/stock_controller.py | 3 ++- .../purchase_receipt/purchase_receipt.py | 25 +++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 5a04f71002..d816780053 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -824,6 +824,7 @@ class StockController(AccountsController): credit, remarks, against_account, + against_type="Account", debit_in_account_currency=None, credit_in_account_currency=None, account_currency=None, @@ -838,7 +839,7 @@ class StockController(AccountsController): "cost_center": cost_center, "debit": debit, "credit": credit, - "against_type": "Account", + "against_type": against_type, "against": against_account, "remarks": remarks, } diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 04eff54c43..836dda7811 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -449,6 +449,7 @@ class PurchaseReceipt(BuyingController): debit=0.0, credit=discrepancy_caused_by_exchange_rate_difference, remarks=remarks, + against_type="Supplier", against_account=self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=credit_currency, @@ -462,6 +463,7 @@ class PurchaseReceipt(BuyingController): debit=discrepancy_caused_by_exchange_rate_difference, credit=0.0, remarks=remarks, + against_type="Supplier", against_account=self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=credit_currency, @@ -666,7 +668,7 @@ class PurchaseReceipt(BuyingController): (self.name, expenses_included_in_valuation), ) - against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0]) + against_accounts = [d.account for d in gl_entries if flt(d.debit) > 0] total_valuation_amount = sum(valuation_tax.values()) amount_including_divisional_loss = negative_expense_to_be_booked stock_rbnb = self.get_company_default("stock_received_but_not_billed") @@ -687,16 +689,17 @@ class PurchaseReceipt(BuyingController): ) amount_including_divisional_loss -= applicable_amount - self.add_gl_entry( - gl_entries=gl_entries, - account=account, - cost_center=tax.cost_center, - debit=0.0, - credit=applicable_amount, - remarks=self.remarks or _("Accounting Entry for Stock"), - against_account=against_account, - item=tax, - ) + for against in against_accounts: + self.add_gl_entry( + gl_entries=gl_entries, + account=account, + cost_center=tax.cost_center, + debit=0.0, + credit=flt(applicable_amount) / len(against_accounts), + remarks=self.remarks or _("Accounting Entry for Stock"), + against_account=against, + item=tax, + ) i += 1 From 952e8cf60ca138ddb5941221421d87c2d00800c4 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 3 Oct 2023 15:55:34 +0530 Subject: [PATCH 10/35] fix: asset capitalization tests --- .../asset_capitalization/test_asset_capitalization.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py index 6e0a6856f5..1c445da20d 100644 --- a/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/test_asset_capitalization.py @@ -97,12 +97,12 @@ class TestAssetCapitalization(unittest.TestCase): # Test General Ledger Entries expected_gle = { - "_Test Fixed Asset - TCP1": 3000, + "_Test Fixed Asset - TCP1": 2999.99, "Expenses Included In Asset Valuation - TCP1": -1000, "_Test Warehouse - TCP1": -2000, + "Round Off - TCP1": 0.01, } actual_gle = get_actual_gle_dict(asset_capitalization.name) - self.assertEqual(actual_gle, expected_gle) # Test Stock Ledger Entries @@ -187,9 +187,10 @@ class TestAssetCapitalization(unittest.TestCase): # Test General Ledger Entries default_expense_account = frappe.db.get_value("Company", company, "default_expense_account") expected_gle = { - "_Test Fixed Asset - _TC": 3000, + "_Test Fixed Asset - _TC": 2999.99, "Expenses Included In Asset Valuation - _TC": -1000, default_expense_account: -2000, + "Round Off - _TC": 0.01, } actual_gle = get_actual_gle_dict(asset_capitalization.name) @@ -303,9 +304,10 @@ class TestAssetCapitalization(unittest.TestCase): # Test General Ledger Entries expected_gle = { - "_Test Warehouse - TCP1": consumed_asset_value_before_disposal, "_Test Accumulated Depreciations - TCP1": accumulated_depreciation, "_Test Fixed Asset - TCP1": -consumed_asset_purchase_value, + "_Test Warehouse - TCP1": consumed_asset_value_before_disposal - 0.01, + "Round Off - TCP1": 0.01, } actual_gle = get_actual_gle_dict(asset_capitalization.name) self.assertEqual(actual_gle, expected_gle) From aab5737ff3b95cd38de9240666854805bbb272a4 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 11 Oct 2023 15:55:02 +0530 Subject: [PATCH 11/35] fix: make JV account against field a dynamic link --- .../journal_entry_account.json | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 3ba8cea94b..0e5dde0e3a 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -37,6 +37,7 @@ "col_break3", "is_advance", "user_remark", + "against_type", "against_account" ], "fields": [ @@ -249,12 +250,13 @@ }, { "fieldname": "against_account", - "fieldtype": "Text", + "fieldtype": "Dynamic Link", "hidden": 1, "label": "Against Account", "no_copy": 1, "oldfieldname": "against_account", "oldfieldtype": "Text", + "options": "against_type", "print_hide": 1 }, { @@ -279,12 +281,20 @@ "hidden": 1, "label": "Reference Detail No", "no_copy": 1 + }, + { + "fieldname": "against_type", + "fieldtype": "Link", + "hidden": 1, + "label": "Against Type", + "options": "DocType", + "print_hide": 1 } ], "idx": 1, "istable": 1, "links": [], - "modified": "2023-06-16 14:11:13.507807", + "modified": "2023-10-11 13:05:21.489496", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", From 28445058ef4a9c9a6b4831f5223ffda2f1a4bfaf Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 11 Oct 2023 15:56:13 +0530 Subject: [PATCH 12/35] fix: split exchange gain loss account entries --- .../exchange_rate_revaluation.py | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py index 3b5698b118..bace7bfd30 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py @@ -467,6 +467,16 @@ class ExchangeRateRevaluation(Document): else "credit_in_account_currency" ) + balance_in_account_currency = flt( + abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency") + ) + difference_amount = ( + flt(d.get("new_exchange_rate"), d.precision("new_exchange_rate")) * balance_in_account_currency + ) + difference_amount -= ( + flt(d.get("current_exchange_rate"), d.precision("current_exchange_rate")) + * balance_in_account_currency + ) journal_entry_accounts.append( { "account": d.get("account"), @@ -503,28 +513,26 @@ class ExchangeRateRevaluation(Document): "reference_name": self.name, } ) + journal_entry_accounts.append( + { + "party_type": d.get("party_type"), + "party": d.get("party"), + "account": unrealized_exchange_gain_loss_account, + "balance": get_balance_on(unrealized_exchange_gain_loss_account), + "debit_in_account_currency": abs(difference_amount) if difference_amount < 0 else 0, + "credit_in_account_currency": difference_amount if difference_amount > 0 else 0, + "cost_center": erpnext.get_default_cost_center(self.company), + "exchange_rate": 1, + "reference_type": "Exchange Rate Revaluation", + "reference_name": self.name, + } + ) journal_entry.set("accounts", journal_entry_accounts) journal_entry.set_amounts_in_company_currency() journal_entry.set_total_debit_credit() self.gain_loss_unbooked += journal_entry.difference - self.gain_loss_unbooked - journal_entry.append( - "accounts", - { - "account": unrealized_exchange_gain_loss_account, - "balance": get_balance_on(unrealized_exchange_gain_loss_account), - "debit_in_account_currency": abs(self.gain_loss_unbooked) - if self.gain_loss_unbooked < 0 - else 0, - "credit_in_account_currency": self.gain_loss_unbooked if self.gain_loss_unbooked > 0 else 0, - "cost_center": erpnext.get_default_cost_center(self.company), - "exchange_rate": 1, - "reference_type": "Exchange Rate Revaluation", - "reference_name": self.name, - }, - ) - journal_entry.set_amounts_in_company_currency() journal_entry.set_total_debit_credit() journal_entry.save() From 35d92abe731b5d3d6b091297defaafc76ecc2af5 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 11 Oct 2023 15:56:59 +0530 Subject: [PATCH 13/35] fix: remove multiple against account values from gle --- .../doctype/journal_entry/journal_entry.py | 36 +++++++++++++------ 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 0616643a68..e4a89395d0 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -680,23 +680,39 @@ class JournalEntry(AccountsController): if self.voucher_type in ("Deferred Revenue", "Deferred Expense"): for d in self.get("accounts"): if d.reference_type == "Sales Invoice": - field = "customer" + against_type = "Customer" else: - field = "supplier" + against_type = "Supplier" - d.against_account = frappe.db.get_value(d.reference_type, d.reference_name, field) + d.against_type = against_type + d.against_account = frappe.db.get_value( + d.reference_type, d.reference_name, against_type.lower() + ) else: for d in self.get("accounts"): if flt(d.debit) > 0: - accounts_debited.append(d.party or d.account) + accounts_debited.append(d) if flt(d.credit) > 0: - accounts_credited.append(d.party or d.account) + accounts_credited.append(d) for d in self.get("accounts"): - if flt(d.debit) > 0: - d.against_account = ", ".join(list(set(accounts_credited))) - if flt(d.credit) > 0: - d.against_account = ", ".join(list(set(accounts_debited))) + if d.exchange_rate != 1.0: + d.against_type = d.party_type + d.against_account = d.party + elif flt(d.debit) > 0: + for acc in accounts_credited: + if acc.party == d.party: + d.against_type = "Account" + d.against_account = d.account + d.party_type = "" + d.party = "" + elif flt(d.credit) > 0: + for acc in accounts_debited: + if acc.party == d.party: + d.against_type = "Account" + d.against_account = d.account + d.party_type = "" + d.party = "" def validate_debit_credit_amount(self): if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency): @@ -906,7 +922,7 @@ class JournalEntry(AccountsController): "party_type": d.party_type, "due_date": self.due_date, "party": d.party, - "against_type": "Account", + "against_type": d.against_type, "against": d.against_account, "debit": flt(d.debit, d.precision("debit")), "credit": flt(d.credit, d.precision("credit")), From 3d00d74fed4ce065118bedce886972bb6c43b614 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 6 Nov 2023 16:45:56 +0530 Subject: [PATCH 14/35] fix: combine jv entries for rate revaluation --- .../exchange_rate_revaluation.py | 40 ++++++++----------- 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py index bace7bfd30..3b5698b118 100644 --- a/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py +++ b/erpnext/accounts/doctype/exchange_rate_revaluation/exchange_rate_revaluation.py @@ -467,16 +467,6 @@ class ExchangeRateRevaluation(Document): else "credit_in_account_currency" ) - balance_in_account_currency = flt( - abs(d.get("balance_in_account_currency")), d.precision("balance_in_account_currency") - ) - difference_amount = ( - flt(d.get("new_exchange_rate"), d.precision("new_exchange_rate")) * balance_in_account_currency - ) - difference_amount -= ( - flt(d.get("current_exchange_rate"), d.precision("current_exchange_rate")) - * balance_in_account_currency - ) journal_entry_accounts.append( { "account": d.get("account"), @@ -513,26 +503,28 @@ class ExchangeRateRevaluation(Document): "reference_name": self.name, } ) - journal_entry_accounts.append( - { - "party_type": d.get("party_type"), - "party": d.get("party"), - "account": unrealized_exchange_gain_loss_account, - "balance": get_balance_on(unrealized_exchange_gain_loss_account), - "debit_in_account_currency": abs(difference_amount) if difference_amount < 0 else 0, - "credit_in_account_currency": difference_amount if difference_amount > 0 else 0, - "cost_center": erpnext.get_default_cost_center(self.company), - "exchange_rate": 1, - "reference_type": "Exchange Rate Revaluation", - "reference_name": self.name, - } - ) journal_entry.set("accounts", journal_entry_accounts) journal_entry.set_amounts_in_company_currency() journal_entry.set_total_debit_credit() self.gain_loss_unbooked += journal_entry.difference - self.gain_loss_unbooked + journal_entry.append( + "accounts", + { + "account": unrealized_exchange_gain_loss_account, + "balance": get_balance_on(unrealized_exchange_gain_loss_account), + "debit_in_account_currency": abs(self.gain_loss_unbooked) + if self.gain_loss_unbooked < 0 + else 0, + "credit_in_account_currency": self.gain_loss_unbooked if self.gain_loss_unbooked > 0 else 0, + "cost_center": erpnext.get_default_cost_center(self.company), + "exchange_rate": 1, + "reference_type": "Exchange Rate Revaluation", + "reference_name": self.name, + }, + ) + journal_entry.set_amounts_in_company_currency() journal_entry.set_total_debit_credit() journal_entry.save() From ff0343d2cc9e1818beaf4047b8232183858d09d6 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 6 Nov 2023 16:46:43 +0530 Subject: [PATCH 15/35] fix: auto separate against accounts --- .../doctype/journal_entry/journal_entry.py | 147 +++++++++++------- 1 file changed, 95 insertions(+), 52 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index e4a89395d0..1b7b82bafc 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -676,7 +676,6 @@ class JournalEntry(AccountsController): ) def set_against_account(self): - accounts_debited, accounts_credited = [], [] if self.voucher_type in ("Deferred Revenue", "Deferred Expense"): for d in self.get("accounts"): if d.reference_type == "Sales Invoice": @@ -689,30 +688,40 @@ class JournalEntry(AccountsController): d.reference_type, d.reference_name, against_type.lower() ) else: - for d in self.get("accounts"): - if flt(d.debit) > 0: - accounts_debited.append(d) - if flt(d.credit) > 0: - accounts_credited.append(d) + self.get_against_accounts() - for d in self.get("accounts"): - if d.exchange_rate != 1.0: - d.against_type = d.party_type - d.against_account = d.party - elif flt(d.debit) > 0: - for acc in accounts_credited: - if acc.party == d.party: - d.against_type = "Account" - d.against_account = d.account - d.party_type = "" - d.party = "" - elif flt(d.credit) > 0: - for acc in accounts_debited: - if acc.party == d.party: - d.against_type = "Account" - d.against_account = d.account - d.party_type = "" - d.party = "" + def get_against_accounts(self): + accounts_debited, accounts_credited, against_accounts = [], [], [] + split_account = {} + separate_against_account_entries = 1 + for d in self.get("accounts"): + if flt(d.debit) > 0 or flt(d.debit_in_account_currency) > 0: + accounts_debited.append(d) + elif flt(d.credit) > 0 or flt(d.credit_in_account_currency) > 0: + accounts_credited.append(d) + + if d.against_account: + separate_against_account_entries = 0 + break + + if separate_against_account_entries: + if len(accounts_credited) > 1 and len(accounts_debited) > 1: + frappe.msgprint( + _( + "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed.".format( + frappe.bold("against"), frappe.bold("Accounting Entries") + ) + ), + alert=True, + ) + elif len(accounts_credited) == 1: + against_accounts = accounts_debited + split_account = accounts_credited[0] + elif len(accounts_debited) == 1: + against_accounts = accounts_credited + split_account = accounts_debited[0] + + return separate_against_account_entries, against_accounts, split_account def validate_debit_credit_amount(self): if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency): @@ -909,41 +918,75 @@ class JournalEntry(AccountsController): def build_gl_map(self): gl_map = [] + separate_against_account_entries, against_accounts, split_account = self.get_against_accounts() for d in self.get("accounts"): if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"): r = [d.user_remark, self.remark] r = [x for x in r if x] remarks = "\n".join(r) - gl_map.append( - self.get_gl_dict( - { - "account": d.account, - "party_type": d.party_type, - "due_date": self.due_date, - "party": d.party, - "against_type": d.against_type, - "against": d.against_account, - "debit": flt(d.debit, d.precision("debit")), - "credit": flt(d.credit, d.precision("credit")), - "account_currency": d.account_currency, - "debit_in_account_currency": flt( - d.debit_in_account_currency, d.precision("debit_in_account_currency") - ), - "credit_in_account_currency": flt( - d.credit_in_account_currency, d.precision("credit_in_account_currency") - ), - "against_voucher_type": d.reference_type, - "against_voucher": d.reference_name, - "remarks": remarks, - "voucher_detail_no": d.reference_detail_no, - "cost_center": d.cost_center, - "project": d.project, - "finance_book": self.finance_book, - }, - item=d, - ) + gl_dict = self.get_gl_dict( + { + "account": d.account, + "party_type": d.party_type, + "due_date": self.due_date, + "party": d.party, + "debit": flt(d.debit, d.precision("debit")), + "credit": flt(d.credit, d.precision("credit")), + "account_currency": d.account_currency, + "debit_in_account_currency": flt( + d.debit_in_account_currency, d.precision("debit_in_account_currency") + ), + "credit_in_account_currency": flt( + d.credit_in_account_currency, d.precision("credit_in_account_currency") + ), + "against_voucher_type": d.reference_type, + "against_voucher": d.reference_name, + "remarks": remarks, + "voucher_detail_no": d.reference_detail_no, + "cost_center": d.cost_center, + "project": d.project, + "finance_book": self.finance_book, + }, + item=d, ) + + if not separate_against_account_entries: + gl_dict.update({"against_type": d.against_type, "against_account": d.against_account}) + gl_map.append(gl_dict) + + elif d in against_accounts: + gl_dict.update( + { + "against_type": split_account.party_type or "Account", + "against_account": split_account.party or split_account.account, + } + ) + gl_map.append(gl_dict) + + else: + for against_account in against_accounts: + against_account = against_account.as_dict() + debit = against_account.credit or against_account.credit_in_account_currency + credit = against_account.debit or against_account.debit_in_account_currency + gl_dict = gl_dict.copy() + gl_dict.update( + { + "against_type": against_account.party_type or "Account", + "against": against_account.party or against_account.account, + "debit": flt(debit, d.precision("debit")), + "credit": flt(credit, d.precision("credit")), + "account_currency": d.account_currency, + "debit_in_account_currency": flt( + debit / d.exchange_rate, d.precision("debit_in_account_currency") + ), + "credit_in_account_currency": flt( + credit / d.exchange_rate, d.precision("credit_in_account_currency") + ), + } + ) + gl_map.append(gl_dict) + return gl_map def make_gl_entries(self, cancel=0, adv_adj=0): From 758ec720deb78507f4972b8b71cb3731f6ee43c4 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 6 Nov 2023 17:14:55 +0530 Subject: [PATCH 16/35] fix: remove join for against in purchase receipt --- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 6874044a6c..72a2465526 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -411,7 +411,7 @@ class PurchaseReceipt(BuyingController): account_currency=account_currency, item=item, ) - + self.add_gl_entry( gl_entries=gl_entries, account=self.get_company_default("exchange_gain_loss_account"), @@ -684,7 +684,7 @@ class PurchaseReceipt(BuyingController): # Backward compatibility: # and charges added via Landed Cost Voucher, # post valuation related charges on "Stock Received But Not Billed" - against_account = ", ".join([d.account for d in gl_entries if flt(d.debit) > 0]) + against_accounts = [d.account for d in gl_entries if flt(d.debit) > 0] total_valuation_amount = sum(valuation_tax.values()) amount_including_divisional_loss = negative_expense_to_be_booked stock_rbnb = ( From a1f8595a6a78ef94d1c82fefc44f4294d38cb856 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 6 Nov 2023 17:20:11 +0530 Subject: [PATCH 17/35] chore: linting issue --- erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index 99b9c4ef44..cf89b333c6 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -920,7 +920,7 @@ class PurchaseInvoice(BuyingController): item=item, ) ) - + # update gross amount of asset bought through this document assets = frappe.db.get_all( "Asset", filters={"purchase_invoice": self.name, "item_code": item.item_code} From e845b63228baffb3165aee6c24f038477cfb71bf Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Mon, 6 Nov 2023 20:37:05 +0530 Subject: [PATCH 18/35] fix: single dr cr entries --- .../doctype/journal_entry/journal_entry.py | 79 ++++++++++++------- 1 file changed, 51 insertions(+), 28 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 1b7b82bafc..da6c8cf7cd 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -691,21 +691,13 @@ class JournalEntry(AccountsController): self.get_against_accounts() def get_against_accounts(self): - accounts_debited, accounts_credited, against_accounts = [], [], [] - split_account = {} - separate_against_account_entries = 1 - for d in self.get("accounts"): - if flt(d.debit) > 0 or flt(d.debit_in_account_currency) > 0: - accounts_debited.append(d) - elif flt(d.credit) > 0 or flt(d.credit_in_account_currency) > 0: - accounts_credited.append(d) + self.against_accounts = [] + self.split_account = {} + self.get_debited_credited_accounts() - if d.against_account: - separate_against_account_entries = 0 - break - - if separate_against_account_entries: - if len(accounts_credited) > 1 and len(accounts_debited) > 1: + if self.separate_against_account_entries: + no_of_credited_acc, no_of_debited_acc = len(self.accounts_credited), len(self.accounts_debited) + if no_of_credited_acc > 1 and no_of_debited_acc > 1: frappe.msgprint( _( "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed.".format( @@ -714,14 +706,37 @@ class JournalEntry(AccountsController): ), alert=True, ) - elif len(accounts_credited) == 1: - against_accounts = accounts_debited - split_account = accounts_credited[0] - elif len(accounts_debited) == 1: - against_accounts = accounts_credited - split_account = accounts_debited[0] + elif no_of_credited_acc == 1 and no_of_debited_acc == 1: + self.set_against_accounts_for_single_dr_cr() + self.separate_against_account_entries = 0 + elif no_of_credited_acc == 1: + self.against_accounts = self.accounts_debited + self.split_account = self.accounts_credited[0] + elif no_of_debited_acc == 1: + self.against_accounts = self.accounts_credited + self.split_account = self.accounts_debited[0] - return separate_against_account_entries, against_accounts, split_account + def get_debited_credited_accounts(self): + self.accounts_debited, self.accounts_credited = [], [] + self.separate_against_account_entries = 1 + for d in self.get("accounts"): + if has_debit_amount(d): + self.accounts_debited.append(d) + elif has_credit_amount(d): + self.accounts_credited.append(d) + + if d.against_account: + self.separate_against_account_entries = 0 + break + + def set_against_accounts_for_single_dr_cr(self): + for d in self.accounts: + if has_debit_amount(d): + against_account = self.accounts_credited[0] + elif has_credit_amount(d): + against_account = self.accounts_debited[0] + d.against_type = against_account.party_type or "Account" + d.against_account = against_account.party or against_account.account def validate_debit_credit_amount(self): if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency): @@ -918,7 +933,7 @@ class JournalEntry(AccountsController): def build_gl_map(self): gl_map = [] - separate_against_account_entries, against_accounts, split_account = self.get_against_accounts() + self.get_against_accounts() for d in self.get("accounts"): if d.debit or d.credit or (self.voucher_type == "Exchange Gain Or Loss"): r = [d.user_remark, self.remark] @@ -951,21 +966,21 @@ class JournalEntry(AccountsController): item=d, ) - if not separate_against_account_entries: - gl_dict.update({"against_type": d.against_type, "against_account": d.against_account}) + if not self.separate_against_account_entries: + gl_dict.update({"against_type": d.against_type, "against": d.against_account}) gl_map.append(gl_dict) - elif d in against_accounts: + elif d in self.against_accounts: gl_dict.update( { - "against_type": split_account.party_type or "Account", - "against_account": split_account.party or split_account.account, + "against_type": self.split_account.get("party_type") or "Account", + "against": self.split_account.get("party") or self.split_account.get("account"), } ) gl_map.append(gl_dict) else: - for against_account in against_accounts: + for against_account in self.against_accounts: against_account = against_account.as_dict() debit = against_account.credit or against_account.credit_in_account_currency credit = against_account.debit or against_account.debit_in_account_currency @@ -1611,3 +1626,11 @@ def make_reverse_journal_entry(source_name, target_doc=None): ) return doclist + + +def has_credit_amount(account): + return flt(account.credit) > 0 or flt(account.credit_in_account_currency) > 0 + + +def has_debit_amount(account): + return flt(account.debit) > 0 or flt(account.debit_in_account_currency) > 0 From 5ce395a60a0ebace32382343110e0ceccac4880e Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 7 Nov 2023 12:52:49 +0530 Subject: [PATCH 19/35] fix: purchase receipt test --- erpnext/stock/doctype/purchase_receipt/purchase_receipt.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index 72a2465526..1fcde44053 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -406,6 +406,7 @@ class PurchaseReceipt(BuyingController): debit=0.0, credit=discrepancy_caused_by_exchange_rate_difference, remarks=remarks, + against_type="Supplier", against_account=self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=account_currency, @@ -419,6 +420,7 @@ class PurchaseReceipt(BuyingController): debit=discrepancy_caused_by_exchange_rate_difference, credit=0.0, remarks=remarks, + against_type="Supplier", against_account=self.supplier, debit_in_account_currency=-1 * discrepancy_caused_by_exchange_rate_difference, account_currency=account_currency, From ea4b6ff27bc9406c5c2abd4519938bb7942aa3f4 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 7 Nov 2023 13:05:38 +0530 Subject: [PATCH 20/35] fix: remove string from against field in loyalty point entry --- erpnext/accounts/doctype/sales_invoice/sales_invoice.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 8033dbff09..a059c32dfa 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -7,7 +7,7 @@ from frappe import _, msgprint, throw from frappe.contacts.doctype.address.address import get_address_display from frappe.model.mapper import get_mapped_doc from frappe.model.utils import get_fetch_values -from frappe.utils import add_days, cint, cstr, flt, formatdate, get_link_to_form, getdate, nowdate +from frappe.utils import add_days, cint, flt, formatdate, get_link_to_form, getdate, nowdate import erpnext from erpnext.accounts.deferred_revenue import validate_service_stop_date @@ -1239,9 +1239,7 @@ class SalesInvoice(SellingController): "party_type": "Customer", "party": self.customer, "against_type": "Account", - "against": "Expense account - " - + cstr(self.loyalty_redemption_account) - + " for the Loyalty Program", + "against": self.loyalty_redemption_account, "credit": self.loyalty_amount, "against_voucher": self.return_against if cint(self.is_return) else self.name, "against_voucher_type": self.doctype, From 68c6ad6036ad9ce1f40ea4f20568988c5bbe5deb Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 7 Nov 2023 15:31:52 +0530 Subject: [PATCH 21/35] fix: test for balance in forex account after revaluation --- .../doctype/journal_entry/journal_entry.py | 24 +++++++------------ erpnext/accounts/general_ledger.py | 4 ++-- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index da6c8cf7cd..27d14c2e3f 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -706,7 +706,7 @@ class JournalEntry(AccountsController): ), alert=True, ) - elif no_of_credited_acc == 1 and no_of_debited_acc == 1: + elif no_of_credited_acc <= 1 and no_of_debited_acc <= 1: self.set_against_accounts_for_single_dr_cr() self.separate_against_account_entries = 0 elif no_of_credited_acc == 1: @@ -720,9 +720,9 @@ class JournalEntry(AccountsController): self.accounts_debited, self.accounts_credited = [], [] self.separate_against_account_entries = 1 for d in self.get("accounts"): - if has_debit_amount(d): + if flt(d.debit) > 0: self.accounts_debited.append(d) - elif has_credit_amount(d): + elif flt(d.credit) > 0: self.accounts_credited.append(d) if d.against_account: @@ -730,13 +730,15 @@ class JournalEntry(AccountsController): break def set_against_accounts_for_single_dr_cr(self): + against_account = None for d in self.accounts: - if has_debit_amount(d): + if flt(d.debit) > 0: against_account = self.accounts_credited[0] - elif has_credit_amount(d): + elif flt(d.credit) > 0: against_account = self.accounts_debited[0] - d.against_type = against_account.party_type or "Account" - d.against_account = against_account.party or against_account.account + if against_account: + d.against_type = against_account.party_type or "Account" + d.against_account = against_account.party or against_account.account def validate_debit_credit_amount(self): if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency): @@ -1626,11 +1628,3 @@ def make_reverse_journal_entry(source_name, target_doc=None): ) return doclist - - -def has_credit_amount(account): - return flt(account.credit) > 0 or flt(account.credit_in_account_currency) > 0 - - -def has_debit_amount(account): - return flt(account.debit) > 0 or flt(account.debit_in_account_currency) > 0 diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 70a8470614..2f721c8013 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -356,7 +356,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): process_debit_credit_difference(gl_map) if gl_map: - check_freezing_date(gl_map[0]["posting_date"], adv_adj) + # check_freezing_date(gl_map[0]["posting_date"], adv_adj) is_opening = any(d.get("is_opening") == "Yes" for d in gl_map) if gl_map[0]["voucher_type"] != "Period Closing Voucher": validate_against_pcv(is_opening, gl_map[0]["posting_date"], gl_map[0]["company"]) @@ -593,7 +593,7 @@ def make_reverse_gl_entries( partial_cancel=partial_cancel, ) validate_accounting_period(gl_entries) - check_freezing_date(gl_entries[0]["posting_date"], adv_adj) + # check_freezing_date(gl_entries[0]["posting_date"], adv_adj) is_opening = any(d.get("is_opening") == "Yes" for d in gl_entries) validate_against_pcv(is_opening, gl_entries[0]["posting_date"], gl_entries[0]["company"]) From 291a4991246b5a53491066eb46efda0de2a8002f Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 8 Nov 2023 00:46:52 +0530 Subject: [PATCH 22/35] fix: split expected jv entries for scrap asset --- erpnext/accounts/general_ledger.py | 4 ++-- erpnext/assets/doctype/asset/test_asset.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 2f721c8013..70a8470614 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -356,7 +356,7 @@ def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False): process_debit_credit_difference(gl_map) if gl_map: - # check_freezing_date(gl_map[0]["posting_date"], adv_adj) + check_freezing_date(gl_map[0]["posting_date"], adv_adj) is_opening = any(d.get("is_opening") == "Yes" for d in gl_map) if gl_map[0]["voucher_type"] != "Period Closing Voucher": validate_against_pcv(is_opening, gl_map[0]["posting_date"], gl_map[0]["company"]) @@ -593,7 +593,7 @@ def make_reverse_gl_entries( partial_cancel=partial_cancel, ) validate_accounting_period(gl_entries) - # check_freezing_date(gl_entries[0]["posting_date"], adv_adj) + check_freezing_date(gl_entries[0]["posting_date"], adv_adj) is_opening = any(d.get("is_opening") == "Yes" for d in gl_entries) validate_against_pcv(is_opening, gl_entries[0]["posting_date"], gl_entries[0]["company"]) diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py index 9e3ec6faa8..536845ed26 100644 --- a/erpnext/assets/doctype/asset/test_asset.py +++ b/erpnext/assets/doctype/asset/test_asset.py @@ -256,7 +256,16 @@ class TestAsset(AssetSetup): flt(18000.0 + pro_rata_amount, asset.precision("gross_purchase_amount")), 0.0, ), - ("_Test Fixed Asset - _TC", 0.0, 100000.0), + ( + "_Test Fixed Asset - _TC", + 0.0, + flt(18000.0 + pro_rata_amount, asset.precision("gross_purchase_amount")), + ), + ( + "_Test Fixed Asset - _TC", + 0.0, + flt(82000.0 - pro_rata_amount, asset.precision("gross_purchase_amount")), + ), ( "_Test Gain/Loss on Asset Disposal - _TC", flt(82000.0 - pro_rata_amount, asset.precision("gross_purchase_amount")), @@ -267,7 +276,7 @@ class TestAsset(AssetSetup): gle = frappe.db.sql( """select account, debit, credit from `tabGL Entry` where voucher_type='Journal Entry' and voucher_no = %s - order by account""", + order by account, credit""", asset.journal_entry_for_scrap, ) self.assertSequenceEqual(gle, expected_gle) From 5f5d75a0bbce2e28411ca79e7eaeca669933692a Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 8 Nov 2023 11:19:45 +0530 Subject: [PATCH 23/35] chore: linting issues --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 27d14c2e3f..1c737fc543 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -700,10 +700,8 @@ class JournalEntry(AccountsController): if no_of_credited_acc > 1 and no_of_debited_acc > 1: frappe.msgprint( _( - "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed.".format( - frappe.bold("against"), frappe.bold("Accounting Entries") - ) - ), + "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed." + ).format(frappe.bold("against"), frappe.bold("Accounting Entries")), alert=True, ) elif no_of_credited_acc <= 1 and no_of_debited_acc <= 1: From f9c88ea7bc96837ece6c477e4dc9a324985d98ac Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 8 Nov 2023 12:55:41 +0530 Subject: [PATCH 24/35] refactor: keep old against fields intact --- .../accounts/doctype/gl_entry/gl_entry.json | 23 ++++++++++++------- .../journal_entry_account.json | 23 ++++++++++++------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.json b/erpnext/accounts/doctype/gl_entry/gl_entry.json index 1adeaa54d8..16df40f435 100644 --- a/erpnext/accounts/doctype/gl_entry/gl_entry.json +++ b/erpnext/accounts/doctype/gl_entry/gl_entry.json @@ -19,6 +19,7 @@ "credit_in_account_currency", "against_type", "against", + "against_link", "against_voucher_type", "against_voucher", "voucher_type", @@ -137,13 +138,19 @@ "options": "DocType" }, { - "fieldname": "against", - "fieldtype": "Dynamic Link", - "in_filter": 1, - "label": "Against", - "oldfieldname": "against", - "oldfieldtype": "Text", - "options": "against_type" + "fieldname": "against", + "fieldtype": "Text", + "in_filter": 1, + "label": "Against", + "oldfieldname": "against", + "oldfieldtype": "Text" + }, + { + "fieldname": "against_link", + "fieldtype": "Dynamic Link", + "in_filter": 1, + "label": "Against", + "options": "against_type" }, { "fieldname": "against_voucher_type", @@ -295,7 +302,7 @@ "idx": 1, "in_create": 1, "links": [], - "modified": "2023-09-25 12:03:23.031733", + "modified": "2023-11-08 12:20:23.031733", "modified_by": "Administrator", "module": "Accounts", "name": "GL Entry", diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 0e5dde0e3a..8d8c83751b 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -38,7 +38,8 @@ "is_advance", "user_remark", "against_type", - "against_account" + "against_account", + "against_account_link" ], "fields": [ { @@ -249,15 +250,21 @@ "print_hide": 1 }, { - "fieldname": "against_account", + "fieldname": "against_account", + "fieldtype": "Text", + "hidden": 1, + "label": "Against Account", + "no_copy": 1, + "oldfieldname": "against_account", + "oldfieldtype": "Text", + "print_hide": 1 + }, + { + "fieldname": "against_account_link", "fieldtype": "Dynamic Link", - "hidden": 1, "label": "Against Account", "no_copy": 1, - "oldfieldname": "against_account", - "oldfieldtype": "Text", - "options": "against_type", - "print_hide": 1 + "options": "against_type" }, { "collapsible": 1, @@ -294,7 +301,7 @@ "idx": 1, "istable": 1, "links": [], - "modified": "2023-10-11 13:05:21.489496", + "modified": "2023-11-08 12:20:21.489496", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", From 09439334cae6a7306dad8e54a9f81f9ffa483f8b Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 8 Nov 2023 12:57:00 +0530 Subject: [PATCH 25/35] refactor: use both fields to store against values --- erpnext/accounts/deferred_revenue.py | 2 ++ .../invoice_discounting.py | 2 ++ .../doctype/journal_entry/journal_entry.py | 17 +++++++++++---- .../doctype/payment_entry/payment_entry.py | 6 ++++++ .../purchase_invoice/purchase_invoice.py | 21 +++++++++++++++++++ .../doctype/sales_invoice/sales_invoice.py | 14 +++++++++++++ erpnext/assets/doctype/asset/asset.py | 2 ++ .../asset_capitalization.py | 5 +++++ .../doctype/asset_repair/asset_repair.py | 4 ++++ erpnext/controllers/accounts_controller.py | 4 ++++ erpnext/controllers/stock_controller.py | 5 +++++ .../regional/united_arab_emirates/utils.py | 1 + .../stock/doctype/stock_entry/stock_entry.py | 2 ++ 13 files changed, 81 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/deferred_revenue.py b/erpnext/accounts/deferred_revenue.py index 00d5ea3245..c2188c0da1 100644 --- a/erpnext/accounts/deferred_revenue.py +++ b/erpnext/accounts/deferred_revenue.py @@ -521,6 +521,7 @@ def make_gl_entries( "account": credit_account, "against_type": against_type, "against": against, + "against_link": against, "credit": base_amount, "credit_in_account_currency": amount, "cost_center": cost_center, @@ -541,6 +542,7 @@ def make_gl_entries( "account": debit_account, "against_type": against_type, "against": against, + "against_link": against, "debit": base_amount, "debit_in_account_currency": amount, "cost_center": cost_center, diff --git a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py index 744dff4670..ebfa0de3ae 100644 --- a/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py +++ b/erpnext/accounts/doctype/invoice_discounting/invoice_discounting.py @@ -127,6 +127,7 @@ class InvoiceDiscounting(AccountsController): "party": d.customer, "against_type": "Account", "against": self.accounts_receivable_credit, + "against_link": self.accounts_receivable_credit, "credit": outstanding_in_company_currency, "credit_in_account_currency": outstanding_in_company_currency if inv.party_account_currency == company_currency @@ -148,6 +149,7 @@ class InvoiceDiscounting(AccountsController): "party": d.customer, "against_type": "Account", "against": inv.debit_to, + "against_link": inv.debit_to, "debit": outstanding_in_company_currency, "debit_in_account_currency": outstanding_in_company_currency if ar_credit_account_currency == company_currency diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 1c737fc543..9f76d9df19 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -683,10 +683,10 @@ class JournalEntry(AccountsController): else: against_type = "Supplier" + against_account = frappe.db.get_value(d.reference_type, d.reference_name, against_type.lower()) d.against_type = against_type - d.against_account = frappe.db.get_value( - d.reference_type, d.reference_name, against_type.lower() - ) + d.against_account = against_account + d.against_account_link = against_account else: self.get_against_accounts() @@ -737,6 +737,7 @@ class JournalEntry(AccountsController): if against_account: d.against_type = against_account.party_type or "Account" d.against_account = against_account.party or against_account.account + d.against_account_link = against_account.party or against_account.account def validate_debit_credit_amount(self): if not (self.voucher_type == "Exchange Gain Or Loss" and self.multi_currency): @@ -967,7 +968,13 @@ class JournalEntry(AccountsController): ) if not self.separate_against_account_entries: - gl_dict.update({"against_type": d.against_type, "against": d.against_account}) + gl_dict.update( + { + "against_type": d.against_type, + "against": d.against_account, + "against_link": d.against_account, + } + ) gl_map.append(gl_dict) elif d in self.against_accounts: @@ -975,6 +982,7 @@ class JournalEntry(AccountsController): { "against_type": self.split_account.get("party_type") or "Account", "against": self.split_account.get("party") or self.split_account.get("account"), + "against_link": self.split_account.get("party") or self.split_account.get("account"), } ) gl_map.append(gl_dict) @@ -989,6 +997,7 @@ class JournalEntry(AccountsController): { "against_type": against_account.party_type or "Account", "against": against_account.party or against_account.account, + "against_link": against_account.party or against_account.account, "debit": flt(debit, d.precision("debit")), "credit": flt(credit, d.precision("credit")), "account_currency": d.account_currency, diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.py b/erpnext/accounts/doctype/payment_entry/payment_entry.py index ff558b2f48..ff8695f770 100644 --- a/erpnext/accounts/doctype/payment_entry/payment_entry.py +++ b/erpnext/accounts/doctype/payment_entry/payment_entry.py @@ -1078,6 +1078,7 @@ class PaymentEntry(AccountsController): "party": self.party, "against_type": "Account", "against": against_account, + "against_link": against_account, "account_currency": self.party_account_currency, "cost_center": self.cost_center, }, @@ -1237,6 +1238,7 @@ class PaymentEntry(AccountsController): "account_currency": self.paid_from_account_currency, "against_type": self.party_type if self.payment_type == "Pay" else "Account", "against": self.party if self.payment_type == "Pay" else self.paid_to, + "against_link": self.party if self.payment_type == "Pay" else self.paid_to, "credit_in_account_currency": self.paid_amount, "credit": self.base_paid_amount, "cost_center": self.cost_center, @@ -1253,6 +1255,7 @@ class PaymentEntry(AccountsController): "account_currency": self.paid_to_account_currency, "against_type": self.party_type if self.payment_type == "Receive" else "Account", "against": self.party if self.payment_type == "Receive" else self.paid_from, + "against_link": self.party if self.payment_type == "Receive" else self.paid_from, "debit_in_account_currency": self.received_amount, "debit": self.base_received_amount, "cost_center": self.cost_center, @@ -1287,6 +1290,7 @@ class PaymentEntry(AccountsController): "account": d.account_head, "against_type": against_type, "against": against, + "against_link": against, dr_or_cr: tax_amount, dr_or_cr + "_in_account_currency": base_tax_amount if account_currency == self.company_currency @@ -1313,6 +1317,7 @@ class PaymentEntry(AccountsController): "account": payment_account, "against_type": against_type, "against": against, + "against_link": against, rev_dr_or_cr: tax_amount, rev_dr_or_cr + "_in_account_currency": base_tax_amount if account_currency == self.company_currency @@ -1339,6 +1344,7 @@ class PaymentEntry(AccountsController): "account_currency": account_currency, "against_type": self.party_type or "Account", "against": self.party or self.paid_from, + "against_link": self.party or self.paid_from, "debit_in_account_currency": d.amount, "debit": d.amount, "cost_center": d.cost_center, diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py index cf89b333c6..53c131a507 100644 --- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -643,6 +643,7 @@ class PurchaseInvoice(BuyingController): "due_date": self.due_date, "against_type": "Account", "against": self.against_expense_account, + "against_link": self.against_expense_account, "credit": base_grand_total, "credit_in_account_currency": base_grand_total if self.party_account_currency == self.company_currency @@ -717,6 +718,7 @@ class PurchaseInvoice(BuyingController): "account": warehouse_account[item.warehouse]["account"], "against_type": "Account", "against": warehouse_account[item.from_warehouse]["account"], + "against_link": warehouse_account[item.from_warehouse]["account"], "cost_center": item.cost_center, "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -738,6 +740,7 @@ class PurchaseInvoice(BuyingController): "account": warehouse_account[item.from_warehouse]["account"], "against_type": "Account", "against": warehouse_account[item.warehouse]["account"], + "against_link": warehouse_account[item.warehouse]["account"], "cost_center": item.cost_center, "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -756,6 +759,7 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit": flt(item.base_net_amount, item.precision("base_net_amount")), "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, @@ -774,6 +778,7 @@ class PurchaseInvoice(BuyingController): "account": item.expense_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit": warehouse_debit_amount, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "cost_center": item.cost_center, @@ -794,6 +799,7 @@ class PurchaseInvoice(BuyingController): "account": account, "against_type": "Account", "against": item.expense_account, + "against_link": item.expense_account, "cost_center": item.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": flt(amount["base_amount"]), @@ -815,6 +821,7 @@ class PurchaseInvoice(BuyingController): "account": supplier_warehouse_account, "against_type": "Account", "against": item.expense_account, + "against_link": item.expense_account, "cost_center": item.cost_center, "project": item.project or self.project, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -871,6 +878,7 @@ class PurchaseInvoice(BuyingController): "account": expense_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit": amount, "cost_center": item.cost_center, "project": item.project or self.project, @@ -898,6 +906,7 @@ class PurchaseInvoice(BuyingController): "account": expense_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit": discrepancy_caused_by_exchange_rate_difference, "cost_center": item.cost_center, "project": item.project or self.project, @@ -912,6 +921,7 @@ class PurchaseInvoice(BuyingController): "account": self.get_company_default("exchange_gain_loss_account"), "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "credit": discrepancy_caused_by_exchange_rate_difference, "cost_center": item.cost_center, "project": item.project or self.project, @@ -958,6 +968,7 @@ class PurchaseInvoice(BuyingController): "account": stock_rbnb, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit": flt(item.item_tax_amount, item.precision("item_tax_amount")), "remarks": self.remarks or _("Accounting Entry for Stock"), "cost_center": self.cost_center, @@ -1007,6 +1018,7 @@ class PurchaseInvoice(BuyingController): "account": cost_of_goods_sold_account, "against_type": "Account", "against": item.expense_account, + "against_link": item.expense_account, "debit": stock_adjustment_amt, "remarks": self.get("remarks") or _("Stock Adjustment"), "cost_center": item.cost_center, @@ -1038,6 +1050,7 @@ class PurchaseInvoice(BuyingController): "account": tax.account_head, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, dr_or_cr: base_amount, dr_or_cr + "_in_account_currency": base_amount if account_currency == self.company_currency @@ -1088,6 +1101,7 @@ class PurchaseInvoice(BuyingController): "against_type": "Supplier", "cost_center": tax.cost_center, "against": self.supplier, + "against_link": self.supplier, "credit": applicable_amount, "remarks": self.remarks or _("Accounting Entry for Stock"), }, @@ -1107,6 +1121,7 @@ class PurchaseInvoice(BuyingController): "cost_center": tax.cost_center, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "credit": valuation_tax[tax.name], "remarks": self.remarks or _("Accounting Entry for Stock"), }, @@ -1123,6 +1138,7 @@ class PurchaseInvoice(BuyingController): "account": self.unrealized_profit_loss_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "credit": flt(self.total_taxes_and_charges), "credit_in_account_currency": flt(self.base_total_taxes_and_charges), "cost_center": self.cost_center, @@ -1145,6 +1161,7 @@ class PurchaseInvoice(BuyingController): "party": self.supplier, "against_type": "Account", "against": self.cash_bank_account, + "against_link": self.cash_bank_account, "debit": self.base_paid_amount, "debit_in_account_currency": self.base_paid_amount if self.party_account_currency == self.company_currency @@ -1167,6 +1184,7 @@ class PurchaseInvoice(BuyingController): "account": self.cash_bank_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "credit": self.base_paid_amount, "credit_in_account_currency": self.base_paid_amount if bank_account_currency == self.company_currency @@ -1192,6 +1210,7 @@ class PurchaseInvoice(BuyingController): "party": self.supplier, "against_type": "Account", "against": self.write_off_account, + "against_link": self.write_off_account, "debit": self.base_write_off_amount, "debit_in_account_currency": self.base_write_off_amount if self.party_account_currency == self.company_currency @@ -1213,6 +1232,7 @@ class PurchaseInvoice(BuyingController): "account": self.write_off_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "credit": flt(self.base_write_off_amount), "credit_in_account_currency": self.base_write_off_amount if write_off_account_currency == self.company_currency @@ -1241,6 +1261,7 @@ class PurchaseInvoice(BuyingController): "account": round_off_account, "against_type": "Supplier", "against": self.supplier, + "against_link": self.supplier, "debit_in_account_currency": self.rounding_adjustment, "debit": self.base_rounding_adjustment, "cost_center": round_off_cost_center diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index a059c32dfa..87b40c09bd 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -1042,6 +1042,7 @@ class SalesInvoice(SellingController): "due_date": self.due_date, "against_type": "Account", "against": self.against_income_account, + "against_link": self.against_income_account, "debit": base_grand_total, "debit_in_account_currency": base_grand_total if self.party_account_currency == self.company_currency @@ -1072,6 +1073,7 @@ class SalesInvoice(SellingController): "account": tax.account_head, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "credit": flt(base_amount, tax.precision("tax_amount_after_discount_amount")), "credit_in_account_currency": ( flt(base_amount, tax.precision("base_tax_amount_after_discount_amount")) @@ -1094,6 +1096,7 @@ class SalesInvoice(SellingController): "account": self.unrealized_profit_loss_account, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "debit": flt(self.total_taxes_and_charges), "debit_in_account_currency": flt(self.base_total_taxes_and_charges), "cost_center": self.cost_center, @@ -1163,6 +1166,7 @@ class SalesInvoice(SellingController): for gle in fixed_asset_gl_entries: gle["against_type"] = "Customer" gle["against"] = self.customer + gle["against_link"] = self.customer gl_entries.append(self.get_gl_dict(gle, item=item)) self.set_asset_status(asset) @@ -1185,6 +1189,7 @@ class SalesInvoice(SellingController): "account": income_account, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "credit": flt(base_amount, item.precision("base_net_amount")), "credit_in_account_currency": ( flt(base_amount, item.precision("base_net_amount")) @@ -1240,6 +1245,7 @@ class SalesInvoice(SellingController): "party": self.customer, "against_type": "Account", "against": self.loyalty_redemption_account, + "against_link": self.loyalty_redemption_account, "credit": self.loyalty_amount, "against_voucher": self.return_against if cint(self.is_return) else self.name, "against_voucher_type": self.doctype, @@ -1255,6 +1261,7 @@ class SalesInvoice(SellingController): "cost_center": self.cost_center or self.loyalty_redemption_cost_center, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "debit": self.loyalty_amount, "remark": "Loyalty Points redeemed by the customer", }, @@ -1283,6 +1290,7 @@ class SalesInvoice(SellingController): "party": self.customer, "against_type": "Account", "against": payment_mode.account, + "against_link": payment_mode.account, "credit": payment_mode.base_amount, "credit_in_account_currency": payment_mode.base_amount if self.party_account_currency == self.company_currency @@ -1305,6 +1313,7 @@ class SalesInvoice(SellingController): "account": payment_mode.account, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "debit": payment_mode.base_amount, "debit_in_account_currency": payment_mode.base_amount if payment_mode_account_currency == self.company_currency @@ -1330,6 +1339,7 @@ class SalesInvoice(SellingController): "party": self.customer, "against_type": "Account", "against": self.account_for_change_amount, + "against_link": self.account_for_change_amount, "debit": flt(self.base_change_amount), "debit_in_account_currency": flt(self.base_change_amount) if self.party_account_currency == self.company_currency @@ -1352,6 +1362,7 @@ class SalesInvoice(SellingController): "account": self.account_for_change_amount, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "credit": self.base_change_amount, "cost_center": self.cost_center, }, @@ -1379,6 +1390,7 @@ class SalesInvoice(SellingController): "party": self.customer, "against_type": "Account", "against": self.write_off_account, + "against_link": self.write_off_account, "credit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")), "credit_in_account_currency": ( flt(self.base_write_off_amount, self.precision("base_write_off_amount")) @@ -1400,6 +1412,7 @@ class SalesInvoice(SellingController): "account": self.write_off_account, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "debit": flt(self.base_write_off_amount, self.precision("base_write_off_amount")), "debit_in_account_currency": ( flt(self.base_write_off_amount, self.precision("base_write_off_amount")) @@ -1429,6 +1442,7 @@ class SalesInvoice(SellingController): "account": round_off_account, "against_type": "Customer", "against": self.customer, + "against_link": self.customer, "credit_in_account_currency": flt( self.rounding_adjustment, self.precision("rounding_adjustment") ), diff --git a/erpnext/assets/doctype/asset/asset.py b/erpnext/assets/doctype/asset/asset.py index 32518a109a..8908d8e5d0 100644 --- a/erpnext/assets/doctype/asset/asset.py +++ b/erpnext/assets/doctype/asset/asset.py @@ -610,6 +610,7 @@ class Asset(AccountsController): "account": cwip_account, "against_type": "Account", "against": fixed_asset_account, + "against_link": fixed_asset_account, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "posting_date": self.available_for_use_date, "credit": self.purchase_receipt_amount, @@ -626,6 +627,7 @@ class Asset(AccountsController): "account": fixed_asset_account, "against_type": "Account", "against": cwip_account, + "against_link": cwip_account, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "posting_date": self.available_for_use_date, "debit": self.purchase_receipt_amount, diff --git a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py index 229c16d18a..31aee3386d 100644 --- a/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py +++ b/erpnext/assets/doctype/asset_capitalization/asset_capitalization.py @@ -432,6 +432,7 @@ class AssetCapitalization(StockController): "account": account, "against_type": "Account", "against": target_account, + "against_link": target_account, "cost_center": item_row.cost_center, "project": item_row.get("project") or self.get("project"), "remarks": self.get("remarks") or "Accounting Entry for Stock", @@ -474,6 +475,7 @@ class AssetCapitalization(StockController): for gle in fixed_asset_gl_entries: gle["against_type"] = "Account" gle["against"] = target_account + gle["against_link"] = target_account gl_entries.append(self.get_gl_dict(gle, item=item)) target_against.add(gle["account"]) @@ -491,6 +493,7 @@ class AssetCapitalization(StockController): "account": item_row.expense_account, "against_type": "Account", "against": target_account, + "against_link": target_account, "cost_center": item_row.cost_center, "project": item_row.get("project") or self.get("project"), "remarks": self.get("remarks") or "Accounting Entry for Stock", @@ -510,6 +513,7 @@ class AssetCapitalization(StockController): "account": self.target_fixed_asset_account, "against_type": "Account", "against": target_account, + "against_link": target_account, "remarks": self.get("remarks") or _("Accounting Entry for Asset"), "debit": flt(self.total_value, precision) / len(target_against), "cost_center": self.get("cost_center"), @@ -530,6 +534,7 @@ class AssetCapitalization(StockController): "account": account, "against_type": "Account", "against": target_account, + "against_link": target_account, "cost_center": self.cost_center, "project": self.get("project"), "remarks": self.get("remarks") or "Accounting Entry for Stock", diff --git a/erpnext/assets/doctype/asset_repair/asset_repair.py b/erpnext/assets/doctype/asset_repair/asset_repair.py index 65d2f8ef18..0b072b2a69 100644 --- a/erpnext/assets/doctype/asset_repair/asset_repair.py +++ b/erpnext/assets/doctype/asset_repair/asset_repair.py @@ -243,6 +243,7 @@ class AssetRepair(AccountsController): "debit_in_account_currency": self.repair_cost, "against_type": "Account", "against": pi_expense_account, + "against_link": pi_expense_account, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, @@ -263,6 +264,7 @@ class AssetRepair(AccountsController): "credit_in_account_currency": self.repair_cost, "against_type": "Account", "against": fixed_asset_account, + "against_link": fixed_asset_account, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, @@ -298,6 +300,7 @@ class AssetRepair(AccountsController): "credit_in_account_currency": item.amount, "against_type": "Account", "against": fixed_asset_account, + "against_link": fixed_asset_account, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, @@ -316,6 +319,7 @@ class AssetRepair(AccountsController): "debit_in_account_currency": item.amount, "against_type": "Account", "against": item.expense_account or default_expense_account, + "against_link": item.expense_account or default_expense_account, "voucher_type": self.doctype, "voucher_no": self.name, "cost_center": self.cost_center, diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py index e984730d74..c9c248c3ea 100644 --- a/erpnext/controllers/accounts_controller.py +++ b/erpnext/controllers/accounts_controller.py @@ -1098,6 +1098,7 @@ class AccountsController(TransactionBase): "account": round_off_account, "against_type": against_type, "against": against, + "against_link": against, credit_or_debit: precision_loss, "cost_center": round_off_cost_center if self.use_company_roundoff_cost_center @@ -1479,6 +1480,7 @@ class AccountsController(TransactionBase): "account": item.discount_account, "against_type": against_type, "against": supplier_or_customer, + "against_link": supplier_or_customer, dr_or_cr: flt( discount_amount * self.get("conversion_rate"), item.precision("discount_amount") ), @@ -1498,6 +1500,7 @@ class AccountsController(TransactionBase): "account": income_or_expense_account, "against_type": against_type, "against": supplier_or_customer, + "against_link": supplier_or_customer, rev_dr_cr: flt( discount_amount * self.get("conversion_rate"), item.precision("discount_amount") ), @@ -1522,6 +1525,7 @@ class AccountsController(TransactionBase): "account": self.additional_discount_account, "against_type": against_type, "against": supplier_or_customer, + "against_link": supplier_or_customer, dr_or_cr: self.base_discount_amount, "cost_center": self.cost_center or erpnext.get_default_cost_center(self.company), }, diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 335f2b0ea6..a005c8cb8a 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -164,6 +164,7 @@ class StockController(AccountsController): "account": warehouse_account[sle.warehouse]["account"], "against_type": "Account", "against": expense_account, + "against_link": expense_account, "cost_center": item_row.cost_center, "project": item_row.project or self.get("project"), "remarks": self.get("remarks") or _("Accounting Entry for Stock"), @@ -181,6 +182,7 @@ class StockController(AccountsController): "account": expense_account, "against_type": "Account", "against": warehouse_account[sle.warehouse]["account"], + "against_link": warehouse_account[sle.warehouse]["account"], "cost_center": item_row.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "debit": -1 * flt(sle.stock_value_difference, precision), @@ -214,6 +216,7 @@ class StockController(AccountsController): "account": expense_account, "against_type": "Account", "against": warehouse_asset_account, + "against_link": warehouse_asset_account, "cost_center": item_row.cost_center, "project": item_row.project or self.get("project"), "remarks": _("Rounding gain/loss Entry for Stock Transfer"), @@ -231,6 +234,7 @@ class StockController(AccountsController): "account": warehouse_asset_account, "against_type": "Account", "against": expense_account, + "against_link": expense_account, "cost_center": item_row.cost_center, "remarks": _("Rounding gain/loss Entry for Stock Transfer"), "credit": sle_rounding_diff, @@ -847,6 +851,7 @@ class StockController(AccountsController): "credit": credit, "against_type": against_type, "against": against_account, + "against_link": against_account, "remarks": remarks, } diff --git a/erpnext/regional/united_arab_emirates/utils.py b/erpnext/regional/united_arab_emirates/utils.py index a850d5be7c..250a4b1495 100644 --- a/erpnext/regional/united_arab_emirates/utils.py +++ b/erpnext/regional/united_arab_emirates/utils.py @@ -155,6 +155,7 @@ def make_gl_entry(tax, gl_entries, doc, tax_accounts): "posting_date": doc.posting_date, "against_type": "Supplier", "against": doc.supplier, + "against_link": doc.supplier, dr_or_cr: tax.base_tax_amount_after_discount_amount, dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount if account_currency == doc.company_currency diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 1ed2f98a9d..e87658bc98 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1388,6 +1388,7 @@ class StockEntry(StockController): "account": account, "against_type": "Account", "against": d.expense_account, + "against_link": d.expense_account, "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit_in_account_currency": flt(amount["amount"]), @@ -1403,6 +1404,7 @@ class StockEntry(StockController): "account": d.expense_account, "against_type": "Account", "against": account, + "against_link": account, "cost_center": d.cost_center, "remarks": self.get("remarks") or _("Accounting Entry for Stock"), "credit": -1 From 450c2470e959f4d705afc3212546249ad406bee3 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 8 Nov 2023 14:08:57 +0530 Subject: [PATCH 26/35] refactor: set against account link for jv --- erpnext/accounts/doctype/journal_entry/journal_entry.py | 3 ++- erpnext/accounts/utils.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index 9f76d9df19..c70ad2fdaa 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -230,6 +230,7 @@ class JournalEntry(AccountsController): "account": tax_withholding_details.get("account_head"), rev_debit_or_credit: tax_withholding_details.get("tax_amount"), "against_account": parties[0], + "against_account_link": parties[0], }, ) @@ -723,7 +724,7 @@ class JournalEntry(AccountsController): elif flt(d.credit) > 0: self.accounts_credited.append(d) - if d.against_account: + if d.against_account_link: self.separate_against_account_entries = 0 break diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index e0adac412b..0edfc2ad5a 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -629,6 +629,7 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False): new_row.set("reference_name", d["against_voucher"]) new_row.against_account = cstr(jv_detail.against_account) + new_row.against_account_link = cstr(jv_detail.against_account) new_row.is_advance = cstr(jv_detail.is_advance) new_row.docstatus = 1 From 96f31847b203eb58cc92e04747700de859e8eb97 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Wed, 29 Nov 2023 16:04:36 +0530 Subject: [PATCH 27/35] fix: set cwip account for company before tests --- .../asset_value_adjustment/test_asset_value_adjustment.py | 3 +++ 1 file changed, 3 insertions(+) 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 5d49759727..2c97baece5 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 @@ -18,6 +18,9 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import make_pu class TestAssetValueAdjustment(unittest.TestCase): def setUp(self): create_asset_data() + frappe.db.set_value( + "Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC" + ) def test_current_asset_value(self): pr = make_purchase_receipt( From 9aeb3932d0f7dbf3daf5f8ba2e6e9f02082a0f54 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sat, 2 Dec 2023 19:50:16 +0530 Subject: [PATCH 28/35] fix: fetch against link value in gl report --- erpnext/accounts/general_ledger.py | 1 + erpnext/accounts/report/general_ledger/general_ledger.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index 70a8470614..6e4cc128a4 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -280,6 +280,7 @@ def check_if_in_list(gle, gl_map, dimensions=None): "project", "finance_book", "voucher_no", + "against_link", ] if dimensions: diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py index fa557a133f..08be4319e4 100644 --- a/erpnext/accounts/report/general_ledger/general_ledger.py +++ b/erpnext/accounts/report/general_ledger/general_ledger.py @@ -203,7 +203,7 @@ def get_gl_entries(filters, accounting_dimensions): voucher_type, voucher_no, {dimension_fields} cost_center, project, {transaction_currency_fields} against_voucher_type, against_voucher, account_currency, - against, is_opening, creation {select_fields} + against_link, against, is_opening, creation {select_fields} from `tabGL Entry` where company=%(company)s {conditions} {order_by_statement} @@ -391,6 +391,7 @@ def initialize_gle_map(gl_entries, filters): group_by = group_by_field(filters.get("group_by")) for gle in gl_entries: + gle.against = gle.get("against_link") or gle.get("against") gle_map.setdefault(gle.get(group_by), _dict(totals=get_totals_dict(), entries=[])) return gle_map From 6d31563920a8daeac7a782b070e6c44fd01a9f17 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 3 Dec 2023 22:33:21 +0530 Subject: [PATCH 29/35] feat: auto set against accounts for value pairs --- .../doctype/journal_entry/journal_entry.py | 43 ++++++++++++++----- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index fb7ede3e89..eb9c7c74ca 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -686,11 +686,40 @@ class JournalEntry(AccountsController): against_account = frappe.db.get_value(d.reference_type, d.reference_name, against_type.lower()) d.against_type = against_type - d.against_account = against_account d.against_account_link = against_account else: + self.get_debited_credited_accounts() + if len(self.accounts_credited) > 1 and len(self.accounts_debited) > 1: + self.auto_set_against_accounts() + return self.get_against_accounts() + def auto_set_against_accounts(self): + for i in range(0, len(self.accounts), 2): + acc = self.accounts[i] + against_acc = self.accounts[i + 1] + if acc.debit_in_account_currency > 0: + current_val = acc.debit_in_account_currency * flt(acc.exchange_rate) + against_val = against_acc.credit_in_account_currency * flt(against_acc.exchange_rate) + else: + current_val = acc.credit_in_account_currency * flt(acc.exchange_rate) + against_val = against_acc.debit_in_account_currency * flt(against_acc.exchange_rate) + + if current_val == against_val: + acc.against_type = against_acc.party_type or "Account" + against_acc.against_type = acc.party_type or "Account" + + acc.against_account_link = against_acc.party or against_acc.account + against_acc.against_account_link = acc.party or acc.account + else: + frappe.msgprint( + _( + "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed." + ).format(frappe.bold("against"), frappe.bold("Accounting Entries")), + alert=True, + ) + break + def get_against_accounts(self): self.against_accounts = [] self.split_account = {} @@ -698,14 +727,7 @@ class JournalEntry(AccountsController): if self.separate_against_account_entries: no_of_credited_acc, no_of_debited_acc = len(self.accounts_credited), len(self.accounts_debited) - if no_of_credited_acc > 1 and no_of_debited_acc > 1: - frappe.msgprint( - _( - "Unable to automatically determine {0} accounts. Set them up in the {1} table if needed." - ).format(frappe.bold("against"), frappe.bold("Accounting Entries")), - alert=True, - ) - elif no_of_credited_acc <= 1 and no_of_debited_acc <= 1: + if no_of_credited_acc <= 1 and no_of_debited_acc <= 1: self.set_against_accounts_for_single_dr_cr() self.separate_against_account_entries = 0 elif no_of_credited_acc == 1: @@ -972,8 +994,7 @@ class JournalEntry(AccountsController): gl_dict.update( { "against_type": d.against_type, - "against": d.against_account, - "against_link": d.against_account, + "against_link": d.against_account_link, } ) gl_map.append(gl_dict) From 11190aac4c8ac6897c989dd4478b05d85d08fe4c Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 3 Dec 2023 22:35:01 +0530 Subject: [PATCH 30/35] fix: unhide against type field --- .../journal_entry_account/journal_entry_account.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json index 2b423ac51d..01006bd3db 100644 --- a/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json +++ b/erpnext/accounts/doctype/journal_entry_account/journal_entry_account.json @@ -294,16 +294,14 @@ { "fieldname": "against_type", "fieldtype": "Link", - "hidden": 1, "label": "Against Type", - "options": "DocType", - "print_hide": 1 + "options": "DocType" } ], "idx": 1, "istable": 1, "links": [], - "modified": "2023-11-23 11:44:25.841187", + "modified": "2023-12-02 23:21:22.205409", "modified_by": "Administrator", "module": "Accounts", "name": "Journal Entry Account", From 262cafc430cc55ac08ac5dc5bd297e94b06ad126 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Sun, 3 Dec 2023 22:36:54 +0530 Subject: [PATCH 31/35] fix: query for against types --- .../doctype/journal_entry/journal_entry.js | 25 +++++++++++++++++++ .../doctype/journal_entry/journal_entry.py | 7 ++++++ 2 files changed, 32 insertions(+) diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js index 9684a0d9d1..e1b436106a 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.js +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js @@ -220,6 +220,16 @@ erpnext.accounts.JournalEntry = class JournalEntry extends frappe.ui.form.Contro return erpnext.journal_entry.account_query(me.frm); }); + me.frm.set_query("against_account_link", "accounts", function(doc, cdt, cdn) { + return erpnext.journal_entry.against_account_query(me.frm); + }); + + me.frm.set_query("against_type", "accounts", function(){ + return { + query: "erpnext.accounts.doctype.journal_entry.journal_entry.get_against_type", + } + }) + me.frm.set_query("party_type", "accounts", function(doc, cdt, cdn) { const row = locals[cdt][cdn]; @@ -591,6 +601,21 @@ $.extend(erpnext.journal_entry, { return { filters: filters }; }, + against_account_query: function(frm) { + if (frm.doc.against_type != "Account"){ + return { filters: {} }; + } + else { + let filters = { company: frm.doc.company, is_group: 0 }; + if(!frm.doc.multi_currency) { + $.extend(filters, { + account_currency: ['in', [frappe.get_doc(":Company", frm.doc.company).default_currency, null]] + }); + } + return { filters: filters }; + } + }, + reverse_journal_entry: function() { frappe.model.open_mapped_doc({ method: "erpnext.accounts.doctype.journal_entry.journal_entry.make_reverse_journal_entry", diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py index eb9c7c74ca..e30e780bb6 100644 --- a/erpnext/accounts/doctype/journal_entry/journal_entry.py +++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py @@ -1657,3 +1657,10 @@ def make_reverse_journal_entry(source_name, target_doc=None): ) return doclist + + +@frappe.whitelist() +def get_against_type(doctype, txt, searchfield, start, page_len, filters): + against_types = frappe.db.get_list("Party Type", pluck="name") + ["Account"] + doctype = frappe.qb.DocType("DocType") + return frappe.qb.from_(doctype).select(doctype.name).where(doctype.name.isin(against_types)).run() From a56b79cc72241f6a4540cb93b1b0f39926137cdc Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 5 Dec 2023 12:46:22 +0530 Subject: [PATCH 32/35] fix: check for split entries in stock entry test --- erpnext/stock/doctype/stock_entry/test_stock_entry.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/stock_entry/test_stock_entry.py b/erpnext/stock/doctype/stock_entry/test_stock_entry.py index b640983a09..186ea27335 100644 --- a/erpnext/stock/doctype/stock_entry/test_stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/test_stock_entry.py @@ -504,7 +504,14 @@ class TestStockEntry(FrappeTestCase): self.check_gl_entries( "Stock Entry", repack.name, - sorted([[stock_in_hand_account, 1200, 0.0], ["Cost of Goods Sold - TCP1", 0.0, 1200.0]]), + sorted( + [ + ["Cost of Goods Sold - TCP1", 0.0, 1200.0], + ["Stock Adjustment - TCP1", 0.0, 1200.0], + ["Stock Adjustment - TCP1", 1200.0, 0.0], + [stock_in_hand_account, 1200.0, 0.0], + ] + ), ) def check_stock_ledger_entries(self, voucher_type, voucher_no, expected_sle): From 24ccb3eb78f2bf88efed26e268039c38e6baf536 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 5 Dec 2023 12:47:06 +0530 Subject: [PATCH 33/35] fix: subcontracting receipt gle test --- .../test_subcontracting_receipt.py | 27 +++++++------------ 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py index f0e4e00074..22a679a1ed 100644 --- a/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py +++ b/erpnext/subcontracting/doctype/subcontracting_receipt/test_subcontracting_receipt.py @@ -365,24 +365,17 @@ class TestSubcontractingReceipt(FrappeTestCase): fg_warehouse_ac = get_inventory_account(scr.company, scr.items[0].warehouse) supplier_warehouse_ac = get_inventory_account(scr.company, scr.supplier_warehouse) expense_account = scr.items[0].expense_account + expected_values = [ + [fg_warehouse_ac, 2100.0, 0.0], # FG Amount (D) + [supplier_warehouse_ac, 0.0, 1000.0], # RM Cost (C) + [additional_costs_expense_account, 0.0, 100.0], # Additional Cost (C) + [expense_account, 0.0, 1000.0], # Service Cost (C) + ] - if fg_warehouse_ac == supplier_warehouse_ac: - expected_values = { - fg_warehouse_ac: [2100.0, 1000.0], # FG Amount (D), RM Cost (C) - expense_account: [0.0, 1000.0], # Service Cost (C) - additional_costs_expense_account: [0.0, 100.0], # Additional Cost (C) - } - else: - expected_values = { - fg_warehouse_ac: [2100.0, 0.0], # FG Amount (D) - supplier_warehouse_ac: [0.0, 1000.0], # RM Cost (C) - expense_account: [0.0, 1000.0], # Service Cost (C) - additional_costs_expense_account: [0.0, 100.0], # Additional Cost (C) - } - - for gle in gl_entries: - self.assertEqual(expected_values[gle.account][0], gle.debit) - self.assertEqual(expected_values[gle.account][1], gle.credit) + for i in range(len(expected_values)): + self.assertEqual(expected_values[i][0], gl_entries[i]["account"]) + self.assertEqual(expected_values[i][1], gl_entries[i]["debit"]) + self.assertEqual(expected_values[i][2], gl_entries[i]["credit"]) scr.reload() scr.cancel() From 47c78a5a7324cdea5fde7f4e269c933572ccaf56 Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 5 Dec 2023 12:48:25 +0530 Subject: [PATCH 34/35] fix: check for unmerged gle in purchase receipt test --- erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index 146cbff1aa..e418aadfaa 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -990,7 +990,7 @@ class TestPurchaseReceipt(FrappeTestCase): gl_entries = get_gl_entries("Purchase Receipt", pr.name) sl_entries = get_sl_entries("Purchase Receipt", pr.name) - self.assertFalse(gl_entries) + self.assertEqual(len(gl_entries), 2) expected_sle = {"Work In Progress - TCP1": -5, "Stores - TCP1": 5} From 005c5a587ff7322a6f3fb1099aa0c94e6873c7fe Mon Sep 17 00:00:00 2001 From: Gursheen Anand Date: Tue, 5 Dec 2023 13:16:54 +0530 Subject: [PATCH 35/35] chore: orderby in gle --- .../purchase_receipt/test_purchase_receipt.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py index e418aadfaa..d2740694b3 100644 --- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py @@ -4,6 +4,7 @@ import frappe from frappe.tests.utils import FrappeTestCase, change_settings from frappe.utils import add_days, cint, cstr, flt, nowtime, today +from pypika import Order from pypika import functions as fn import erpnext @@ -2235,13 +2236,13 @@ def get_sl_entries(voucher_type, voucher_no): def get_gl_entries(voucher_type, voucher_no): - return frappe.db.sql( - """select account, debit, credit, cost_center, is_cancelled - from `tabGL Entry` where voucher_type=%s and voucher_no=%s - order by account desc""", - (voucher_type, voucher_no), - as_dict=1, - ) + gle = frappe.qb.DocType("GL Entry") + return ( + frappe.qb.from_(gle) + .select(gle.account, gle.debit, gle.credit, gle.cost_center, gle.is_cancelled) + .where((gle.voucher_type == voucher_type) & (gle.voucher_no == voucher_no)) + .orderby(gle.account, gle.debit, order=Order.desc) + ).run(as_dict=True) def get_taxes(**args):